FV3 Bundle
PrimalMinimizer.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_PRIMALMINIMIZER_H_
12 #define OOPS_ASSIMILATION_PRIMALMINIMIZER_H_
13 
14 #include <string>
15 
16 #include "eckit/config/Configuration.h"
21 #include "oops/util/Logger.h"
22 
23 namespace oops {
24 
25 /// Primal Minimizer
26 /*!
27  * PrimalMinimizer is the base class for all minimizers that minimize the
28  * variational data assimilation cost function in primal (model) space.
29  */
30 
31 // -----------------------------------------------------------------------------
32 
33 template<typename MODEL> class PrimalMinimizer : public Minimizer<MODEL> {
39 
40  public:
41  explicit PrimalMinimizer(const CostFct_ & J): Minimizer_(J), J_(J) {}
43  const std::string classname() const override = 0;
44 
45  private:
46  CtrlInc_ * doMinimize(const eckit::Configuration &) override;
47  virtual double solve(CtrlInc_ &, const CtrlInc_ &,
48  const Hessian_ &, const Bmat_ &,
49  const int, const double) = 0;
50 
51  const CostFct_ & J_;
52 };
53 
54 // =============================================================================
55 
56 template<typename MODEL>
57 ControlIncrement<MODEL> * PrimalMinimizer<MODEL>::doMinimize(const eckit::Configuration & config) {
58  int ninner = config.getInt("ninner");
59  double gnreduc = config.getDouble("gradient_norm_reduction");
60 
61  bool runOnlineAdjTest = false;
62  if (config.has("onlineDiagnostics")) {
63  const eckit::LocalConfiguration onlineDiag(config, "onlineDiagnostics");
64  runOnlineAdjTest = onlineDiag.getBool("onlineAdjTest");
65  }
66 
67  Log::info() << classname() << ": max iter = " << ninner
68  << ", requested norm reduction = " << gnreduc << std::endl;
69 
70 // Define the matrices
71  Hessian_ hessian(J_, runOnlineAdjTest);
72  Bmat_ B(J_);
73 
74 // Compute RHS
75  CtrlInc_ rhs(J_.jb());
76  J_.computeGradientFG(rhs);
77  J_.jb().addGradientFG(rhs);
78  rhs *= -1.0;
79  Log::info() << classname() << " rhs" << rhs << std::endl;
80 
81 // Define minimisation starting point
82  CtrlInc_ * dx = new CtrlInc_(J_.jb());
83 
84 // Solve the linear system
85  double reduc = this->solve(*dx, rhs, hessian, B, ninner, gnreduc);
86 
87  Log::test() << classname() << ": reduction in residual norm = " << reduc << std::endl;
88  Log::info() << classname() << " output" << *dx << std::endl;
89 
90  return dx;
91 }
92 
93 // -----------------------------------------------------------------------------
94 
95 } // namespace oops
96 
97 #endif // OOPS_ASSIMILATION_PRIMALMINIMIZER_H_
ControlIncrement< MODEL > CtrlInc_
CostFunction< MODEL > CostFct_
CtrlInc_ * doMinimize(const eckit::Configuration &) override
Cost Function.
Definition: CostFunction.h:56
PrimalMinimizer(const CostFct_ &J)
program test
The namespace for the main oops code.
Primal Minimizer.
const std::string classname() const override=0
subroutine, public info(self)
Minimizer< MODEL > Minimizer_
BMatrix< MODEL > Bmat_
HessianMatrix< MODEL > Hessian_
The Hessian matrix: .
Definition: HessianMatrix.h:33
const CostFct_ & J_
The matrix.
Definition: BMatrix.h:27
virtual double solve(CtrlInc_ &, const CtrlInc_ &, const Hessian_ &, const Bmat_ &, const int, const double)=0
A Minimizer knows how to minimize a cost function.
Definition: Minimizer.h:39