OOPS
StateEnsemble4D.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019-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_STATEENSEMBLE4D_H_
9 #define OOPS_BASE_STATEENSEMBLE4D_H_
10 
11 #include <utility>
12 #include <vector>
13 
14 #include "eckit/config/LocalConfiguration.h"
16 #include "oops/base/Accumulator.h"
17 #include "oops/base/Variables.h"
19 #include "oops/util/Logger.h"
20 
21 namespace oops {
22 
23 // -----------------------------------------------------------------------------
24 
25 /// \brief Ensemble of 4D states
26 template<typename MODEL> class StateEnsemble4D {
29 
30  public:
31  /// Create ensemble of 4D states
32  StateEnsemble4D(const Geometry_ &, const eckit::Configuration &);
33 
34  /// calculate ensemble mean
35  State4D_ mean() const;
36 
37  /// Accessors
38  unsigned int size() const { return states_.size(); }
39  State4D_ & operator[](const int ii) { return states_[ii]; }
40  const State4D_ & operator[](const int ii) const { return states_[ii]; }
41 
42  /// Information
43  const Variables & variables() const {return states_[0].variables();}
44 
45  private:
46  std::vector<State4D_> states_;
47 };
48 
49 // ====================================================================================
50 
51 template<typename MODEL>
53  const eckit::Configuration & config)
54  : states_() {
55  std::vector<eckit::LocalConfiguration> memberConfig;
56  config.get("members", memberConfig);
57  states_.reserve(memberConfig.size());
58  // Loop over all ensemble members
59  for (size_t jj = 0; jj < memberConfig.size(); ++jj) {
60  states_.emplace_back(State4D_(resol, memberConfig[jj]));
61  }
62  Log::trace() << "StateEnsemble4D:contructor done" << std::endl;
63 }
64 
65 // -----------------------------------------------------------------------------
66 
67 template<typename MODEL>
69  // Compute ensemble mean
70  Accumulator<MODEL, State4D_, State4D_> ensmean(states_[0]);
71 
72  const double rr = 1.0/static_cast<double>(states_.size());
73  for (size_t iens = 0; iens < states_.size(); ++iens) {
74  ensmean.accumul(rr, states_[iens]);
75  }
76 
77  Log::trace() << "StateEnsemble4D::mean done" << std::endl;
78  return std::move(ensmean);
79 }
80 
81 // -----------------------------------------------------------------------------
82 
83 } // namespace oops
84 
85 #endif // OOPS_BASE_STATEENSEMBLE4D_H_
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::StateEnsemble4D::size
unsigned int size() const
Accessors.
Definition: StateEnsemble4D.h:38
oops::StateEnsemble4D::operator[]
const State4D_ & operator[](const int ii) const
Definition: StateEnsemble4D.h:40
oops::StateEnsemble4D::variables
const Variables & variables() const
Information.
Definition: StateEnsemble4D.h:43
oops::StateEnsemble4D::State4D_
State4D< MODEL > State4D_
Definition: StateEnsemble4D.h:28
oops::StateEnsemble4D::states_
std::vector< State4D_ > states_
Definition: StateEnsemble4D.h:46
oops::StateEnsemble4D::Geometry_
Geometry< MODEL > Geometry_
Definition: StateEnsemble4D.h:27
oops::StateEnsemble4D::operator[]
State4D_ & operator[](const int ii)
Definition: StateEnsemble4D.h:39
oops::State4D
Four dimensional state.
Definition: State4D.h:35
oops::StateEnsemble4D::mean
State4D_ mean() const
calculate ensemble mean
Definition: StateEnsemble4D.h:68
oops::Geometry
Geometry class used in oops; subclass of interface class above.
Definition: oops/interface/Geometry.h:189
Accumulator.h
oops::Accumulator
Definition: Accumulator.h:22
State4D.h
oops::StateEnsemble4D::StateEnsemble4D
StateEnsemble4D(const Geometry_ &, const eckit::Configuration &)
Create ensemble of 4D states.
Definition: StateEnsemble4D.h:52
oops::StateEnsemble4D
Ensemble of 4D states.
Definition: StateEnsemble4D.h:26
oops::Accumulator::accumul
void accumul(const double &zz, const FLDS &xx)
Definition: Accumulator.h:32
oops::Variables
Definition: oops/base/Variables.h:23
Variables.h
Geometry.h