FV3 Bundle
ControlIncrement.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_CONTROLINCREMENT_H_
12 #define OOPS_ASSIMILATION_CONTROLINCREMENT_H_
13 
14 #include <ostream>
15 #include <sstream>
16 #include <string>
17 
18 #include "eckit/config/Configuration.h"
23 #include "oops/util/dot_product.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/ObjectCounter.h"
26 #include "oops/util/Printable.h"
27 
28 namespace oops {
29 
30 /// Control variable increment
31 /*!
32  * The control variable acts as a container for the inputs of the variational
33  * data assimilation cost functions in physical space.
34  * That includes the states at the start the assimilation window or of each
35  * sub-window but also additional variables such as model bias, VarBC
36  * coefficients, or other control variables for algorithms that use them.
37  * The control variable increment contains variations of the
38  * control variable.
39  */
40 
41 template<typename MODEL> class CostJbTotal;
42 
43 template<typename MODEL> class ControlIncrement;
44 
45 // -----------------------------------------------------------------------------
46 template<typename MODEL>
47 class ControlIncrement : public util::Printable,
48  private util::ObjectCounter<ControlIncrement<MODEL> > {
54 
55  public:
56  static const std::string classname() {return "oops::ControlIncrement";}
57 
58 /// Constructor, destructor
59  explicit ControlIncrement(const JbTotal_ &);
60  ControlIncrement(const ControlIncrement &, const bool copy = true);
61  ControlIncrement(const ControlIncrement &, const eckit::Configuration &);
64 
65 /// Linear algebra operators
66  void zero();
70  ControlIncrement & operator*=(const double);
71  void axpy(const double, const ControlIncrement &);
72  double dot_product_with(const ControlIncrement &) const;
73 
74 /// I/O and diagnostics
75  void read(const eckit::Configuration &);
76  void write(const eckit::Configuration &) const;
77 
78 /// Get geometry
79  Geometry_ geometry() const {return incrm4d_.geometry();}
80 
81 /// Get state control variable
82  Increment4D_ & state() {return incrm4d_;}
83  const Increment4D_ & state() const {return incrm4d_;}
84 
85 /// Get augmented model control variable
87  const ModelAuxIncr_ & modVar() const {return modbias_;}
88 
89 /// Get augmented observation control variable
90  ObsAuxIncr_ & obsVar() {return obsbias_;}
91  const ObsAuxIncr_ & obsVar() const {return obsbias_;}
92 
93  private:
94  void print(std::ostream &) const;
96  ModelAuxIncr_ modbias_; // not only for bias, better name?
97  ObsAuxIncr_ obsbias_; // not only for bias, better name?
98 };
99 
100 // =============================================================================
101 
102 template<typename MODEL>
104  : incrm4d_(jb.jbState()), modbias_(jb.resolution(), jb.jbModBias().config()),
105  obsbias_(jb.jbObsBias().config())
106 {
107  Log::trace() << "ControlIncrement:ControlIncrement created." << std::endl;
108 }
109 // -----------------------------------------------------------------------------
110 template<typename MODEL>
112  : incrm4d_(other.incrm4d_, copy), modbias_(other.modbias_, copy),
113  obsbias_(other.obsbias_, copy)
114 {
115  Log::trace() << "ControlIncrement:ControlIncrement copied." << std::endl;
116 }
117 // -----------------------------------------------------------------------------
118 template<typename MODEL>
120  const eckit::Configuration & tlConf)
121  : incrm4d_(other.incrm4d_, tlConf), modbias_(other.modbias_, tlConf),
122  obsbias_(other.obsbias_, tlConf)
123 {
124  Log::trace() << "ControlIncrement:ControlIncrement copied." << std::endl;
125 }
126 // -----------------------------------------------------------------------------
127 template<typename MODEL>
129  const ControlIncrement & other)
130  : incrm4d_(geom, other.incrm4d_), modbias_(other.modbias_, true),
131  obsbias_(other.obsbias_, true)
132 {
133  Log::trace() << "ControlIncrement:ControlIncrement copied." << std::endl;
134 }
135 // -----------------------------------------------------------------------------
136 template<typename MODEL>
138 // -----------------------------------------------------------------------------
139 template<typename MODEL> ControlIncrement<MODEL> &
141  incrm4d_ = rhs.incrm4d_;
142  modbias_ = rhs.modbias_;
143  obsbias_ = rhs.obsbias_;
144  return *this;
145 }
146 // -----------------------------------------------------------------------------
147 template<typename MODEL> ControlIncrement<MODEL> &
149  incrm4d_ += rhs.incrm4d_;
150  modbias_ += rhs.modbias_;
151  obsbias_ += rhs.obsbias_;
152  return *this;
153 }
154 // -----------------------------------------------------------------------------
155 template<typename MODEL> ControlIncrement<MODEL> &
157  incrm4d_ -= rhs.incrm4d_;
158  modbias_ -= rhs.modbias_;
159  obsbias_ -= rhs.obsbias_;
160  return *this;
161 }
162 // -----------------------------------------------------------------------------
163 template<typename MODEL>
165  incrm4d_ *= zz;
166  modbias_ *= zz;
167  obsbias_ *= zz;
168  return *this;
169 }
170 // -----------------------------------------------------------------------------
171 template<typename MODEL>
173  incrm4d_.zero();
174  modbias_.zero();
175  obsbias_.zero();
176 }
177 // -----------------------------------------------------------------------------
178 template<typename MODEL>
179 void ControlIncrement<MODEL>::axpy(const double zz, const ControlIncrement & rhs) {
180  incrm4d_.axpy(zz, rhs.incrm4d_);
181  modbias_.axpy(zz, rhs.modbias_);
182  obsbias_.axpy(zz, rhs.obsbias_);
183 }
184 // -----------------------------------------------------------------------------
185 template<typename MODEL>
186 void ControlIncrement<MODEL>::read(const eckit::Configuration & config) {
187  incrm4d_.read(config);
188  modbias_.read(config);
189  obsbias_.read(config);
190 }
191 // -----------------------------------------------------------------------------
192 template<typename MODEL>
193 void ControlIncrement<MODEL>::write(const eckit::Configuration & config) const {
194  incrm4d_.write(config);
195  modbias_.write(config);
196  obsbias_.write(config);
197 }
198 // -----------------------------------------------------------------------------
199 template <typename MODEL>
200 void ControlIncrement<MODEL>::print(std::ostream & outs) const {
201  outs << incrm4d_;
202  outs << modbias_;
203  outs << obsbias_;
204 }
205 // -----------------------------------------------------------------------------
206 template<typename MODEL>
208  double zz = 0.0;
209  zz += dot_product(incrm4d_, x2.incrm4d_);
210  zz += dot_product(modbias_, x2.modbias_);
211  zz += dot_product(obsbias_, x2.obsbias_);
212  return zz;
213 }
214 // -----------------------------------------------------------------------------
215 } // namespace oops
216 
217 #endif // OOPS_ASSIMILATION_CONTROLINCREMENT_H_
ControlIncrement & operator-=(const ControlIncrement &)
void read(const eckit::Configuration &)
I/O and diagnostics.
Geometry_ geometry() const
Get geometry.
ObsAuxIncr_ & obsVar()
Get augmented observation control variable.
subroutine, public copy(self, rhs)
ModelAuxIncr_ & modVar()
Get augmented model control variable.
integer(long), parameter true
const ObsAuxIncr_ & obsVar() const
ControlIncrement & operator*=(const double)
The namespace for the main oops code.
const ModelAuxIncr_ & modVar() const
Increment4D_ & state()
Get state control variable.
ControlIncrement & operator=(const ControlIncrement &)
CostJbTotal< MODEL > JbTotal_
Control variable increment.
State increment.
Definition: CostJbState.h:28
Increment4D< MODEL > Increment4D_
double dot_product_with(const ControlIncrement &) const
const Increment4D_ & state() const
ObsAuxIncrement< MODEL > ObsAuxIncr_
ModelAuxIncrement< MODEL > ModelAuxIncr_
Geometry_ geometry() const
Get geometry.
Definition: Increment4D.h:73
static const std::string classname()
Geometry< MODEL > Geometry_
void zero()
Linear algebra operators.
ControlIncrement(const JbTotal_ &)
Constructor, destructor.
void write(const eckit::Configuration &) const
void print(std::ostream &) const
ControlIncrement & operator+=(const ControlIncrement &)
void axpy(const double, const ControlIncrement &)