IODA Bundle
GenEnsPertB.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_RUNS_GENENSPERTB_H_
12 #define OOPS_RUNS_GENENSPERTB_H_
13 
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 
18 
19 #include "eckit/config/Configuration.h"
20 #include "oops/base/Geometry.h"
21 #include "oops/base/Increment.h"
23 #include "oops/base/Model.h"
26 #include "oops/base/State.h"
27 #include "oops/base/StateWriter.h"
28 #include "oops/base/Variables.h"
30 #include "oops/mpi/mpi.h"
31 #include "oops/runs/Application.h"
32 #include "oops/util/DateTime.h"
33 #include "oops/util/Duration.h"
34 #include "oops/util/Logger.h"
35 
36 namespace oops {
37 
38 template <typename MODEL> class GenEnsPertB : public Application {
44 
45  public:
46 // -----------------------------------------------------------------------------
47  explicit GenEnsPertB(const eckit::mpi::Comm & comm = oops::mpi::world()) : Application(comm) {
48  instantiateCovarFactory<MODEL>();
49  }
50 // -----------------------------------------------------------------------------
51  virtual ~GenEnsPertB() {}
52 // -----------------------------------------------------------------------------
53  int execute(const eckit::Configuration & fullConfig) const {
54 // Setup resolution
55  const eckit::LocalConfiguration resolConfig(fullConfig, "geometry");
56  const Geometry_ resol(resolConfig, this->getComm());
57 
58 // Setup Model
59  const eckit::LocalConfiguration modelConfig(fullConfig, "model");
60  const Model_ model(resol, modelConfig);
61 
62 // Setup initial state
63  const eckit::LocalConfiguration initialConfig(fullConfig, "initial condition");
64  const State_ xx(resol, initialConfig);
65  Log::test() << "Initial state: " << xx << std::endl;
66 
67 // Setup augmented state
68  const ModelAux_ moderr(resol, fullConfig.getSubConfiguration("model aux control"));
69 
70 // Setup times
71  const util::Duration fclength(fullConfig.getString("forecast length"));
72  const util::DateTime bgndate(xx.validTime());
73  const util::DateTime enddate(bgndate + fclength);
74  Log::info() << "Running forecast from " << bgndate << " to " << enddate << std::endl;
75 
76 // Setup variables
77  const Variables vars(fullConfig, "perturbed variables");
78 
79 // Setup B matrix
80  const eckit::LocalConfiguration covar(fullConfig, "background error");
81  std::unique_ptr< ModelSpaceCovarianceBase<MODEL> >
82  Bmat(CovarianceFactory<MODEL>::create(covar, resol, vars, xx, xx));
83 
84 // Generate perturbed states
85  Increment_ dx(resol, vars, bgndate);
86  const int members = fullConfig.getInt("members");
87  for (int jm = 0; jm < members; ++jm) {
88 // Generate pertubation
89  Bmat->randomize(dx);
90 
91 // Add mean state
92  State_ xp(xx);
93  xp += dx;
94 
95 // Setup forecast outputs
97 
98  eckit::LocalConfiguration outConfig(fullConfig, "output");
99  outConfig.set("member", jm+1);
100 
101  post.enrollProcessor(new StateWriter<State_>(outConfig));
102 
103 // Run forecast
104  model.forecast(xp, moderr, fclength, post);
105  Log::test() << "Member " << jm << " final state: " << xp << std::endl;
106  }
107 
108  return 0;
109  }
110 // -----------------------------------------------------------------------------
111  private:
112  std::string appname() const {
113  return "oops::GenEnsPertB<" + MODEL::name() + ">";
114  }
115 // -----------------------------------------------------------------------------
116 };
117 
118 } // namespace oops
119 #endif // OOPS_RUNS_GENENSPERTB_H_
program test
const eckit::mpi::Comm & getComm() const
Definition: Application.h:36
State< MODEL > State_
Definition: GenEnsPertB.h:43
Geometry< MODEL > Geometry_
Definition: GenEnsPertB.h:39
std::string appname() const
Definition: GenEnsPertB.h:112
Model< MODEL > Model_
Definition: GenEnsPertB.h:40
int execute(const eckit::Configuration &fullConfig) const
Definition: GenEnsPertB.h:53
GenEnsPertB(const eckit::mpi::Comm &comm=oops::mpi::world())
Definition: GenEnsPertB.h:47
ModelAuxControl< MODEL > ModelAux_
Definition: GenEnsPertB.h:41
virtual ~GenEnsPertB()
Definition: GenEnsPertB.h:51
Increment< MODEL > Increment_
Definition: GenEnsPertB.h:42
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
Abstract nonlinear forecast model used by high level algorithms and applications.
void forecast(State_ &xx, const ModelAux_ &, const util::Duration &len, PostProcessor< State_ > &post) const
Run the forecast from state xx for len time, with post postprocessors Does not need to be implemented...
Control model post processing.
Definition: PostProcessor.h:30
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:38
State class used in oops; subclass of interface class interface::State.
Handles writing-out of forecast fields.
Definition: StateWriter.h:26
const util::DateTime validTime() const
Accessor to the time of this State.
const eckit::mpi::Comm & world()
Default communicator with all MPI tasks (ie MPI_COMM_WORLD)
Definition: oops/mpi/mpi.cc:84
The namespace for the main oops code.