OOPS
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 <memory>
15 #include <string>
16 
17 
18 #include "eckit/config/LocalConfiguration.h"
27 #include "oops/base/State.h"
28 #include "oops/base/StateInfo.h"
29 #include "oops/base/StateWriter.h"
33 #include "oops/mpi/mpi.h"
34 #include "oops/runs/Application.h"
35 #include "oops/util/DateTime.h"
36 #include "oops/util/Logger.h"
37 #include "oops/util/printRunStats.h"
38 
39 namespace oops {
40 
41 template <typename MODEL, typename OBS> class Variational : public Application {
43 
44  public:
45 // -----------------------------------------------------------------------------
46  explicit Variational(const eckit::mpi::Comm & comm = oops::mpi::world()) : Application(comm) {
47  instantiateCostFactory<MODEL, OBS>();
48  instantiateCovarFactory<MODEL>();
49  instantiateMinFactory<MODEL, OBS>();
50  instantiateObsErrorFactory<OBS>();
51  instantiateObsFilterFactory<OBS>();
52  instantiateLinearModelFactory<MODEL>();
53  instantiateVariableChangeFactory<MODEL>();
54  }
55 // -----------------------------------------------------------------------------
56  virtual ~Variational() {}
57 // -----------------------------------------------------------------------------
58  int execute(const eckit::Configuration & fullConfig) const {
59 /// The background is constructed inside the cost function because its valid
60 /// time within the assimilation window can be different (3D-Var vs. 4D-Var),
61 /// it can be 3D or 4D (strong vs weak constraint), etc...
62  util::printRunStats("Variational start");
63 
64 // Setup cost function
65  eckit::LocalConfiguration cfConf(fullConfig, "cost function");
66  std::unique_ptr<CostFunction<MODEL, OBS>>
67  J(CostFactory<MODEL, OBS>::create(cfConf, this->getComm()));
68  Log::trace() << "Variational: cost function has been set up" << std::endl;
69 
70 // Initialize first guess from background
71  ControlVariable<MODEL, OBS> xx(J->jb().getBackground());
72  Log::trace() << "Variational: first guess has been set up" << std::endl;
73 
74 // Perform Incremental Variational Assimilation
75  eckit::LocalConfiguration varConf(fullConfig, "variational");
76  int iouter = IncrementalAssimilation<MODEL, OBS>(xx, *J, varConf);
77  Log::info() << "Variational: incremental assimilation done "
78  << iouter << " iterations." << std::endl;
79 
80 // Save analysis and final diagnostics
82  const util::DateTime winbgn(cfConf.getString("window begin"));
83  const eckit::LocalConfiguration outConfig(fullConfig, "output");
84  post.enrollProcessor(new StateWriter<State_>(outConfig));
85 
86  eckit::LocalConfiguration finalConfig(fullConfig, "final");
87  finalConfig.set("iteration", iouter);
88  if (finalConfig.has("prints")) {
89  const eckit::LocalConfiguration prtConfig(finalConfig, "prints");
90  post.enrollProcessor(new StateInfo<State_>("final", prtConfig));
91  }
92 
93  J->evaluate(xx, finalConfig, post);
94 
95 // Save ObsAux
96  xx.obsVar().write(cfConf);
97 
98  util::printRunStats("Variational end");
99  return 0;
100  }
101 // -----------------------------------------------------------------------------
102  private:
103  std::string appname() const {
104  return "oops::Variational<" + MODEL::name() + ", " + OBS::name() + ">";
105  }
106 // -----------------------------------------------------------------------------
107 };
108 
109 } // namespace oops
110 #endif // OOPS_RUNS_VARIATIONAL_H_
const eckit::mpi::Comm & getComm() const
Definition: Application.h:36
Control variable.
ObsAuxCtrls_ & obsVar()
Get augmented observation control variable.
Cost Function Factory.
Definition: CostFunction.h:128
void write(const eckit::Configuration &) const
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: StateInfo.h:28
Handles writing-out of forecast fields.
Definition: StateWriter.h:26
Variational(const eckit::mpi::Comm &comm=oops::mpi::world())
Definition: Variational.h:46
int execute(const eckit::Configuration &fullConfig) const
Definition: Variational.h:58
std::string appname() const
Definition: Variational.h:103
State< MODEL > State_
Definition: Variational.h:42
virtual ~Variational()
Definition: Variational.h:56
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.