Loading [MathJax]/jax/output/HTML-CSS/config.js
OGS
Linear.cpp
Go to the documentation of this file.
1
12
13#include <numeric>
14
15namespace MaterialPropertyLib
16{
17Linear::Linear(std::string name,
18 PropertyDataType const& property_reference_value,
19 std::vector<IndependentVariable> const& vs)
20 : independent_variables_(vs)
21{
22 name_ = std::move(name);
23 value_ = property_reference_value;
24}
25
28 double const t, double const /*dt*/) const
29{
30 auto calculate_linearized_ratio =
31 [&variable_array, pos, t](double const initial_linearized_ratio,
32 auto const& iv)
33 {
34 double x = 0.0;
35 if (auto* var_ptr = std::get_if<Variable>(&iv.type))
36 {
37 x = std::get<double>(variable_array[*var_ptr]);
38 }
39 else if (auto* str_ptr = std::get_if<std::string>(&iv.type))
40 {
41 if (*str_ptr == "t")
42 x = t;
43 else if (*str_ptr == "x")
44 x = pos.getCoordinates().value()[0];
45 else if (*str_ptr == "y")
46 x = pos.getCoordinates().value()[1];
47 else if (*str_ptr == "z")
48 x = pos.getCoordinates().value()[2];
49 else
51 "Unknown independent_variable {:s} for curve property.",
52 *str_ptr)
53 }
54 else
55 {
57 "Could not convert independent_variable neither to a Variable "
58 "nor to a std::string.");
59 }
60
61 return initial_linearized_ratio +
62 std::get<double>(iv.slope) *
63 (x - std::get<double>(iv.reference_condition));
64 };
65
66 double const linearized_ratio_to_reference_value =
67 std::accumulate(independent_variables_.begin(),
69 1.0,
70 calculate_linearized_ratio);
71
72 return std::get<double>(value_) * linearized_ratio_to_reference_value;
73}
74
76 Variable const variable,
77 ParameterLib::SpatialPosition const& /*pos*/,
78 double const /*t*/, double const /*dt*/) const
79{
80 auto const independent_variable = std::find_if(
83 [&variable](auto const& iv) -> bool
84 {
85 if (auto const* var_ptr = std::get_if<Variable>(&iv.type))
86 {
87 return *var_ptr == variable;
88 }
89 return false;
90 });
91
92 return independent_variable != independent_variables_.end()
93 ? std::get<double>(value_) *
94 std::get<double>(independent_variable->slope)
95 : decltype(value_){};
96}
97
98PropertyDataType Linear::d2Value(VariableArray const& /*variable_array*/,
99 Variable const /*pv1*/, Variable const /*pv2*/,
100 ParameterLib::SpatialPosition const& /*pos*/,
101 double const /*t*/, double const /*dt*/) const
102{
103 return decltype(value_){};
104}
105
106} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
std::vector< IndependentVariable > const independent_variables_
Definition Linear.h:62
PropertyDataType dValue(VariableArray const &variable_array, Variable const variable, ParameterLib::SpatialPosition const &, double const, double const) const override
Definition Linear.cpp:75
Linear(std::string name, PropertyDataType const &property_reference_value, std::vector< IndependentVariable > const &vs)
Definition Linear.cpp:17
PropertyDataType value_
The single value of a property.
Definition Property.h:292
virtual PropertyDataType value() const
Definition Property.cpp:76
std::optional< MathLib::Point3d > const getCoordinates() const
std::variant< double, Eigen::Matrix< double, 2, 1 >, Eigen::Matrix< double, 3, 1 >, Eigen::Matrix< double, 2, 2 >, Eigen::Matrix< double, 3, 3 >, Eigen::Matrix< double, 4, 1 >, Eigen::Matrix< double, 6, 1 >, Eigen::MatrixXd > PropertyDataType
Definition Property.h:31