FV3 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 <sstream>
15 #include <string>
16 
17 #include <boost/scoped_ptr.hpp>
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/runs/Application.h"
31 #include "oops/util/DateTime.h"
32 #include "oops/util/Duration.h"
33 #include "oops/util/Logger.h"
34 
35 namespace oops {
36 
37 template <typename MODEL> class GenEnsPertB : public Application {
43 
44  public:
45 // -----------------------------------------------------------------------------
47  instantiateCovarFactory<MODEL>();
48  }
49 // -----------------------------------------------------------------------------
50  virtual ~GenEnsPertB() {}
51 // -----------------------------------------------------------------------------
52  int execute(const eckit::Configuration & fullConfig) const {
53 // Setup resolution
54  const eckit::LocalConfiguration resolConfig(fullConfig, "resolution");
55  const Geometry_ resol(resolConfig);
56 
57 // Setup variables
58  const eckit::LocalConfiguration varConfig(fullConfig, "variables");
59  const Variables vars(varConfig);
60 
61 // Setup Model
62  const eckit::LocalConfiguration modelConfig(fullConfig, "model");
63  const Model_ model(resol, modelConfig);
64 
65 // Setup initial state
66  const eckit::LocalConfiguration initialConfig(fullConfig, "initial");
67  const State_ xx(resol, model.variables(), initialConfig);
68  Log::test() << "Initial state: " << xx << std::endl;
69 
70 // Setup augmented state
71  const ModelAux_ moderr(resol, initialConfig);
72 
73 // Setup times
74  const util::Duration fclength(fullConfig.getString("forecast_length"));
75  const util::DateTime bgndate(xx.validTime());
76  const util::DateTime enddate(bgndate + fclength);
77  Log::info() << "Running forecast from " << bgndate << " to " << enddate << std::endl;
78 
79 // Setup B matrix
80  const eckit::LocalConfiguration covar(fullConfig, "Covariance");
81  boost::scoped_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_>(bgndate, 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_
Handles writing-out of forecast fields.
Definition: StateWriter.h:26
virtual ~GenEnsPertB()
Definition: GenEnsPertB.h:50
Encapsulates the model state.
program test
character(len=32) name
The namespace for the main oops code.
Increment< MODEL > Increment_
Definition: GenEnsPertB.h:41
Model< MODEL > Model_
Definition: GenEnsPertB.h:39
Geometry< MODEL > Geometry_
Definition: GenEnsPertB.h:38
subroutine, public info(self)
Encapsulates the nonlinear forecast model.
State< MODEL > State_
Definition: GenEnsPertB.h:42
Increment Class: Difference between two states.
Control model post processing.
Definition: PostProcessor.h:31
ModelAuxControl< MODEL > ModelAux_
Definition: GenEnsPertB.h:40
std::string appname() const
Definition: GenEnsPertB.h:112
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:39
int execute(const eckit::Configuration &fullConfig) const
Definition: GenEnsPertB.h:52