OGS
ParameterLib::TimeDependentHeterogeneousParameter Class Referencefinal

Detailed Description

Definition at line 22 of file TimeDependentHeterogeneousParameter.h.

#include <TimeDependentHeterogeneousParameter.h>

Inheritance diagram for ParameterLib::TimeDependentHeterogeneousParameter:
[legend]
Collaboration diagram for ParameterLib::TimeDependentHeterogeneousParameter:
[legend]

Public Types

using PairTimeParameterName = std::pair<double, std::string>
 
using PairTimeParameter = std::pair<double, Parameter<double> const* const>
 

Public Member Functions

 TimeDependentHeterogeneousParameter (std::string name, std::vector< PairTimeParameterName > time_parameter_name_mapping)
 
int getNumberOfGlobalComponents () const override
 
bool isTimeDependent () const override
 
std::vector< double > operator() (double const t, SpatialPosition const &pos) const override
 Returns the parameter value at the given time and position.
 
void initialize (std::vector< std::unique_ptr< ParameterBase > > const &parameters) override
 
- Public Member Functions inherited from ParameterLib::Parameter< double >
 ~Parameter () override=default
 
virtual Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > getNodalValuesOnElement (MeshLib::Element const &element, double const t) const
 Returns a matrix of values for all nodes of the given element.
 
 ParameterBase (std::string name_, MeshLib::Mesh const *mesh=nullptr)
 
- Public Member Functions inherited from ParameterLib::ParameterBase
 ParameterBase (std::string name_, MeshLib::Mesh const *mesh=nullptr)
 
virtual ~ParameterBase ()=default
 
void setCoordinateSystem (CoordinateSystem const &coordinate_system)
 
MeshLib::Mesh const * mesh () const
 

Private Attributes

std::vector< PairTimeParameterName_time_parameter_name_mapping
 
std::vector< PairTimeParameter_time_parameter_mapping
 

Additional Inherited Members

- Public Attributes inherited from ParameterLib::ParameterBase
std::string const name
 
- Protected Member Functions inherited from ParameterLib::ParameterBase
std::vector< double > rotateWithCoordinateSystem (std::vector< double > const &values, SpatialPosition const &pos) const
 
- Protected Attributes inherited from ParameterLib::ParameterBase
std::optional< CoordinateSystem_coordinate_system
 
MeshLib::Mesh const * _mesh
 

Member Typedef Documentation

◆ PairTimeParameter

Definition at line 26 of file TimeDependentHeterogeneousParameter.h.

◆ PairTimeParameterName

Constructor & Destructor Documentation

◆ TimeDependentHeterogeneousParameter()

ParameterLib::TimeDependentHeterogeneousParameter::TimeDependentHeterogeneousParameter ( std::string name,
std::vector< PairTimeParameterName > time_parameter_name_mapping )

Definition at line 19 of file TimeDependentHeterogeneousParameter.cpp.

23 : Parameter<double>(std::move(name), nullptr),
24 _time_parameter_name_mapping(std::move(time_parameter_name_mapping))
25{
26}
std::string const name
Definition Parameter.h:73

Member Function Documentation

◆ getNumberOfGlobalComponents()

int ParameterLib::TimeDependentHeterogeneousParameter::getNumberOfGlobalComponents ( ) const
overridevirtual

Returns the number of components this Parameter has at every position and point in time.

Implements ParameterLib::Parameter< double >.

Definition at line 28 of file TimeDependentHeterogeneousParameter.cpp.

29{
30 return _time_parameter_mapping[0].second->getNumberOfGlobalComponents();
31}

References _time_parameter_mapping, and ParameterLib::Parameter< T >::getNumberOfGlobalComponents().

◆ initialize()

void ParameterLib::TimeDependentHeterogeneousParameter::initialize ( std::vector< std::unique_ptr< ParameterBase > > const & parameters)
overridevirtual

The TimeDependentHeterogeneousParameter depends in each time step on a parameter. Since, at construction time of the TimeDependentHeterogeneousParameter other parameter needs not to be constructed and hence can't be used to setup the object this is done later on in the initialize method.

Reimplemented from ParameterLib::ParameterBase.

Definition at line 85 of file TimeDependentHeterogeneousParameter.cpp.

87{
88 DBUG("TimeDependentHeterogeneousParameter init {:d} time series entries.",
90 for (auto const& time_parameter_map : _time_parameter_name_mapping)
91 {
92 auto parameter =
93 &findParameter<double>(time_parameter_map.second, parameters, 0);
94 _time_parameter_mapping.emplace_back(time_parameter_map.first,
95 parameter);
96 }
97
98 // check that all parameters have the same number of components
99 auto const n =
100 _time_parameter_mapping[0].second->getNumberOfGlobalComponents();
101 if (!std::all_of(_time_parameter_mapping.begin(),
103 [n](auto const p)
104 { return n == p.second->getNumberOfGlobalComponents(); }))
105 {
106 OGS_FATAL(
107 "All referenced parameters in time dependent heterogeneous "
108 "parameter '{:s}' have to have the same number of components.",
109 name);
110 }
111}
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
Definition Utils.h:102

References _time_parameter_mapping, _time_parameter_name_mapping, DBUG(), ParameterLib::findParameter(), ParameterLib::ParameterBase::name, and OGS_FATAL.

◆ isTimeDependent()

bool ParameterLib::TimeDependentHeterogeneousParameter::isTimeDependent ( ) const
overridevirtual

Implements ParameterLib::ParameterBase.

Definition at line 33 of file TimeDependentHeterogeneousParameter.cpp.

34{
35 return true;
36}

◆ operator()()

std::vector< double > ParameterLib::TimeDependentHeterogeneousParameter::operator() ( double const t,
SpatialPosition const & pos ) const
overridevirtual

Returns the parameter value at the given time and position.

Implements ParameterLib::Parameter< double >.

Definition at line 38 of file TimeDependentHeterogeneousParameter.cpp.

40{
41 // No local coordinate transformation here, which might happen twice
42 // otherwise.
43 assert(!this->_coordinate_system ||
44 "Coordinate system not expected to be set for curve scaled "
45 "parameters.");
46 if (t < _time_parameter_mapping[0].first)
47 {
48 return _time_parameter_mapping[0].second->operator()(t, pos);
49 }
50 if (_time_parameter_mapping.back().first <= t)
51 {
52 return _time_parameter_mapping.back().second->operator()(t, pos);
53 }
54 std::size_t k(1);
55 for (; k < _time_parameter_mapping.size(); ++k)
56 {
57 if (_time_parameter_mapping[k - 1].first <= t &&
58 t < _time_parameter_mapping[k].first)
59 {
60 break;
61 }
62 }
63 if (k == _time_parameter_mapping.size())
64 {
66 "Could not find parameter for time {}. There are {:d} "
67 "time-parameter pairs.",
68 t, _time_parameter_mapping.size());
69 }
70 auto const t0 = _time_parameter_mapping[k - 1].first;
71 auto const t1 = _time_parameter_mapping[k].first;
72 auto const alpha = (t - t0) / (t1 - t0);
73
74 auto r0 = _time_parameter_mapping[k - 1].second->operator()(t, pos);
75 std::transform(r0.begin(), r0.end(), r0.begin(),
76 [alpha](auto const& v) { return (1 - alpha) * v; });
77 auto r1 = _time_parameter_mapping[k].second->operator()(t, pos);
78 std::transform(r1.begin(), r1.end(), r1.begin(),
79 [alpha](auto const& v) { return alpha * v; });
80 std::transform(r0.begin(), r0.end(), r1.begin(), r0.begin(),
81 [](auto const& v0, auto const& v1) { return v0 + v1; });
82 return r0;
83}
std::optional< CoordinateSystem > _coordinate_system
Definition Parameter.h:126

References ParameterLib::ParameterBase::_coordinate_system, _time_parameter_mapping, and OGS_FATAL.

Member Data Documentation

◆ _time_parameter_mapping

std::vector<PairTimeParameter> ParameterLib::TimeDependentHeterogeneousParameter::_time_parameter_mapping
private

◆ _time_parameter_name_mapping

std::vector<PairTimeParameterName> ParameterLib::TimeDependentHeterogeneousParameter::_time_parameter_name_mapping
private

Definition at line 50 of file TimeDependentHeterogeneousParameter.h.

Referenced by initialize().


The documentation for this class was generated from the following files: