FV3 Bundle
LBHessianMatrix.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_ASSIMILATION_LBHESSIANMATRIX_H_
12 #define OOPS_ASSIMILATION_LBHESSIANMATRIX_H_
13 
14 #include <boost/noncopyable.hpp>
15 
21 
22 namespace oops {
23  template<typename MODEL> class JqTermTLAD;
24 
25 /// The Hessian matrix: \f$ I + B H^T R^{-1} H \f$.
26 /*!
27  * The solvers represent matrices as objects that implement a "multiply"
28  * method. This class defines objects that apply a generalized Hessian
29  * matrix which includes all the terms of the cost function.
30  */
31 
32 template<typename MODEL> class LBHessianMatrix : private boost::noncopyable {
37 
38  public:
39  explicit LBHessianMatrix(const CostFct_ & j): j_(j) {}
40 
41  void multiply(const CtrlInc_ & dx, CtrlInc_ & dz) const {
42 // Setup TL terms of cost function
44  JqTermTLAD_ * jqtl = j_.jb().initializeTL();
45  costtl.enrollProcessor(jqtl);
46  unsigned iq = 0;
47  if (jqtl) iq = 1;
48  for (unsigned jj = 0; jj < j_.nterms(); ++jj) {
49  costtl.enrollProcessor(j_.jterm(jj).setupTL(dx));
50  }
51 
52 // Run TLM
53  CtrlInc_ mdx(dx);
54  j_.runTLM(mdx, costtl);
55 
56 // Finalize Jb+Jq
57 
58 // Get TLM outputs, multiply by covariance inverses and setup ADJ forcing terms
60  dz.zero();
61  CtrlInc_ dw(j_.jb());
62 
63 // Jb
64  CtrlInc_ tmp(j_.jb());
65  j_.jb().finalizeTL(jqtl, dx, dw);
66  tmp = dw;
67  JqTermTLAD_ * jqad = j_.jb().initializeAD(dz, tmp);
68  costad.enrollProcessor(jqad);
69 
70  j_.zeroAD(dw);
71 // Jo + Jc
72  for (unsigned jj = 0; jj < j_.nterms(); ++jj) {
73  boost::scoped_ptr<GeneralizedDepartures> ww(costtl.releaseOutputFromTL(iq+jj));
74  boost::shared_ptr<GeneralizedDepartures> zz(j_.jterm(jj).multiplyCoInv(*ww));
75  costad.enrollProcessor(j_.jterm(jj).setupAD(zz, dw));
76  }
77 
78 // Run ADJ
79  j_.runADJ(dw, costad);
80 
81 // Multiply by B
82  CtrlInc_ zz(j_.jb());
83  j_.jb().multiplyB(dw, zz);
84 
85  dz += zz;
86  j_.jb().finalizeAD(jqad);
87  }
88 
89  private:
90  CostFct_ const & j_;
91 };
92 
93 } // namespace oops
94 
95 #endif // OOPS_ASSIMILATION_LBHESSIANMATRIX_H_
const JbTotal_ & jb() const
Access .
Definition: CostFunction.h:97
GeneralizedDepartures * releaseOutputFromTL(unsigned int ii)
Get TL dual space output.
virtual void runTLM(CtrlInc_ &, PostProcessorTLAD< MODEL > &, PostProcessor< Increment_ > post=PostProcessor< Increment_ >(), const bool idModel=false) const =0
The Hessian matrix: .
Cost Function.
Definition: CostFunction.h:56
unsigned nterms() const
Definition: CostFunction.h:100
l_size ! loop over number of fields ke do j
void multiply(const CtrlInc_ &dx, CtrlInc_ &dz) const
JqTermTLAD< MODEL > JqTermTLAD_
CostFct_ const & j_
ControlIncrement< MODEL > CtrlInc_
The namespace for the main oops code.
virtual void runADJ(CtrlInc_ &, PostProcessorTLAD< MODEL > &, PostProcessor< Increment_ > post=PostProcessor< Increment_ >(), const bool idModel=false) const =0
CostFunction< MODEL > CostFct_
void finalizeAD(JqTermTLAD_ *) const
Definition: CostJbTotal.h:264
JqTermTLAD_ * initializeTL() const
Initialize before starting the TL run.
Definition: CostJbTotal.h:237
Control model post processing.
LBHessianMatrix(const CostFct_ &j)
JqTermTLAD_ * initializeAD(CtrlInc_ &, const CtrlInc_ &) const
Initialize before starting the AD run.
Definition: CostJbTotal.h:254
void enrollProcessor(PostBaseTLAD_ *pp)
void finalizeTL(JqTermTLAD_ *, const CtrlInc_ &, CtrlInc_ &) const
Definition: CostJbTotal.h:245
Increment Class: Difference between two states.
virtual PostPtrTLAD_ setupAD(boost::shared_ptr< const GeneralizedDepartures >, ControlIncrement< MODEL > &) const =0
Initialize before starting the AD run.
virtual GeneralizedDepartures * multiplyCoInv(const GeneralizedDepartures &) const =0
virtual PostPtrTLAD_ setupTL(const ControlIncrement< MODEL > &) const =0
Initialize before starting the TL run.
void zero()
Linear algebra operators.
void multiplyB(const CtrlInc_ &, CtrlInc_ &) const
Multiply by covariance matrix and its inverse.
Definition: CostJbTotal.h:271
Increment< MODEL > Increment_
const CostBase_ & jterm(const unsigned ii) const
Access terms of the cost function other than .
Definition: CostFunction.h:99
virtual void zeroAD(CtrlInc_ &) const =0