OOPS
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"
23 #include "oops/base/StateWriter.h"
24 #include "oops/base/Variables.h"
27 #include "oops/interface/Model.h"
29 #include "oops/interface/State.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_
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
ModelSpaceCovarianceBase.h
oops::CovarianceFactory
Covariance Factory.
Definition: ModelSpaceCovarianceBase.h:93
mpi.h
model
Definition: l95/defaults/model.py:1
oops::ModelAuxControl
Definition: oops/interface/ModelAuxControl.h:35
oops::GenEnsPertB::Model_
Model< MODEL > Model_
Definition: GenEnsPertB.h:40
oops::StateWriter
Handles writing-out of forecast fields.
Definition: StateWriter.h:26
oops::PostProcessor::enrollProcessor
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:38
Application.h
oops::Application::getComm
const eckit::mpi::Comm & getComm() const
Definition: Application.h:36
oops::GenEnsPertB::appname
std::string appname() const
Definition: GenEnsPertB.h:112
oops::GenEnsPertB
Definition: GenEnsPertB.h:38
PostProcessor.h
oops::GenEnsPertB::GenEnsPertB
GenEnsPertB(const eckit::mpi::Comm &comm=oops::mpi::world())
Definition: GenEnsPertB.h:47
oops::Geometry
Geometry class used in oops; subclass of interface class above.
Definition: oops/interface/Geometry.h:189
Model.h
instantiateCovarFactory.h
oops::GenEnsPertB::Geometry_
Geometry< MODEL > Geometry_
Definition: GenEnsPertB.h:39
oops::State
Encapsulates the model state.
Definition: CostJbState.h:28
oops::GenEnsPertB::ModelAux_
ModelAuxControl< MODEL > ModelAux_
Definition: GenEnsPertB.h:41
oops::Application
Definition: Application.h:29
oops::PostProcessor
Control model post processing.
Definition: PostProcessor.h:30
oops::GenEnsPertB::Increment_
Increment< MODEL > Increment_
Definition: GenEnsPertB.h:42
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::GenEnsPertB::State_
State< MODEL > State_
Definition: GenEnsPertB.h:43
StateWriter.h
oops::Increment
Increment Class: Difference between two states.
Definition: CostJbState.h:27
oops::GenEnsPertB::~GenEnsPertB
virtual ~GenEnsPertB()
Definition: GenEnsPertB.h:51
Variables.h
oops::Model
Encapsulates the nonlinear forecast model Note: to see methods that need to be implemented in the for...
Definition: oops/interface/Model.h:54
ModelAuxControl.h
oops::GenEnsPertB::execute
int execute(const eckit::Configuration &fullConfig) const
Definition: GenEnsPertB.h:53
Geometry.h
Increment.h