FV3 Bundle
oops/interface/LinearVariableChange.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018 UCAR
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  */
7 
8 #ifndef OOPS_INTERFACE_LINEARVARIABLECHANGE_H_
9 #define OOPS_INTERFACE_LINEARVARIABLECHANGE_H_
10 
11 #include <string>
12 
13 #include <boost/noncopyable.hpp>
14 #include <boost/scoped_ptr.hpp>
15 
17 #include "oops/base/Variables.h"
20 #include "oops/interface/State.h"
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 /// Wrapper for change of variable
34 
35 template <typename MODEL, typename CHVAR>
40 
41  public:
42  static const std::string classname() {return "oops::LinearVariableChange";}
43 
44  LinearVariableChange(const State_ &, const State_ &,
45  const Geometry_ &, const eckit::Configuration &);
46  virtual ~LinearVariableChange();
47 
48  void multiply(const Increment_ &, Increment_ &) const override;
49  void multiplyInverse(const Increment_ &, Increment_ &) const override;
50  void multiplyAD(const Increment_ &, Increment_ &) const override;
51  void multiplyInverseAD(const Increment_ &, Increment_ &) const override;
52 
53  private:
54  void print(std::ostream &) const override;
55 
56  boost::scoped_ptr<CHVAR> chvar_;
57 };
58 
59 // =============================================================================
60 
61 template<typename MODEL, typename CHVAR>
63  const Geometry_ & geom,
64  const eckit::Configuration & conf)
65  : LinearVariableChangeBase<MODEL>(conf), chvar_()
66 {
67  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::LinearVariableChange starting" << std::endl;
68  util::Timer timer(classname(), "LinearVariableChange");
69  chvar_.reset(new CHVAR(bg.state(), fg.state(), geom.geometry(), conf));
70  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::LinearVariableChange done" << std::endl;
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 template<typename MODEL, typename CHVAR>
77  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::~LinearVariableChange starting" << std::endl;
78  util::Timer timer(classname(), "~LinearVariableChange");
79  chvar_.reset();
80  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::~LinearVariableChange done" << std::endl;
81 }
82 
83 // -----------------------------------------------------------------------------
84 
85 template<typename MODEL, typename CHVAR>
87  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiply starting" << std::endl;
88  util::Timer timer(classname(), "multiply");
89  chvar_->multiply(dx1.increment(), dx2.increment());
90  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiply done" << std::endl;
91 }
92 
93 // -----------------------------------------------------------------------------
94 
95 template<typename MODEL, typename CHVAR>
97  Increment_ & dx2) const {
98  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverse starting" << std::endl;
99  util::Timer timer(classname(), "multiplyInverse");
100  chvar_->multiplyInverse(dx1.increment(), dx2.increment());
101  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverse done" << std::endl;
102 }
103 
104 // -----------------------------------------------------------------------------
105 
106 template<typename MODEL, typename CHVAR>
108  Increment_ & dx2) const {
109  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyAD starting" << std::endl;
110  util::Timer timer(classname(), "multiplyAD");
111  chvar_->multiplyAD(dx1.increment(), dx2.increment());
112  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyAD done" << std::endl;
113 }
114 
115 // -----------------------------------------------------------------------------
116 
117 template<typename MODEL, typename CHVAR>
119  Increment_ & dx2) const {
120  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverseAD starting" << std::endl;
121  util::Timer timer(classname(), "multiplyInverseAD");
122  chvar_->multiplyInverseAD(dx1.increment(), dx2.increment());
123  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverseAD done" << std::endl;
124 }
125 
126 // -----------------------------------------------------------------------------
127 
128 template<typename MODEL, typename CHVAR>
129 void LinearVariableChange<MODEL, CHVAR>::print(std::ostream & os) const {
130  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::print starting" << std::endl;
131  util::Timer timer(classname(), "print");
132  os << *chvar_;
133  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::print done" << std::endl;
134 }
135 
136 // -----------------------------------------------------------------------------
137 
138 } // namespace oops
139 
140 #endif // OOPS_INTERFACE_LINEARVARIABLECHANGE_H_
Definition: conf.py:1
void multiply(const Increment_ &, Increment_ &) const override
Encapsulates the model state.
State_ & state()
Interfacing.
The namespace for the main oops code.
Base class for generic variable transform.
Wrapper for change of variable.
Increment_ & increment()
Interfacing.
const Geometry_ & geometry() const
Interfacing.
Increment Class: Difference between two states.
void multiplyInverseAD(const Increment_ &, Increment_ &) const override
void print(std::ostream &) const override
void multiplyInverse(const Increment_ &, Increment_ &) const override
LinearVariableChange(const State_ &, const State_ &, const Geometry_ &, const eckit::Configuration &)
void multiplyAD(const Increment_ &, Increment_ &) const override