FV3 Bundle
LocalizationBUMP.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 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_GENERIC_LOCALIZATIONBUMP_H_
9 #define OOPS_GENERIC_LOCALIZATIONBUMP_H_
10 
11 #include <sstream>
12 #include <string>
13 #include <vector>
14 
15 #include <boost/scoped_ptr.hpp>
16 
17 #include "eckit/config/Configuration.h"
20 #include "oops/base/Variables.h"
21 #include "oops/generic/oobump_f.h"
24 #include "oops/util/DateTime.h"
25 #include "oops/util/Duration.h"
26 #include "oops/util/Logger.h"
27 
28 namespace eckit {
29  class Configuration;
30 }
31 
32 namespace oops {
33 
34 // -----------------------------------------------------------------------------
35 /// BUMP localization matrix.
36 
37 template<typename MODEL>
38 class LocalizationBUMP : public LocalizationBase<MODEL> {
39  typedef typename MODEL::Geometry Geometry_;
40  typedef typename MODEL::Increment Increment_;
41  typedef typename MODEL::State State_;
42 
43  typedef boost::shared_ptr<StateEnsemble<MODEL> > EnsemblePtr_;
45 
46  public:
47  LocalizationBUMP(const Geometry_ &, const eckit::Configuration &);
49 
50  void multiply(Increment_ &) const;
51 
52  private:
53  void print(std::ostream &) const;
54 
56  int keyBUMP_;
57 };
58 
59 // =============================================================================
60 
61 template<typename MODEL>
63  const eckit::Configuration & conf)
64  : colocated_(1), keyBUMP_(0)
65 {
66  const eckit::Configuration * fconf = &conf;
67 
68 // Setup variables
69  const eckit::LocalConfiguration varConfig(conf, "variables");
70  const Variables vars(varConfig);
71 
72 // Setup dummy time
73  const util::DateTime date(conf.getString("date"));
74 
75 // Setup dummy increment
76  Increment_ dx(resol, vars, date);
77 
78 // Define unstructured grid coordinates
80  dx.ug_coord(ug, colocated_);
81 
82 // Define ensemble size
83  int new_hdiag = conf.getInt("new_hdiag");
84  int ens1_ne;
85  if (new_hdiag == 1) {
86  EnsemblePtr_ ens_ptr = EnsemblesCollection_::getInstance()[dx.validTime()];
87  ens1_ne = ens_ptr->size();
88  } else {
89  ens1_ne = 0;
90  }
91 
92 // Create BUMP
93  create_oobump_f90(keyBUMP_, ug.toFortran(), &fconf, ens1_ne, 1, 0, 0);
94 
95 // Copy ensemble members
96  if (new_hdiag == 1) {
97  EnsemblePtr_ ens_ptr = EnsemblesCollection_::getInstance()[dx.validTime()];
98  const double rk = sqrt((static_cast<double>(ens1_ne) - 1.0));
99  for (int ie = 0; ie < ens1_ne; ++ie) {
100  Log::info() << "Copy ensemble member " << ie+1 << " / "
101  << ens1_ne << " to BUMP" << std::endl;
102 
103  // Renormalize member
104  dx =(*ens_ptr)[ie].increment();
105  dx *= rk;
106 
107  // Define unstructured grid field
108  UnstructuredGrid ugmem;
109  dx.field_to_ug(ugmem, colocated_);
110 
111  // Copy field into BUMP ensemble
113  }
114  }
115 
116 // Run BUMP
118 
119 // Copy test
120  std::ifstream infile("bump.test");
121  std::string line;
122  while (std::getline(infile, line)) Log::test() << line << std::endl;
123  remove("bump.test");
124 
125  Log::trace() << "LocalizationBUMP:LocalizationBUMP constructed" << std::endl;
126 }
127 
128 // -----------------------------------------------------------------------------
129 
130 template<typename MODEL>
132  delete_oobump_f90(keyBUMP_);
133  Log::trace() << "LocalizationBUMP:~LocalizationBUMP destructed" << std::endl;
134 }
135 
136 // -----------------------------------------------------------------------------
137 
138 template<typename MODEL>
140  Log::trace() << "LocalizationBUMP:multiply starting" << std::endl;
141  UnstructuredGrid ug;
142  dx.field_to_ug(ug, colocated_);
143  multiply_oobump_nicas_f90(keyBUMP_, ug.toFortran());
144  dx.field_from_ug(ug);
145  Log::trace() << "LocalizationBUMP:multiply done" << std::endl;
146 }
147 
148 // -----------------------------------------------------------------------------
149 
150 template<typename MODEL>
151 void LocalizationBUMP<MODEL>::print(std::ostream & os) const {
152  os << "LocalizationBUMP<MODEL>::print not implemeted yet";
153 }
154 
155 // -----------------------------------------------------------------------------
156 
157 } // namespace oops
158 
159 #endif // OOPS_GENERIC_LOCALIZATIONBUMP_H_
void delete_oobump_f90(const int &)
boost::shared_ptr< StateEnsemble< MODEL > > EnsemblePtr_
MODEL::Increment Increment_
void multiply(Increment_ &) const
Definition: conf.py:1
static EnsemblesCollection< MODEL > & getInstance()
string date
Definition: TLM_vs_NLM.py:10
program test
LocalizationBUMP(const Geometry_ &, const eckit::Configuration &)
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 &)
BUMP localization matrix.
void print(std::ostream &) const
integer, private ie
Definition: fms_io.F90:494
subroutine, public info(self)
int readEnsMember(1)
EnsemblesCollection< MODEL > EnsemblesCollection_
Base class for localizations.
void multiply_oobump_nicas_f90(const int &, const int &)
void run_oobump_drivers_f90(const int &)
void add_oobump_member_f90(const int &, const int &, const int &, const int &)
MODEL::Geometry Geometry_