FV3 Bundle
oops/interface/ObsErrorCovariance.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_OBSERRORCOVARIANCE_H_
12 #define OOPS_INTERFACE_OBSERRORCOVARIANCE_H_
13 
14 #include <string>
15 
16 #include <boost/noncopyable.hpp>
17 #include <boost/scoped_ptr.hpp>
18 
22 #include "oops/util/Printable.h"
23 
24 namespace eckit {
25  class Configuration;
26 }
27 
28 namespace oops {
29 
30 // -----------------------------------------------------------------------------
31 /// Observation error covariance matrix
32 /*!
33  * This class provides the operations associated with the observation
34  * error covariance matrix. It wraps the actual observation error covariance
35  * which can be a model specific one or a generic one.
36  * The interface for the observation error comprises two levels (ObsErrorCovariance
37  * and ObsErrorBase) because we want run time polymorphism.
38  * The ObsErrorCovariance does conversion of arguments to templated ObsVector and
39  * the tracing and timing. The ObsErrorBase does the conversion to model specific
40  * ObsVector.
41  */
42 
43 template <typename MODEL>
44 class ObsErrorCovariance : public util::Printable,
45  private util::ObjectCounter<ObsErrorCovariance<MODEL> >,
46  private boost::noncopyable {
50 
51  public:
52  static const std::string classname() {return "oops::ObsErrorCovariance";}
53 
54  ObsErrorCovariance(const ObsSpace_ &, const eckit::Configuration &);
56 
57 /// Linearize and reset for inner loop if needed
58  void linearize(const ObsVector_ &);
59 
60 /// Multiply a Departure by \f$R\f$ and \f$R^{-1}\f$
61  ObsVector_ * multiply(const ObsVector_ &) const;
62  ObsVector_ * inverseMultiply(const ObsVector_ &) const;
63 
64 /// Generate random perturbation
65  void randomize(ObsVector_ &) const;
66 
67 /// Get mean error for Jo table
68  double getRMSE() const;
69 
70  private:
71  void print(std::ostream &) const;
72  boost::scoped_ptr<ObsErrorBase_> covar_;
73 };
74 
75 // ====================================================================================
76 
77 template <typename MODEL>
79  const eckit::Configuration & conf)
80  : covar_()
81 {
82  Log::trace() << "ObsErrorCovariance<MODEL>::ObsErrorCovariance starting" << std::endl;
83  util::Timer timer(classname(), "ObsErrorCovariance");
85  Log::trace() << "ObsErrorCovariance<MODEL>::ObsErrorCovariance done" << std::endl;
86 }
87 
88 // -----------------------------------------------------------------------------
89 
90 template <typename MODEL>
92  Log::trace() << "ObsErrorCovariance<MODEL>::~ObsErrorCovariance starting" << std::endl;
93  util::Timer timer(classname(), "~ObsErrorCovariance");
94  covar_.reset();
95  Log::trace() << "ObsErrorCovariance<MODEL>::~ObsErrorCovariance done" << std::endl;
96 }
97 
98 // -----------------------------------------------------------------------------
99 
100 template <typename MODEL>
102  Log::trace() << "ObsErrorCovariance<MODEL>::linearize starting" << std::endl;
103  util::Timer timer(classname(), "linearize");
104  covar_->linearize(yy.obsvector());
105  Log::trace() << "ObsErrorCovariance<MODEL>::linearize done" << std::endl;
106 }
107 
108 // -----------------------------------------------------------------------------
109 
110 template <typename MODEL>
112  Log::trace() << "ObsErrorCovariance<MODEL>::multiply starting" << std::endl;
113  util::Timer timer(classname(), "multiply");
114  ObsVector_ * dz = new ObsVector_(covar_->multiply(dy.obsvector()));
115  Log::trace() << "ObsErrorCovariance<MODEL>::multiply done" << std::endl;
116  return dz;
117 }
118 
119 // -----------------------------------------------------------------------------
120 
121 template <typename MODEL>
123  Log::trace() << "ObsErrorCovariance<MODEL>::inverseMultiply starting" << std::endl;
124  util::Timer timer(classname(), "inverseMultiply");
125  ObsVector_ * dz = new ObsVector_(covar_->inverseMultiply(dy.obsvector()));
126  Log::trace() << "ObsErrorCovariance<MODEL>::inverseMultiply done" << std::endl;
127  return dz;
128 }
129 
130 // -----------------------------------------------------------------------------
131 
132 template <typename MODEL>
134  Log::trace() << "ObsErrorCovariance<MODEL>::randomize starting" << std::endl;
135  util::Timer timer(classname(), "randomize");
136  covar_->randomize(dy.obsvector());
137  Log::trace() << "ObsErrorCovariance<MODEL>::randomize done" << std::endl;
138 }
139 
140 // -----------------------------------------------------------------------------
141 
142 template <typename MODEL>
144  Log::trace() << "ObsErrorCovariance<MODEL>::getRMSE starting" << std::endl;
145  util::Timer timer(classname(), "getRMSE");
146  double zz = covar_->getRMSE();
147  Log::trace() << "ObsErrorCovariance<MODEL>::getRMSE done" << std::endl;
148  return zz;
149 }
150 
151 // -----------------------------------------------------------------------------
152 
153 template<typename MODEL>
154 void ObsErrorCovariance<MODEL>::print(std::ostream & os) const {
155  Log::trace() << "ObsErrorCovariance<MODEL>::print starting" << std::endl;
156  util::Timer timer(classname(), "print");
157  os << *covar_;
158  Log::trace() << "ObsErrorCovariance<MODEL>::print done" << std::endl;
159 }
160 
161 // -----------------------------------------------------------------------------
162 
163 } // namespace oops
164 
165 #endif // OOPS_INTERFACE_OBSERRORCOVARIANCE_H_
void randomize(ObsVector_ &) const
Generate random perturbation.
Definition: conf.py:1
void linearize(const ObsVector_ &)
Linearize and reset for inner loop if needed.
The namespace for the main oops code.
ObsVector_ & obsvector()
Interfacing.
double getRMSE() const
Get mean error for Jo table.
ObsErrorCovariance(const ObsSpace_ &, const eckit::Configuration &)
boost::scoped_ptr< ObsErrorBase_ > covar_
ObsErrorFactory Factory.
Definition: ObsErrorBase.h:65
Base class for observation error covariance matrices.
Definition: ObsErrorBase.h:39
Observation error covariance matrix.
ObsVector_ * inverseMultiply(const ObsVector_ &) const
ObsVector_ * multiply(const ObsVector_ &) const
Multiply a Departure by and .