OOPS
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 <memory>
15 #include <string>
16 
17 #include <boost/noncopyable.hpp>
18 
19 #include "eckit/config/Configuration.h"
20 #include "oops/base/Variables.h"
23 #include "oops/util/ObjectCounter.h"
24 #include "oops/util/Printable.h"
25 #include "oops/util/Timer.h"
26 
27 namespace oops {
28 
29 // -----------------------------------------------------------------------------
30 template <typename OBS>
31 class GeoVaLs : public util::Printable,
32  private util::ObjectCounter<GeoVaLs<OBS> > {
33  typedef typename OBS::GeoVaLs GeoVaLs_;
36 
37  public:
38  static const std::string classname() {return "oops::GeoVaLs";}
39 
40  GeoVaLs(const Locations_ &, const Variables &);
41  GeoVaLs(const eckit::Configuration &, const ObsSpace_ &, const Variables &);
42  GeoVaLs(const GeoVaLs &);
43 
44  ~GeoVaLs();
45 
46 /// Interfacing
47  const GeoVaLs_ & geovals() const {return *gvals_;}
48  GeoVaLs_ & geovals() {return *gvals_;}
49 
50 /// Linear algebra and utilities, mostly for writing tests
51  void zero();
52  void random();
53  double rms() const;
54  double normalizedrms(const GeoVaLs &) const;
55  GeoVaLs & operator=(const GeoVaLs &);
56  GeoVaLs & operator*=(const double &);
57  GeoVaLs & operator+=(const GeoVaLs &);
58  GeoVaLs & operator-=(const GeoVaLs &);
59  GeoVaLs & operator*=(const GeoVaLs &);
60  double dot_product_with(const GeoVaLs &) const;
61  void read(const eckit::Configuration &);
62  void write(const eckit::Configuration &) const;
63 
64  private:
65  void print(std::ostream &) const;
66  std::unique_ptr<GeoVaLs_> gvals_;
67 };
68 
69 // -----------------------------------------------------------------------------
70 
71 template <typename OBS>
72 GeoVaLs<OBS>::GeoVaLs(const Locations_ & locs, const Variables & vars) : gvals_() {
73  Log::trace() << "GeoVaLs<OBS>::GeoVaLs starting" << std::endl;
74  util::Timer timer(classname(), "GeoVaLs");
75  gvals_.reset(new GeoVaLs_(locs.locations(), vars));
76  Log::trace() << "GeoVaLs<OBS>::GeoVaLs done" << std::endl;
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 template <typename OBS>
82  GeoVaLs<OBS>::GeoVaLs(const eckit::Configuration & conf,
83  const ObsSpace_ & ospace, const Variables & vars)
84  : gvals_() {
85  Log::trace() << "GeoVaLs<OBS>::GeoVaLs read starting" << std::endl;
86  util::Timer timer(classname(), "GeoVaLs");
87  gvals_.reset(new GeoVaLs_(conf, ospace.obsspace(), vars));
88  Log::trace() << "GeoVaLs<OBS>::GeoVaLs read done" << std::endl;
89 }
90 
91 // -----------------------------------------------------------------------------
92 
93 template <typename OBS>
94 GeoVaLs<OBS>::GeoVaLs(const GeoVaLs & other): gvals_() {
95  Log::trace() << "GeoVaLs<OBS>::GeoVaLs starting" << std::endl;
96  util::Timer timer(classname(), "GeoVaLs");
97  gvals_.reset(new GeoVaLs_(*other.gvals_));
98  Log::trace() << "ObsVector<OBS>::GeoVaLs done" << std::endl;
99 }
100 
101 // -----------------------------------------------------------------------------
102 
103 template <typename OBS>
105  Log::trace() << "GeoVaLs<OBS>::~GeoVaLs starting" << std::endl;
106  util::Timer timer(classname(), "~GeoVaLs");
107  gvals_.reset();
108  Log::trace() << "GeoVaLs<OBS>::~GeoVaLs done" << std::endl;
109 }
110 
111 // -----------------------------------------------------------------------------
112 
113 template <typename OBS>
114 double GeoVaLs<OBS>::dot_product_with(const GeoVaLs & other) const {
115  Log::trace() << "GeoVaLs<OBS>::dot_product_with starting" << std::endl;
116  util::Timer timer(classname(), "dot_product_with");
117  double zz = gvals_->dot_product_with(*other.gvals_);
118  Log::trace() << "GeoVaLs<OBS>::dot_product_with done" << std::endl;
119  return zz;
120 }
121 
122 // -----------------------------------------------------------------------------
123 
124 template <typename OBS>
126  Log::trace() << "GeoVaLs<OBS>::operator= starting" << std::endl;
127  util::Timer timer(classname(), "operator=");
128  *gvals_ = *rhs.gvals_;
129  Log::trace() << "GeovaLs<OBS>::operator= done" << std::endl;
130  return *this;
131 }
132 
133 // -----------------------------------------------------------------------------
134 
135 template <typename OBS>
137  Log::trace() << "GeoVaLs<OBS>::+=(GeoVaLs, GeoVaLs) starting" << std::endl;
138  util::Timer timer(classname(), "operator+=");
139  *gvals_ += *rhs.gvals_;
140  Log::trace() << "GeoVaLs<OBS>::+= done" << std::endl;
141  return *this;
142 }
143 
144 // -----------------------------------------------------------------------------
145 
146 template <typename OBS>
148  Log::trace() << "GeoVaLs<OBS>::-=(GeoVaLs, GeoVaLs) starting" << std::endl;
149  util::Timer timer(classname(), "operator-=");
150  *gvals_ -= *rhs.gvals_;
151  Log::trace() << "GeoVaLs<OBS>::-= done" << std::endl;
152  return *this;
153 }
154 
155 // -----------------------------------------------------------------------------
156 
157 template <typename OBS>
159  Log::trace() << "GeoVaLs<OBS>::*=(GeoVaLs, GeoVaLs) starting" << std::endl;
160  util::Timer timer(classname(), "operator*=(schur)");
161  *gvals_ *= *rhs.gvals_;
162  Log::trace() << "GeoVaLs<OBS>::*= done" << std::endl;
163  return *this;
164 }
165 
166 // -----------------------------------------------------------------------------
167 
168 template<typename OBS>
170  Log::trace() << "GeoVaLs<OBS>::operator*= starting" << std::endl;
171  util::Timer timer(classname(), "operator*=");
172  *gvals_ *= zz;
173  Log::trace() << "GeoVaLs<OBS>::operator*= done" << std::endl;
174  return *this;
175 }
176 
177 // -----------------------------------------------------------------------------
178 
179 template <typename OBS>
180 double GeoVaLs<OBS>::rms() const {
181  Log::trace() << "GeoVaLs<OBS>::rms starting" << std::endl;
182  util::Timer timer(classname(), "rms");
183  double zz = gvals_->rms();
184  Log::trace() << "GeoVaLs<OBS>::rms done" << std::endl;
185  return zz;
186 }
187 
188 // -----------------------------------------------------------------------------
189 
190 template <typename OBS>
191 double GeoVaLs<OBS>::normalizedrms(const GeoVaLs & rhs) const {
192  Log::trace() << "GeoVaLs<OBS>::normalizedrms starting" << std::endl;
193  util::Timer timer(classname(), "normalizedrms");
194  double zz = gvals_->normalizedrms(*rhs.gvals_);
195  Log::trace() << "GeoVaLs<OBS>::normalizedrms done" << std::endl;
196  return zz;
197 }
198 
199 // -----------------------------------------------------------------------------
200 
201 template <typename OBS>
203  Log::trace() << "GeoVaLs<OBS>::zero starting" << std::endl;
204  util::Timer timer(classname(), "zero");
205  gvals_->zero();
206  Log::trace() << "GeoVaLs<OBS>::zero done" << std::endl;
207 }
208 
209 // -----------------------------------------------------------------------------
210 
211 template <typename OBS>
213  Log::trace() << "GeoVaLs<OBS>::random starting" << std::endl;
214  util::Timer timer(classname(), "random");
215  gvals_->random();
216  Log::trace() << "GeoVaLs<OBS>::random done" << std::endl;
217 }
218 
219 // -----------------------------------------------------------------------------
220 
221 template<typename OBS>
222 void GeoVaLs<OBS>::read(const eckit::Configuration & conf) {
223  Log::trace() << "GeoVaLs<OBS>::read starting" << std::endl;
224  util::Timer timer(classname(), "read");
225  gvals_->read(conf);
226  Log::trace() << "GeoVaLs<OBS>::read done" << std::endl;
227 }
228 
229 // -----------------------------------------------------------------------------
230 
231 template<typename OBS>
232 void GeoVaLs<OBS>::write(const eckit::Configuration & conf) const {
233  Log::trace() << "GeoVaLs<OBS>::write starting" << std::endl;
234  util::Timer timer(classname(), "write");
235  gvals_->write(conf);
236  Log::trace() << "GeoVaLs<OBS>::write done" << std::endl;
237 }
238 
239 // -----------------------------------------------------------------------------
240 
241 template<typename OBS>
242 void GeoVaLs<OBS>::print(std::ostream & os) const {
243  Log::trace() << "GeoVaLs<OBS>::print starting" << std::endl;
244  util::Timer timer(classname(), "print");
245  os << *gvals_;
246  Log::trace() << "GeoVaLs<OBS>::print done" << std::endl;
247 }
248 
249 // -----------------------------------------------------------------------------
250 
251 } // namespace oops
252 
253 #endif // OOPS_INTERFACE_GEOVALS_H_
oops::GeoVaLs::print
void print(std::ostream &) const
Definition: oops/interface/GeoVaLs.h:242
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::GeoVaLs::geovals
GeoVaLs_ & geovals()
Definition: oops/interface/GeoVaLs.h:48
oops::GeoVaLs::normalizedrms
double normalizedrms(const GeoVaLs &) const
Definition: oops/interface/GeoVaLs.h:191
oops::GeoVaLs::operator-=
GeoVaLs & operator-=(const GeoVaLs &)
Definition: oops/interface/GeoVaLs.h:147
oops::GeoVaLs::geovals
const GeoVaLs_ & geovals() const
Interfacing.
Definition: oops/interface/GeoVaLs.h:47
oops::GeoVaLs::ObsSpace_
ObsSpace< OBS > ObsSpace_
Definition: oops/interface/GeoVaLs.h:34
Locations.h
oops::GeoVaLs::write
void write(const eckit::Configuration &) const
Definition: oops/interface/GeoVaLs.h:232
oops::GeoVaLs::zero
void zero()
Linear algebra and utilities, mostly for writing tests.
Definition: oops/interface/GeoVaLs.h:202
oops::ObsSpace
Definition: oops/interface/ObsSpace.h:42
oops::GeoVaLs::read
void read(const eckit::Configuration &)
Definition: oops/interface/GeoVaLs.h:222
oops::GeoVaLs::random
void random()
Definition: oops/interface/GeoVaLs.h:212
oops::GeoVaLs::operator=
GeoVaLs & operator=(const GeoVaLs &)
Definition: oops/interface/GeoVaLs.h:125
oops::GeoVaLs::~GeoVaLs
~GeoVaLs()
Definition: oops/interface/GeoVaLs.h:104
oops::ObsSpace::obsspace
ObsSpace_ & obsspace() const
Interfacing.
Definition: oops/interface/ObsSpace.h:61
oops::GeoVaLs::GeoVaLs
GeoVaLs(const Locations_ &, const Variables &)
Definition: oops/interface/GeoVaLs.h:72
oops::GeoVaLs::gvals_
std::unique_ptr< GeoVaLs_ > gvals_
Definition: oops/interface/GeoVaLs.h:66
oops::GeoVaLs::rms
double rms() const
Definition: oops/interface/GeoVaLs.h:180
oops::GeoVaLs::Locations_
Locations< OBS > Locations_
Definition: oops/interface/GeoVaLs.h:35
oops::GeoVaLs::dot_product_with
double dot_product_with(const GeoVaLs &) const
Definition: oops/interface/GeoVaLs.h:114
oops::GeoVaLs::GeoVaLs_
OBS::GeoVaLs GeoVaLs_
Definition: oops/interface/GeoVaLs.h:33
oops::GeoVaLs::operator+=
GeoVaLs & operator+=(const GeoVaLs &)
Definition: oops/interface/GeoVaLs.h:136
ObsSpace.h
oops::Locations::locations
const Locations_ & locations() const
Interfacing.
Definition: oops/interface/Locations.h:54
oops::Variables
Definition: oops/base/Variables.h:23
oops::Locations
Locations of observations for observation operator.
Definition: oops/interface/Locations.h:36
oops::GeoVaLs::operator*=
GeoVaLs & operator*=(const double &)
Definition: oops/interface/GeoVaLs.h:169
oops::GeoVaLs::classname
static const std::string classname()
Definition: oops/interface/GeoVaLs.h:38
oops::GeoVaLs
Definition: oops/interface/GeoVaLs.h:32
Variables.h