FV3 Bundle
oops/interface/ModelAuxIncrement.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_MODELAUXINCREMENT_H_
12 #define OOPS_INTERFACE_MODELAUXINCREMENT_H_
13 
14 #include <iostream>
15 #include <string>
16 
17 #include <boost/scoped_ptr.hpp>
18 
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 oops {
31 
32 // -----------------------------------------------------------------------------
33 
34 template <typename MODEL>
35 class ModelAuxIncrement : public util::Printable,
36  private util::ObjectCounter<ModelAuxIncrement<MODEL> > {
37  typedef typename MODEL::ModelAuxIncrement ModelAuxIncrement_;
40 
41  public:
42  static const std::string classname() {return "oops::ModelAuxIncrement";}
43 
44 /// Constructor, destructor
45  ModelAuxIncrement(const Geometry_ &, const eckit::Configuration &);
46  explicit ModelAuxIncrement(const ModelAuxIncrement &, const bool copy = true);
47  ModelAuxIncrement(const ModelAuxIncrement &, const eckit::Configuration &);
49 
50 /// Interfacing
51  const ModelAuxIncrement_ & modelauxincrement() const {return *aux_;}
53 
54 /// Linear algebra operators
55  void diff(const ModelAuxControl_ &, const ModelAuxControl_ &);
56  void zero();
60  ModelAuxIncrement & operator*=(const double &);
61  void axpy(const double &, const ModelAuxIncrement &);
62  double dot_product_with(const ModelAuxIncrement &) const;
63 
64 /// I/O and diagnostics
65  void read(const eckit::Configuration &);
66  void write(const eckit::Configuration &) const;
67  double norm() const;
68 
69  private:
70  void print(std::ostream &) const;
71  boost::scoped_ptr<ModelAuxIncrement_> aux_;
72 };
73 
74 // -----------------------------------------------------------------------------
75 
76 template <typename MODEL>
78  const ModelAuxIncrement<MODEL> & dx) {
79  Log::trace() << "operator+=(ModelAuxControl, ModelAuxIncrement) starting" << std::endl;
80  util::Timer timer("oops::ModelAuxIncrement", "operator+=ModelAuxControl");
82  Log::trace() << "operator+=(ModelAuxControl, ModelAuxIncrement) done" << std::endl;
83  return xx;
84 }
85 
86 // =============================================================================
87 
88 template<typename MODEL>
90  const eckit::Configuration & conf) : aux_()
91 {
92  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement starting" << std::endl;
93  util::Timer timer(classname(), "ModelAuxIncrement");
94  aux_.reset(new ModelAuxIncrement_(resol.geometry(), conf));
95  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement done" << std::endl;
96 }
97 // -----------------------------------------------------------------------------
98 template<typename MODEL>
100  const bool copy) : aux_()
101 {
102  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement copy starting" << std::endl;
103  util::Timer timer(classname(), "ModelAuxIncrement");
104  aux_.reset(new ModelAuxIncrement_(*other.aux_, copy));
105  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement copy done" << std::endl;
106 }
107 // -----------------------------------------------------------------------------
108 template<typename MODEL>
110  const eckit::Configuration & conf) : aux_()
111 {
112  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement interpolated starting" << std::endl;
113  util::Timer timer(classname(), "ModelAuxIncrement");
114  aux_.reset(new ModelAuxIncrement_(*other.aux_, conf));
115  Log::trace() << "ModelAuxIncrement<MODEL>::ModelAuxIncrement interpolated done" << std::endl;
116 }
117 // -----------------------------------------------------------------------------
118 template<typename MODEL>
120  Log::trace() << "ModelAuxIncrement<MODEL>::~ModelAuxIncrement starting" << std::endl;
121  util::Timer timer(classname(), "~ModelAuxIncrement");
122  aux_.reset();
123  Log::trace() << "ModelAuxIncrement<MODEL>::~ModelAuxIncrement done" << std::endl;
124 }
125 // -----------------------------------------------------------------------------
126 template<typename MODEL>
128  Log::trace() << "ModelAuxIncrement<MODEL>::diff starting" << std::endl;
129  util::Timer timer(classname(), "diff");
130  aux_->diff(x1.modelauxcontrol(), x2.modelauxcontrol());
131  Log::trace() << "ModelAuxIncrement<MODEL>::diff done" << std::endl;
132 }
133 // -----------------------------------------------------------------------------
134 template<typename MODEL>
136  Log::trace() << "ModelAuxIncrement<MODEL>::zero starting" << std::endl;
137  util::Timer timer(classname(), "zero");
138  aux_->zero();
139  Log::trace() << "ModelAuxIncrement<MODEL>::zero done" << std::endl;
140 }
141 // -----------------------------------------------------------------------------
142 template<typename MODEL>
144  Log::trace() << "ModelAuxIncrement<MODEL>::operator= starting" << std::endl;
145  util::Timer timer(classname(), "operator=");
146  *aux_ = *rhs.aux_;
147  Log::trace() << "ModelAuxIncrement<MODEL>::operator= done" << std::endl;
148  return *this;
149 }
150 // -----------------------------------------------------------------------------
151 template<typename MODEL>
153  Log::trace() << "ModelAuxIncrement<MODEL>::operator+= starting" << std::endl;
154  util::Timer timer(classname(), "operator+=");
155  *aux_ += *rhs.aux_;
156  Log::trace() << "ModelAuxIncrement<MODEL>::operator+= done" << std::endl;
157  return *this;
158 }
159 // -----------------------------------------------------------------------------
160 template<typename MODEL>
162  Log::trace() << "ModelAuxIncrement<MODEL>::operator-= starting" << std::endl;
163  util::Timer timer(classname(), "operator-=");
164  *aux_ -= *rhs.aux_;
165  Log::trace() << "ModelAuxIncrement<MODEL>::operator-= done" << std::endl;
166  return *this;
167 }
168 // -----------------------------------------------------------------------------
169 template<typename MODEL>
171  Log::trace() << "ModelAuxIncrement<MODEL>::operator*= starting" << std::endl;
172  util::Timer timer(classname(), "operator*=");
173  *aux_ *= zz;
174  Log::trace() << "ModelAuxIncrement<MODEL>::operator*= done" << std::endl;
175  return *this;
176 }
177 // -----------------------------------------------------------------------------
178 template<typename MODEL>
179 void ModelAuxIncrement<MODEL>::axpy(const double & zz, const ModelAuxIncrement & dx) {
180  Log::trace() << "ModelAuxIncrement<MODEL>::axpy starting" << std::endl;
181  util::Timer timer(classname(), "axpy");
182  aux_->axpy(zz, *dx.aux_);
183  Log::trace() << "ModelAuxIncrement<MODEL>::axpy done" << std::endl;
184 }
185 // -----------------------------------------------------------------------------
186 template<typename MODEL>
188  Log::trace() << "ModelAuxIncrement<MODEL>::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() << "ModelAuxIncrement<MODEL>::dot_product_with done" << std::endl;
192  return zz;
193 }
194 // -----------------------------------------------------------------------------
195 template<typename MODEL>
196 void ModelAuxIncrement<MODEL>::read(const eckit::Configuration & conf) {
197  Log::trace() << "ModelAuxIncrement<MODEL>::read starting" << std::endl;
198  util::Timer timer(classname(), "read");
199  aux_->read(conf);
200  Log::trace() << "ModelAuxIncrement<MODEL>::read done" << std::endl;
201 }
202 // -----------------------------------------------------------------------------
203 template<typename MODEL>
204 void ModelAuxIncrement<MODEL>::write(const eckit::Configuration & conf) const {
205  Log::trace() << "ModelAuxIncrement<MODEL>::write starting" << std::endl;
206  util::Timer timer(classname(), "write");
207  aux_->write(conf);
208  Log::trace() << "ModelAuxIncrement<MODEL>::write done" << std::endl;
209 }
210 // -----------------------------------------------------------------------------
211 template<typename MODEL>
213  Log::trace() << "ModelAuxIncrement<MODEL>::norm starting" << std::endl;
214  util::Timer timer(classname(), "norm");
215  double zz = aux_->norm();
216  Log::trace() << "ModelAuxIncrement<MODEL>::norm done" << std::endl;
217  return zz;
218 }
219 // -----------------------------------------------------------------------------
220 template<typename MODEL>
221 void ModelAuxIncrement<MODEL>::print(std::ostream & os) const {
222  Log::trace() << "ModelAuxIncrement<MODEL>::print starting" << std::endl;
223  util::Timer timer(classname(), "print");
224  os << *aux_;
225  Log::trace() << "ModelAuxIncrement<MODEL>::print done" << std::endl;
226 }
227 // -----------------------------------------------------------------------------
228 
229 } // namespace oops
230 
231 #endif // OOPS_INTERFACE_MODELAUXINCREMENT_H_
void read(const eckit::Configuration &)
I/O and diagnostics.
double dot_product_with(const ModelAuxIncrement &) const
ModelAuxIncrement & operator*=(const double &)
subroutine, public copy(self, rhs)
Definition: conf.py:1
void diff(const ModelAuxControl_ &, const ModelAuxControl_ &)
Linear algebra operators.
State< MODEL > & operator+=(State< MODEL > &xx, const Increment< MODEL > &dx)
The namespace for the main oops code.
ModelAuxControl< MODEL > ModelAuxControl_
ModelAuxIncrement(const Geometry_ &, const eckit::Configuration &)
Constructor, destructor.
ModelAuxIncrement & operator=(const ModelAuxIncrement &)
void write(const eckit::Configuration &) const
void axpy(const double &, const ModelAuxIncrement &)
const ModelAuxControl_ & modelauxcontrol() const
Interfacing.
static const std::string classname()
const Geometry_ & geometry() const
Interfacing.
const ModelAuxIncrement_ & modelauxincrement() const
Interfacing.
ModelAuxIncrement & operator-=(const ModelAuxIncrement &)
MODEL::ModelAuxIncrement ModelAuxIncrement_
boost::scoped_ptr< ModelAuxIncrement_ > aux_
ModelAuxIncrement & operator+=(const ModelAuxIncrement &)