Go to the documentation of this file.
11 #ifndef OOPS_BASE_LINEARMODELBASE_H_
12 #define OOPS_BASE_LINEARMODELBASE_H_
19 #include <boost/make_unique.hpp>
20 #include <boost/noncopyable.hpp>
27 #include "oops/util/AssociativeContainers.h"
28 #include "oops/util/Duration.h"
29 #include "oops/util/Logger.h"
30 #include "oops/util/ObjectCounter.h"
31 #include "oops/util/parameters/ConfigurationParameter.h"
32 #include "oops/util/parameters/HasParameters_.h"
33 #include "oops/util/parameters/OptionalParameter.h"
34 #include "oops/util/parameters/Parameters.h"
35 #include "oops/util/parameters/RequiredPolymorphicParameter.h"
36 #include "oops/util/Printable.h"
51 template <
typename MODEL>
53 private boost::noncopyable {
61 static const std::string
classname() {
return "oops::LinearModelBase";}
85 virtual void setTrajectory(
const typename MODEL::State &,
typename MODEL::State &,
86 const typename MODEL::ModelAuxControl &) = 0;
90 virtual void stepTL(
typename MODEL::Increment &,
91 const typename MODEL::ModelAuxIncrement &)
const = 0;
92 virtual void finalizeTL(
typename MODEL::Increment &)
const = 0;
96 virtual void stepAD(
typename MODEL::Increment &,
typename MODEL::ModelAuxIncrement &)
const = 0;
97 virtual void finalizeAD(
typename MODEL::Increment &)
const = 0;
100 virtual void print(std::ostream &)
const = 0;
105 template <
typename MODEL>
122 OptionalParameter<std::string>
name{
"name",
this};
146 template <
typename MODEL>
154 RequiredPolymorphicParameter<LinearModelParametersBase, LinearModelFactory<MODEL>>
161 template <
typename MODEL>
162 class LinearModelFactory {
176 static std::unique_ptr<LinearModelParametersBase>
createParameters(
const std::string &name);
195 static std::map < std::string, LinearModelFactory<MODEL> * > &
getMakers() {
196 static std::map < std::string, LinearModelFactory<MODEL> * > makers_;
203 template<
class MODEL,
class T>
208 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericLinearModelParameters>
Parameters_;
214 const auto &stronglyTypedParameters =
dynamic_cast<const Parameters_&
>(parameters);
216 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParameters));
220 return boost::make_unique<Parameters_>();
229 template <
typename MODEL>
231 if (getMakers().find(name) != getMakers().end()) {
232 throw std::runtime_error(name +
" already registered in tangent linear model factory.");
234 getMakers()[name] =
this;
239 template <
typename MODEL>
242 Log::trace() <<
"LinearModelBase<MODEL>::create starting" << std::endl;
243 const std::string &
id = parameters.
name.value().value();
244 typename std::map<std::string, LinearModelFactory<MODEL>*>::iterator
245 jerr = getMakers().find(
id);
246 if (jerr == getMakers().end()) {
247 Log::error() <<
id <<
" does not exist in the tangent linear model factory." << std::endl;
248 Log::error() <<
"Factory contains " << getMakers().size() <<
" elements:" << std::endl;
250 jj = getMakers().begin(); jj != getMakers().end(); ++jj) {
251 Log::error() <<
"A " << jj->first <<
" linear model" << std::endl;
253 throw std::runtime_error(
id +
" does not exist in tangent linear model factory.");
256 Log::trace() <<
"LinearModelBase<MODEL>::create done" << std::endl;
262 template <
typename MODEL>
264 const std::string &name) {
265 typename std::map<std::string, LinearModelFactory<MODEL>*>::iterator it = getMakers().find(name);
266 if (it == getMakers().end()) {
267 throw std::runtime_error(name +
" does not exist in the tangent linear model factory");
269 return it->second->makeParameters();
274 template<
typename MODEL>
277 Log::trace() <<
"LinearModelBase<MODEL>::setTrajectory starting" << std::endl;
279 Log::trace() <<
"LinearModelBase<MODEL>::setTrajectory done" << std::endl;
284 template<
typename MODEL>
286 Log::trace() <<
"LinearModelBase<MODEL>::initializeTL starting" << std::endl;
288 Log::trace() <<
"LinearModelBase<MODEL>::initializeTL done" << std::endl;
293 template<
typename MODEL>
295 Log::trace() <<
"LinearModelBase<MODEL>::stepTL starting" << std::endl;
297 Log::trace() <<
"LinearModelBase<MODEL>::stepTL done" << std::endl;
302 template<
typename MODEL>
304 Log::trace() <<
"LinearModelBase<MODEL>::finalizeTL starting" << std::endl;
306 Log::trace() <<
"LinearModelBase<MODEL>::finalizeTL done" << std::endl;
311 template<
typename MODEL>
313 Log::trace() <<
"LinearModelBase<MODEL>::initializeAD starting" << std::endl;
315 Log::trace() <<
"LinearModelBase<MODEL>::initializeAD done" << std::endl;
320 template<
typename MODEL>
322 Log::trace() <<
"LinearModelBase<MODEL>::stepAD starting" << std::endl;
324 Log::trace() <<
"LinearModelBase<MODEL>::stepAD done" << std::endl;
329 template<
typename MODEL>
331 Log::trace() <<
"LinearModelBase<MODEL>::finalizeAD starting" << std::endl;
333 Log::trace() <<
"LinearModelBase<MODEL>::finalizeAD done" << std::endl;
340 #endif // OOPS_BASE_LINEARMODELBASE_H_
static LinearModelBase< MODEL > * create(const Geometry_ &, const LinearModelParametersBase ¶meters)
Create and return a new tangent linear model.
Geometry< MODEL > Geometry_
virtual void initializeAD(typename MODEL::Increment &) const =0
The namespace for the main oops code.
virtual void initializeTL(typename MODEL::Increment &) const =0
static std::vector< std::string > getMakerNames()
Return the names of all tangent linear models that can be created by one of the registered makers.
static const std::string classname()
virtual const oops::Variables & variables() const =0
A subclass of LinearModelParametersBase storing the values of all options in a single Configuration o...
static std::map< std::string, LinearModelFactory< MODEL > * > & getMakers()
Contains a polymorphic parameter holding an instance of a subclass of LinearModelParametersBase.
static std::unique_ptr< LinearModelParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of LinearModelParametersBase storing parameters of tang...
virtual LinearModelBase< MODEL > * make(const Geometry_ &, const LinearModelParametersBase &)=0
RequiredPolymorphicParameter< LinearModelParametersBase, LinearModelFactory< MODEL > > modelParameters
void finalizeTL(Increment_ &) const
void initializeTL(Increment_ &) const
LinearModelBase< MODEL > * make(const Geometry_ &geom, const LinearModelParametersBase ¶meters) override
virtual void print(std::ostream &) const =0
OptionalParameter< std::string > name
Model name.
State_ & state()
Interfacing.
LinearModelMaker(const std::string &name)
TParameters_IfAvailableElseFallbackType_t< T, GenericLinearModelParameters > Parameters_
void setTrajectory(const State_ &, State_ &, const ModelAux_ &)
void stepAD(Increment_ &, ModelAuxIncr_ &) const
virtual void stepAD(typename MODEL::Increment &, typename MODEL::ModelAuxIncrement &) const =0
Increment< MODEL > Increment_
virtual const util::Duration & timeResolution() const =0
const ModelAuxIncrement_ & modelauxincrement() const
Interfacing.
ModelAuxIncrement< MODEL > ModelAuxIncr_
virtual void stepTL(typename MODEL::Increment &, const typename MODEL::ModelAuxIncrement &) const =0
void initializeAD(Increment_ &) const
virtual void finalizeAD(typename MODEL::Increment &) const =0
Increment_ & increment()
Interfacing.
virtual std::unique_ptr< LinearModelParametersBase > makeParameters() const =0
Geometry class used in oops; subclass of interface class above.
virtual void finalizeTL(typename MODEL::Increment &) const =0
virtual void setTrajectory(const typename MODEL::State &, typename MODEL::State &, const typename MODEL::ModelAuxControl &)=0
Base class for encapsulation of the linear forecast model.
Base class for classes storing model-specific parameters.
Geometry< MODEL > Geometry_
ConfigurationParameter config
virtual ~LinearModelBase()
Encapsulates the model state.
LinearModelFactory(const std::string &name)
Register a maker able to create tangent linear models of type name.
void finalizeAD(Increment_ &) const
ModelAuxControl< MODEL > ModelAux_
Geometry< MODEL > Geometry_
std::unique_ptr< LinearModelParametersBase > makeParameters() const override
Increment Class: Difference between two states.
virtual ~LinearModelFactory()=default
Tangent linear model factory.
const ModelAuxControl_ & modelauxcontrol() const
Interfacing.
const Geometry_ & geometry() const
Interfacing with other oops classes.
void stepTL(Increment_ &, const ModelAuxIncr_ &) const