FV3 Bundle
LBMinimizer.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_LBMINIMIZER_H_
12 #define OOPS_ASSIMILATION_LBMINIMIZER_H_
13 
14 #include <string>
15 
16 #include <boost/scoped_ptr.hpp>
17 
18 #include "eckit/config/Configuration.h"
24 #include "oops/util/Logger.h"
25 
26 namespace oops {
27 
28 /// LB (Left B-preconditioned) Minimizers
29 /*!
30  * LBMinimizer is the base class for all minimizers that use \f$ B\f$ to
31  * precondition the variational minimisation problem
32  *
33  * NOTE: not suitable for weak constraint state formulation
34  */
35 
36 // -----------------------------------------------------------------------------
37 
38 template<typename MODEL> class LBMinimizer : public Minimizer<MODEL> {
44 
45  public:
46  explicit LBMinimizer(const CostFct_ & J): Minimizer_(J), J_(J), gradJb_(0) {}
48  const std::string classname() const override = 0;
49 
50  private:
51  CtrlInc_ * doMinimize(const eckit::Configuration &) override;
52  virtual void solve(CtrlInc_ &, CtrlInc_ &,
53  const LBHessianMatrix_ &, const int, const double) = 0;
54 
55  const CostFct_ & J_;
56  boost::scoped_ptr<CtrlInc_> gradJb_;
57 };
58 
59 // =============================================================================
60 
61 template<typename MODEL>
62 ControlIncrement<MODEL> * LBMinimizer<MODEL>::doMinimize(const eckit::Configuration & config) {
63  int ninner = config.getInt("ninner");
64  double gnreduc = config.getDouble("gradient_norm_reduction");
65 
66  if (gradJb_ == 0) {
67  gradJb_.reset(new CtrlInc_(J_.jb()));
68  } else {
69  gradJb_.reset(new CtrlInc_(J_.jb().resolution(), *gradJb_));
70  }
71 
72  Log::info() << std::endl;
73  Log::info() << classname() << ": max iter = " << ninner
74  << ", requested norm reduction = " << gnreduc << std::endl;
75 
76 // Define the matrices
77  const Bmat_ B(J_);
79 
80 // Compute RHS (sum dx^{b}_{i} + ) B H^T R^{-1} d
81  CtrlInc_ rhs(J_.jb());
82  CtrlInc_ brhs(J_.jb());
83  J_.computeGradientFG(rhs);
84  J_.jb().multiplyB(rhs, brhs);
85  J_.jb().addGradientFG(brhs, *gradJb_);
86 
87  brhs *= -1.0;
88  Log::info() << classname() << " rhs" << brhs << std::endl;
89 
90 // Define minimisation starting point
91  CtrlInc_ * dx = new CtrlInc_(J_.jb());
92 
93 // Solve the linear system
94  this->solve(*dx, brhs, LBHessianMatrix, ninner, gnreduc);
95 
96  Log::info() << classname() << " output increment:" << *dx << std::endl;
97 
98 // Update gradient Jb
99  *gradJb_ += *dx;
100 
101  return dx;
102 }
103 
104 // -----------------------------------------------------------------------------
105 
106 } // namespace oops
107 
108 #endif // OOPS_ASSIMILATION_LBMINIMIZER_H_
LBHessianMatrix< MODEL > LBHessianMatrix_
Definition: LBMinimizer.h:42
const std::string classname() const override=0
LB (Left B-preconditioned) Minimizers.
Definition: LBMinimizer.h:38
LBMinimizer(const CostFct_ &J)
Definition: LBMinimizer.h:46
The Hessian matrix: .
Cost Function.
Definition: CostFunction.h:56
BMatrix< MODEL > Bmat_
Definition: LBMinimizer.h:41
CtrlInc_ * doMinimize(const eckit::Configuration &) override
Definition: LBMinimizer.h:62
The namespace for the main oops code.
boost::scoped_ptr< CtrlInc_ > gradJb_
Definition: LBMinimizer.h:56
subroutine, public info(self)
ControlIncrement< MODEL > CtrlInc_
Definition: LBMinimizer.h:40
The matrix.
Definition: BMatrix.h:27
Minimizer< MODEL > Minimizer_
Definition: LBMinimizer.h:43
const CostFct_ & J_
Definition: LBMinimizer.h:55
virtual void solve(CtrlInc_ &, CtrlInc_ &, const LBHessianMatrix_ &, const int, const double)=0
A Minimizer knows how to minimize a cost function.
Definition: Minimizer.h:39
CostFunction< MODEL > CostFct_
Definition: LBMinimizer.h:39