IODA Bundle
oops/interface/ModelAuxIncrement.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_INTERFACE_MODELAUXINCREMENT_H_
12 #define OOPS_INTERFACE_MODELAUXINCREMENT_H_
13 
14 #include <iostream>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 #include "oops/base/Geometry.h"
21 #include "oops/util/Logger.h"
22 #include "oops/util/ObjectCounter.h"
23 #include "oops/util/Printable.h"
24 #include "oops/util/Serializable.h"
25 #include "oops/util/Timer.h"
26 
27 namespace eckit {
28  class Configuration;
29 }
30 
31 namespace oops {
32 
33 // -----------------------------------------------------------------------------
34 
35 template <typename MODEL>
36 class ModelAuxIncrement : public util::Printable,
37  public util::Serializable,
38  private util::ObjectCounter<ModelAuxIncrement<MODEL> > {
39  typedef typename MODEL::ModelAuxIncrement ModelAuxIncrement_;
42 
43  public:
44  static const std::string classname() {return "oops::ModelAuxIncrement";}
45 
46 /// Constructor, destructor
47  ModelAuxIncrement(const Geometry_ &, const eckit::Configuration &);
48  explicit ModelAuxIncrement(const ModelAuxIncrement &, const bool copy = true);
49  ModelAuxIncrement(const ModelAuxIncrement &, const eckit::Configuration &);
51 
52 /// Interfacing
53  const ModelAuxIncrement_ & modelauxincrement() const {return *aux_;}
55 
56 /// Linear algebra operators
57  void diff(const ModelAuxControl_ &, const ModelAuxControl_ &);
58  void zero();
62  ModelAuxIncrement & operator*=(const double &);
63  void axpy(const double &, const ModelAuxIncrement &);
64  double dot_product_with(const ModelAuxIncrement &) const;
65 
66 /// I/O and diagnostics
67  void read(const eckit::Configuration &);
68  void write(const eckit::Configuration &) const;
69  double norm() const;
70 
71 /// Serialize and deserialize
72  size_t serialSize() const override;
73  void serialize(std::vector<double> &) const override;
74  void deserialize(const std::vector<double> &, size_t &) override;
75 
76  private:
77  void print(std::ostream &) const override;
78  std::unique_ptr<ModelAuxIncrement_> aux_;
79 };
80 
81 // -----------------------------------------------------------------------------
82 
83 template <typename MODEL>
85  const ModelAuxIncrement<MODEL> & dx) {
86  Log::trace() << "operator+=(ModelAuxControl, ModelAuxIncrement) starting" << std::endl;
87  util::Timer timer("oops::ModelAuxIncrement", "operator+=ModelAuxControl");
89  Log::trace() << "operator+=(ModelAuxControl, ModelAuxIncrement) done" << std::endl;
90  return xx;
91 }
92 
93 // =============================================================================
94 
95 template<typename MODEL>
97  const eckit::Configuration & conf) : aux_()
98 {
99  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement starting" << std::endl;
100  util::Timer timer(classname(), "ModelAuxIncrement");
101  aux_.reset(new ModelAuxIncrement_(resol.geometry(), conf));
102  this->setObjectSize(aux_->serialSize()*sizeof(double));
103  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement done" << std::endl;
104 }
105 // -----------------------------------------------------------------------------
106 template<typename MODEL>
108  const bool copy) : aux_()
109 {
110  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement copy starting" << std::endl;
111  util::Timer timer(classname(), "ModelAuxIncrement");
112  aux_.reset(new ModelAuxIncrement_(*other.aux_, copy));
113  this->setObjectSize(aux_->serialSize()*sizeof(double));
114  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement copy done" << std::endl;
115 }
116 // -----------------------------------------------------------------------------
117 template<typename MODEL>
119  const eckit::Configuration & conf) : aux_()
120 {
121  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement interpolated starting" << std::endl;
122  util::Timer timer(classname(), "ModelAuxIncrement");
123  aux_.reset(new ModelAuxIncrement_(*other.aux_, conf));
124  this->setObjectSize(aux_->serialSize()*sizeof(double));
125  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement interpolated done" << std::endl;
126 }
127 // -----------------------------------------------------------------------------
128 template<typename MODEL>
130  Log::trace() << "ModelAuxIncrement<MODEL>::~ModelAuxIncrement starting" << std::endl;
131  util::Timer timer(classname(), "~ModelAuxIncrement");
132  aux_.reset();
133  Log::trace() << "ModelAuxIncrement<MODEL>::~ModelAuxIncrement done" << std::endl;
134 }
135 // -----------------------------------------------------------------------------
136 template<typename MODEL>
138  Log::trace() << "ModelAuxIncrement<MODEL>::diff starting" << std::endl;
139  util::Timer timer(classname(), "diff");
140  aux_->diff(x1.modelauxcontrol(), x2.modelauxcontrol());
141  Log::trace() << "ModelAuxIncrement<MODEL>::diff done" << std::endl;
142 }
143 // -----------------------------------------------------------------------------
144 template<typename MODEL>
146  Log::trace() << "ModelAuxIncrement<MODEL>::zero starting" << std::endl;
147  util::Timer timer(classname(), "zero");
148  aux_->zero();
149  Log::trace() << "ModelAuxIncrement<MODEL>::zero done" << std::endl;
150 }
151 // -----------------------------------------------------------------------------
152 template<typename MODEL>
154  Log::trace() << "ModelAuxIncrement<MODEL>::operator= starting" << std::endl;
155  util::Timer timer(classname(), "operator=");
156  *aux_ = *rhs.aux_;
157  Log::trace() << "ModelAuxIncrement<MODEL>::operator= done" << std::endl;
158  return *this;
159 }
160 // -----------------------------------------------------------------------------
161 template<typename MODEL>
163  Log::trace() << "ModelAuxIncrement<MODEL>::operator+= starting" << std::endl;
164  util::Timer timer(classname(), "operator+=");
165  *aux_ += *rhs.aux_;
166  Log::trace() << "ModelAuxIncrement<MODEL>::operator+= done" << std::endl;
167  return *this;
168 }
169 // -----------------------------------------------------------------------------
170 template<typename MODEL>
172  Log::trace() << "ModelAuxIncrement<MODEL>::operator-= starting" << std::endl;
173  util::Timer timer(classname(), "operator-=");
174  *aux_ -= *rhs.aux_;
175  Log::trace() << "ModelAuxIncrement<MODEL>::operator-= done" << std::endl;
176  return *this;
177 }
178 // -----------------------------------------------------------------------------
179 template<typename MODEL>
181  Log::trace() << "ModelAuxIncrement<MODEL>::operator*= starting" << std::endl;
182  util::Timer timer(classname(), "operator*=");
183  *aux_ *= zz;
184  Log::trace() << "ModelAuxIncrement<MODEL>::operator*= done" << std::endl;
185  return *this;
186 }
187 // -----------------------------------------------------------------------------
188 template<typename MODEL>
189 void ModelAuxIncrement<MODEL>::axpy(const double & zz, const ModelAuxIncrement & dx) {
190  Log::trace() << "ModelAuxIncrement<MODEL>::axpy starting" << std::endl;
191  util::Timer timer(classname(), "axpy");
192  aux_->axpy(zz, *dx.aux_);
193  Log::trace() << "ModelAuxIncrement<MODEL>::axpy done" << std::endl;
194 }
195 // -----------------------------------------------------------------------------
196 template<typename MODEL>
198  Log::trace() << "ModelAuxIncrement<MODEL>::dot_product_with starting" << std::endl;
199  util::Timer timer(classname(), "dot_product_with");
200  double zz = aux_->dot_product_with(*dx.aux_);
201  Log::trace() << "ModelAuxIncrement<MODEL>::dot_product_with done" << std::endl;
202  return zz;
203 }
204 // -----------------------------------------------------------------------------
205 template<typename MODEL>
206 void ModelAuxIncrement<MODEL>::read(const eckit::Configuration & conf) {
207  Log::trace() << "ModelAuxIncrement<MODEL>::read starting" << std::endl;
208  util::Timer timer(classname(), "read");
209  aux_->read(conf);
210  Log::trace() << "ModelAuxIncrement<MODEL>::read done" << std::endl;
211 }
212 // -----------------------------------------------------------------------------
213 template<typename MODEL>
214 void ModelAuxIncrement<MODEL>::write(const eckit::Configuration & conf) const {
215  Log::trace() << "ModelAuxIncrement<MODEL>::write starting" << std::endl;
216  util::Timer timer(classname(), "write");
217  aux_->write(conf);
218  Log::trace() << "ModelAuxIncrement<MODEL>::write done" << std::endl;
219 }
220 // -----------------------------------------------------------------------------
221 template<typename MODEL>
223  Log::trace() << "ModelAuxIncrement<MODEL>::norm starting" << std::endl;
224  util::Timer timer(classname(), "norm");
225  double zz = aux_->norm();
226  Log::trace() << "ModelAuxIncrement<MODEL>::norm done" << std::endl;
227  return zz;
228 }
229 // -----------------------------------------------------------------------------
230 template<typename MODEL>
232  Log::trace() << "ModelAuxIncrement<MODEL>::serialSize" << std::endl;
233  util::Timer timer(classname(), "serialSize");
234  return aux_->serialSize();
235 }
236 // -----------------------------------------------------------------------------
237 template<typename MODEL>
238 void ModelAuxIncrement<MODEL>::serialize(std::vector<double> & vect) const {
239  Log::trace() << "ModelAuxIncrement<MODEL>::serialize starting" << std::endl;
240  util::Timer timer(classname(), "serialize");
241  aux_->serialize(vect);
242  Log::trace() << "ModelAuxIncrement<MODEL>::serialize done" << std::endl;
243 }
244 // -----------------------------------------------------------------------------
245 template<typename MODEL>
246 void ModelAuxIncrement<MODEL>::deserialize(const std::vector<double> & vect, size_t & current) {
247  Log::trace() << "ModelAuxIncrement<MODEL>::deserialize starting" << std::endl;
248  util::Timer timer(classname(), "deserialize");
249  aux_->deserialize(vect, current);
250  Log::trace() << "ModelAuxIncrement<MODEL>::deserialize done" << std::endl;
251 }
252 // -----------------------------------------------------------------------------
253 template<typename MODEL>
254 void ModelAuxIncrement<MODEL>::print(std::ostream & os) const {
255  Log::trace() << "ModelAuxIncrement<MODEL>::print starting" << std::endl;
256  util::Timer timer(classname(), "print");
257  os << *aux_;
258  Log::trace() << "ModelAuxIncrement<MODEL>::print done" << std::endl;
259 }
260 // -----------------------------------------------------------------------------
261 
262 } // namespace oops
263 
264 #endif // OOPS_INTERFACE_MODELAUXINCREMENT_H_
Geometry class used in oops; subclass of interface class interface::Geometry.
const ModelAuxControl_ & modelauxcontrol() const
Interfacing.
void deserialize(const std::vector< double > &, size_t &) override
ModelAuxIncrement(const Geometry_ &, const eckit::Configuration &)
Constructor, destructor.
ModelAuxIncrement & operator+=(const ModelAuxIncrement &)
ModelAuxIncrement & operator=(const ModelAuxIncrement &)
MODEL::ModelAuxIncrement ModelAuxIncrement_
void serialize(std::vector< double > &) const override
const ModelAuxIncrement_ & modelauxincrement() const
Interfacing.
size_t serialSize() const override
Serialize and deserialize.
void read(const eckit::Configuration &)
I/O and diagnostics.
void write(const eckit::Configuration &) const
std::unique_ptr< ModelAuxIncrement_ > aux_
double dot_product_with(const ModelAuxIncrement &) const
void diff(const ModelAuxControl_ &, const ModelAuxControl_ &)
Linear algebra operators.
static const std::string classname()
ModelAuxControl< MODEL > ModelAuxControl_
void print(std::ostream &) const override
ModelAuxIncrement & operator-=(const ModelAuxIncrement &)
void axpy(const double &, const ModelAuxIncrement &)
ModelAuxIncrement & operator*=(const double &)
const Geometry_ & geometry() const
IODA_DL void copy(const ObjectSelection &from, ObjectSelection &to, const ScaleMapping &scale_map)
Generic data copying function.
Definition: Copying.cpp:63
The namespace for the main oops code.
State< MODEL > & operator+=(State< MODEL > &xx, const Increment< MODEL > &dx)
Add on dx incrment to model state xx.