OOPS
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, typename OBS> class PrimalMinimizer : public Minimizer<MODEL, OBS> {
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, typename OBS>
58 PrimalMinimizer<MODEL, OBS>::doMinimize(const eckit::Configuration & config) {
59  int ninner = config.getInt("ninner");
60  double gnreduc = config.getDouble("gradient norm reduction");
61 
62  bool runOnlineAdjTest = config.getBool("online diagnostics.online adj test", false);
63 
64  Log::info() << classname() << ": max iter = " << ninner
65  << ", requested norm reduction = " << gnreduc << std::endl;
66 
67 // Define the matrices
68  Hessian_ hessian(J_, runOnlineAdjTest);
69  Bmat_ B(J_);
70 
71 // Compute RHS
72  CtrlInc_ rhs(J_.jb());
73  J_.computeGradientFG(rhs);
74  J_.jb().addGradientFG(rhs);
75  rhs *= -1.0;
76  Log::info() << classname() << " rhs" << rhs << std::endl;
77 
78 // Define minimisation starting point
79  CtrlInc_ * dx = new CtrlInc_(J_.jb());
80 
81 // Solve the linear system
82  double reduc = this->solve(*dx, rhs, hessian, B, ninner, gnreduc);
83 
84  Log::test() << classname() << ": reduction in residual norm = " << reduc << std::endl;
85  Log::info() << classname() << " output" << *dx << std::endl;
86 
87  return dx;
88 }
89 
90 // -----------------------------------------------------------------------------
91 
92 } // namespace oops
93 
94 #endif // OOPS_ASSIMILATION_PRIMALMINIMIZER_H_
oops::PrimalMinimizer
Primal Minimizer.
Definition: PrimalMinimizer.h:33
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::PrimalMinimizer::Minimizer_
Minimizer< MODEL, OBS > Minimizer_
Definition: PrimalMinimizer.h:38
oops::Minimizer
A Minimizer knows how to minimize a cost function.
Definition: Minimizer.h:37
CostFunction.h
oops::PrimalMinimizer::CtrlInc_
ControlIncrement< MODEL, OBS > CtrlInc_
Definition: PrimalMinimizer.h:35
oops::PrimalMinimizer::classname
const std::string classname() const override=0
oops::PrimalMinimizer::PrimalMinimizer
PrimalMinimizer(const CostFct_ &J)
Definition: PrimalMinimizer.h:41
oops::PrimalMinimizer::Hessian_
HessianMatrix< MODEL, OBS > Hessian_
Definition: PrimalMinimizer.h:37
oops::ControlIncrement
Definition: ControlIncrement.h:46
oops::PrimalMinimizer::~PrimalMinimizer
~PrimalMinimizer()
Definition: PrimalMinimizer.h:42
oops::PrimalMinimizer::doMinimize
CtrlInc_ * doMinimize(const eckit::Configuration &) override
Definition: PrimalMinimizer.h:58
oops::PrimalMinimizer::Bmat_
BMatrix< MODEL, OBS > Bmat_
Definition: PrimalMinimizer.h:36
oops::PrimalMinimizer::CostFct_
CostFunction< MODEL, OBS > CostFct_
Definition: PrimalMinimizer.h:34
oops::HessianMatrix
The Hessian matrix: .
Definition: HessianMatrix.h:31
BMatrix.h
Minimizer.h
ControlIncrement.h
oops::BMatrix
The matrix.
Definition: BMatrix.h:27
oops::CostFunction
Cost Function.
Definition: CostFunction.h:53
oops::PrimalMinimizer::J_
const CostFct_ & J_
Definition: PrimalMinimizer.h:51
oops::PrimalMinimizer::solve
virtual double solve(CtrlInc_ &, const CtrlInc_ &, const Hessian_ &, const Bmat_ &, const int, const double)=0