OOPS
EnsRecenter.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 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_RUNS_ENSRECENTER_H_
9 #define OOPS_RUNS_ENSRECENTER_H_
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 
16 #include "eckit/config/LocalConfiguration.h"
17 #include "oops/base/Variables.h"
20 #include "oops/interface/State.h"
21 #include "oops/mpi/mpi.h"
22 #include "oops/runs/Application.h"
23 #include "oops/util/DateTime.h"
24 
25 namespace oops {
26 
27 template <typename MODEL> class EnsRecenter : public Application {
31 
32  public:
33  // -----------------------------------------------------------------------------
34  explicit EnsRecenter(const eckit::mpi::Comm & comm = oops::mpi::world()) : Application(comm) {}
35  // -----------------------------------------------------------------------------
36  virtual ~EnsRecenter() {}
37  // -----------------------------------------------------------------------------
38  int execute(const eckit::Configuration & fullConfig) const {
39  // Setup Geometry
40  const eckit::LocalConfiguration resolConfig(fullConfig, "geometry");
41  const Geometry_ resol(resolConfig, this->getComm());
42 
43  // Get central state
44  const eckit::LocalConfiguration bkgConfig(fullConfig, "center");
45  State_ x_center(resol, bkgConfig);
46 
47  // Get ensemble configuration
48  std::vector<eckit::LocalConfiguration> ensConfig;
49  fullConfig.get("ensemble", ensConfig);
50 
51  // Get ensemble size
52  unsigned nm = ensConfig.size();
53 
54  // Compute ensemble mean
55  State_ ensmean(x_center);
56  ensmean.zero();
57  const double rk = 1.0/(static_cast<double>(nm));
58  for (unsigned jj = 0; jj < nm; ++jj) {
59  State_ x(resol, ensConfig[jj]);
60  ensmean.accumul(rk, x);
61  Log::test() << "Original member " << jj << " : " << x << std::endl;
62  }
63  Log::test() << "Ensemble mean: " << std::endl << ensmean << std::endl;
64 
65  // Setup variables
66  const Variables vars(fullConfig, "recenter variables");
67 
68  // Recenter ensemble around central and save
69  for (unsigned jj = 0; jj < nm; ++jj) {
70  State_ x(resol, ensConfig[jj]);
71  Increment_ pert(resol, vars, x.validTime());
72  pert.diff(x, ensmean);
73  x = x_center;
74  x += pert;
75 
76  // Save recentered member
77  eckit::LocalConfiguration recenterout(fullConfig, "recentered output");
78  recenterout.set("member", static_cast<int>(jj+1) );
79  x.write(recenterout);
80  Log::test() << "Recentered member " << jj << " : " << x << std::endl;
81  }
82  return 0;
83  }
84  // -----------------------------------------------------------------------------
85  private:
86  std::string appname() const {
87  return "oops::EnsRecenter<" + MODEL::name() + ">";
88  }
89  // -----------------------------------------------------------------------------
90 };
91 
92 } // namespace oops
93 
94 #endif // OOPS_RUNS_ENSRECENTER_H_
oops::State::validTime
const util::DateTime validTime() const
Time.
Definition: oops/interface/State.h:60
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::EnsRecenter::execute
int execute(const eckit::Configuration &fullConfig) const
Definition: EnsRecenter.h:38
mpi.h
oops::Increment::diff
void diff(const State_ &, const State_ &)
Interactions with State.
Definition: oops/interface/Increment.h:196
oops::EnsRecenter::appname
std::string appname() const
Definition: EnsRecenter.h:86
oops::State::zero
void zero()
Accumulator.
Definition: oops/interface/State.h:278
oops::State::write
void write(const eckit::Configuration &) const
Definition: oops/interface/State.h:191
Application.h
oops::Application::getComm
const eckit::mpi::Comm & getComm() const
Definition: Application.h:36
oops::EnsRecenter::~EnsRecenter
virtual ~EnsRecenter()
Definition: EnsRecenter.h:36
oops::EnsRecenter::State_
State< MODEL > State_
Definition: EnsRecenter.h:30
oops::Geometry
Geometry class used in oops; subclass of interface class above.
Definition: oops/interface/Geometry.h:189
oops::EnsRecenter::EnsRecenter
EnsRecenter(const eckit::mpi::Comm &comm=oops::mpi::world())
Definition: EnsRecenter.h:34
oops::EnsRecenter::Geometry_
Geometry< MODEL > Geometry_
Definition: EnsRecenter.h:28
oops::State
Encapsulates the model state.
Definition: CostJbState.h:28
oops::EnsRecenter::Increment_
Increment< MODEL > Increment_
Definition: EnsRecenter.h:29
oops::Application
Definition: Application.h:29
oops::State::accumul
void accumul(const double &, const State &)
Definition: oops/interface/State.h:288
State.h
oops::mpi::world
const eckit::mpi::Comm & world()
Default communicator with all MPI tasks (ie MPI_COMM_WORLD)
Definition: oops/mpi/mpi.cc:22
oops::Variables
Definition: oops/base/Variables.h:23
oops::Increment
Increment Class: Difference between two states.
Definition: CostJbState.h:27
Variables.h
oops::EnsRecenter
Definition: EnsRecenter.h:27
Geometry.h
Increment.h