OOPS
ObsAuxCovariances.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2019 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_BASE_OBSAUXCOVARIANCES_H_
9 #define OOPS_BASE_OBSAUXCOVARIANCES_H_
10 
11 #include <iostream>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include <boost/noncopyable.hpp>
17 
18 #include "eckit/config/Configuration.h"
21 #include "oops/base/ObsSpaces.h"
23 #include "oops/util/Logger.h"
24 #include "oops/util/Printable.h"
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 /// \brief Holds a vector of ObsAuxCovariance
30 // -----------------------------------------------------------------------------
31 
32 template <typename OBS>
33 class ObsAuxCovariances : public util::Printable,
34  private boost::noncopyable {
39 
40  public:
41  static const std::string classname() {return "oops::ObsAuxCovariances";}
42 
43  ObsAuxCovariances(const ObsSpaces_ &, const eckit::Configuration &);
45 
46 /// Operators
47  void linearize(const ObsAuxControls_ &, const eckit::Configuration &);
48  void multiply(const ObsAuxIncrements_ &, ObsAuxIncrements_ &) const;
50  void randomize(ObsAuxIncrements_ &) const;
51 
52  const eckit::LocalConfiguration & config() const {return conf_;}
53  const ObsSpaces_ & obspaces() const {return odb_;}
54 
55  private:
56  void print(std::ostream &) const;
57  std::vector<std::unique_ptr<ObsAuxCovariance_> > cov_;
58  const ObsSpaces_ & odb_;
59  const eckit::LocalConfiguration conf_;
60 };
61 
62 // =============================================================================
63 
64 template<typename OBS>
66  const eckit::Configuration & conf)
67  : cov_(0), odb_(odb), conf_(conf)
68 {
69  Log::trace() << "ObsAuxCovariances<OBS>::ObsAuxCovariances starting" << std::endl;
70  std::vector<eckit::LocalConfiguration> obsconf = conf.getSubConfigurations();
71  for (std::size_t jobs = 0; jobs < obsconf.size(); ++jobs) {
72  eckit::LocalConfiguration obsauxconf = obsconf[jobs].getSubConfiguration("obs bias");
73  typename ObsAuxCovariance_::Parameters_ obsauxparams;
74  obsauxparams.validateAndDeserialize(obsauxconf);
75  cov_.push_back(
76  std::unique_ptr<ObsAuxCovariance_>(new ObsAuxCovariance_(odb[jobs], obsauxparams)));
77  }
78  Log::trace() << "ObsAuxCovariances<OBS>::ObsAuxCovariances done" << std::endl;
79 }
80 
81 // -----------------------------------------------------------------------------
82 
83 template<typename OBS>
85  Log::trace() << "ObsAuxCovariances<OBS>::~ObsAuxCovariances starting" << std::endl;
86  for (std::size_t jobs = 0; jobs < cov_.size(); ++jobs) {
87  cov_[jobs].reset();
88  }
89  Log::trace() << "ObsAuxCovariances<OBS>::~ObsAuxCovariances done" << std::endl;
90 }
91 
92 // -----------------------------------------------------------------------------
93 
94 template<typename OBS>
96  const eckit::Configuration & innerConf) {
97  Log::trace() << "ObsAuxCovariances<OBS>::linearize starting" << std::endl;
98  ASSERT(cov_.size() == xx.size());
99  for (std::size_t jobs = 0; jobs < xx.size(); ++jobs) {
100  cov_[jobs]->linearize(xx[jobs], innerConf);
101  }
102  Log::trace() << "ObsAuxCovariances<OBS>::linearize done" << std::endl;
103 }
104 
105 // -----------------------------------------------------------------------------
106 
107 template<typename OBS>
109  ObsAuxIncrements_ & dx2) const {
110  Log::trace() << "ObsAuxCovariances<OBS>::multiply starting" << std::endl;
111  ASSERT(dx1.size() == dx2.size() && cov_.size() == dx1.size());
112  for (std::size_t jobs = 0; jobs < dx1.size(); ++jobs) {
113  cov_[jobs]->multiply(dx1[jobs], dx2[jobs]);
114  }
115  Log::trace() << "ObsAuxCovariances<OBS>::multiply done" << std::endl;
116 }
117 
118 // -----------------------------------------------------------------------------
119 
120 template<typename OBS>
122  ObsAuxIncrements_ & dx2) const {
123  Log::trace() << "ObsAuxCovariances<OBS>::inverseMultiply starting" << std::endl;
124  ASSERT(dx1.size() == dx2.size() && cov_.size() == dx1.size());
125  for (std::size_t jobs = 0; jobs < dx1.size(); ++jobs) {
126  cov_[jobs]->inverseMultiply(dx1[jobs], dx2[jobs]);
127  }
128  Log::trace() << "ObsAuxCovariances<OBS>::inverseMultiply done" << std::endl;
129 }
130 
131 // -----------------------------------------------------------------------------
132 
133 template<typename OBS>
135  Log::trace() << "ObsAuxCovariances<OBS>::randomize starting" << std::endl;
136  ASSERT(cov_.size() == dx.size());
137  for (std::size_t jobs = 0; jobs < dx.size(); ++jobs) {
138  cov_[jobs]->randomize(dx[jobs]);
139  }
140  Log::trace() << "ObsAuxCovariances<OBS>::randomize done" << std::endl;
141 }
142 
143 // -----------------------------------------------------------------------------
144 
145 template<typename OBS>
146 void ObsAuxCovariances<OBS>::print(std::ostream & os) const {
147  Log::trace() << "ObsAuxCovariances<OBS>::print starting" << std::endl;
148  for (std::size_t jobs = 0; jobs < cov_.size(); ++jobs) os << *cov_.at(jobs) << " ";
149  Log::trace() << "ObsAuxCovariances<OBS>::print done" << std::endl;
150 }
151 
152 // -----------------------------------------------------------------------------
153 
154 } // namespace oops
155 
156 #endif // OOPS_BASE_OBSAUXCOVARIANCES_H_
Holds a vector of ObsAuxControl.
std::size_t size() const
Access.
Auxiliary error covariance related to observations, templated on <OBS>
ObsAuxCovariance_::Parameters_ Parameters_
Holds a vector of ObsAuxCovariance.
void multiply(const ObsAuxIncrements_ &, ObsAuxIncrements_ &) const
const eckit::LocalConfiguration & config() const
void print(std::ostream &) const
void linearize(const ObsAuxControls_ &, const eckit::Configuration &)
Operators.
void randomize(ObsAuxIncrements_ &) const
const eckit::LocalConfiguration conf_
ObsAuxCovariances(const ObsSpaces_ &, const eckit::Configuration &)
std::vector< std::unique_ptr< ObsAuxCovariance_ > > cov_
ObsSpaces< OBS > ObsSpaces_
const ObsSpaces_ & obspaces() const
ObsAuxIncrements< OBS > ObsAuxIncrements_
ObsAuxControls< OBS > ObsAuxControls_
const ObsSpaces_ & odb_
static const std::string classname()
void inverseMultiply(const ObsAuxIncrements_ &, ObsAuxIncrements_ &) const
ObsAuxCovariance< OBS > ObsAuxCovariance_
Holds a vector of ObsAuxIncrement.
std::size_t size() const
Access.
The namespace for the main oops code.