FV3 Bundle
oops/interface/State.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_INTERFACE_STATE_H_
12 #define OOPS_INTERFACE_STATE_H_
13 
14 #include <string>
15 
16 #include <boost/scoped_ptr.hpp>
17 
18 #include "eckit/config/Configuration.h"
19 #include "oops/base/GridPoint.h"
21 #include "oops/base/Variables.h"
24 #include "oops/interface/GeoVaLs.h"
27 #include "oops/util/DateTime.h"
28 #include "oops/util/ObjectCounter.h"
29 #include "oops/util/Printable.h"
30 #include "oops/util/Timer.h"
31 
32 namespace oops {
33 
34 /// Encapsulates the model state
35 
36 // -----------------------------------------------------------------------------
37 
38 template <typename MODEL>
39 class State : public util::Printable,
40  private util::ObjectCounter<State<MODEL> > {
41  typedef typename MODEL::State State_;
47 
48  public:
49  static const std::string classname() {return "oops::State";}
50 
51 /// Constructor, destructor
52  State(const Geometry_ &, const Variables &, const util::DateTime &);
53  State(const Geometry_ &, const Variables &, const eckit::Configuration &);
54  State(const Geometry_ &, const State &);
55  State(const State &);
56  ~State();
57  State & operator=(const State &); // Is that used anywhere?
58 
59 /// Interfacing
60  State_ & state() {return *state_;}
61  const State_ & state() const {return *state_;}
62 
63 /// Get state values at observation locations
64  void getValues(const Locations_ &, const Variables &, GeoVaLs_ &) const;
65  void getValues(const Locations_ &, const Variables &, GeoVaLs_ &, InterpolatorTraj_ &) const;
66 
67 /// Time
68  const util::DateTime validTime() const {return state_->validTime();}
69 
70 /// I/O and diagnostics
71  void read(const eckit::Configuration &);
72  void write(const eckit::Configuration &) const;
73  double norm() const; // Only for tests
74  Geometry_ geometry() const;
75 
76  GridPoint getPoint(const GeometryIterator_ & iter) const;
77 
78  protected:
79  void zero();
80  void accumul(const double &, const State &);
81 
82  private:
83  void print(std::ostream &) const;
84  boost::scoped_ptr<State_> state_;
85 };
86 
87 // =============================================================================
88 
89 template<typename MODEL>
91  const util::DateTime & time) : state_()
92 {
93  Log::trace() << "State<MODEL>::State starting" << std::endl;
94  util::Timer timer(classname(), "State");
95  state_.reset(new State_(resol.geometry(), vars, time));
96  Log::trace() << "State<MODEL>::State done" << std::endl;
97 }
98 
99 // -----------------------------------------------------------------------------
100 
101 template<typename MODEL>
103  const eckit::Configuration & conf) : state_()
104 {
105  Log::trace() << "State<MODEL>::State read starting" << std::endl;
106  util::Timer timer(classname(), "State");
107  state_.reset(new State_(resol.geometry(), vars, conf));
108  Log::trace() << "State<MODEL>::State read done" << std::endl;
109 }
110 
111 // -----------------------------------------------------------------------------
112 
113 template<typename MODEL>
114 State<MODEL>::State(const Geometry_ & resol, const State & other) : state_()
115 {
116  Log::trace() << "State<MODEL>::State interpolated starting" << std::endl;
117  util::Timer timer(classname(), "State");
118  state_.reset(new State_(resol.geometry(), *other.state_));
119  Log::trace() << "State<MODEL>::State interpolated done" << std::endl;
120 }
121 
122 // -----------------------------------------------------------------------------
123 
124 template<typename MODEL>
125 State<MODEL>::State(const State & other) : state_()
126 {
127  Log::trace() << "State<MODEL>::State starting copy" << std::endl;
128  util::Timer timer(classname(), "State");
129  state_.reset(new State_(*other.state_));
130  Log::trace() << "State<MODEL>::State copy done" << std::endl;
131 }
132 
133 // -----------------------------------------------------------------------------
134 
135 template<typename MODEL>
137  Log::trace() << "State<MODEL>::~State starting" << std::endl;
138  util::Timer timer(classname(), "~State");
139  state_.reset();
140  Log::trace() << "State<MODEL>::~State done" << std::endl;
141 }
142 
143 // -----------------------------------------------------------------------------
144 
145 template<typename MODEL>
147  Log::trace() << "State<MODEL>::operator= starting" << std::endl;
148  util::Timer timer(classname(), "operator=");
149  *state_ = *rhs.state_;
150  Log::trace() << "State<MODEL>::operator= done" << std::endl;
151  return *this;
152 }
153 
154 // -----------------------------------------------------------------------------
155 
156 template<typename MODEL>
158  GeoVaLs_ & gvals) const {
159  Log::trace() << "State<MODEL>::getValues starting" << std::endl;
160  util::Timer timer(classname(), "getValues");
161  state_->getValues(locs.locations(), vars, gvals.geovals());
162  Log::trace() << "State<MODEL>::getValues done" << std::endl;
163 }
164 
165 // -----------------------------------------------------------------------------
166 
167 template<typename MODEL>
169  GeoVaLs_ & gvals, InterpolatorTraj_ & traj) const {
170  Log::trace() << "State<MODEL>::getValues traj starting" << std::endl;
171  util::Timer timer(classname(), "getValues");
172  state_->getValues(locs.locations(), vars, gvals.geovals(), traj.interpolatortraj());
173  Log::trace() << "State<MODEL>::getValues traj done" << std::endl;
174 }
175 
176 // -----------------------------------------------------------------------------
177 
178 template<typename MODEL>
179 void State<MODEL>::read(const eckit::Configuration & conf) {
180  Log::trace() << "State<MODEL>::read starting" << std::endl;
181  util::Timer timer(classname(), "read");
182  state_->read(conf);
183  Log::trace() << "State<MODEL>::read done" << std::endl;
184 }
185 
186 // -----------------------------------------------------------------------------
187 
188 template<typename MODEL>
189 void State<MODEL>::write(const eckit::Configuration & conf) const {
190  Log::trace() << "State<MODEL>::write starting" << std::endl;
191  util::Timer timer(classname(), "write");
192  state_->write(conf);
193  Log::trace() << "State<MODEL>::write done" << std::endl;
194 }
195 
196 // -----------------------------------------------------------------------------
197 
198 template<typename MODEL>
199 double State<MODEL>::norm() const {
200  Log::trace() << "State<MODEL>::norm starting" << std::endl;
201  util::Timer timer(classname(), "norm");
202  double zz = state_->norm();
203  Log::trace() << "State<MODEL>::norm done" << std::endl;
204  return zz;
205 }
206 
207 // -----------------------------------------------------------------------------
208 
209 template<typename MODEL>
211  Log::trace() << "State<MODEL>::geometry starting" << std::endl;
212  util::Timer timer(classname(), "geometry");
213  Geometry<MODEL> geom(state_->geometry());
214  Log::trace() << "State<MODEL>::geometry done" << std::endl;
215  return geom;
216 }
217 
218 // -----------------------------------------------------------------------------
219 
220 
221 template<typename MODEL>
222 void State<MODEL>::print(std::ostream & os) const {
223  Log::trace() << "State<MODEL>::print starting" << std::endl;
224  util::Timer timer(classname(), "print");
225  os << *state_;
226  Log::trace() << "State<MODEL>::print done" << std::endl;
227 }
228 
229 // -----------------------------------------------------------------------------
230 
231 template<typename MODEL>
233  Log::trace() << "State<MODEL>::zero starting" << std::endl;
234  util::Timer timer(classname(), "zero");
235  state_->zero();
236  Log::trace() << "State<MODEL>::zero done" << std::endl;
237 }
238 
239 // -----------------------------------------------------------------------------
240 
241 template<typename MODEL>
242 void State<MODEL>::accumul(const double & zz, const State & xx) {
243  Log::trace() << "State<MODEL>::accumul starting" << std::endl;
244  util::Timer timer(classname(), "accumul");
245  state_->accumul(zz, *xx.state_);
246  Log::trace() << "State<MODEL>::accumul done" << std::endl;
247 }
248 
249 // -----------------------------------------------------------------------------
250 
251 template<typename MODEL>
253  Log::trace() << "State<MODEL>::getPoint starting" << std::endl;
254  util::Timer timer(classname(), "getPoint");
255  GridPoint gp = state_->getPoint(iter.geometryiter());
256  Log::trace() << "State<MODEL>::getPoint done" << std::endl;
257  return gp;
258 }
259 
260 // -----------------------------------------------------------------------------
261 
262 } // namespace oops
263 
264 #endif // OOPS_INTERFACE_STATE_H_
boost::scoped_ptr< State_ > state_
const GeoVaLs_ & geovals() const
Interfacing.
InterpolatorTraj< MODEL > InterpolatorTraj_
State & operator=(const State &)
MODEL::State State_
Geometry< MODEL > Geometry_
void getValues(const Locations_ &, const Variables &, GeoVaLs_ &) const
Get state values at observation locations.
Definition: conf.py:1
State(const Geometry_ &, const Variables &, const util::DateTime &)
Constructor, destructor.
GeometryIterator< MODEL > GeometryIterator_
Encapsulates the model state.
State_ & state()
Interfacing.
const Locations_ & locations() const
Interfacing.
static const std::string classname()
double norm() const
The namespace for the main oops code.
const GeometryIterator_ & geometryiter() const
Interfacing.
const State_ & state() const
GridPoint getPoint(const GeometryIterator_ &iter) const
void accumul(const double &, const State &)
const Geometry_ & geometry() const
Interfacing.
InterpolatorTraj_ & interpolatortraj()
Interfacing.
Locations< MODEL > Locations_
GeoVaLs< MODEL > GeoVaLs_
void read(const eckit::Configuration &)
I/O and diagnostics.
Geometry_ geometry() const
void write(const eckit::Configuration &) const
void print(std::ostream &) const
const util::DateTime validTime() const
Time.