12 #ifndef OOPS_INTERFACE_STATE_H_
13 #define OOPS_INTERFACE_STATE_H_
19 #include "eckit/config/Configuration.h"
23 #include "oops/util/DateTime.h"
24 #include "oops/util/gatherPrint.h"
25 #include "oops/util/ObjectCounter.h"
26 #include "oops/util/Printable.h"
27 #include "oops/util/Serializable.h"
28 #include "oops/util/Timer.h"
38 template <
typename MODEL>
39 class State :
public util::Printable,
40 public util::Serializable,
41 private util::ObjectCounter<State<MODEL> > {
42 typedef typename MODEL::State
State_;
46 static const std::string
classname() {
return "oops::State";}
72 void read(
const eckit::Configuration &);
74 void write(
const eckit::Configuration &)
const;
90 void serialize(std::vector<double> &)
const override;
91 void deserialize(
const std::vector<double> &,
size_t &)
override;
95 void print(std::ostream &)
const override;
100 template<
typename MODEL>
102 const util::DateTime & time) : state_()
104 Log::trace() <<
"State<MODEL>::State starting" << std::endl;
107 this->setObjectSize(
state_->serialSize()*
sizeof(
double));
108 Log::trace() <<
"State<MODEL>::State done" << std::endl;
113 template<
typename MODEL>
117 Log::trace() <<
"State<MODEL>::State read starting" << std::endl;
120 eckit::LocalConfiguration myconf;
121 if (conf.has(
"states")) {
123 std::vector<eckit::LocalConfiguration> confs;
124 conf.get(
"states", confs);
125 ASSERT(confs.size() == resol.
timeComm().size());
126 myconf = confs[resol.
timeComm().rank()];
129 myconf = eckit::LocalConfiguration(conf);
133 this->setObjectSize(
state_->serialSize()*
sizeof(
double));
134 Log::trace() <<
"State<MODEL>::State read done" << std::endl;
139 template<
typename MODEL>
143 Log::trace() <<
"State<MODEL>::State interpolated starting" << std::endl;
146 this->setObjectSize(
state_->serialSize()*
sizeof(
double));
147 Log::trace() <<
"State<MODEL>::State interpolated done" << std::endl;
152 template<
typename MODEL>
155 Log::trace() <<
"State<MODEL>::State starting copy" << std::endl;
158 this->setObjectSize(
state_->serialSize()*
sizeof(
double));
159 Log::trace() <<
"State<MODEL>::State copy done" << std::endl;
164 template<
typename MODEL>
166 Log::trace() <<
"State<MODEL>::~State starting" << std::endl;
167 util::Timer timer(classname(),
"~State");
169 Log::trace() <<
"State<MODEL>::~State done" << std::endl;
174 template<
typename MODEL>
176 Log::trace() <<
"State<MODEL>::operator= starting" << std::endl;
177 util::Timer timer(classname(),
"operator=");
179 Log::trace() <<
"State<MODEL>::operator= done" << std::endl;
185 template<
typename MODEL>
187 Log::trace() <<
"State<MODEL>::read starting" << std::endl;
188 util::Timer timer(classname(),
"read");
190 Log::trace() <<
"State<MODEL>::read done" << std::endl;
195 template<
typename MODEL>
197 Log::trace() <<
"State<MODEL>::write starting" << std::endl;
198 util::Timer timer(classname(),
"write");
200 Log::trace() <<
"State<MODEL>::write done" << std::endl;
205 template<
typename MODEL>
207 Log::trace() <<
"State<MODEL>::norm starting" << std::endl;
208 util::Timer timer(classname(),
"norm");
209 double zz = state_->norm();
210 Log::trace() <<
"State<MODEL>::norm done" << std::endl;
216 template<
typename MODEL>
218 Log::trace() <<
"State<MODEL>::geometry starting" << std::endl;
219 util::Timer timer(classname(),
"geometry");
221 Log::trace() <<
"State<MODEL>::geometry done" << std::endl;
227 template<
typename MODEL>
229 Log::trace() <<
"State<MODEL>::variables starting" << std::endl;
230 util::Timer timer(classname(),
"variables");
231 return state_->variables();
236 template<
typename MODEL>
238 Log::trace() <<
"State<MODEL>::serialSize" << std::endl;
239 util::Timer timer(classname(),
"serialSize");
240 return state_->serialSize();
245 template<
typename MODEL>
247 Log::trace() <<
"State<MODEL>::serialize starting" << std::endl;
248 util::Timer timer(classname(),
"serialize");
249 state_->serialize(vect);
250 Log::trace() <<
"State<MODEL>::serialize done" << std::endl;
255 template<
typename MODEL>
257 Log::trace() <<
"State<MODEL>::State deserialize starting" << std::endl;
258 util::Timer timer(classname(),
"deserialize");
259 state_->deserialize(vect, current);
260 Log::trace() <<
"State<MODEL>::State deserialize done" << std::endl;
265 template<
typename MODEL>
267 Log::trace() <<
"State<MODEL>::print starting" << std::endl;
268 util::Timer timer(classname(),
"print");
270 Log::trace() <<
"State<MODEL>::print done" << std::endl;
275 template<
typename MODEL>
277 Log::trace() <<
"State<MODEL>::zero starting" << std::endl;
278 util::Timer timer(classname(),
"zero");
280 Log::trace() <<
"State<MODEL>::zero done" << std::endl;
285 template<
typename MODEL>
287 Log::trace() <<
"State<MODEL>::accumul starting" << std::endl;
288 util::Timer timer(classname(),
"accumul");
289 state_->accumul(zz, *xx.
state_);
290 Log::trace() <<
"State<MODEL>::accumul done" << std::endl;
Geometry class used in oops; subclass of interface class interface::Geometry.
const eckit::mpi::Comm & timeComm() const
Accessor to the MPI communicator for distribution in time.
const Geometry_ & geometry() const
Encapsulates the model state.
void print(std::ostream &) const override
Geometry_ geometry() const
Accessor to geometry associated with this State.
State & operator=(const State &)
Assignment operator.
oops::Geometry< MODEL > Geometry_
void zero()
Zero out this State.
State(const Geometry_ &resol, const Variables &vars, const util::DateTime &time)
Constructor for specified resol, with vars, valid at time.
const util::DateTime validTime() const
Accessor to the time of this State.
static const std::string classname()
const Variables & variables() const
Accessor to variables associated with this State.
State_ & state()
Accessor.
size_t serialSize() const override
Serialize and deserialize (used in 4DEnVar, weak-constraint 4DVar and Block-Lanczos minimizer)
const State_ & state() const
const accessor
void updateTime(const util::Duration &dt)
Update this State's valid time by dt.
~State()
Destructor (defined explicitly for timing and tracing)
void accumul(const double &w, const State &x)
Accumulate (add w * x to the state)
void serialize(std::vector< double > &) const override
std::unique_ptr< State_ > state_
void read(const eckit::Configuration &)
Read this State from file.
void write(const eckit::Configuration &) const
Write this State out to file.
void deserialize(const std::vector< double > &, size_t &) override
double norm() const
Norm (used in tests)
The namespace for the main oops code.