FV3 Bundle
ErrorCovarianceBUMP.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_GENERIC_ERRORCOVARIANCEBUMP_H_
12 #define OOPS_GENERIC_ERRORCOVARIANCEBUMP_H_
13 
14 #include <string>
15 #include <vector>
16 
17 #include <boost/noncopyable.hpp>
18 #include <boost/scoped_ptr.hpp>
19 
21 #include "oops/base/Variables.h"
22 #include "oops/generic/oobump_f.h"
26 #include "oops/interface/State.h"
27 #include "oops/util/Logger.h"
28 #include "oops/util/ObjectCounter.h"
29 #include "oops/util/Printable.h"
30 #include "oops/util/Timer.h"
31 
32 namespace eckit {
33  class LocalConfiguration;
34  class Configuration;
35 }
36 
37 namespace oops {
38 
39 // -----------------------------------------------------------------------------
40 
41 /// Model space error covariance on generic unstructured grid
42 
43 template <typename MODEL>
45  public util::Printable,
46  private util::ObjectCounter<ErrorCovarianceBUMP<MODEL> >,
47  private boost::noncopyable {
51 
52  public:
53  static const std::string classname() {return "oops::ErrorCovarianceBUMP";}
54 
55  ErrorCovarianceBUMP(const Geometry_ &, const Variables &,
56  const eckit::Configuration &, const State_ &, const State_ &);
57  virtual ~ErrorCovarianceBUMP();
58 
59  void randomize(Increment_ &) const override;
60 
61  private:
62  void doMultiply(const Increment_ &, Increment_ &) const override;
63  void doInverseMultiply(const Increment_ &, Increment_ &) const override;
64 
65  void print(std::ostream &) const override;
66 
69  int keyBUMP_;
70 };
71 
72 // =============================================================================
73 
74 template<typename MODEL>
76  const Variables & vars,
77  const eckit::Configuration & conf,
78  const State_ & xb, const State_ & fg)
79  : ModelSpaceCovarianceBase<MODEL>(xb, fg, resol, conf), vars_(vars), colocated_(1), keyBUMP_(0)
80 {
81  Log::trace() << "ErrorCovarianceBUMP::ErrorCovarianceBUMP starting" << std::endl;
82  const eckit::Configuration * fconf = &conf;
83 
84 // Setup dummy increment
85  Increment_ dx(resol, vars_, fg.validTime());
86 
87 // Define unstructured grid coordinates
89  dx.ug_coord(ug, colocated_);
90 
91 // Delete BUMP if present
93 
94 // Create BUMP
95  create_oobump_f90(keyBUMP_, ug.toFortran(), &fconf, 0, 1, 0, 1);
96 
97 // Read data from files
98  if (conf.has("input")) {
99  std::vector<eckit::LocalConfiguration> inputConfigs;
100  conf.get("input", inputConfigs);
101  for (const auto & subconf : inputConfigs) {
102  dx.read(subconf);
103  dx.field_to_ug(ug, colocated_);
104  std::string param = subconf.getString("parameter");
105  const int nstr = param.size();
106  const char *cstr = param.c_str();
107  set_oobump_param_f90(keyBUMP_, nstr, cstr, ug.toFortran());
108  }
109  }
110 
111 // Run BUMP
113 
114 // Copy test
115  std::ifstream infile("bump.test");
116  std::string line;
117  while (std::getline(infile, line)) Log::test() << line << std::endl;
118  remove("bump.test");
119 
120  Log::trace() << "ErrorCovarianceBUMP::ErrorCovarianceBUMP done" << std::endl;
121 }
122 
123 // -----------------------------------------------------------------------------
124 
125 template<typename MODEL>
127  Log::trace() << "ErrorCovarianceBUMP<MODEL>::~ErrorCovarianceBUMP starting" << std::endl;
128  util::Timer timer(classname(), "~ErrorCovarianceBUMP");
129  delete_oobump_f90(keyBUMP_);
130  Log::trace() << "ErrorCovarianceBUMP<MODEL>::~ErrorCovarianceBUMP done" << std::endl;
131 }
132 
133 // -----------------------------------------------------------------------------
134 
135 template<typename MODEL>
137  Increment_ & dx2) const {
138  Log::trace() << "ErrorCovarianceBUMP<MODEL>::doMultiply starting" << std::endl;
139  util::Timer timer(classname(), "doMultiply");
140  UnstructuredGrid ug;
141  dx1.field_to_ug(ug, colocated_);
142  multiply_oobump_nicas_f90(keyBUMP_, ug.toFortran());
143  dx2.field_from_ug(ug);
144  Log::trace() << "ErrorCovarianceBUMP<MODEL>::doMultiply done" << std::endl;
145 }
146 
147 // -----------------------------------------------------------------------------
148 
149 template<typename MODEL>
151  Increment_ & dx2) const {
152  Log::trace() << "ErrorCovarianceBUMP<MODEL>::doInverseMultiply starting" << std::endl;
153  util::Timer timer(classname(), "doInverseMultiply");
154  dx2.zero();
155  Log::info() << "ErrorCovarianceBUMP<MODEL>::doInverseMultiply not implemented" << std::endl;
156  Log::trace() << "ErrorCovarianceBUMP<MODEL>::doInverseMultiply done" << std::endl;
157 }
158 
159 // -----------------------------------------------------------------------------
160 
161 template<typename MODEL>
163  Log::trace() << "ErrorCovarianceBUMP<MODEL>::randomize starting" << std::endl;
164  util::Timer timer(classname(), "randomize");
165  dx.random();
166  Log::trace() << "ErrorCovarianceBUMP<MODEL>::randomize done" << std::endl;
167 }
168 
169 // -----------------------------------------------------------------------------
170 
171 template<typename MODEL>
172 void ErrorCovarianceBUMP<MODEL>::print(std::ostream & os) const {
173  Log::trace() << "ErrorCovarianceBUMP<MODEL>::print starting" << std::endl;
174  util::Timer timer(classname(), "print");
175  os << "ErrorCovarianceBUMP<MODEL>::print not implemented";
176  Log::trace() << "ErrorCovarianceBUMP<MODEL>::print done" << std::endl;
177 }
178 
179 // -----------------------------------------------------------------------------
180 
181 } // namespace oops
182 
183 #endif // OOPS_GENERIC_ERRORCOVARIANCEBUMP_H_
void doMultiply(const Increment_ &, Increment_ &) const override
void delete_oobump_f90(const int &)
Model space error covariance on generic unstructured grid.
static const std::string classname()
Definition: conf.py:1
void doInverseMultiply(const Increment_ &, Increment_ &) const override
Increment< MODEL > Increment_
void zero()
Linear algebra operators.
Encapsulates the model state.
program test
The namespace for the main oops code.
void create_oobump_f90(int &, const int &, const eckit::Configuration *const *, const int &, const int &, const int &, const int &)
void field_to_ug(UnstructuredGrid &, const int &) const
subroutine, public info(self)
real(fp), parameter xb
Definition: ufo_aod_mod.F90:41
void print(std::ostream &) const override
void set_oobump_param_f90(const int &, const int &, const char *, const int &)
Abstract base class for model space error covariances.
ErrorCovarianceBUMP(const Geometry_ &, const Variables &, const eckit::Configuration &, const State_ &, const State_ &)
Increment Class: Difference between two states.
void multiply_oobump_nicas_f90(const int &, const int &)
void randomize(Increment_ &) const override
void run_oobump_drivers_f90(const int &)
void field_from_ug(const UnstructuredGrid &)
const util::DateTime validTime() const
Time.