FV3 Bundle
ObsErrors.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_BASE_OBSERRORS_H_
12 #define OOPS_BASE_OBSERRORS_H_
13 
14 #include <string>
15 #include <vector>
16 
17 #include <boost/noncopyable.hpp>
18 #include <boost/shared_ptr.hpp>
19 
20 #include "eckit/config/LocalConfiguration.h"
21 #include "oops/base/Departures.h"
22 #include "oops/base/Observations.h"
23 #include "oops/base/ObsSpaces.h"
26 #include "oops/util/Logger.h"
27 #include "oops/util/Printable.h"
28 
29 namespace oops {
30 
31 // -----------------------------------------------------------------------------
32 
33 template <typename MODEL>
34 class ObsErrors : public util::Printable,
35  private boost::noncopyable {
41 
42  public:
43  static const std::string classname() {return "oops::ObsErrors";}
44 
45  explicit ObsErrors(const ObsSpace_ &);
46  ~ObsErrors();
47 
48 /// Access
49  std::size_t size() const {return err_.size();}
50  const ObsError_ & operator[](const std::size_t ii) const {return *err_.at(ii);}
51 
52 /// Linearize and reset for inner loop if needed
53  void linearize(const Observations_ &);
54 
55 /// Multiply a Departure by \f$R\f$ and \f$R^{-1}\f$
56  Departures_ * multiply(const Departures_ &) const;
57  Departures_ * inverseMultiply(const Departures_ &) const;
58 
59 /// Generate random perturbation
60  void randomize(Departures_ &) const;
61 
62  private:
63  void print(std::ostream &) const;
64  std::vector<boost::shared_ptr<ObsError_> > err_;
65 };
66 
67 // -----------------------------------------------------------------------------
68 
69 template <typename MODEL>
71 {
72  for (std::size_t jj = 0; jj < os.size(); ++jj) {
73  eckit::LocalConfiguration conf(os[jj].config(), "Covariance");
74  boost::shared_ptr<ObsError_> tmp(new ObsError_(os[jj], conf));
75  err_.push_back(tmp);
76  }
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 template <typename MODEL>
83 
84 // -----------------------------------------------------------------------------
85 
86 template <typename MODEL>
88  for (std::size_t jj = 0; jj < err_.size(); ++jj) {
89  err_[jj]->linearize(yy[jj]);
90  }
91 }
92 
93 // -----------------------------------------------------------------------------
94 
95 template <typename MODEL>
97  std::vector<boost::shared_ptr<ObsVector_> > ovec;
98  for (std::size_t jj = 0; jj < err_.size(); ++jj) {
99  boost::shared_ptr<ObsVector_> tmp(err_[jj]->multiply(dy[jj]));
100  ovec.push_back(tmp);
101  }
102  return new Departures_(ovec);
103 }
104 
105 // -----------------------------------------------------------------------------
106 
107 template <typename MODEL>
109  std::vector<boost::shared_ptr<ObsVector_> > ovec;
110  for (std::size_t jj = 0; jj < err_.size(); ++jj) {
111  boost::shared_ptr<ObsVector_> tmp(err_[jj]->inverseMultiply(dy[jj]));
112  ovec.push_back(tmp);
113  }
114  return new Departures_(ovec);
115 }
116 
117 // -----------------------------------------------------------------------------
118 
119 template <typename MODEL>
121  for (std::size_t jj = 0; jj < err_.size(); ++jj) {
122  err_[jj]->randomize(dy[jj]);
123  }
124 }
125 
126 // -----------------------------------------------------------------------------
127 
128 template<typename MODEL>
129 void ObsErrors<MODEL>::print(std::ostream & os) const {
130  for (std::size_t jj = 0; jj < err_.size(); ++jj) os << *err_[jj];
131 }
132 
133 // -----------------------------------------------------------------------------
134 
135 } // namespace oops
136 
137 #endif // OOPS_BASE_OBSERRORS_H_
void linearize(const Observations_ &)
Linearize and reset for inner loop if needed.
Definition: ObsErrors.h:87
ObsVector< MODEL > ObsVector_
Definition: ObsErrors.h:40
ObsErrorCovariance< MODEL > ObsError_
Definition: ObsErrors.h:38
void print(std::ostream &) const
Definition: ObsErrors.h:129
Difference between two observation vectors.
Definition: Departures.h:36
ObsSpaces< MODEL > ObsSpace_
Definition: ObsErrors.h:39
Definition: conf.py:1
Observations< MODEL > Observations_
Definition: ObsErrors.h:37
Observations Class.
Definition: Observations.h:36
Departures< MODEL > Departures_
Definition: ObsErrors.h:36
The namespace for the main oops code.
const ObsError_ & operator[](const std::size_t ii) const
Definition: ObsErrors.h:50
subroutine, public multiply(self, geom, xctl, xmod)
std::vector< boost::shared_ptr< ObsError_ > > err_
Definition: ObsErrors.h:64
static const std::string classname()
Definition: ObsErrors.h:43
void randomize(Departures_ &) const
Generate random perturbation.
Definition: ObsErrors.h:120
std::size_t size() const
Access.
Definition: ObsErrors.h:49
ObsErrors(const ObsSpace_ &)
Definition: ObsErrors.h:70
Observation error covariance matrix.
Departures_ * inverseMultiply(const Departures_ &) const
Definition: ObsErrors.h:108
std::size_t size() const
Access.
Definition: ObsSpaces.h:51
Departures_ * multiply(const Departures_ &) const
Multiply a Departure by and .
Definition: ObsErrors.h:96