FV3 Bundle
oops/src/oops/interface/GeoVaLs.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_GEOVALS_H_
12 #define OOPS_INTERFACE_GEOVALS_H_
13 
14 #include <string>
15 
16 #include <boost/noncopyable.hpp>
17 #include <boost/scoped_ptr.hpp>
18 
19 #include "eckit/config/Configuration.h"
20 #include "oops/base/Variables.h"
22 #include "oops/util/ObjectCounter.h"
23 #include "oops/util/Printable.h"
24 #include "oops/util/Timer.h"
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 template <typename MODEL>
30 class GeoVaLs : public util::Printable,
31  private util::ObjectCounter<GeoVaLs<MODEL> > {
32  typedef typename MODEL::GeoVaLs GeoVaLs_;
34 
35  public:
36  static const std::string classname() {return "oops::GeoVaLs";}
37 
38  GeoVaLs(const Locations_ &, const Variables &);
39  GeoVaLs(const eckit::Configuration &, const Variables &);
40  GeoVaLs(const GeoVaLs &);
41 
42  ~GeoVaLs();
43 
44 /// Interfacing
45  const GeoVaLs_ & geovals() const {return *gvals_;}
46  GeoVaLs_ & geovals() {return *gvals_;}
47 
48 /// Linear algebra and utilities, mostly for writing tests
49  void abs();
50  void zero();
51  void random();
52  double norm() const;
53  GeoVaLs & operator=(const GeoVaLs &);
54  GeoVaLs & operator*=(const double &);
55  GeoVaLs & operator+=(const GeoVaLs &);
56  GeoVaLs & operator-=(const GeoVaLs &);
57  GeoVaLs & operator/=(const GeoVaLs &);
58  double dot_product_with(const GeoVaLs &) const;
59  void read(const eckit::Configuration &);
60  void analytic_init(const Locations_ &, const eckit::Configuration &);
61  void write(const eckit::Configuration &) const;
62 
63  private:
64  void print(std::ostream &) const;
65  boost::scoped_ptr<GeoVaLs_> gvals_;
66 };
67 
68 // -----------------------------------------------------------------------------
69 
70 template <typename MODEL>
71 GeoVaLs<MODEL>::GeoVaLs(const Locations_ & locs, const Variables & vars) : gvals_() {
72  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs starting" << std::endl;
73  util::Timer timer(classname(), "GeoVaLs");
74  gvals_.reset(new GeoVaLs_(locs.locations(), vars));
75  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs done" << std::endl;
76 }
77 
78 // -----------------------------------------------------------------------------
79 
80 template <typename MODEL>
81  GeoVaLs<MODEL>::GeoVaLs(const eckit::Configuration & conf, const Variables & vars)
82  : gvals_() {
83  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs read starting" << std::endl;
84  util::Timer timer(classname(), "GeoVaLs");
85  gvals_.reset(new GeoVaLs_(conf, vars));
86  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs read done" << std::endl;
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 template <typename MODEL>
92 GeoVaLs<MODEL>::GeoVaLs(const GeoVaLs & other): gvals_() {
93  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs starting" << std::endl;
94  util::Timer timer(classname(), "GeoVaLs");
95  gvals_.reset(new GeoVaLs_(*other.gvals_));
96  Log::trace() << "ObsVector<MODEL>::GeoVaLs done" << std::endl;
97 }
98 
99 // -----------------------------------------------------------------------------
100 
101 template <typename MODEL>
103  Log::trace() << "GeoVaLs<MODEL>::~GeoVaLs starting" << std::endl;
104  util::Timer timer(classname(), "~GeoVaLs");
105  gvals_.reset();
106  Log::trace() << "GeoVaLs<MODEL>::~GeoVaLs done" << std::endl;
107 }
108 
109 // -----------------------------------------------------------------------------
110 
111 template <typename MODEL>
112 double GeoVaLs<MODEL>::dot_product_with(const GeoVaLs & other) const {
113  Log::trace() << "GeoVaLs<MODEL>::dot_product_with starting" << std::endl;
114  util::Timer timer(classname(), "dot_product_with");
115  double zz = gvals_->dot_product_with(*other.gvals_);
116  Log::trace() << "GeoVaLs<MODEL>::dot_product_with done" << std::endl;
117  return zz;
118 }
119 
120 // -----------------------------------------------------------------------------
121 
122 template <typename MODEL>
124  Log::trace() << "GeoVaLs<MODEL>::operator= starting" << std::endl;
125  util::Timer timer(classname(), "operator=");
126  *gvals_ = *rhs.gvals_;
127  Log::trace() << "GeovaLs<MODEL>::operator= done" << std::endl;
128  return *this;
129 }
130 
131 // -----------------------------------------------------------------------------
132 
133 template <typename MODEL>
135  Log::trace() << "GeoVaLs<MODEL>::+=(GeoVaLs, GeoVaLs) starting" << std::endl;
136  util::Timer timer(classname(), "operator+=");
137  *gvals_ += *rhs.gvals_;
138  Log::trace() << "GeoVaLs<MODEL>::+= done" << std::endl;
139  return *this;
140 }
141 
142 // -----------------------------------------------------------------------------
143 
144 template <typename MODEL>
146  Log::trace() << "GeoVaLs<MODEL>::-=(GeoVaLs, GeoVaLs) starting" << std::endl;
147  util::Timer timer(classname(), "operator-=");
148  *gvals_ -= *rhs.gvals_;
149  Log::trace() << "GeoVaLs<MODEL>::+= done" << std::endl;
150  return *this;
151 }
152 
153 // -----------------------------------------------------------------------------
154 /*! GeoVaLs Normalization Operator
155  *
156  * This is a normalization operator that first computes the normalization
157  * factor for each variable based on the rms amplitude of that variable across
158  * all locations in the reference GeoVaLs object (rhs). Then each element of
159  * the input GeoVals object (*this) is divided by these normalization factors.
160  */
161 
162 template <typename MODEL>
164  Log::trace() << "GeoVaLs<MODEL>::/=(GeoVaLs, GeoVaLs) starting" << std::endl;
165  util::Timer timer(classname(), "operator/=");
166  *gvals_ /= *rhs.gvals_;
167  Log::trace() << "GeoVaLs<MODEL>::+= done" << std::endl;
168  return *this;
169 }
170 
171 // -----------------------------------------------------------------------------
172 
173 template<typename MODEL>
175  Log::trace() << "GeoVaLs<MODEL>::operator*= starting" << std::endl;
176  util::Timer timer(classname(), "operator*=");
177  *gvals_ *= zz;
178  Log::trace() << "GeoVaLs<MODEL>::operator*= done" << std::endl;
179  return *this;
180 }
181 
182 // -----------------------------------------------------------------------------
183 
184 template <typename MODEL>
186  Log::trace() << "GeoVaLs<MODEL>::abs starting" << std::endl;
187  util::Timer timer(classname(), "abs");
188  gvals_->abs();
189  Log::trace() << "GeoVaLs<MODEL>::abs done" << std::endl;
190 }
191 // -----------------------------------------------------------------------------
192 
193 template <typename MODEL>
195  Log::trace() << "GeoVaLs<MODEL>::zero starting" << std::endl;
196  util::Timer timer(classname(), "zero");
197  gvals_->zero();
198  Log::trace() << "GeoVaLs<MODEL>::zero done" << std::endl;
199 }
200 
201 // -----------------------------------------------------------------------------
202 
203 template <typename MODEL>
204 double GeoVaLs<MODEL>::norm() const {
205  Log::trace() << "GeoVaLs<MODEL>::norm starting" << std::endl;
206  util::Timer timer(classname(), "norm");
207  double zz = gvals_->norm();
208  Log::trace() << "GeoVaLs<MODEL>::norm done" << std::endl;
209  return zz;
210 }
211 
212 // -----------------------------------------------------------------------------
213 
214 template <typename MODEL>
216  Log::trace() << "GeoVaLs<MODEL>::random starting" << std::endl;
217  util::Timer timer(classname(), "random");
218  gvals_->random();
219  Log::trace() << "GeoVaLs<MODEL>::random done" << std::endl;
220 }
221 
222 // -----------------------------------------------------------------------------
223 
224 template<typename MODEL>
225 void GeoVaLs<MODEL>::read(const eckit::Configuration & conf) {
226  Log::trace() << "GeoVaLs<MODEL>::read starting" << std::endl;
227  util::Timer timer(classname(), "read");
228  gvals_->read(conf);
229  Log::trace() << "GeoVaLs<MODEL>::read done" << std::endl;
230 }
231 
232 // -----------------------------------------------------------------------------
233 
234 template<typename MODEL>
235 void GeoVaLs<MODEL>::write(const eckit::Configuration & conf) const {
236  Log::trace() << "GeoVaLs<MODEL>::write starting" << std::endl;
237  util::Timer timer(classname(), "write");
238  gvals_->write(conf);
239  Log::trace() << "GeoVaLs<MODEL>::write done" << std::endl;
240 }
241 
242 // -----------------------------------------------------------------------------
243 /*! \brief GeoVaLs Analytic Initialization
244  *
245  * \details **analytic_init()** was introduced in May, 2018 (initially as a
246  * constructor) for use with the interpolation test. The interpolation test
247  * requires an initialization of a GeoVaLs object based on the same analytic
248  * formulae used for the State initialization (see test::TestStateInterpolation()
249  * for further information). This in turn requires information about the
250  * vertical profile in addition to the latitude and longitude positional
251  * information in the Locations object. Currently, this information
252  * about the vertical profile is obtained from an existing GeoVaLs object
253  * (passed as *other*) that represents the output of the State::interpolate()
254  * method. The State.StateGenerate section of the configuration file is
255  * also passed to this constructor to provide further information required
256  * for the analytic initialization.
257  *
258  * \date May, 2018: created as a constructor (M. Miesch, JCSDA)
259  * \date June, 2018: moved to a method (M. Miesch, JCSDA)
260  *
261  * \sa test::TestStateInterpolation()
262  */
263 
264 template <typename MODEL>
266  const eckit::Configuration & conf) {
267  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs analytic init starting" << std::endl;
268  util::Timer timer(classname(), "GeoVaLs");
269  gvals_->analytic_init(locs.locations(), conf);
270  Log::trace() << "GeoVaLs<MODEL>::GeoVaLs analytic init done" << std::endl;
271 }
272 
273 // -----------------------------------------------------------------------------
274 
275 template<typename MODEL>
276 void GeoVaLs<MODEL>::print(std::ostream & os) const {
277  Log::trace() << "GeoVaLs<MODEL>::print starting" << std::endl;
278  util::Timer timer(classname(), "print");
279  os << *gvals_;
280  Log::trace() << "GeoVaLs<MODEL>::print done" << std::endl;
281 }
282 
283 // -----------------------------------------------------------------------------
284 
285 } // namespace oops
286 
287 #endif // OOPS_INTERFACE_GEOVALS_H_
const GeoVaLs_ & geovals() const
Interfacing.
Locations< MODEL > Locations_
GeoVaLs & operator=(const GeoVaLs &)
GeoVaLs & operator+=(const GeoVaLs &)
Definition: conf.py:1
GeoVaLs & operator-=(const GeoVaLs &)
void abs()
Linear algebra and utilities, mostly for writing tests.
boost::scoped_ptr< GeoVaLs_ > gvals_
const Locations_ & locations() const
Interfacing.
The namespace for the main oops code.
void write(const eckit::Configuration &) const
GeoVaLs & operator*=(const double &)
void analytic_init(const Locations_ &, const eckit::Configuration &)
GeoVaLs Analytic Initialization.
void read(const eckit::Configuration &)
GeoVaLs & operator/=(const GeoVaLs &)
GeoVaLs Normalization Operator.
GeoVaLs(const Locations_ &, const Variables &)
static const std::string classname()
double dot_product_with(const GeoVaLs &) const
void print(std::ostream &) const