FV3 Bundle
oops/interface/Increment.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_INCREMENT_H_
12 #define OOPS_INTERFACE_INCREMENT_H_
13 
14 #include <string>
15 
17 #include "oops/base/Variables.h"
20 #include "oops/interface/GeoVaLs.h"
23 #include "oops/interface/State.h"
24 #include "oops/util/DateTime.h"
25 #include "oops/util/Duration.h"
26 #include "oops/util/ObjectCounter.h"
27 #include "oops/util/Printable.h"
28 #include "oops/util/Timer.h"
29 
30 namespace oops {
31 
32 /// Increment Class: Difference between two states
33 /*!
34  * Some fields that are present in a State may not be present in an Increment.
35  */
36 
37 // -----------------------------------------------------------------------------
38 
39 template <typename MODEL>
41  public util::Printable,
42  private util::ObjectCounter<Increment<MODEL> > {
43  typedef typename MODEL::Increment Increment_;
49 
50  public:
51  static const std::string classname() {return "oops::Increment";}
52 
53 /// Constructor, destructor
54  Increment(const Geometry_ &, const Variables &, const util::DateTime &);
55  Increment(const Geometry_ &, const Increment &);
56  Increment(const Increment &, const bool copy = true);
57  virtual ~Increment();
58 
59 /// Interfacing
61  const Increment_ & increment() const {return *increment_;}
62 
63 /// Get increment values at observation locations
64  void getValuesTL(const Locations_ &, const Variables &,
65  GeoVaLs_ &, const InterpolatorTraj_ &) const;
66  void getValuesAD(const Locations_ &, const Variables &,
67  const GeoVaLs_ &, const InterpolatorTraj_ &);
68 
69 /// Interactions with State
70  void diff(const State_ &, const State_ &);
71 
72 /// Time
73  const util::DateTime validTime() const {return increment_->validTime();}
74  void updateTime(const util::Duration & dt) {increment_->updateTime(dt);}
75 
76 /// Linear algebra operators
77  void zero();
78  void zero(const util::DateTime &);
79  void dirac(const eckit::Configuration &);
80  Increment & operator =(const Increment &);
81  Increment & operator+=(const Increment &);
82  Increment & operator-=(const Increment &);
83  Increment & operator*=(const double &);
84  void axpy(const double &, const Increment &, const bool check = true);
85  double dot_product_with(const Increment &) const;
86  void schur_product_with(const Increment &);
87  void random();
88  void accumul(const double &, const State_ &);
89 
90 /// I/O and diagnostics
91  void read(const eckit::Configuration &);
92  void write(const eckit::Configuration &) const;
93  double norm() const;
94 
95 /// Get geometry
96  Geometry_ geometry() const;
97 
98 /// Unstructured grid
99  void ug_coord(UnstructuredGrid &, const int &) const;
100  void field_to_ug(UnstructuredGrid &, const int &) const;
101  void field_from_ug(const UnstructuredGrid &);
102 
103  private:
104  void print(std::ostream &) const;
105  boost::scoped_ptr<Increment_> increment_;
106 };
107 
108 // -----------------------------------------------------------------------------
109 
110 template <typename MODEL>
112  Log::trace() << "operator+=(State, Increment) starting" << std::endl;
113  util::Timer timer("oops::Increment", "operator+=(State, Increment)");
114  xx.state() += dx.increment();
115  Log::trace() << "operator+=(State, Increment) done" << std::endl;
116  return xx;
117 }
118 
119 // =============================================================================
120 /// Constructor, destructor
121 // -----------------------------------------------------------------------------
122 
123 template<typename MODEL>
125  const util::DateTime & time) : increment_()
126 {
127  Log::trace() << "Increment<MODEL>::Increment starting" << std::endl;
128  util::Timer timer(classname(), "Increment");
129  increment_.reset(new Increment_(resol.geometry(), vars, time));
130  Log::trace() << "Increment<MODEL>::Increment done" << std::endl;
131 }
132 
133 // -----------------------------------------------------------------------------
134 
135 template<typename MODEL>
136 Increment<MODEL>::Increment(const Geometry_ & resol, const Increment & other)
137  : increment_()
138 {
139  Log::trace() << "Increment<MODEL>::Increment starting" << std::endl;
140  util::Timer timer(classname(), "Increment");
141  increment_.reset(new Increment_(resol.geometry(), *other.increment_));
142  Log::trace() << "Increment<MODEL>::Increment done" << std::endl;
143 }
144 
145 // -----------------------------------------------------------------------------
146 
147 template<typename MODEL>
148 Increment<MODEL>::Increment(const Increment & other, const bool copy) : increment_()
149 {
150  Log::trace() << "Increment<MODEL>::Increment copy starting" << std::endl;
151  util::Timer timer(classname(), "Increment");
152  increment_.reset(new Increment_(*other.increment_, copy));
153  Log::trace() << "Increment<MODEL>::Increment copy done" << std::endl;
154 }
155 
156 // -----------------------------------------------------------------------------
157 
158 template<typename MODEL>
160  Log::trace() << "Increment<MODEL>::~Increment starting" << std::endl;
161  util::Timer timer(classname(), "~Increment");
162  increment_.reset();
163  Log::trace() << "Increment<MODEL>::~Increment done" << std::endl;
164 }
165 
166 // -----------------------------------------------------------------------------
167 
168 template<typename MODEL>
170  GeoVaLs_ & gvals, const InterpolatorTraj_ & traj) const {
171  Log::trace() << "Increment<MODEL>::getValuesTL starting" << std::endl;
172  util::Timer timer(classname(), "getValuesTL");
173  increment_->getValuesTL(loc.locations(), vars, gvals.geovals(), traj.interpolatortraj());
174  Log::trace() << "Increment<MODEL>::getValuesTL done" << std::endl;
175 }
176 
177 // -----------------------------------------------------------------------------
178 
179 template<typename MODEL>
181  const GeoVaLs_ & gvals, const InterpolatorTraj_ & traj) {
182  Log::trace() << "Increment<MODEL>::getValuesAD starting" << std::endl;
183  util::Timer timer(classname(), "getValuesAD");
184  increment_->getValuesAD(loc.locations(), vars, gvals.geovals(), traj.interpolatortraj());
185  Log::trace() << "Increment<MODEL>::getValuesAD done" << std::endl;
186 }
187 
188 // -----------------------------------------------------------------------------
189 
190 template<typename MODEL>
191 void Increment<MODEL>::diff(const State_ & x1, const State_ & x2) {
192  Log::trace() << "Increment<MODEL>::diff starting" << std::endl;
193  util::Timer timer(classname(), "diff");
194  increment_->diff(x1.state(), x2.state());
195  Log::trace() << "Increment<MODEL>::diff done" << std::endl;
196 }
197 
198 // -----------------------------------------------------------------------------
199 
200 template<typename MODEL>
202  Log::trace() << "Increment<MODEL>::zero starting" << std::endl;
203  util::Timer timer(classname(), "zero");
204  increment_->zero();
205  Log::trace() << "Increment<MODEL>::zero done" << std::endl;
206 }
207 
208 // -----------------------------------------------------------------------------
209 
210 template<typename MODEL>
211 void Increment<MODEL>::zero(const util::DateTime & tt) {
212  Log::trace() << "Increment<MODEL>::zero starting" << std::endl;
213  util::Timer timer(classname(), "zero");
214  increment_->zero(tt);
215  Log::trace() << "Increment<MODEL>::zero done" << std::endl;
216 }
217 
218 // -----------------------------------------------------------------------------
219 
220 template<typename MODEL>
221 void Increment<MODEL>::dirac(const eckit::Configuration & config) {
222  Log::trace() << "Increment<MODEL>::dirac starting" << std::endl;
223  util::Timer timer(classname(), "dirac");
224  increment_->dirac(config);
225  Log::trace() << "Increment<MODEL>::dirac done" << std::endl;
226 }
227 
228 // -----------------------------------------------------------------------------
229 
230 template<typename MODEL>
232  Log::trace() << "Increment<MODEL>::operator= starting" << std::endl;
233  util::Timer timer(classname(), "operator=");
234  *increment_ = *rhs.increment_;
235  Log::trace() << "Increment<MODEL>::operator= done" << std::endl;
236  return *this;
237 }
238 
239 // -----------------------------------------------------------------------------
240 
241 template<typename MODEL>
243  Log::trace() << "Increment<MODEL>::operator+= starting" << std::endl;
244  util::Timer timer(classname(), "operator+=");
245  *increment_ += *rhs.increment_;
246  Log::trace() << "Increment<MODEL>::operator+= done" << std::endl;
247  return *this;
248 }
249 
250 // -----------------------------------------------------------------------------
251 
252 template<typename MODEL>
254  Log::trace() << "Increment<MODEL>::operator-= starting" << std::endl;
255  util::Timer timer(classname(), "operator-=");
256  *increment_ -= *rhs.increment_;
257  Log::trace() << "Increment<MODEL>::operator-= done" << std::endl;
258  return *this;
259 }
260 
261 // -----------------------------------------------------------------------------
262 
263 template<typename MODEL>
265  Log::trace() << "Increment<MODEL>::operator*= starting" << std::endl;
266  util::Timer timer(classname(), "operator*=");
267  *increment_ *= zz;
268  Log::trace() << "Increment<MODEL>::operator*= done" << std::endl;
269  return *this;
270 }
271 
272 // -----------------------------------------------------------------------------
273 
274 template<typename MODEL>
275 void Increment<MODEL>::axpy(const double & zz, const Increment & dx, const bool check) {
276  Log::trace() << "Increment<MODEL>::axpy starting" << std::endl;
277  util::Timer timer(classname(), "axpy");
278  increment_->axpy(zz, *dx.increment_, check);
279  Log::trace() << "Increment<MODEL>::axpy done" << std::endl;
280 }
281 
282 // -----------------------------------------------------------------------------
283 
284 template<typename MODEL>
286  Log::trace() << "Increment<MODEL>::dot_product_with starting" << std::endl;
287  util::Timer timer(classname(), "dot_product_with");
288  double zz = increment_->dot_product_with(*dx.increment_);
289  Log::trace() << "Increment<MODEL>::dot_product_with done" << std::endl;
290  return zz;
291 }
292 
293 // -----------------------------------------------------------------------------
294 
295 template<typename MODEL>
297  Log::trace() << "Increment<MODEL>::schur_product_with starting" << std::endl;
298  util::Timer timer(classname(), "schur_product_with");
299  increment_->schur_product_with(*dx.increment_);
300  Log::trace() << "Increment<MODEL>::schur_product_with done" << std::endl;
301 }
302 
303 // -----------------------------------------------------------------------------
304 
305 template<typename MODEL>
307  Log::trace() << "Increment<MODEL>::random starting" << std::endl;
308  util::Timer timer(classname(), "random");
309  increment_->random();
310  Log::trace() << "Increment<MODEL>::random done" << std::endl;
311 }
312 
313 // -----------------------------------------------------------------------------
314 
315 template<typename MODEL>
316 void Increment<MODEL>::accumul(const double & zz, const State_ & xx) {
317  Log::trace() << "Increment<MODEL>::accumul starting" << std::endl;
318  util::Timer timer(classname(), "accumul");
319  increment_->accumul(zz, xx.state());
320  Log::trace() << "Increment<MODEL>::accumul done" << std::endl;
321 }
322 
323 // -----------------------------------------------------------------------------
324 
325 template<typename MODEL>
326 void Increment<MODEL>::read(const eckit::Configuration & conf) {
327  Log::trace() << "Increment<MODEL>::read starting" << std::endl;
328  util::Timer timer(classname(), "read");
329  increment_->read(conf);
330  Log::trace() << "Increment<MODEL>::read done" << std::endl;
331 }
332 
333 // -----------------------------------------------------------------------------
334 
335 template<typename MODEL>
336 void Increment<MODEL>::write(const eckit::Configuration & conf) const {
337  Log::trace() << "Increment<MODEL>::write starting" << std::endl;
338  util::Timer timer(classname(), "write");
339  increment_->write(conf);
340  Log::trace() << "Increment<MODEL>::write done" << std::endl;
341 }
342 
343 // -----------------------------------------------------------------------------
344 
345 template<typename MODEL>
346 double Increment<MODEL>::norm() const {
347  Log::trace() << "Increment<MODEL>::norm starting" << std::endl;
348  util::Timer timer(classname(), "norm");
349  double zz = increment_->norm();
350  Log::trace() << "Increment<MODEL>::norm done" << std::endl;
351  return zz;
352 }
353 
354 // -----------------------------------------------------------------------------
355 
356 template<typename MODEL>
358  Log::trace() << "Increment<MODEL>::geometry starting" << std::endl;
359  util::Timer timer(classname(), "geometry");
360  Geometry<MODEL> geom(increment_->geometry());
361  Log::trace() << "Increment<MODEL>::geometry done" << std::endl;
362  return geom;
363 }
364 
365 // -----------------------------------------------------------------------------
366 
367 template<typename MODEL>
368 void Increment<MODEL>::ug_coord(UnstructuredGrid & ug, const int & colocated) const {
369  Log::trace() << "Increment<MODEL>::ug_coord starting" << std::endl;
370  util::Timer timer(classname(), "ug_coord");
371  increment_->ug_coord(ug, colocated);
372  Log::trace() << "Increment<MODEL>::ug_coord done" << std::endl;
373 }
374 
375 // -----------------------------------------------------------------------------
376 
377 template<typename MODEL>
378 void Increment<MODEL>::field_to_ug(UnstructuredGrid & ug, const int & colocated) const {
379  Log::trace() << "Increment<MODEL>::field_to_ug starting" << std::endl;
380  util::Timer timer(classname(), "field_to_ug");
381  increment_->field_to_ug(ug, colocated);
382  Log::trace() << "Increment<MODEL>::field_to_ug done" << std::endl;
383 }
384 
385 // -----------------------------------------------------------------------------
386 
387 template<typename MODEL>
389  Log::trace() << "Increment<MODEL>::field_from_ug starting" << std::endl;
390  util::Timer timer(classname(), "field_from_ug");
391  increment_->field_from_ug(ug);
392  Log::trace() << "Increment<MODEL>::field_from_ug done" << std::endl;
393 }
394 
395 // -----------------------------------------------------------------------------
396 
397 template<typename MODEL>
398 void Increment<MODEL>::print(std::ostream & os) const {
399  Log::trace() << "Increment<MODEL>::print starting" << std::endl;
400  util::Timer timer(classname(), "print");
401  os << *increment_;
402  Log::trace() << "Increment<MODEL>::print done" << std::endl;
403 }
404 
405 // -----------------------------------------------------------------------------
406 
407 } // namespace oops
408 
409 #endif // OOPS_INTERFACE_INCREMENT_H_
const GeoVaLs_ & geovals() const
Interfacing.
void ug_coord(UnstructuredGrid &, const int &) const
Unstructured grid.
const Increment_ & increment() const
Geometry_ geometry() const
Get geometry.
void getValuesAD(const Locations_ &, const Variables &, const GeoVaLs_ &, const InterpolatorTraj_ &)
subroutine, public copy(self, rhs)
Definition: conf.py:1
void write(const eckit::Configuration &) const
const util::DateTime validTime() const
Time.
Increment & operator-=(const Increment &)
void zero()
Linear algebra operators.
MODEL::Increment Increment_
Encapsulates the model state.
State_ & state()
Interfacing.
const Locations_ & locations() const
Interfacing.
State< MODEL > & operator+=(State< MODEL > &xx, const Increment< MODEL > &dx)
static const std::string classname()
void updateTime(const util::Duration &dt)
Geometry< MODEL > Geometry_
The namespace for the main oops code.
InterpolatorTraj< MODEL > InterpolatorTraj_
Locations< MODEL > Locations_
void field_to_ug(UnstructuredGrid &, const int &) const
Increment(const Geometry_ &, const Variables &, const util::DateTime &)
Constructor, destructor.
boost::scoped_ptr< Increment_ > increment_
Increment_ & increment()
Interfacing.
double dot_product_with(const Increment &) const
Increment & operator+=(const Increment &)
void axpy(const double &, const Increment &, const bool check=true)
const Geometry_ & geometry() const
Interfacing.
Increment & operator=(const Increment &)
InterpolatorTraj_ & interpolatortraj()
Interfacing.
void accumul(const double &, const State_ &)
Increment & operator*=(const double &)
Increment Class: Difference between two states.
void diff(const State_ &, const State_ &)
Interactions with State.
void read(const eckit::Configuration &)
I/O and diagnostics.
void getValuesTL(const Locations_ &, const Variables &, GeoVaLs_ &, const InterpolatorTraj_ &) const
Get increment values at observation locations.
void print(std::ostream &) const
Abstract base class for quantities.
void dirac(const eckit::Configuration &)
GeoVaLs< MODEL > GeoVaLs_
void field_from_ug(const UnstructuredGrid &)
void schur_product_with(const Increment &)