FV3 Bundle
oops/interface/ErrorCovariance.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_ERRORCOVARIANCE_H_
12 #define OOPS_INTERFACE_ERRORCOVARIANCE_H_
13 
14 #include <string>
15 
16 #include <boost/noncopyable.hpp>
17 #include <boost/scoped_ptr.hpp>
18 
20 #include "oops/base/Variables.h"
23 #include "oops/interface/State.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/ObjectCounter.h"
26 #include "oops/util/Printable.h"
27 #include "oops/util/Timer.h"
28 
29 namespace eckit {
30  class Configuration;
31 }
32 
33 namespace oops {
34 
35 // -----------------------------------------------------------------------------
36 
37 // Should factory be here and generic covariances wrtten at the MODEL::Increment level? YT
38 
39 /// Wrapper for model space error covariances.
40 /*!
41  * This class provides the operations associated with the model space error
42  * covariance matrices (B or Q). It wraps the actual error covariance matrix
43  * which can be a model specific one or a generic one.
44  */
45 
46 template <typename MODEL>
48  public util::Printable,
49  private util::ObjectCounter<ErrorCovariance<MODEL> >,
50  private boost::noncopyable {
51  typedef typename MODEL::Covariance Covariance_;
55 
56  public:
57  static const std::string classname() {return "oops::ErrorCovariance";}
58 
59  ErrorCovariance(const Geometry_ &, const Variables &, const eckit::Configuration &,
60  const State_ &, const State_ &);
61  virtual ~ErrorCovariance();
62 
63  void randomize(Increment_ &) const override;
64 
65  private:
66  void doMultiply(const Increment_ &, Increment_ &) const override;
67  void doInverseMultiply(const Increment_ &, Increment_ &) const override;
68 
69  void print(std::ostream &) const override;
70 
71  boost::scoped_ptr<Covariance_> covariance_;
72 };
73 
74 // =============================================================================
75 
76 template<typename MODEL>
78  const eckit::Configuration & conf,
79  const State_ & xb, const State_ & fg)
80  : ModelSpaceCovarianceBase<MODEL>(xb, fg, resol, conf), covariance_()
81 {
82  Log::trace() << "ErrorCovariance<MODEL>::ErrorCovariance starting" << std::endl;
83  util::Timer timer(classname(), "ErrorCovariance");
84  covariance_.reset(new Covariance_(resol.geometry(), vars, conf, xb.state(), fg.state()));
85  Log::trace() << "ErrorCovariance<MODEL>::ErrorCovariance done" << std::endl;
86 }
87 
88 // -----------------------------------------------------------------------------
89 
90 template<typename MODEL>
92  Log::trace() << "ErrorCovariance<MODEL>::~ErrorCovariance starting" << std::endl;
93  util::Timer timer(classname(), "~ErrorCovariance");
94  covariance_.reset();
95  Log::trace() << "ErrorCovariance<MODEL>::~ErrorCovariance done" << std::endl;
96 }
97 
98 // -----------------------------------------------------------------------------
99 
100 template<typename MODEL>
102  Log::trace() << "ErrorCovariance<MODEL>::doMultiply starting" << std::endl;
103  util::Timer timer(classname(), "doMultiply");
104  covariance_->multiply(dx1.increment(), dx2.increment());
105  Log::trace() << "ErrorCovariance<MODEL>::doMultiply done" << std::endl;
106 }
107 
108 // -----------------------------------------------------------------------------
109 
110 template<typename MODEL>
112  Log::trace() << "ErrorCovariance<MODEL>::doInverseMultiply starting" << std::endl;
113  util::Timer timer(classname(), "doInverseMultiply");
114  covariance_->inverseMultiply(dx1.increment(), dx2.increment());
115  Log::trace() << "ErrorCovariance<MODEL>::doInverseMultiply done" << std::endl;
116 }
117 
118 // -----------------------------------------------------------------------------
119 
120 template<typename MODEL>
122  Log::trace() << "ErrorCovariance<MODEL>::randomize starting" << std::endl;
123  util::Timer timer(classname(), "randomize");
124  covariance_->randomize(dx.increment());
125  Log::trace() << "ErrorCovariance<MODEL>::randomize done" << std::endl;
126 }
127 
128 // -----------------------------------------------------------------------------
129 
130 template<typename MODEL>
131 void ErrorCovariance<MODEL>::print(std::ostream & os) const {
132  Log::trace() << "ErrorCovariance<MODEL>::print starting" << std::endl;
133  util::Timer timer(classname(), "print");
134  os << *covariance_;
135  Log::trace() << "ErrorCovariance<MODEL>::print done" << std::endl;
136 }
137 
138 // -----------------------------------------------------------------------------
139 
140 } // namespace oops
141 
142 #endif // OOPS_INTERFACE_ERRORCOVARIANCE_H_
void doInverseMultiply(const Increment_ &, Increment_ &) const override
void print(std::ostream &) const override
Definition: conf.py:1
Wrapper for model space error covariances.
Encapsulates the model state.
State_ & state()
Interfacing.
void doMultiply(const Increment_ &, Increment_ &) const override
The namespace for the main oops code.
real(fp), parameter xb
Definition: ufo_aod_mod.F90:41
ErrorCovariance(const Geometry_ &, const Variables &, const eckit::Configuration &, const State_ &, const State_ &)
Increment_ & increment()
Interfacing.
Abstract base class for model space error covariances.
boost::scoped_ptr< Covariance_ > covariance_
const Geometry_ & geometry() const
Interfacing.
static const std::string classname()
Increment Class: Difference between two states.
void randomize(Increment_ &) const override