8 #ifndef OOPS_GENERIC_LINEARMODELBASE_H_
9 #define OOPS_GENERIC_LINEARMODELBASE_H_
16 #include <boost/make_unique.hpp>
17 #include <boost/noncopyable.hpp>
24 #include "oops/util/AssociativeContainers.h"
25 #include "oops/util/Duration.h"
26 #include "oops/util/Logger.h"
27 #include "oops/util/parameters/ConfigurationParameter.h"
28 #include "oops/util/parameters/HasParameters_.h"
29 #include "oops/util/parameters/OptionalParameter.h"
30 #include "oops/util/parameters/Parameters.h"
31 #include "oops/util/parameters/ParametersOrConfiguration.h"
32 #include "oops/util/parameters/RequiredPolymorphicParameter.h"
33 #include "oops/util/Printable.h"
61 template <
typename MODEL>
63 private boost::noncopyable {
70 static const std::string
classname() {
return "oops::LinearModelBase";}
100 virtual void print(std::ostream &)
const = 0;
105 template <
typename MODEL>
122 OptionalParameter<std::string>
name{
"name",
this};
146 template <
typename MODEL>
153 RequiredPolymorphicParameter<LinearModelParametersBase, LinearModelFactory<MODEL>>
160 template <
typename MODEL>
175 static std::unique_ptr<LinearModelParametersBase>
createParameters(
const std::string &name);
194 static std::map < std::string, LinearModelFactory<MODEL> * > &
getMakers() {
195 static std::map < std::string, LinearModelFactory<MODEL> * > makers_;
204 template<
class MODEL,
class T>
209 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericLinearModelParameters>
Parameters_;
218 Log::trace() <<
"LinearModelBase<MODEL>::make starting" << std::endl;
219 const auto &stronglyTypedParameters =
dynamic_cast<const Parameters_&
>(parameters);
221 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParameters));
225 return boost::make_unique<Parameters_>();
231 template <
typename MODEL>
233 if (getMakers().find(name) != getMakers().end()) {
234 throw std::runtime_error(name +
" already registered in the linear model factory.");
236 getMakers()[name] =
this;
241 template <
typename MODEL>
244 Log::trace() <<
"LinearModelFactory<MODEL>::create starting" << std::endl;
245 const std::string &
id = parameters.
name.value().value();
246 typename std::map<std::string, LinearModelFactory<MODEL>*>::iterator
247 jerr = getMakers().find(
id);
248 if (jerr == getMakers().end()) {
249 throw std::runtime_error(
id +
" does not exist in the linear model factory");
252 Log::trace() <<
"LinearModelFactory<MODEL>::create done" << std::endl;
258 template <
typename MODEL>
260 const std::string &name) {
261 Log::trace() <<
"LinearModelFactory<MODEL>::createParameters starting" << std::endl;
262 typename std::map<std::string, LinearModelFactory<MODEL>*>::iterator it = getMakers().find(name);
263 if (it == getMakers().end()) {
264 throw std::runtime_error(name +
" does not exist in the linear model factory");
266 return it->second->makeParameters();
A subclass of LinearModelParametersBase storing the values of all options in a single Configuration o...
ConfigurationParameter config
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
Base class for generic implementations of the linearized forecasting models. Use this class as a base...
virtual void print(std::ostream &) const =0
Print; used for logging.
virtual const oops::Variables & variables() const =0
LinearModel variables (only used in 4DVar)
virtual void setTrajectory(const State_ &, State_ &, const ModelAuxCtl_ &)=0
Set the trajectory for the linear model, called after each step of the forecast.
virtual void initializeAD(Increment_ &) const =0
Tangent linear initialization, called before every run.
virtual void finalizeTL(Increment_ &) const =0
Tangent linear finalization; called after each run.
virtual void finalizeAD(Increment_ &) const =0
Tangent linear finalization; called after each run.
Increment< MODEL > Increment_
ModelAuxIncrement< MODEL > ModelAuxInc_
virtual void initializeTL(Increment_ &) const =0
Tangent linear initialization, called before every run.
virtual void stepTL(Increment_ &, const ModelAuxInc_ &) const =0
Tangent linear "step", called during run; updates increment to the next time.
virtual void stepAD(Increment_ &, ModelAuxInc_ &) const =0
Tangent linear "step", called during run; updates increment to the next time.
virtual const util::Duration & timeResolution() const =0
Time step for running LinearModel's forecast in oops (frequency with which the increment will be upda...
virtual ~LinearModelBase()=default
ModelAuxControl< MODEL > ModelAuxCtl_
static const std::string classname()
LinearModelBase()=default
LinearModelFactory(const std::string &name)
Register a maker able to create linear models of type name.
virtual ~LinearModelFactory()=default
Geometry< MODEL > Geometry_
static LinearModelBase< MODEL > * create(const Geometry_ &, const LinearModelParametersBase ¶meters)
Create and return a new linear model.
virtual std::unique_ptr< LinearModelParametersBase > makeParameters() const =0
static std::vector< std::string > getMakerNames()
Return the names of all linear models that can be created by one of the registered makers.
static std::map< std::string, LinearModelFactory< MODEL > * > & getMakers()
virtual LinearModelBase< MODEL > * make(const Geometry_ &, const LinearModelParametersBase &)=0
static std::unique_ptr< LinearModelParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of LinearModelParametersBase storing parameters of line...
A subclass of LinearModelFactory able to create instances of T (a concrete subclass of LinearModelBas...
std::unique_ptr< LinearModelParametersBase > makeParameters() const override
LinearModelMaker(const std::string &name)
Geometry< MODEL > Geometry_
TParameters_IfAvailableElseFallbackType_t< T, GenericLinearModelParameters > Parameters_
LinearModelBase< MODEL > * make(const Geometry_ &geom, const LinearModelParametersBase ¶meters) override
Base class for classes storing linear model-specific parameters.
OptionalParameter< std::string > name
LinearModel name.
Contains a polymorphic parameter holding an instance of a subclass of LinearModelParametersBase.
RequiredPolymorphicParameter< LinearModelParametersBase, LinearModelFactory< MODEL > > linearModelParameters
Auxiliary state related to model (could be e.g. model bias), not used at the moment.
Auxiliary Increment related to model, not used at the moment.
State class used in oops; subclass of interface class interface::State.
The namespace for the main oops code.