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"
54 template <
typename MODEL>
56 private boost::noncopyable {
70 virtual void print(std::ostream &)
const = 0;
78 template <
typename MODEL>
80 typedef typename MODEL::State
State_;
89 { this->
changeVar(xin.state(), xout.state()); }
102 template <
typename MODEL>
120 ConfigurationParameter config{
this};
127 template <
typename MODEL>
135 PolymorphicParameter<VariableChangeParametersBase, VariableChangeFactory<MODEL>>
142 template <
typename MODEL>
157 static std::unique_ptr<VariableChangeParametersBase>
createParameters(
const std::string &name);
175 virtual std::unique_ptr<VariableChangeParametersBase>
makeParameters()
const = 0;
177 static std::map < std::string, VariableChangeFactory<MODEL> * > &
getMakers() {
178 static std::map < std::string, VariableChangeFactory<MODEL> * > makers_;
185 template<
class MODEL,
class T>
189 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericVariableChangeParameters>
Parameters_;
195 const auto &stronglyTypedParams =
dynamic_cast<const Parameters_&
>(params);
197 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParams));
201 return boost::make_unique<Parameters_>();
212 template<
class MODEL,
class T>
216 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericVariableChangeParameters>
Parameters_;
222 const auto &stronglyTypedParams =
dynamic_cast<const Parameters_&
>(params);
224 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParams));
228 return boost::make_unique<Parameters_>();
238 template <
typename MODEL>
240 if (getMakers().find(name) != getMakers().end()) {
241 throw std::runtime_error(name +
" already registered in the variable change factory.");
243 getMakers()[name] =
this;
248 template <
typename MODEL>
252 Log::trace() <<
"VariableChangeBase<MODEL>::create starting" << std::endl;
255 typename std::map<std::string, VariableChangeFactory<MODEL>*>::iterator
256 jerr = getMakers().find(
id);
257 if (jerr == getMakers().end()) {
258 throw std::runtime_error(
id +
" does not exist in variable change factory.");
261 Log::trace() <<
"VariableChangeBase<MODEL>::create done" << std::endl;
267 template <
typename MODEL>
269 const std::string &name) {
270 typename std::map<std::string, VariableChangeFactory<MODEL>*>::iterator it =
271 getMakers().find(name);
272 if (it == getMakers().end()) {
273 throw std::runtime_error(name +
" does not exist in VariableChangeFactory");
275 return it->second->makeParameters();
GenericVariableChangeBase()=default
virtual void changeVar(const State_ &xin, State_ &xout) const =0
change variables from state xin to xout
virtual ~GenericVariableChangeBase()=default
virtual void print(std::ostream &) const =0
Print, used for logging.
virtual void changeVarInverse(const State_ &xout, State_ &xin) const =0
inverse of changeVar, change variables back from xout to xin
TParameters_IfAvailableElseFallbackType_t< T, GenericVariableChangeParameters > Parameters_
Geometry< MODEL > Geometry_
GenericVariableChangeBase< MODEL > * make(const Geometry_ &resol, const VariableChangeParametersBase ¶ms) override
GenericVariableChangeMaker(const std::string &name)
std::unique_ptr< VariableChangeParametersBase > makeParameters() const override
A subclass of VariableChangeParametersBase storing the values of all options in a single Configuratio...
Geometry class used in oops; subclass of interface class interface::Geometry.
State class used in oops; subclass of interface class interface::State.
Base class for MODEL-specific implementations of VariableChange class. The complete interface that ne...
virtual ~VariableChangeBase()=default
virtual void changeVar(const State_ &xin, State_ &xout) const =0
change variables from state xin to xout
VariableChangeBase()=default
void changeVar(const State< MODEL > &xin, State< MODEL > &xout) const final
virtual void changeVarInverse(const State_ &xout, State_ &xin) const =0
inverse of changeVar, change variables back from xout to xin
void changeVarInverse(const State< MODEL > &xout, State< MODEL > &xin) const final
inverse of changeVar, change variables back from xout to xin
Geometry< MODEL > Geometry_
static std::unique_ptr< VariableChangeParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of VariableChangeParametersBase storing parameters of v...
virtual ~VariableChangeFactory()=default
static std::map< std::string, VariableChangeFactory< MODEL > * > & getMakers()
static std::vector< std::string > getMakerNames()
Return the names of all variable changes that can be created by one of the registered makers.
static GenericVariableChangeBase< MODEL > * create(const Geometry_ &, const VariableChangeParametersBase &)
Create and return a new variable change.
VariableChangeFactory(const std::string &)
Register a maker able to create variable changes of type name.
virtual GenericVariableChangeBase< MODEL > * make(const Geometry_ &, const VariableChangeParametersBase &)=0
virtual std::unique_ptr< VariableChangeParametersBase > makeParameters() const =0
VariableChangeBase< MODEL > * make(const Geometry_ &resol, const VariableChangeParametersBase ¶ms) override
Geometry< MODEL > Geometry_
TParameters_IfAvailableElseFallbackType_t< T, GenericVariableChangeParameters > Parameters_
VariableChangeMaker(const std::string &name)
std::unique_ptr< VariableChangeParametersBase > makeParameters() const override
Base class of classes storing parameters controlling specific variable changes.
Parameter< std::string > variableChange
Variable change type.
Contains a polymorphic parameter holding an instance of a subclass of VariableChangeParametersBase.
PolymorphicParameter< VariableChangeParametersBase, VariableChangeFactory< MODEL > > variableChangeParameters
const Geometry_ & geometry() const
The namespace for the main oops code.