Go to the documentation of this file.
8 #ifndef OOPS_BASE_VARIABLECHANGEBASE_H_
9 #define OOPS_BASE_VARIABLECHANGEBASE_H_
16 #include <boost/make_unique.hpp>
17 #include <boost/noncopyable.hpp>
22 #include "oops/util/AssociativeContainers.h"
23 #include "oops/util/parameters/ConfigurationParameter.h"
24 #include "oops/util/parameters/HasParameters_.h"
25 #include "oops/util/parameters/Parameters.h"
26 #include "oops/util/parameters/PolymorphicParameter.h"
27 #include "oops/util/Printable.h"
47 template <
typename MODEL>
49 private boost::noncopyable {
67 virtual void print(std::ostream &)
const = 0;
74 template <
typename MODEL>
92 ConfigurationParameter config{
this};
99 template <
typename MODEL>
107 PolymorphicParameter<VariableChangeParametersBase, VariableChangeFactory<MODEL>>
114 template <
typename MODEL>
115 class VariableChangeFactory {
135 static std::unique_ptr<VariableChangeParametersBase>
createParameters(
const std::string &name);
153 virtual std::unique_ptr<VariableChangeParametersBase>
makeParameters()
const = 0;
155 static std::map < std::string, VariableChangeFactory<MODEL> * > &
getMakers() {
156 static std::map < std::string, VariableChangeFactory<MODEL> * > makers_;
163 template<
class MODEL,
class T>
167 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericVariableChangeParameters>
Parameters_;
173 const auto &stronglyTypedParams =
dynamic_cast<const Parameters_&
>(params);
175 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParams));
179 return boost::make_unique<Parameters_>();
189 template <
typename MODEL>
191 if (getMakers().find(name) != getMakers().end()) {
192 throw std::runtime_error(name +
" already registered in the variable change factory.");
194 getMakers()[name] =
this;
199 template <
typename MODEL>
203 Log::trace() <<
"VariableChangeBase<MODEL>::create starting" << std::endl;
206 typename std::map<std::string, VariableChangeFactory<MODEL>*>::iterator
207 jerr = getMakers().find(
id);
208 if (jerr == getMakers().end()) {
209 throw std::runtime_error(
id +
" does not exist in variable change factory.");
212 Log::trace() <<
"VariableChangeBase<MODEL>::create done" << std::endl;
218 template <
typename MODEL>
222 parameters.validateAndDeserialize(conf);
228 template <
typename MODEL>
230 const std::string &name) {
231 typename std::map<std::string, VariableChangeFactory<MODEL>*>::iterator it =
232 getMakers().find(name);
233 if (it == getMakers().end()) {
234 throw std::runtime_error(name +
" does not exist in VariableChangeFactory");
236 return it->second->makeParameters();
241 template<
typename MODEL>
243 : varin_(), varout_()
247 Log::trace() <<
"VariableChangeBase<MODEL>::VariableChangeBase input variables: "
252 Log::trace() <<
"VariableChangeBase<MODEL>::VariableChangeBase output variables: "
259 template<
typename MODEL>
266 template<
typename MODEL>
268 Log::trace() <<
"VariableChangeBase<MODEL>::changeVar starting" << std::endl;
271 this->changeVar(xin, xout);
272 Log::trace() <<
"VariableChangeBase<MODEL>::changeVar done" << std::endl;
278 template<
typename MODEL>
280 Log::trace() <<
"VariableChangeBase<MODEL>::changeVarInverse starting" << std::endl;
283 this->changeVarInverse(xin, xout);
284 Log::trace() <<
"VariableChangeBase<MODEL>::changeVarInverse done" << std::endl;
292 #endif // OOPS_BASE_VARIABLECHANGEBASE_H_
const util::DateTime validTime() const
Time.
A subclass of VariableChangeParametersBase storing the values of all options in a single Configuratio...
The namespace for the main oops code.
void setOutputVariables(const Variables &vars)
VariableChangeFactory(const std::string &)
Register a maker able to create variable changes of type name.
std::unique_ptr< VariableChangeParametersBase > makeParameters() const override
virtual void print(std::ostream &) const =0
static VariableChangeBase< MODEL > * create(const VariableChangeParametersBase &, const Geometry_ &)
Create and return a new variable change.
static std::map< std::string, VariableChangeFactory< MODEL > * > & getMakers()
virtual ~VariableChangeFactory()=default
Geometry< MODEL > Geometry_
virtual void changeVar(const State_ &, State_ &) const =0
Contains a polymorphic parameter holding an instance of a subclass of VariableChangeParametersBase.
PolymorphicParameter< VariableChangeParametersBase, VariableChangeFactory< MODEL > > variableChangeParameters
VariableChangeBase(const VariableChangeParametersBase &)
virtual ~VariableChangeBase()
OptionalParameter< Variables > outputVariables
static std::unique_ptr< VariableChangeParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of VariableChangeParametersBase storing parameters of v...
Base class of classes storing parameters controlling specific variable changes.
VariableChangeBase< MODEL > * make(const VariableChangeParametersBase ¶ms, const Geometry_ &resol) override
virtual std::unique_ptr< VariableChangeParametersBase > makeParameters() const =0
virtual VariableChangeBase< MODEL > * make(const VariableChangeParametersBase &, const Geometry_ &)=0
OptionalParameter< Variables > inputVariables
Geometry class used in oops; subclass of interface class above.
virtual void changeVarInverse(const State_ &, State_ &) const =0
std::unique_ptr< Variables > varout_
Geometry_ geometry() const
Encapsulates the model state.
VariableChangeMaker(const std::string &name)
TParameters_IfAvailableElseFallbackType_t< T, GenericVariableChangeParameters > Parameters_
static std::vector< std::string > getMakerNames()
Return the names of all variable changes that can be created by one of the registered makers.
void setInputVariables(const Variables &vars)
Geometry< MODEL > Geometry_
std::unique_ptr< Variables > varin_
OptionalParameter< std::string > variableChange
Variable change type.