FV3 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 <string>
16 
17 #include <boost/scoped_ptr.hpp>
18 
20 #include "oops/util/Logger.h"
21 #include "oops/util/ObjectCounter.h"
22 #include "oops/util/Printable.h"
23 #include "oops/util/Timer.h"
24 
25 namespace eckit {
26  class Configuration;
27 }
28 
29 namespace oops {
30 
31 // -----------------------------------------------------------------------------
32 
33 template <typename MODEL>
34 class ObsAuxIncrement : public util::Printable,
35  private util::ObjectCounter<ObsAuxIncrement<MODEL> > {
36  typedef typename MODEL::ObsAuxIncrement ObsAuxIncrement_;
38 
39  public:
40  static const std::string classname() {return "oops::ObsAuxIncrement";}
41 
42 /// Constructor, destructor
43  explicit ObsAuxIncrement(const eckit::Configuration &);
44  ObsAuxIncrement(const ObsAuxIncrement &, const bool copy = true);
45  ObsAuxIncrement(const ObsAuxIncrement &, const eckit::Configuration &);
47 
48 /// Interfacing
49  const ObsAuxIncrement_ & obsauxincrement() const {return *aux_;}
51 
52 /// Linear algebra operators
53  void diff(const ObsAuxControl_ &, const ObsAuxControl_ &);
54  void zero();
58  ObsAuxIncrement & operator*=(const double &);
59  void axpy(const double &, const ObsAuxIncrement &);
60  double dot_product_with(const ObsAuxIncrement &) const;
61 
62 /// I/O and diagnostics
63  void read(const eckit::Configuration &);
64  void write(const eckit::Configuration &) const;
65  double norm() const;
66 
67  private:
68  void print(std::ostream &) const;
69  boost::scoped_ptr<ObsAuxIncrement_> aux_;
70 };
71 
72 // -----------------------------------------------------------------------------
73 
74 template <typename MODEL>
76  Log::trace() << "operator+=(ObsAuxControl, ObsAuxIncrement) starting" << std::endl;
77  util::Timer timer("oops::ObsAuxIncrement", "operator+=ObsAuxControl");
78  xx.obsauxcontrol() += dx.obsauxincrement();
79  Log::trace() << "operator+=(ObsAuxControl, ObsAuxIncrement) done" << std::endl;
80  return xx;
81 }
82 
83 // =============================================================================
84 
85 template<typename MODEL>
86 ObsAuxIncrement<MODEL>::ObsAuxIncrement(const eckit::Configuration & conf) : aux_()
87 {
88  Log::trace() << "ObsAuxIncrement<MODEL>::ObsAuxIncrement starting" << std::endl;
89  util::Timer timer(classname(), "ObsAuxIncrement");
90  aux_.reset(new ObsAuxIncrement_(conf));
91  Log::trace() << "ObsAuxIncrement<MODEL>::ObsAuxIncrement done" << std::endl;
92 }
93 // -----------------------------------------------------------------------------
94 template<typename MODEL>
96  const bool copy) : aux_()
97 {
98  Log::trace() << "ObsAuxIncrement<MODEL>::ObsAuxIncrement copy starting" << std::endl;
99  util::Timer timer(classname(), "ObsAuxIncrement");
100  aux_.reset(new ObsAuxIncrement_(*other.aux_, copy));
101  Log::trace() << "ObsAuxIncrement<MODEL>::ObsAuxIncrement copy done" << std::endl;
102 }
103 // -----------------------------------------------------------------------------
104 template<typename MODEL>
106  const eckit::Configuration & conf) : aux_()
107 {
108  Log::trace() << "ObsAuxIncrement<MODEL>::ObsAuxIncrement interpolated starting" << std::endl;
109  util::Timer timer(classname(), "ObsAuxIncrement");
110  aux_.reset(new ObsAuxIncrement_(*other.aux_, conf));
111  Log::trace() << "ObsAuxIncrement<MODEL>::ObsAuxIncrement interpolated done" << std::endl;
112 }
113 // -----------------------------------------------------------------------------
114 template<typename MODEL>
116  Log::trace() << "ObsAuxIncrement<MODEL>::~ObsAuxIncrement starting" << std::endl;
117  util::Timer timer(classname(), "~ObsAuxIncrement");
118  aux_.reset();
119  Log::trace() << "ObsAuxIncrement<MODEL>::~ObsAuxIncrement done" << std::endl;
120 }
121 // -----------------------------------------------------------------------------
122 template<typename MODEL>
124  Log::trace() << "ObsAuxIncrement<MODEL>::diff starting" << std::endl;
125  util::Timer timer(classname(), "diff");
126  aux_->diff(x1.obsauxcontrol(), x2.obsauxcontrol());
127  Log::trace() << "ObsAuxIncrement<MODEL>::diff done" << std::endl;
128 }
129 // -----------------------------------------------------------------------------
130 template<typename MODEL>
132  Log::trace() << "ObsAuxIncrement<MODEL>::zero starting" << std::endl;
133  util::Timer timer(classname(), "zero");
134  aux_->zero();
135  Log::trace() << "ObsAuxIncrement<MODEL>::zero done" << std::endl;
136 }
137 // -----------------------------------------------------------------------------
138 template<typename MODEL>
140  Log::trace() << "ObsAuxIncrement<MODEL>::operator= starting" << std::endl;
141  util::Timer timer(classname(), "operator=");
142  *aux_ = *rhs.aux_;
143  Log::trace() << "ObsAuxIncrement<MODEL>::operator= done" << std::endl;
144  return *this;
145 }
146 // -----------------------------------------------------------------------------
147 template<typename MODEL>
149  Log::trace() << "ObsAuxIncrement<MODEL>::operator+= starting" << std::endl;
150  util::Timer timer(classname(), "operator+=");
151  *aux_ += *rhs.aux_;
152  Log::trace() << "ObsAuxIncrement<MODEL>::operator+= done" << std::endl;
153  return *this;
154 }
155 // -----------------------------------------------------------------------------
156 template<typename MODEL>
158  Log::trace() << "ObsAuxIncrement<MODEL>::operator-= starting" << std::endl;
159  util::Timer timer(classname(), "operator-=");
160  *aux_ -= *rhs.aux_;
161  Log::trace() << "ObsAuxIncrement<MODEL>::operator-= done" << std::endl;
162  return *this;
163 }
164 // -----------------------------------------------------------------------------
165 template<typename MODEL>
167  Log::trace() << "ObsAuxIncrement<MODEL>::operator*= starting" << std::endl;
168  util::Timer timer(classname(), "operator*=");
169  *aux_ *= zz;
170  Log::trace() << "ObsAuxIncrement<MODEL>::operator*= done" << std::endl;
171  return *this;
172 }
173 // -----------------------------------------------------------------------------
174 template<typename MODEL>
175 void ObsAuxIncrement<MODEL>::axpy(const double & zz, const ObsAuxIncrement & dx) {
176  Log::trace() << "ObsAuxIncrement<MODEL>::axpy starting" << std::endl;
177  util::Timer timer(classname(), "axpy");
178  aux_->axpy(zz, *dx.aux_);
179  Log::trace() << "ObsAuxIncrement<MODEL>::axpy done" << std::endl;
180 }
181 // -----------------------------------------------------------------------------
182 template<typename MODEL>
184  Log::trace() << "ObsAuxIncrement<MODEL>::dot_product_with starting" << std::endl;
185  util::Timer timer(classname(), "dot_product_with");
186  double zz = aux_->dot_product_with(*dx.aux_);
187  Log::trace() << "ObsAuxIncrement<MODEL>::dot_product_with done" << std::endl;
188  return zz;
189 }
190 // -----------------------------------------------------------------------------
191 template<typename MODEL>
192 void ObsAuxIncrement<MODEL>::read(const eckit::Configuration & conf) {
193  Log::trace() << "ObsAuxIncrement<MODEL>::read starting" << std::endl;
194  util::Timer timer(classname(), "read");
195  aux_->read(conf);
196  Log::trace() << "ObsAuxIncrement<MODEL>::read done" << std::endl;
197 }
198 // -----------------------------------------------------------------------------
199 template<typename MODEL>
200 void ObsAuxIncrement<MODEL>::write(const eckit::Configuration & conf) const {
201  Log::trace() << "ObsAuxIncrement<MODEL>::write starting" << std::endl;
202  util::Timer timer(classname(), "write");
203  aux_->write(conf);
204  Log::trace() << "ObsAuxIncrement<MODEL>::write done" << std::endl;
205 }
206 // -----------------------------------------------------------------------------
207 template<typename MODEL>
209  Log::trace() << "ObsAuxIncrement<MODEL>::norm starting" << std::endl;
210  util::Timer timer(classname(), "norm");
211  double zz = aux_->norm();
212  Log::trace() << "ObsAuxIncrement<MODEL>::norm done" << std::endl;
213  return zz;
214 }
215 // -----------------------------------------------------------------------------
216 template<typename MODEL>
217 void ObsAuxIncrement<MODEL>::print(std::ostream & os) const {
218  Log::trace() << "ObsAuxIncrement<MODEL>::print starting" << std::endl;
219  util::Timer timer(classname(), "print");
220  os << *aux_;
221  Log::trace() << "ObsAuxIncrement<MODEL>::print done" << std::endl;
222 }
223 // -----------------------------------------------------------------------------
224 
225 } // namespace oops
226 
227 #endif // OOPS_INTERFACE_OBSAUXINCREMENT_H_
ObsAuxIncrement(const eckit::Configuration &)
Constructor, destructor.
MODEL::ObsAuxIncrement ObsAuxIncrement_
ObsAuxIncrement & operator-=(const ObsAuxIncrement &)
void diff(const ObsAuxControl_ &, const ObsAuxControl_ &)
Linear algebra operators.
double dot_product_with(const ObsAuxIncrement &) const
subroutine, public copy(self, rhs)
Definition: conf.py:1
ObsAuxIncrement & operator+=(const ObsAuxIncrement &)
const ObsAuxIncrement_ & obsauxincrement() const
Interfacing.
State< MODEL > & operator+=(State< MODEL > &xx, const Increment< MODEL > &dx)
The namespace for the main oops code.
ObsAuxIncrement & operator=(const ObsAuxIncrement &)
static const std::string classname()
void print(std::ostream &) const
ObsAuxControl< MODEL > ObsAuxControl_
boost::scoped_ptr< ObsAuxIncrement_ > aux_
void read(const eckit::Configuration &)
I/O and diagnostics.
ObsAuxIncrement & operator*=(const double &)
void axpy(const double &, const ObsAuxIncrement &)
void write(const eckit::Configuration &) const
const ObsAuxControl_ & obsauxcontrol() const
Interfacing.