OGS
CurveScaledParameter.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <map>
14 #include <utility>
16 #include "Parameter.h"
17 #include "Utils.h"
18 
19 namespace ParameterLib
20 {
21 template <typename T>
22 struct CurveScaledParameter final : public Parameter<T>
23 {
24  CurveScaledParameter(std::string const& name_,
26  std::string referenced_parameter_name)
27  : Parameter<T>(name_),
28  _curve(curve),
29  _referenced_parameter_name(std::move(referenced_parameter_name))
30  {
31  }
32 
33  bool isTimeDependent() const override { return true; }
34  void initialize(
35  std::vector<std::unique_ptr<ParameterBase>> const& parameters) override
36  {
37  _parameter =
38  &findParameter<T>(_referenced_parameter_name, parameters, 0);
40  }
41 
42  int getNumberOfGlobalComponents() const override
43  {
44  return _parameter->getNumberOfGlobalComponents();
45  }
46 
47  std::vector<T> operator()(double const t,
48  SpatialPosition const& pos) const override
49  {
50  // No local coordinate transformation here, which might happen twice
51  // otherwise.
52  assert(!this->_coordinate_system ||
53  "Coordinate system not expected to be set for curve scaled "
54  "parameters.");
55 
56  auto const& tup = (*_parameter)(t, pos);
57  auto const scaling = _curve.getValue(t);
58 
59  auto const num_comp = _parameter->getNumberOfGlobalComponents();
60  std::vector<T> cache(num_comp);
61  for (int c = 0; c < num_comp; ++c)
62  {
63  cache[c] = scaling * tup[c];
64  }
65  return cache;
66  }
67 
68 private:
71  std::string const _referenced_parameter_name;
72 };
73 
74 std::unique_ptr<ParameterBase> createCurveScaledParameter(
75  std::string const& name,
76  BaseLib::ConfigTree const& config,
77  std::map<std::string,
78  std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
79  curves);
80 
81 } // namespace ParameterLib
Definition of the PiecewiseLinearInterpolation class.
double getValue(double pnt_to_interpolate) const
Calculates the interpolation value.
std::unique_ptr< ParameterBase > createCurveScaledParameter(std::string const &name, BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
void initialize(std::vector< std::unique_ptr< ParameterBase >> const &parameters) override
int getNumberOfGlobalComponents() const override
CurveScaledParameter(std::string const &name_, MathLib::PiecewiseLinearInterpolation const &curve, std::string referenced_parameter_name)
std::vector< T > operator()(double const t, SpatialPosition const &pos) const override
Returns the parameter value at the given time and position.
MathLib::PiecewiseLinearInterpolation const & _curve
MeshLib::Mesh const * _mesh
Definition: Parameter.h:129
std::optional< CoordinateSystem > _coordinate_system
Definition: Parameter.h:125