Go to the documentation of this file.
8 #ifndef OOPS_BASE_MODELBASE_H_
9 #define OOPS_BASE_MODELBASE_H_
16 #include <boost/make_unique.hpp>
17 #include <boost/noncopyable.hpp>
22 #include "oops/util/AssociativeContainers.h"
23 #include "oops/util/Duration.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/parameters/ConfigurationParameter.h"
26 #include "oops/util/parameters/HasParameters_.h"
27 #include "oops/util/parameters/OptionalParameter.h"
28 #include "oops/util/parameters/Parameters.h"
29 #include "oops/util/parameters/ParametersOrConfiguration.h"
30 #include "oops/util/parameters/RequiredPolymorphicParameter.h"
31 #include "oops/util/Printable.h"
43 template <
typename MODEL>
45 private boost::noncopyable {
47 typedef typename MODEL::State
State_;
50 static const std::string
classname() {
return "oops::ModelBase";}
70 virtual void print(std::ostream &)
const = 0;
75 template <
typename MODEL>
91 OptionalParameter<std::string>
name{
"name",
this};
115 template <
typename MODEL>
122 RequiredPolymorphicParameter<ModelParametersBase, ModelFactory<MODEL>>
129 template <
typename MODEL>
143 static std::unique_ptr<ModelParametersBase>
createParameters(
const std::string &name);
161 static std::map < std::string, ModelFactory<MODEL> * > &
getMakers() {
162 static std::map < std::string, ModelFactory<MODEL> * > makers_;
171 template<
class MODEL,
class T>
176 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericModelParameters>
Parameters_;
184 Log::trace() <<
"ModelBase<MODEL>::make starting" << std::endl;
185 const auto &stronglyTypedParameters =
dynamic_cast<const Parameters_&
>(parameters);
187 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParameters));
191 return boost::make_unique<Parameters_>();
197 template <
typename MODEL>
199 Log::trace() <<
"ModelFactory<MODEL>::ModelFactory starting" << std::endl;
200 if (getMakers().find(name) != getMakers().end()) {
201 throw std::runtime_error(name +
" already registered in the model factory.");
203 getMakers()[name] =
this;
204 Log::trace() <<
"ModelFactory<MODEL>::ModelFactory done" << std::endl;
209 template <
typename MODEL>
212 Log::trace() <<
"ModelFactory<MODEL>::create starting" << std::endl;
213 const std::string &
id = parameters.
name.value().value();
214 typename std::map<std::string, ModelFactory<MODEL>*>::iterator
215 jerr = getMakers().find(
id);
216 if (jerr == getMakers().end()) {
217 throw std::runtime_error(
id +
" does not exist in the model factory");
220 Log::trace() <<
"ModelFactory<MODEL>::create done" << std::endl;
226 template <
typename MODEL>
228 const std::string &name) {
229 Log::trace() <<
"ModelFactory<MODEL>::createParameters starting" << std::endl;
230 typename std::map<std::string, ModelFactory<MODEL>*>::iterator it = getMakers().find(name);
231 if (it == getMakers().end()) {
232 throw std::runtime_error(name +
" does not exist in the model factory");
234 return it->second->makeParameters();
241 #endif // OOPS_BASE_MODELBASE_H_
Base class for the forecasting model Defines the interfaces for a forecast model.
virtual ModelBase< MODEL > * make(const Geometry_ &, const ModelParametersBase &)=0
The namespace for the main oops code.
OptionalParameter< std::string > name
Model name.
static std::vector< std::string > getMakerNames()
Return the names of all models that can be created by one of the registered makers.
Geometry< MODEL > Geometry_
virtual void initialize(State_ &) const =0
Forecast initialization, called before every forecast run.
ModelBase< MODEL > * make(const Geometry_ &geom, const ModelParametersBase ¶meters) override
virtual const oops::Variables & variables() const =0
Model variables (only used in 4DVar)
ModelMaker(const std::string &name)
virtual void print(std::ostream &) const =0
Print; used for logging.
A subclass of ModelFactory able to create instances of T (a concrete subclass of ModelBase<MODEL>).
Geometry< MODEL > Geometry_
std::unique_ptr< ModelParametersBase > makeParameters() const override
TParameters_IfAvailableElseFallbackType_t< T, GenericModelParameters > Parameters_
A subclass of ModelParametersBase storing the values of all options in a single Configuration object.
MODEL::ModelAuxControl ModelAux_
static const std::string classname()
virtual ~ModelBase()=default
static std::unique_ptr< ModelParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of ModelParametersBase storing parameters of models of ...
virtual ~ModelFactory()=default
static std::map< std::string, ModelFactory< MODEL > * > & getMakers()
Geometry class used in oops; subclass of interface class above.
Contains a polymorphic parameter holding an instance of a subclass of ModelParametersBase.
Base class for classes storing model-specific parameters.
RequiredPolymorphicParameter< ModelParametersBase, ModelFactory< MODEL > > modelParameters
virtual const util::Duration & timeResolution() const =0
Time step for running Model's forecast in oops (frequency with which the State will be updated)
static ModelBase< MODEL > * create(const Geometry_ &, const ModelParametersBase ¶meters)
Create and return a new model.
virtual void finalize(State_ &) const =0
Forecast finalization; called after each forecast run.
ConfigurationParameter config
virtual std::unique_ptr< ModelParametersBase > makeParameters() const =0
virtual void step(State_ &, const ModelAux_ &) const =0
Forecast "step", called during forecast run; updates state to the next time.
ModelFactory(const std::string &name)
Register a maker able to create models of type name.
const Geometry_ & geometry() const
Interfacing with other oops classes.