FV3 Bundle
Variational.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_VARIATIONAL_H_
12 #define OOPS_RUNS_VARIATIONAL_H_
13 
14 #include <string>
15 
16 #include <boost/scoped_ptr.hpp>
17 
18 #include "eckit/config/LocalConfiguration.h"
25 #include "oops/base/Observations.h"
27 #include "oops/base/StateInfo.h"
28 #include "oops/base/StateWriter.h"
33 #include "oops/interface/Model.h"
34 #include "oops/interface/State.h"
35 #include "oops/runs/Application.h"
36 #include "oops/util/DateTime.h"
37 #include "oops/util/Duration.h"
38 #include "oops/util/Logger.h"
39 
40 namespace oops {
41 
42 template <typename MODEL> class Variational : public Application {
46 
47  public:
48 // -----------------------------------------------------------------------------
50  instantiateCostFactory<MODEL>();
51  instantiateCovarFactory<MODEL>();
52  instantiateMinFactory<MODEL>();
53  instantiateObsErrorFactory<MODEL>();
54  instantiateTlmFactory<MODEL>();
55  instantiateLinearVariableChangeFactory<MODEL>();
56  }
57 // -----------------------------------------------------------------------------
58  virtual ~Variational() {}
59 // -----------------------------------------------------------------------------
60  int execute(const eckit::Configuration & fullConfig) const {
61 // Setup resolution
62  const eckit::LocalConfiguration resolConfig(fullConfig, "resolution");
63  const Geometry_ resol(resolConfig);
64 
65 // Setup Model
66  const eckit::LocalConfiguration modelConfig(fullConfig, "model");
67  const Model_ model(resol, modelConfig);
68  Log::trace() << "Variational: model has been set up" << std::endl;
69 
70 /// The background is constructed inside the cost function because its valid
71 /// time within the assimilation window can be different (3D-Var vs. 4D-Var),
72 /// it can be 3D or 4D (strong vs weak constraint), etc...
73 
74 // Setup cost function
75  const eckit::LocalConfiguration cfConf(fullConfig, "cost_function");
76  boost::scoped_ptr< CostFunction<MODEL> > J(CostFactory<MODEL>::create(cfConf, resol, model));
77  Log::trace() << "Variational: cost function has been set up" << std::endl;
78 
79 // Initialize first guess from background
80  ControlVariable<MODEL> xx(J->jb().getBackground());
81  Log::trace() << "Variational: first guess has been set up" << std::endl;
82 
83 // Perform Incremental Variational Assimilation
84  IncrementalAssimilation<MODEL>(xx, *J, fullConfig);
85  Log::trace() << "Variational: incremantal assimilation done" << std::endl;
86 
87 // Save analysis and final diagnostics
89  const util::DateTime winbgn(cfConf.getString("window_begin"));
90  const eckit::LocalConfiguration outConfig(fullConfig, "output");
91  post.enrollProcessor(new StateWriter<State_>(winbgn, outConfig));
92 
93  const eckit::LocalConfiguration finalConfig(fullConfig, "final");
94  if (finalConfig.has("prints")) {
95  const eckit::LocalConfiguration prtConfig(finalConfig, "prints");
96  post.enrollProcessor(new StateInfo<State_>("final", prtConfig));
97  }
98 
99  J->evaluate(xx, finalConfig, post);
100 
101  return 0;
102  }
103 // -----------------------------------------------------------------------------
104  private:
105  std::string appname() const {
106  return "oops::Variational<" + MODEL::name() + ">";
107  }
108 // -----------------------------------------------------------------------------
109 };
110 
111 } // namespace oops
112 #endif // OOPS_RUNS_VARIATIONAL_H_
std::string appname() const
Definition: Variational.h:105
Handles writing-out of forecast fields.
Definition: StateWriter.h:26
virtual ~Variational()
Definition: Variational.h:58
Encapsulates the model state.
Control variable.
character(len=32) name
The namespace for the main oops code.
int execute(const eckit::Configuration &fullConfig) const
Definition: Variational.h:60
Handles writing-out of forecast fields.
Definition: StateInfo.h:28
Model< MODEL > Model_
Definition: Variational.h:44
State< MODEL > State_
Definition: Variational.h:45
Geometry< MODEL > Geometry_
Definition: Variational.h:43
Encapsulates the nonlinear forecast model.
Control model post processing.
Definition: PostProcessor.h:31
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:39
Cost Function Factory.
Definition: CostFunction.h:136