OOPS
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/ObsSpaces.h"
21 #include "oops/base/Variables.h"
24 #include "oops/interface/State.h"
25 #include "oops/util/ObjectCounter.h"
26 #include "oops/util/Printable.h"
27 
28 namespace oops {
29 
30 /// Control variable
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  * This is mostly a convenience class that is used to keep things together
38  * and reduce the number of arguments to be passed around.
39  */
40 
41 template<typename MODEL, typename OBS> class ControlVariable;
42 
43 // -----------------------------------------------------------------------------
44 template<typename MODEL, typename OBS>
45 class ControlVariable : public util::Printable,
46  private util::ObjectCounter<ControlVariable<MODEL, OBS> > {
52 
53  public:
54  static const std::string classname() {return "oops::ControlVariable";}
55 
56 /// The arguments define the number of sub-windows and the resolution
57  ControlVariable(const eckit::Configuration &, const Geometry_ &, const ObsSpaces_ &);
58 /// Constructor added for generic 1d-var under development in ufo
59  ControlVariable(const eckit::Configuration &, const State_ &, const ObsSpaces_ &);
60  explicit ControlVariable(const ControlVariable &);
62 
63 /// I/O and diagnostics
64  void read(const eckit::Configuration &);
65  void write(const eckit::Configuration &) const;
66  double norm() const;
67 
68 /// Get state control variable
69  State_ & state() {return state_;}
70  const State_ & state() const {return state_;}
71 
72 /// Get augmented model control variable
73  ModelAux_ & modVar() {return modbias_;}
74  const ModelAux_ & modVar() const {return modbias_;}
75 
76 /// Get augmented observation control variable
78  const ObsAuxCtrls_ & obsVar() const {return obsbias_;}
79 
80  private:
81  ControlVariable & operator= (const ControlVariable &); // No assignment
82  void print(std::ostream &) const;
83 
85  ModelAux_ modbias_; // not only for bias, better name?
86  ObsAuxCtrls_ obsbias_; // not only for bias, better name?
87 };
88 
89 // =============================================================================
90 
91 template<typename MODEL, typename OBS>
92 ControlVariable<MODEL, OBS>::ControlVariable(const eckit::Configuration & conf,
93  const Geometry_ & resol, const ObsSpaces_ & odb)
94  : state_(resol, eckit::LocalConfiguration(conf, "background")),
95  modbias_(resol, conf.getSubConfiguration("model aux control")),
96  obsbias_(odb, conf)
97 {
98  Log::trace() << "ControlVariable contructed" << std::endl;
99 }
100 
101 // =============================================================================
102 /// Constructor added for generic 1d-var under development in ufo
103 template<typename MODEL, typename OBS>
104 ControlVariable<MODEL, OBS>::ControlVariable(const eckit::Configuration & conf,
105  const State_ & statein, const ObsSpaces_ & odb)
106  : state_(statein),
107  modbias_(statein.geometry(), conf.getSubConfiguration("model aux control")),
108  obsbias_(odb, conf)
109 {
110  Log::trace() << "ControlVariable contructed" << std::endl;
111 }
112 
113 // -----------------------------------------------------------------------------
114 
115 template<typename MODEL, typename OBS>
117  : state_(other.state_), modbias_(other.modbias_), obsbias_(other.obsbias_)
118 {
119  Log::trace() << "ControlVariable copied" << std::endl;
120 }
121 
122 // -----------------------------------------------------------------------------
123 
124 template<typename MODEL, typename OBS>
126  Log::trace() << "ControlVariable destructed" << std::endl;
127 }
128 
129 // -----------------------------------------------------------------------------
130 
131 template<typename MODEL, typename OBS>
132 void ControlVariable<MODEL, OBS>::read(const eckit::Configuration & config) {
133  state_.read(config);
134  modbias_.read(config);
135  obsbias_.read(config);
136 }
137 
138 // -----------------------------------------------------------------------------
139 
140 template<typename MODEL, typename OBS>
141 void ControlVariable<MODEL, OBS>::write(const eckit::Configuration & config) const {
142  state_.write(config);
143  modbias_.write(config);
144  obsbias_.write(config);
145 }
146 
147 // -----------------------------------------------------------------------------
148 
149 template <typename MODEL, typename OBS>
150 void ControlVariable<MODEL, OBS>::print(std::ostream & outs) const {
151  outs << state_;
152  outs << modbias_;
153  outs << obsbias_;
154 }
155 
156 // -----------------------------------------------------------------------------
157 
158 template<typename MODEL, typename OBS>
160  double zz = state_.norm();
161  double zn = zz * zz;
162  zz = modbias_.norm();
163  zn += zz * zz;
164  zz = obsbias_.norm();
165  zn += zz * zz;
166  return sqrt(zn);
167 }
168 
169 // -----------------------------------------------------------------------------
170 } // namespace oops
171 
172 #endif // OOPS_ASSIMILATION_CONTROLVARIABLE_H_
oops::ControlVariable::read
void read(const eckit::Configuration &)
I/O and diagnostics.
Definition: ControlVariable.h:132
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::ControlVariable::ObsAuxCtrls_
ObsAuxControls< OBS > ObsAuxCtrls_
Definition: ControlVariable.h:49
oops::ControlVariable::obsVar
ObsAuxCtrls_ & obsVar()
Get augmented observation control variable.
Definition: ControlVariable.h:77
oops::ControlVariable::modVar
const ModelAux_ & modVar() const
Definition: ControlVariable.h:74
oops::ObsAuxControls
Definition: ObsAuxControls.h:26
oops::ControlVariable
Control variable.
Definition: ControlVariable.h:41
ObsSpaces.h
oops::ControlVariable::State_
State< MODEL > State_
Definition: ControlVariable.h:51
oops::ModelAuxControl
Definition: oops/interface/ModelAuxControl.h:35
oops::ControlVariable::ModelAux_
ModelAuxControl< MODEL > ModelAux_
Definition: ControlVariable.h:48
oops::ControlVariable::print
void print(std::ostream &) const
Definition: ControlVariable.h:150
oops::ControlVariable::Geometry_
Geometry< MODEL > Geometry_
Definition: ControlVariable.h:47
oops::ControlVariable::modVar
ModelAux_ & modVar()
Get augmented model control variable.
Definition: ControlVariable.h:73
oops::ControlVariable::obsbias_
ObsAuxCtrls_ obsbias_
Definition: ControlVariable.h:86
oops::ControlVariable::ObsSpaces_
ObsSpaces< OBS > ObsSpaces_
Definition: ControlVariable.h:50
ObsAuxControls.h
oops::ControlVariable::write
void write(const eckit::Configuration &) const
Definition: ControlVariable.h:141
eckit
Definition: FieldL95.h:22
oops::ControlVariable::state
const State_ & state() const
Definition: ControlVariable.h:70
oops::ControlVariable::modbias_
ModelAux_ modbias_
Definition: ControlVariable.h:85
oops::ControlVariable::operator=
ControlVariable & operator=(const ControlVariable &)
oops::ControlVariable::ControlVariable
ControlVariable(const eckit::Configuration &, const Geometry_ &, const ObsSpaces_ &)
The arguments define the number of sub-windows and the resolution.
Definition: ControlVariable.h:92
oops::ControlVariable::~ControlVariable
~ControlVariable()
Definition: ControlVariable.h:125
oops::Geometry
Geometry class used in oops; subclass of interface class above.
Definition: oops/interface/Geometry.h:189
oops::State
Encapsulates the model state.
Definition: CostJbState.h:28
State.h
oops::ObsSpaces
Definition: ObsSpaces.h:41
oops::ControlVariable::obsVar
const ObsAuxCtrls_ & obsVar() const
Definition: ControlVariable.h:78
oops::ControlVariable::classname
static const std::string classname()
Definition: ControlVariable.h:54
Variables.h
oops::ControlVariable::norm
double norm() const
Definition: ControlVariable.h:159
ModelAuxControl.h
oops::ControlVariable::state
State_ & state()
Get state control variable.
Definition: ControlVariable.h:69
Geometry.h
oops::ControlVariable::state_
State_ state_
Definition: ControlVariable.h:84