IODA Bundle
oops/interface/ObsAuxIncrement.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_OBSAUXINCREMENT_H_
12 #define OOPS_INTERFACE_OBSAUXINCREMENT_H_
13 
14 #include <iostream>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
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 OBS>
36 class ObsAuxIncrement : public util::Printable,
37  public util::Serializable,
38  private util::ObjectCounter<ObsAuxIncrement<OBS> > {
39  typedef typename OBS::ObsAuxIncrement ObsAuxIncrement_;
41 
42  public:
43  typedef typename ObsAuxIncrement_::Parameters_ Parameters_;
44 
45  static const std::string classname() {return "oops::ObsAuxIncrement";}
46 
47 /// Constructor, destructor
48  ObsAuxIncrement(const ObsSpace<OBS> &, const Parameters_ &);
49  /// Copies \p other if \p copy is true, otherwise creates zero increment
50  /// of the same size as \p other.
51  ObsAuxIncrement(const ObsAuxIncrement & other, const bool copy = true);
53 
54 /// Interfacing
55  const ObsAuxIncrement_ & obsauxincrement() const {return *aux_;}
57 
58 /// Linear algebra operators
59  void diff(const ObsAuxControl_ &, const ObsAuxControl_ &);
60  void zero();
64  ObsAuxIncrement & operator*=(const double &);
65  void axpy(const double &, const ObsAuxIncrement &);
66  double dot_product_with(const ObsAuxIncrement &) const;
67 
68 /// I/O and diagnostics
69  void read(const eckit::Configuration &);
70  void write(const eckit::Configuration &) const;
71  double norm() const;
72 
73 /// Serialize and deserialize
74  size_t serialSize() const override;
75  void serialize(std::vector<double> &) const override;
76  void deserialize(const std::vector<double> &, size_t &) override;
77 
78  private:
79  void print(std::ostream &) const override;
80  std::unique_ptr<ObsAuxIncrement_> aux_;
81 };
82 
83 // -----------------------------------------------------------------------------
84 
85 template <typename OBS>
87  Log::trace() << "operator+=(ObsAuxControl, ObsAuxIncrement) starting" << std::endl;
88  util::Timer timer("oops::ObsAuxIncrement", "operator+=ObsAuxControl");
89  xx.obsauxcontrol() += dx.obsauxincrement();
90  Log::trace() << "operator+=(ObsAuxControl, ObsAuxIncrement) done" << std::endl;
91  return xx;
92 }
93 
94 // =============================================================================
95 
96 template<typename OBS>
98  const Parameters_ & params) : aux_()
99 {
100  Log::trace() << "ObsAuxIncrement<OBS>::ObsAuxIncrement starting" << std::endl;
101  util::Timer timer(classname(), "ObsAuxIncrement");
102  aux_.reset(new ObsAuxIncrement_(os.obsspace(), params));
103  this->setObjectSize(aux_->serialSize()*sizeof(double));
104  Log::trace() << "ObsAuxIncrement<OBS>::ObsAuxIncrement done" << std::endl;
105 }
106 // -----------------------------------------------------------------------------
107 template<typename OBS>
109  const bool copy) : aux_()
110 {
111  Log::trace() << "ObsAuxIncrement<OBS>::ObsAuxIncrement copy starting" << std::endl;
112  util::Timer timer(classname(), "ObsAuxIncrement");
113  aux_.reset(new ObsAuxIncrement_(*other.aux_, copy));
114  this->setObjectSize(aux_->serialSize()*sizeof(double));
115  Log::trace() << "ObsAuxIncrement<OBS>::ObsAuxIncrement copy done" << std::endl;
116 }
117 // -----------------------------------------------------------------------------
118 template<typename OBS>
120  Log::trace() << "ObsAuxIncrement<OBS>::~ObsAuxIncrement starting" << std::endl;
121  util::Timer timer(classname(), "~ObsAuxIncrement");
122  aux_.reset();
123  Log::trace() << "ObsAuxIncrement<OBS>::~ObsAuxIncrement done" << std::endl;
124 }
125 // -----------------------------------------------------------------------------
126 template<typename OBS>
128  Log::trace() << "ObsAuxIncrement<OBS>::diff starting" << std::endl;
129  util::Timer timer(classname(), "diff");
130  aux_->diff(x1.obsauxcontrol(), x2.obsauxcontrol());
131  Log::trace() << "ObsAuxIncrement<OBS>::diff done" << std::endl;
132 }
133 // -----------------------------------------------------------------------------
134 template<typename OBS>
136  Log::trace() << "ObsAuxIncrement<OBS>::zero starting" << std::endl;
137  util::Timer timer(classname(), "zero");
138  aux_->zero();
139  Log::trace() << "ObsAuxIncrement<OBS>::zero done" << std::endl;
140 }
141 // -----------------------------------------------------------------------------
142 template<typename OBS>
144  Log::trace() << "ObsAuxIncrement<OBS>::operator= starting" << std::endl;
145  util::Timer timer(classname(), "operator=");
146  *aux_ = *rhs.aux_;
147  Log::trace() << "ObsAuxIncrement<OBS>::operator= done" << std::endl;
148  return *this;
149 }
150 // -----------------------------------------------------------------------------
151 template<typename OBS>
153  Log::trace() << "ObsAuxIncrement<OBS>::operator+= starting" << std::endl;
154  util::Timer timer(classname(), "operator+=");
155  *aux_ += *rhs.aux_;
156  Log::trace() << "ObsAuxIncrement<OBS>::operator+= done" << std::endl;
157  return *this;
158 }
159 // -----------------------------------------------------------------------------
160 template<typename OBS>
162  Log::trace() << "ObsAuxIncrement<OBS>::operator-= starting" << std::endl;
163  util::Timer timer(classname(), "operator-=");
164  *aux_ -= *rhs.aux_;
165  Log::trace() << "ObsAuxIncrement<OBS>::operator-= done" << std::endl;
166  return *this;
167 }
168 // -----------------------------------------------------------------------------
169 template<typename OBS>
171  Log::trace() << "ObsAuxIncrement<OBS>::operator*= starting" << std::endl;
172  util::Timer timer(classname(), "operator*=");
173  *aux_ *= zz;
174  Log::trace() << "ObsAuxIncrement<OBS>::operator*= done" << std::endl;
175  return *this;
176 }
177 // -----------------------------------------------------------------------------
178 template<typename OBS>
179 void ObsAuxIncrement<OBS>::axpy(const double & zz, const ObsAuxIncrement & dx) {
180  Log::trace() << "ObsAuxIncrement<OBS>::axpy starting" << std::endl;
181  util::Timer timer(classname(), "axpy");
182  aux_->axpy(zz, *dx.aux_);
183  Log::trace() << "ObsAuxIncrement<OBS>::axpy done" << std::endl;
184 }
185 // -----------------------------------------------------------------------------
186 template<typename OBS>
188  Log::trace() << "ObsAuxIncrement<OBS>::dot_product_with starting" << std::endl;
189  util::Timer timer(classname(), "dot_product_with");
190  double zz = aux_->dot_product_with(*dx.aux_);
191  Log::trace() << "ObsAuxIncrement<OBS>::dot_product_with done" << std::endl;
192  return zz;
193 }
194 // -----------------------------------------------------------------------------
195 template<typename OBS>
196 void ObsAuxIncrement<OBS>::read(const eckit::Configuration & conf) {
197  Log::trace() << "ObsAuxIncrement<OBS>::read starting" << std::endl;
198  util::Timer timer(classname(), "read");
199  aux_->read(conf);
200  Log::trace() << "ObsAuxIncrement<OBS>::read done" << std::endl;
201 }
202 // -----------------------------------------------------------------------------
203 template<typename OBS>
204 void ObsAuxIncrement<OBS>::write(const eckit::Configuration & conf) const {
205  Log::trace() << "ObsAuxIncrement<OBS>::write starting" << std::endl;
206  util::Timer timer(classname(), "write");
207  aux_->write(conf);
208  Log::trace() << "ObsAuxIncrement<OBS>::write done" << std::endl;
209 }
210 // -----------------------------------------------------------------------------
211 template<typename OBS>
213  Log::trace() << "ObsAuxIncrement<OBS>::norm starting" << std::endl;
214  util::Timer timer(classname(), "norm");
215  double zz = aux_->norm();
216  Log::trace() << "ObsAuxIncrement<OBS>::norm done" << std::endl;
217  return zz;
218 }
219 // -----------------------------------------------------------------------------
220 template<typename OBS>
222  Log::trace() << "ObsAuxIncrement<OBS>::serialSize" << std::endl;
223  util::Timer timer(classname(), "serialSize");
224  return aux_->serialSize();
225 }
226 // -----------------------------------------------------------------------------
227 template<typename OBS>
228 void ObsAuxIncrement<OBS>::serialize(std::vector<double> & vect) const {
229  Log::trace() << "ObsAuxIncrement<OBS>::serialize starting" << std::endl;
230  util::Timer timer(classname(), "serialize");
231  aux_->serialize(vect);
232  Log::trace() << "ObsAuxIncrement<OBS>::serialize done" << std::endl;
233 }
234 // -----------------------------------------------------------------------------
235 template<typename OBS>
236 void ObsAuxIncrement<OBS>::deserialize(const std::vector<double> & vect, size_t & current) {
237  Log::trace() << "ObsAuxIncrement<OBS>::deserialize starting" << std::endl;
238  util::Timer timer(classname(), "deserialize");
239  aux_->deserialize(vect, current);
240  Log::trace() << "ObsAuxIncrement<OBS>::deserialize done" << std::endl;
241 }
242 // -----------------------------------------------------------------------------
243 template<typename OBS>
244 void ObsAuxIncrement<OBS>::print(std::ostream & os) const {
245  Log::trace() << "ObsAuxIncrement<OBS>::print starting" << std::endl;
246  util::Timer timer(classname(), "print");
247  os << *aux_;
248  Log::trace() << "ObsAuxIncrement<OBS>::print done" << std::endl;
249 }
250 // -----------------------------------------------------------------------------
251 
252 } // namespace oops
253 
254 #endif // OOPS_INTERFACE_OBSAUXINCREMENT_H_
const ObsAuxControl_ & obsauxcontrol() const
Interfacing.
std::unique_ptr< ObsAuxIncrement_ > aux_
ObsAuxIncrement_::Parameters_ Parameters_
void axpy(const double &, const ObsAuxIncrement &)
ObsAuxIncrement & operator*=(const double &)
void serialize(std::vector< double > &) const override
void deserialize(const std::vector< double > &, size_t &) override
void read(const eckit::Configuration &)
I/O and diagnostics.
size_t serialSize() const override
Serialize and deserialize.
void write(const eckit::Configuration &) const
ObsAuxIncrement(const ObsSpace< OBS > &, const Parameters_ &)
Constructor, destructor.
ObsAuxIncrement & operator-=(const ObsAuxIncrement &)
ObsAuxIncrement & operator=(const ObsAuxIncrement &)
void print(std::ostream &) const override
double dot_product_with(const ObsAuxIncrement &) const
const ObsAuxIncrement_ & obsauxincrement() const
Interfacing.
static const std::string classname()
void diff(const ObsAuxControl_ &, const ObsAuxControl_ &)
Linear algebra operators.
ObsAuxIncrement & operator+=(const ObsAuxIncrement &)
ObsSpace_ & obsspace() const
Interfacing.
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.