OOPS
DeparturesEnsemble.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018-2020 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_DEPARTURESENSEMBLE_H_
9 #define OOPS_BASE_DEPARTURESENSEMBLE_H_
10 
11 #include <Eigen/Dense>
12 #include <memory>
13 #include <vector>
14 
15 #include "oops/base/Departures.h"
16 #include "oops/base/ObsSpaces.h"
18 #include "oops/util/Logger.h"
19 
20 namespace oops {
21 
22 // -----------------------------------------------------------------------------
23 
24 /// \brief Ensemble of Departures (can hold ensemble perturbations in the observation space)
25 template<typename OBS> class DeparturesEnsemble {
28  template <typename DATA> using ObsData_ = ObsDataVector<OBS, DATA>;
29  template <typename DATA> using ObsDataVec_ = std::vector<std::shared_ptr<ObsData_<DATA>>>;
30 
31  public:
32  /// Creates ensemble of empty Departures size \p nens
33  DeparturesEnsemble(const ObsSpaces_ &, const size_t nens);
34 
35  /// Accessors and size
36  size_t size() const {return ensemblePerturbs_.size();}
37  Departures_ & operator[](const size_t ii) {return ensemblePerturbs_[ii];}
38  const Departures_ & operator[](const size_t ii) const {return ensemblePerturbs_[ii];}
39 
40 /// pack ensemble of dep. as contiguous block of memory
41  Eigen::MatrixXd packEigen(const Departures_ &) const;
42 
43  private:
44  std::vector<Departures_> ensemblePerturbs_; // ensemble perturbations
45 };
46 
47 // ====================================================================================
48 
49 template<typename OBS>
51  : ensemblePerturbs_() {
52  ensemblePerturbs_.reserve(nens);
53  for (size_t iens = 0; iens < nens; ++iens) {
54  ensemblePerturbs_.emplace_back(obsdb);
55  }
56  Log::trace() << "DeparturesEnsemble created" << std::endl;
57 }
58 
59 // -----------------------------------------------------------------------------
60 
61 template<typename OBS>
62 Eigen::MatrixXd DeparturesEnsemble<OBS>::packEigen(const Departures_ & mask) const {
63  std::size_t myNobs = ensemblePerturbs_[0].packEigenSize(mask);
64  std::size_t myNens = ensemblePerturbs_.size();
65 
66  Eigen::MatrixXd depEns(myNens, myNobs);
67  for (std::size_t iens = 0; iens < myNens; ++iens) {
68  depEns.row(iens) = ensemblePerturbs_[iens].packEigen(mask);
69  }
70  Log::trace() << "DeparturesEnsemble::packEigen() completed" << std::endl;
71  return depEns;
72 }
73 
74 // -----------------------------------------------------------------------------
75 
76 } // namespace oops
77 
78 #endif // OOPS_BASE_DEPARTURESENSEMBLE_H_
Ensemble of Departures (can hold ensemble perturbations in the observation space)
const Departures_ & operator[](const size_t ii) const
Eigen::MatrixXd packEigen(const Departures_ &) const
pack ensemble of dep. as contiguous block of memory
size_t size() const
Accessors and size.
std::vector< std::shared_ptr< ObsData_< DATA > >> ObsDataVec_
DeparturesEnsemble(const ObsSpaces_ &, const size_t nens)
Creates ensemble of empty Departures size nens.
Departures< OBS > Departures_
std::vector< Departures_ > ensemblePerturbs_
Departures_ & operator[](const size_t ii)
Difference between two observation vectors.
Definition: Departures.h:44
ObsDataVector is a vector templated on data type, in the observation space.
The namespace for the main oops code.