OOPS
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 <memory>
12 #include <string>
13 
14 #include <boost/noncopyable.hpp>
15 
16 #include "oops/base/Geometry.h"
17 #include "oops/base/Increment.h"
19 #include "oops/base/State.h"
20 #include "oops/base/Variables.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  /// Defined as CHVAR::Parameters_ if CHVAR defines a Parameters_ type; otherwise as
43  /// GenericLinearVariableChangeParameters
44  typedef TParameters_IfAvailableElseFallbackType_t<
46 
47  static const std::string classname() {return "oops::LinearVariableChange";}
48 
49  LinearVariableChange(const State_ &, const State_ &,
50  const Geometry_ &, const Parameters_ &);
51  virtual ~LinearVariableChange();
52 
53  void multiply(const Increment_ &, Increment_ &) const override;
54  void multiplyInverse(const Increment_ &, Increment_ &) const override;
55  void multiplyAD(const Increment_ &, Increment_ &) const override;
56  void multiplyInverseAD(const Increment_ &, Increment_ &) const override;
57 
58  private:
59  void print(std::ostream &) const override;
60 
61  std::unique_ptr<CHVAR> chvar_;
62 };
63 
64 // =============================================================================
65 
66 template<typename MODEL, typename CHVAR>
68  const Geometry_ & geom,
69  const Parameters_ & params)
70  : LinearVariableChangeBase<MODEL>(params), chvar_()
71 {
72  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::LinearVariableChange starting" << std::endl;
73  util::Timer timer(classname(), "LinearVariableChange");
74  chvar_.reset(new CHVAR(bg.state(), fg.state(), geom.geometry(),
75  parametersOrConfiguration<HasParameters_<CHVAR>::value>(params)));
76  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::LinearVariableChange done" << std::endl;
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 template<typename MODEL, typename CHVAR>
83  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::~LinearVariableChange starting" << std::endl;
84  util::Timer timer(classname(), "~LinearVariableChange");
85  chvar_.reset();
86  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::~LinearVariableChange done" << std::endl;
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 template<typename MODEL, typename CHVAR>
93  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiply starting" << std::endl;
94  util::Timer timer(classname(), "multiply");
95  chvar_->multiply(dx1.increment(), dx2.increment());
96  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiply done" << std::endl;
97 }
98 
99 // -----------------------------------------------------------------------------
100 
101 template<typename MODEL, typename CHVAR>
103  Increment_ & dx2) const {
104  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverse starting" << std::endl;
105  util::Timer timer(classname(), "multiplyInverse");
106  chvar_->multiplyInverse(dx1.increment(), dx2.increment());
107  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverse done" << std::endl;
108 }
109 
110 // -----------------------------------------------------------------------------
111 
112 template<typename MODEL, typename CHVAR>
114  Increment_ & dx2) const {
115  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyAD starting" << std::endl;
116  util::Timer timer(classname(), "multiplyAD");
117  chvar_->multiplyAD(dx1.increment(), dx2.increment());
118  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyAD done" << std::endl;
119 }
120 
121 // -----------------------------------------------------------------------------
122 
123 template<typename MODEL, typename CHVAR>
125  Increment_ & dx2) const {
126  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverseAD starting" << std::endl;
127  util::Timer timer(classname(), "multiplyInverseAD");
128  chvar_->multiplyInverseAD(dx1.increment(), dx2.increment());
129  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::multiplyInverseAD done" << std::endl;
130 }
131 
132 // -----------------------------------------------------------------------------
133 
134 template<typename MODEL, typename CHVAR>
135 void LinearVariableChange<MODEL, CHVAR>::print(std::ostream & os) const {
136  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::print starting" << std::endl;
137  util::Timer timer(classname(), "print");
138  os << *chvar_;
139  Log::trace() << "LinearVariableChange<MODEL, CHVAR>::print done" << std::endl;
140 }
141 
142 // -----------------------------------------------------------------------------
143 
144 } // namespace oops
145 
146 #endif // OOPS_INTERFACE_LINEARVARIABLECHANGE_H_
A subclass of LinearVariableChangeParametersBase storing the values of all options in a single Config...
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
TParameters_IfAvailableElseFallbackType_t< CHVAR, GenericLinearVariableChangeParameters > Parameters_
void multiplyInverse(const Increment_ &, Increment_ &) const override
LinearVariableChange(const State_ &, const State_ &, const Geometry_ &, const Parameters_ &)
void multiply(const Increment_ &, Increment_ &) const override
void multiplyAD(const Increment_ &, Increment_ &) const override
void print(std::ostream &) const override
void multiplyInverseAD(const Increment_ &, Increment_ &) const override
State class used in oops; subclass of interface class interface::State.
const Geometry_ & geometry() const
const Increment_ & increment() const
State_ & state()
Accessor.
Definition: FieldL95.h:22
The namespace for the main oops code.