Loading [MathJax]/extensions/tex2jax.js
OOPS
All Classes Namespaces Files Functions Variables Typedefs Macros Pages
AddIncrement.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UCAR
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  */
7 
8 #ifndef OOPS_RUNS_ADDINCREMENT_H_
9 #define OOPS_RUNS_ADDINCREMENT_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include "eckit/config/LocalConfiguration.h"
15 #include "oops/base/Geometry.h"
16 #include "oops/base/Increment.h"
17 #include "oops/base/State.h"
18 #include "oops/mpi/mpi.h"
19 #include "oops/runs/Application.h"
20 #include "oops/util/DateTime.h"
21 #include "oops/util/Duration.h"
22 #include "oops/util/Logger.h"
23 
24 namespace oops {
25 
26 template <typename MODEL> class AddIncrement : public Application {
30 
31  public:
32 // -----------------------------------------------------------------------------
33  explicit AddIncrement(const eckit::mpi::Comm & comm = oops::mpi::world()) : Application(comm) {}
34 // -----------------------------------------------------------------------------
35  virtual ~AddIncrement() {}
36 // -----------------------------------------------------------------------------
37  int execute(const eckit::Configuration & fullConfig) const {
38 // Setup resolution
39  const eckit::LocalConfiguration stateResolConf(fullConfig, "state geometry");
40  const Geometry_ stateResol(stateResolConf, this->getComm());
41 
42  const eckit::LocalConfiguration incResolConf(fullConfig, "increment geometry");
43  const Geometry_ incResol(incResolConf, this->getComm());
44 
45 // Read state
46  const eckit::LocalConfiguration stateConf(fullConfig, "state");
47  State_ xx(stateResol, stateConf);
48  Log::test() << "State: " << xx << std::endl;
49 
50 // Read increment
51  const eckit::LocalConfiguration incConf(fullConfig, "increment");
52  std::vector<std::string> incvv;
53  incConf.get("added variables", incvv);
54  oops::Variables incVars(incvv);
55  Increment_ dx(incResol, incVars, xx.validTime());
56  dx.read(incConf);
57  Log::test() << "Increment: " << dx << std::endl;
58 
59 // Scale increment
60  if (incConf.has("scaling factor")) {
61  dx *= incConf.getDouble("scaling factor");
62  Log::test() << "Scaled the increment: " << dx << std::endl;
63  }
64 
65 // Assertions on state versus increment
66  ASSERT(xx.validTime() == dx.validTime());
67 
68 // Add increment to state
69  xx += dx;
70 
71 // Write state
72  const eckit::LocalConfiguration outputConfig(fullConfig, "output");
73  xx.write(outputConfig);
74 
75  Log::test() << "State plus increment: " << xx << std::endl;
76 
77  return 0;
78  }
79 // -----------------------------------------------------------------------------
80  private:
81  std::string appname() const {
82  return "oops::AddIncrement<" + MODEL::name() + ">";
83  }
84 // -----------------------------------------------------------------------------
85 };
86 
87 } // namespace oops
88 #endif // OOPS_RUNS_ADDINCREMENT_H_
std::string appname() const
Definition: AddIncrement.h:81
AddIncrement(const eckit::mpi::Comm &comm=oops::mpi::world())
Definition: AddIncrement.h:33
virtual ~AddIncrement()
Definition: AddIncrement.h:35
Geometry< MODEL > Geometry_
Definition: AddIncrement.h:27
int execute(const eckit::Configuration &fullConfig) const
Definition: AddIncrement.h:37
Increment< MODEL > Increment_
Definition: AddIncrement.h:29
State< MODEL > State_
Definition: AddIncrement.h:28
const eckit::mpi::Comm & getComm() const
Definition: Application.h:36
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
State class used in oops; subclass of interface class interface::State.
void read(const eckit::Configuration &)
Read this Increment from file.
const util::DateTime validTime() const
Accessor to the time of this Increment.
const util::DateTime validTime() const
Accessor to the time of this State.
void write(const eckit::Configuration &) const
Write this State out to file.
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.