FV3 Bundle
oops/src/oops/interface/ObsVector.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_OBSVECTOR_H_
12 #define OOPS_INTERFACE_OBSVECTOR_H_
13 
14 #include <math.h>
15 #include <ostream>
16 #include <string>
17 
18 #include <boost/scoped_ptr.hpp>
19 
21 #include "oops/util/Logger.h"
22 #include "oops/util/ObjectCounter.h"
23 #include "oops/util/Printable.h"
24 #include "oops/util/Timer.h"
25 
26 namespace eckit {
27  class Configuration;
28 }
29 
30 namespace util {
31  class DateTime;
32 }
33 
34 namespace oops {
35 
36 // -----------------------------------------------------------------------------
37 
38 template <typename MODEL>
39 class ObsVector : public util::Printable,
40  private util::ObjectCounter<ObsVector<MODEL> > {
41  typedef typename MODEL::ObsVector ObsVector_;
42 
43  public:
44  static const std::string classname() {return "oops::ObsVector";}
45 
46  explicit ObsVector(const ObservationSpace<MODEL> &);
47  explicit ObsVector(const ObsVector &, const bool copy = true);
48  explicit ObsVector(ObsVector_ *);
49  ~ObsVector();
50 
51 /// Interfacing
52  ObsVector_ & obsvector() {return *data_;}
53  const ObsVector_ & obsvector() const {return *data_;}
54 
55 // Linear algebra
56  ObsVector & operator = (const ObsVector &);
57  ObsVector & operator*= (const double &);
58  ObsVector & operator+= (const ObsVector &);
59  ObsVector & operator-= (const ObsVector &);
60  ObsVector & operator*= (const ObsVector &);
61  ObsVector & operator/= (const ObsVector &);
62 
63  void zero();
64  void axpy(const double &, const ObsVector &);
65  void invert();
66  void random();
67  double dot_product_with(const ObsVector &) const;
68  double rms() const;
69  unsigned int size() const {return data_->size();}
70 
71 // I/O
72  void read(const std::string &);
73  void save(const std::string &) const;
74 
75  private:
76  void print(std::ostream &) const;
77  boost::scoped_ptr<ObsVector_> data_;
78 };
79 
80 // -----------------------------------------------------------------------------
81 template <typename MODEL>
83  Log::trace() << "ObsVector<MODEL>::ObsVector starting" << std::endl;
84  util::Timer timer(classname(), "ObsVector");
85 
86  data_.reset(new ObsVector_(os.observationspace()));
87 
88  Log::trace() << "ObsVector<MODEL>::ObsVector done" << std::endl;
89 }
90 // -----------------------------------------------------------------------------
91 template <typename MODEL>
92 ObsVector<MODEL>::ObsVector(const ObsVector & other, const bool copy): data_() {
93  Log::trace() << "ObsVector<MODEL>::ObsVector starting" << std::endl;
94  util::Timer timer(classname(), "ObsVector");
95 
96  data_.reset(new ObsVector_(*other.data_, copy));
97 
98  Log::trace() << "ObsVector<MODEL>::ObsVector done" << std::endl;
99 }
100 // -----------------------------------------------------------------------------
101 template <typename MODEL>
103  Log::trace() << "ObsVector<MODEL>::ObsVector done" << std::endl;
104 }
105 // -----------------------------------------------------------------------------
106 template <typename MODEL>
108  Log::trace() << "ObsVector<MODEL>::~ObsVector starting" << std::endl;
109  util::Timer timer(classname(), "~ObsVector");
110 
111  data_.reset();
112 
113  Log::trace() << "ObsVector<MODEL>::~ObsVector done" << std::endl;
114 }
115 // -----------------------------------------------------------------------------
116 template <typename MODEL>
118  Log::trace() << "ObsVector<MODEL>::operator= starting" << std::endl;
119  util::Timer timer(classname(), "operator=");
120 
121  *data_ = *rhs.data_;
122 
123  Log::trace() << "ObsVector<MODEL>::operator= done" << std::endl;
124  return *this;
125 }
126 // -----------------------------------------------------------------------------
127 template <typename MODEL>
129  Log::trace() << "ObsVector<MODEL>::operator*= starting" << std::endl;
130  util::Timer timer(classname(), "operator*=");
131 
132  *data_ *= zz;
133 
134  Log::trace() << "ObsVector<MODEL>::operator*= done" << std::endl;
135  return *this;
136 }
137 // -----------------------------------------------------------------------------
138 template <typename MODEL>
140  Log::trace() << "ObsVector<MODEL>::operator+= starting" << std::endl;
141  util::Timer timer(classname(), "operator+=");
142 
143  *data_ += *rhs.data_;
144 
145  Log::trace() << "ObsVector<MODEL>::operator+= done" << std::endl;
146  return *this;
147 }
148 // -----------------------------------------------------------------------------
149 template <typename MODEL>
151  Log::trace() << "ObsVector<MODEL>::operator-= starting" << std::endl;
152  util::Timer timer(classname(), "operator-=");
153 
154  *data_ -= *rhs.data_;
155 
156  Log::trace() << "ObsVector<MODEL>::operator-= done" << std::endl;
157  return *this;
158 }
159 // -----------------------------------------------------------------------------
160 template <typename MODEL>
162  Log::trace() << "ObsVector<MODEL>::operator*= starting" << std::endl;
163  util::Timer timer(classname(), "operator*=");
164 
165  *data_ *= *rhs.data_;
166 
167  Log::trace() << "ObsVector<MODEL>::operator*= done" << std::endl;
168  return *this;
169 }
170 // -----------------------------------------------------------------------------
171 template <typename MODEL>
173  Log::trace() << "ObsVector<MODEL>::operator/= starting" << std::endl;
174  util::Timer timer(classname(), "operator/=");
175 
176  *data_ /= *rhs.data_;
177 
178  Log::trace() << "ObsVector<MODEL>::operator/= done" << std::endl;
179  return *this;
180 }
181 // -----------------------------------------------------------------------------
182 template <typename MODEL>
184  Log::trace() << "ObsVector<MODEL>::zero starting" << std::endl;
185  util::Timer timer(classname(), "zero");
186 
187  data_->zero();
188 
189  Log::trace() << "ObsVector<MODEL>::zero done" << std::endl;
190 }
191 // -----------------------------------------------------------------------------
192 template <typename MODEL>
193 void ObsVector<MODEL>::axpy(const double & zz, const ObsVector & rhs) {
194  Log::trace() << "ObsVector<MODEL>::axpy starting" << std::endl;
195  util::Timer timer(classname(), "axpy");
196 
197  data_->axpy(zz, *rhs.data_);
198 
199  Log::trace() << "ObsVector<MODEL>::axpy done" << std::endl;
200 }
201 // -----------------------------------------------------------------------------
202 template <typename MODEL>
204  Log::trace() << "ObsVector<MODEL>::invert starting" << std::endl;
205  util::Timer timer(classname(), "invert");
206 
207  data_->invert();
208 
209  Log::trace() << "ObsVector<MODEL>::invert done" << std::endl;
210 }
211 // -----------------------------------------------------------------------------
212 template <typename MODEL>
214  Log::trace() << "ObsVector<MODEL>::random starting" << std::endl;
215  util::Timer timer(classname(), "random");
216 
217  data_->random();
218 
219  Log::trace() << "ObsVector<MODEL>::random done" << std::endl;
220 }
221 // -----------------------------------------------------------------------------
222 template <typename MODEL>
223 double ObsVector<MODEL>::dot_product_with(const ObsVector & other) const {
224  Log::trace() << "ObsVector<MODEL>::dot_product starting" << std::endl;
225  util::Timer timer(classname(), "dot_product");
226 
227  const double zz = data_->dot_product_with(*other.data_);
228 
229  Log::trace() << "ObsVector<MODEL>::dot_product done" << std::endl;
230  return zz;
231 }
232 // -----------------------------------------------------------------------------
233 template <typename MODEL>
234 double ObsVector<MODEL>::rms() const {
235  Log::trace() << "ObsVector<MODEL>::rms starting" << std::endl;
236  util::Timer timer(classname(), "rms");
237 
238  const double zz = data_->rms();
239 
240  Log::trace() << "ObsVector<MODEL>::rms done" << std::endl;
241  return zz;
242 }
243 // -----------------------------------------------------------------------------
244 template <typename MODEL>
245 void ObsVector<MODEL>::print(std::ostream & os) const {
246  Log::trace() << "ObsVector<MODEL>::print starting" << std::endl;
247  util::Timer timer(classname(), "print");
248 
249  os << *data_;
250 
251  Log::trace() << "ObsVector<MODEL>::print done" << std::endl;
252 }
253 // -----------------------------------------------------------------------------
254 template <typename MODEL>
255 void ObsVector<MODEL>::read(const std::string & name) {
256  Log::trace() << "ObsVector<MODEL>::read starting" << std::endl;
257  util::Timer timer(classname(), "read");
258 
259  data_->read(name);
260 
261  Log::trace() << "ObsVector<MODEL>::read done" << std::endl;
262 }
263 // -----------------------------------------------------------------------------
264 template <typename MODEL>
265 void ObsVector<MODEL>::save(const std::string & name) const {
266  Log::trace() << "ObsVector<MODEL>::save starting";
267  util::Timer timer(classname(), "save");
268 
269  data_->save(name);
270 
271  Log::trace() << "ObsVector<MODEL>::save done" << std::endl;
272 }
273 // -----------------------------------------------------------------------------
274 
275 } // namespace oops
276 
277 #endif // OOPS_INTERFACE_OBSVECTOR_H_
void axpy(const double &, const ObsVector &)
ObsVector & operator=(const ObsVector &)
subroutine, public copy(self, rhs)
ObsVector(const ObservationSpace< MODEL > &)
const ObsVector_ & obsvector() const
character(len=32) name
void read(const std::string &)
The namespace for the main oops code.
ObsVector & operator*=(const double &)
void print(std::ostream &) const
ObsVector_ & obsvector()
Interfacing.
boost::scoped_ptr< ObsVector_ > data_
void save(const std::string &) const
ObsVector & operator-=(const ObsVector &)
ObsVector & operator/=(const ObsVector &)
ObsSpace_ & observationspace() const
Interfacing.
double dot_product_with(const ObsVector &) const
ObsVector & operator+=(const ObsVector &)
static const std::string classname()