FV3 Bundle
ControlVariable.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_CONTROLVARIABLE_H_
12 #define OOPS_ASSIMILATION_CONTROLVARIABLE_H_
13 
14 #include <cmath>
15 #include <ostream>
16 #include <string>
17 
18 #include "eckit/config/Configuration.h"
20 #include "oops/base/Variables.h"
24 #include "oops/util/ObjectCounter.h"
25 #include "oops/util/Printable.h"
26 
27 namespace oops {
28 
29 /// Control variable
30 /*!
31  * The control variable acts as a container for the inputs of the variational
32  * data assimilation cost functions in physical space.
33  * That includes the states at the start the assimilation window or of each
34  * sub-window but also additional variables such as model bias, VarBC
35  * coefficients, or other control variables for algorithms that use them.
36  * This is mostly a convenience class that is used to keep things together
37  * and reduce the number of arguments to be passed around.
38  */
39 
40 template<typename MODEL> class ControlVariable;
41 
42 // -----------------------------------------------------------------------------
43 template<typename MODEL>
44 class ControlVariable : public util::Printable,
45  private util::ObjectCounter<ControlVariable<MODEL> > {
50 
51  public:
52  static const std::string classname() {return "oops::ControlVariable";}
53 
54 /// The arguments define the number of sub-windows and the resolution
55  ControlVariable(const eckit::Configuration &, const Variables &, const Geometry_ &);
56  explicit ControlVariable(const ControlVariable &);
58 
59 /// I/O and diagnostics
60  void read(const eckit::Configuration &);
61  void write(const eckit::Configuration &) const;
62  double norm() const;
63 
64 /// Get state control variable
65  State4D_ & state() {return state4d_;}
66  const State4D_ & state() const {return state4d_;}
67 
68 /// Get augmented model control variable
69  ModelAux_ & modVar() {return modbias_;}
70  const ModelAux_ & modVar() const {return modbias_;}
71 
72 /// Get augmented observation control variable
73  ObsAuxCtrl_ & obsVar() {return obsbias_;}
74  const ObsAuxCtrl_ & obsVar() const {return obsbias_;}
75 
76  private:
77  ControlVariable & operator= (const ControlVariable &); // No assignment
78  void print(std::ostream &) const;
79 
81  ModelAux_ modbias_; // not only for bias, better name?
82  ObsAuxCtrl_ obsbias_; // not only for bias, better name?
83 };
84 
85 // =============================================================================
86 
87 template<typename MODEL>
88 ControlVariable<MODEL>::ControlVariable(const eckit::Configuration & conf,
89  const Variables & vars, const Geometry_ & resol)
90  : state4d_(conf, vars, resol),
91  modbias_(resol, conf.getSubConfiguration("ModelBias")),
92  obsbias_(conf.getSubConfiguration("ObsBias"))
93 {
94  Log::trace() << "ControlVariable contructed" << std::endl;
95 }
96 
97 // -----------------------------------------------------------------------------
98 
99 template<typename MODEL>
101  : state4d_(other.state4d_), modbias_(other.modbias_), obsbias_(other.obsbias_)
102 {
103  Log::trace() << "ControlVariable copied" << std::endl;
104 }
105 
106 // -----------------------------------------------------------------------------
107 
108 template<typename MODEL>
110  Log::trace() << "ControlVariable destructed" << std::endl;
111 }
112 
113 // -----------------------------------------------------------------------------
114 
115 template<typename MODEL>
116 void ControlVariable<MODEL>::read(const eckit::Configuration & config) {
117  state4d_.read(config);
118  modbias_.read(config);
119  obsbias_.read(config);
120 }
121 
122 // -----------------------------------------------------------------------------
123 
124 template<typename MODEL>
125 void ControlVariable<MODEL>::write(const eckit::Configuration & config) const {
126  state4d_.write(config);
127  modbias_.write(config);
128  obsbias_.write(config);
129 }
130 
131 // -----------------------------------------------------------------------------
132 
133 template <typename MODEL>
134 void ControlVariable<MODEL>::print(std::ostream & outs) const {
135  outs << state4d_;
136  outs << modbias_;
137  outs << obsbias_;
138 }
139 
140 // -----------------------------------------------------------------------------
141 
142 template<typename MODEL>
144  double zz = state4d_.norm();
145  double zn = zz * zz;
146  zz = modbias_.norm();
147  zn += zz * zz;
148  zz = obsbias_.norm();
149  zn += zz * zz;
150  return sqrt(zn);
151 }
152 
153 // -----------------------------------------------------------------------------
154 } // namespace oops
155 
156 #endif // OOPS_ASSIMILATION_CONTROLVARIABLE_H_
State4D_ & state()
Get state control variable.
void write(const eckit::Configuration &) const
ControlVariable(const eckit::Configuration &, const Variables &, const Geometry_ &)
The arguments define the number of sub-windows and the resolution.
State4D< MODEL > State4D_
ModelAuxControl< MODEL > ModelAux_
static const std::string classname()
const State4D_ & state() const
Definition: conf.py:1
const ObsAuxCtrl_ & obsVar() const
ControlVariable & operator=(const ControlVariable &)
Control variable.
The namespace for the main oops code.
ModelAux_ & modVar()
Get augmented model control variable.
Four dimensional state.
Definition: CostJbState.h:29
const ModelAux_ & modVar() const
void read(const eckit::Configuration &)
I/O and diagnostics.
Geometry< MODEL > Geometry_
void print(std::ostream &) const
ObsAuxControl< MODEL > ObsAuxCtrl_
ObsAuxCtrl_ & obsVar()
Get augmented observation control variable.