Go to the documentation of this file.
8 #ifndef OOPS_BASE_LINEARVARIABLECHANGEBASE_H_
9 #define OOPS_BASE_LINEARVARIABLECHANGEBASE_H_
16 #include <boost/make_unique.hpp>
17 #include <boost/noncopyable.hpp>
19 #include "eckit/exception/Exceptions.h"
26 #include "oops/util/AssociativeContainers.h"
27 #include "oops/util/parameters/ConfigurationParameter.h"
28 #include "oops/util/parameters/HasParameters_.h"
29 #include "oops/util/parameters/Parameters.h"
30 #include "oops/util/parameters/RequiredPolymorphicParameter.h"
31 #include "oops/util/Printable.h"
51 template <
typename MODEL>
53 private boost::noncopyable {
77 virtual void print(std::ostream &)
const = 0;
84 template <
typename MODEL>
102 ConfigurationParameter config{
this};
109 template <
typename MODEL>
125 template <
typename MODEL>
126 class LinearVariableChangeFactory {
146 const eckit::Configuration & conf);
150 static std::unique_ptr<LinearVariableChangeParametersBase>
createParameters(
151 const std::string &name);
170 virtual std::unique_ptr<LinearVariableChangeParametersBase>
makeParameters()
const = 0;
172 static std::map < std::string, LinearVariableChangeFactory<MODEL> * > &
getMakers() {
173 static std::map < std::string, LinearVariableChangeFactory<MODEL> * > makers_;
180 template<
class MODEL,
class T>
184 typedef TParameters_IfAvailableElseFallbackType_t<T, GenericLinearVariableChangeParameters>
193 const auto &stronglyTypedParams =
dynamic_cast<const Parameters_&
>(params);
194 return new T(bg, fg, geom,
195 parametersOrConfiguration<HasParameters_<T>::value>(stronglyTypedParams));
198 std::unique_ptr<LinearVariableChangeParametersBase>
makeParameters()
const override {
199 return boost::make_unique<Parameters_>();
209 template <
typename MODEL>
211 if (getMakers().find(name) != getMakers().end()) {
212 throw std::runtime_error(name +
" already registered in the linear variable change factory.");
214 getMakers()[name] =
this;
219 template <
typename MODEL>
223 Log::trace() <<
"LinearVariableChangeBase<MODEL>::create starting" << std::endl;
224 const std::string &
id = parameters.
variableChange.value().value();
225 typename std::map<std::string, LinearVariableChangeFactory<MODEL>*>::iterator
226 jerr = getMakers().find(
id);
228 if (jerr == getMakers().end()) {
229 Log::error() <<
id <<
" does not exist in LinearVariableChangeFactory." << std::endl;
230 Log::error() <<
"Factory contains " << getMakers().size() <<
" elements:" << std::endl;
232 jj = getMakers().begin(); jj != getMakers().end(); ++jj) {
233 Log::error() <<
"A " << jj->first <<
" variable change option" << std::endl;
235 throw std::runtime_error(
id +
" does not exist in the linear variable change factory.");
239 Log::trace() <<
"LinearVariableChangeBase<MODEL>::create done" << std::endl;
245 template <
typename MODEL>
248 const Geometry_ & geom,
const eckit::Configuration & conf) {
250 parameters.validateAndDeserialize(conf);
256 template <
typename MODEL>
257 std::unique_ptr<LinearVariableChangeParametersBase>
259 const std::string &name) {
260 typename std::map<std::string, LinearVariableChangeFactory<MODEL>*>::iterator it =
261 getMakers().find(name);
262 if (it == getMakers().end()) {
263 throw std::runtime_error(name +
" does not exist in LinearVariableChangeFactory");
265 return it->second->makeParameters();
270 template<
typename MODEL>
273 : varin_(), varout_()
277 Log::trace() <<
"LinearVariableChangeBase<MODEL>::LinearVariableChangeBase input variables: "
282 Log::trace() <<
"LinearVariableChangeBase<MODEL>::LinearVariableChangeBase output variables: "
289 template<
typename MODEL>
291 const eckit::Configuration & conf)
297 template<
typename MODEL>
301 this->multiply(dxin, dxout);
307 template<
typename MODEL>
311 this->multiplyAD(dxin, dxout);
317 template<
typename MODEL>
321 this->multiplyInverse(dxin, dxout);
327 template<
typename MODEL>
331 this->multiplyInverseAD(dxin, dxout);
339 #endif // OOPS_BASE_LINEARVARIABLECHANGEBASE_H_
The namespace for the main oops code.
OptionalParameter< std::string > variableChange
Variable change type.
static std::map< std::string, LinearVariableChangeFactory< MODEL > * > & getMakers()
virtual void multiplyInverseAD(const Increment_ &, Increment_ &) const =0
void setInputVariables(const Variables &vars)
static std::unique_ptr< LinearVariableChangeParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of LinearVariableChangeParametersBase storing parameter...
virtual std::unique_ptr< LinearVariableChangeParametersBase > makeParameters() const =0
Geometry_ geometry() const
Get geometry.
LinearVariableChange factory.
virtual ~LinearVariableChangeBase()
OptionalParameter< Variables > inputVariables
static std::vector< std::string > getMakerNames()
Return the names of all linear variable changes that can be created by one of the registered makers.
std::unique_ptr< Variables > varin_
Contains a polymorphic parameter holding an instance of a subclass of LinearVariableChangeParametersB...
LinearVariableChangeFactory(const std::string &name)
Register a maker able to create linear variable changes of type name.
A subclass of LinearVariableChangeParametersBase storing the values of all options in a single Config...
std::unique_ptr< Variables > varout_
virtual void multiplyAD(const Increment_ &, Increment_ &) const =0
void setOutputVariables(const Variables &vars)
Base class of classes storing parameters controlling specific linear variable changes.
RequiredPolymorphicParameter< LinearVariableChangeParametersBase, LinearVariableChangeFactory< MODEL > > variableChangeParameters
const util::DateTime validTime() const
Time.
LinearVariableChangeMaker(const std::string &name)
Geometry< MODEL > Geometry_
std::unique_ptr< LinearVariableChangeParametersBase > makeParameters() const override
virtual void print(std::ostream &) const =0
LinearVariableChangeBase< MODEL > * make(const State_ &bg, const State_ &fg, const Geometry_ &geom, const LinearVariableChangeParametersBase ¶ms) override
OptionalParameter< Variables > outputVariables
LinearVariableChangeBase(const LinearVariableChangeParametersBase &)
virtual void multiply(const Increment_ &, Increment_ &) const =0
virtual LinearVariableChangeBase< MODEL > * make(const State_ &, const State_ &, const Geometry_ &, const LinearVariableChangeParametersBase &)=0
TParameters_IfAvailableElseFallbackType_t< T, GenericLinearVariableChangeParameters > Parameters_
Geometry class used in oops; subclass of interface class above.
virtual ~LinearVariableChangeFactory()=default
Encapsulates the model state.
Geometry< MODEL > Geometry_
static LinearVariableChangeBase< MODEL > * create(const State_ &, const State_ &, const Geometry_ &, const LinearVariableChangeParametersBase ¶meters)
Create and return a new linear variable change.
Increment Class: Difference between two states.
virtual void multiplyInverse(const Increment_ &, Increment_ &) const =0
Geometry< MODEL > Geometry_
Increment< MODEL > Increment_