FV3 Bundle
State4D.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_ASSIMILATION_STATE4D_H_
12 #define OOPS_ASSIMILATION_STATE4D_H_
13 
14 #include <cmath>
15 #include <ostream>
16 #include <string>
17 #include <vector>
18 #include <boost/foreach.hpp>
19 #include <boost/ptr_container/ptr_vector.hpp>
20 
21 #include "eckit/config/LocalConfiguration.h"
23 #include "oops/interface/State.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/Printable.h"
26 
27 namespace oops {
28 
29 /// Four dimensional state
30 /*!
31  * The 4D state is mostly used as part of the VDA control variable.
32  */
33 
34 // -----------------------------------------------------------------------------
35 template<typename MODEL> class State4D : public util::Printable {
38 
39  public:
40  static const std::string classname() {return "State4D";}
41 
42 /// The arguments define the number of sub-windows and the resolution
43  State4D(const eckit::Configuration &, const Variables &, const Geometry_ &);
44  explicit State4D(const State4D &);
45  ~State4D();
46 
47 /// I/O and diagnostics
48  void read(const eckit::Configuration &);
49  void write(const eckit::Configuration &) const;
50  double norm() const;
51 
52 /// Get model space control variable
53  bool checkStatesNumber(const unsigned int nn) const {return state4d_.size() == nn;}
54  size_t size() const {return state4d_.size();}
55  State_ & operator[](const int ii) {return state4d_[ii];}
56  const State_ & operator[](const int ii) const {return state4d_[ii];}
57 
58  private:
59  State4D & operator= (const State4D &); // No assignment
60  void print(std::ostream &) const;
61 
62  boost::ptr_vector<State_> state4d_;
63 };
64 
65 // =============================================================================
66 
67 template<typename MODEL>
68 State4D<MODEL>::State4D(const eckit::Configuration & config, const Variables & vars,
69  const Geometry_ & resol) {
70  std::vector<eckit::LocalConfiguration> files;
71  config.get("state", files);
72  Log::debug() << "State4D: reading " << files.size() << " states." << std::endl;
73 
74  for (size_t jsub = 0; jsub < files.size(); ++jsub) {
75  Log::debug() << "State4D:reading" << files[jsub] << std::endl;
76  State_ * js = new State_(resol, vars, files[jsub]);
77  Log::debug() << "State4D:State4D: read bg at " << js->validTime() << std::endl;
78  state4d_.push_back(js);
79  }
80  Log::trace() << "State4D constructed." << std::endl;
81 }
82 
83 // -----------------------------------------------------------------------------
84 
85 template<typename MODEL>
87  BOOST_FOREACH(const State_ & js, other.state4d_)
88  state4d_.push_back(new State_(js));
89  Log::trace() << "State4D copied." << std::endl;
90 }
91 
92 // -----------------------------------------------------------------------------
93 
94 template<typename MODEL>
96  Log::trace() << "State4D destructed." << std::endl;
97 }
98 
99 // -----------------------------------------------------------------------------
100 
101 template<typename MODEL>
102 void State4D<MODEL>::read(const eckit::Configuration & config) {
103  std::vector<eckit::LocalConfiguration> confs;
104  config.get("state", confs);
105  ASSERT(state4d_.size() == confs.size());
106  unsigned jsub = 0;
107  BOOST_FOREACH(State_ & js, state4d_) {
108  Log::debug() << "State4D:read" << confs[jsub] << std::endl;
109  js.read(confs[jsub]);
110  ++jsub;
111  }
112 }
113 
114 // -----------------------------------------------------------------------------
115 
116 template<typename MODEL>
117 void State4D<MODEL>::write(const eckit::Configuration & config) const {
118  std::vector<eckit::LocalConfiguration> confs;
119  config.get("state", confs);
120  ASSERT(state4d_.size() == confs.size());
121  unsigned int jsub = 0;
122  BOOST_FOREACH(const State_ & js, state4d_) {
123  Log::debug() << "State4D:write" << confs[jsub] << std::endl;
124  js.write(confs[jsub]);
125  ++jsub;
126  }
127 }
128 
129 // -----------------------------------------------------------------------------
130 
131 template <typename MODEL>
132 void State4D<MODEL>::print(std::ostream & outs) const {
133  BOOST_FOREACH(const State_ & js, state4d_) {
134  outs << js << std::endl;
135  }
136 }
137 
138 // -----------------------------------------------------------------------------
139 
140 template<typename MODEL>
141 double State4D<MODEL>::norm() const {
142  double zn = 0.0;
143  BOOST_FOREACH(const State_ & js, state4d_) {
144  double zz = js.norm();
145  zn += zz * zz;
146  }
147  return sqrt(zn);
148 }
149 
150 // -----------------------------------------------------------------------------
151 
152 } // namespace oops
153 
154 #endif // OOPS_ASSIMILATION_STATE4D_H_
void read(const eckit::Configuration &)
I/O and diagnostics.
Definition: State4D.h:102
double norm() const
Definition: State4D.h:141
Geometry< MODEL > Geometry_
Definition: State4D.h:36
void write(const eckit::Configuration &) const
Definition: State4D.h:117
Encapsulates the model state.
The namespace for the main oops code.
logical debug
Definition: mpp.F90:1297
State_ & operator[](const int ii)
Definition: State4D.h:55
type(file_type), dimension(:), allocatable, save files
Definition: diag_data.F90:780
const State_ & operator[](const int ii) const
Definition: State4D.h:56
boost::ptr_vector< State_ > state4d_
Definition: State4D.h:62
State4D & operator=(const State4D &)
size_t size() const
Definition: State4D.h:54
State< MODEL > State_
Definition: State4D.h:37
void print(std::ostream &) const
Definition: State4D.h:132
Four dimensional state.
Definition: CostJbState.h:29
static const std::string classname()
Definition: State4D.h:40
bool checkStatesNumber(const unsigned int nn) const
Get model space control variable.
Definition: State4D.h:53
l_size ! loop over number of fields ke do je do ie to js
State4D(const eckit::Configuration &, const Variables &, const Geometry_ &)
The arguments define the number of sub-windows and the resolution.
Definition: State4D.h:68