OGS
Linear.cpp
Go to the documentation of this file.
1
10
12
13#include <numeric>
14
15namespace MaterialPropertyLib
16{
18 VariableArray const& variable_array,
20 double const t) const
21{
22 double x = valueUnclamped(variable_array, pos, t);
23
24 if (min)
25 {
26 x = std::max(x, *min);
27 }
28 if (max)
29 {
30 x = std::min(x, *max);
31 }
32
33 return x;
34}
35
37 VariableArray const& variable_array,
39 double const t) const
40{
41 if (auto* var_ptr = std::get_if<Variable>(&type))
42 {
43 return std::get<double>(variable_array[*var_ptr]);
44 }
45
46 if (auto* str_ptr = std::get_if<std::string>(&type))
47 {
48 if (*str_ptr == "t")
49 return t;
50
51 if (*str_ptr == "x")
52 return pos.getCoordinates().value()[0];
53
54 if (*str_ptr == "y")
55 return pos.getCoordinates().value()[1];
56
57 if (*str_ptr == "z")
58 return pos.getCoordinates().value()[2];
59
60 OGS_FATAL("Unknown independent variable {:s} for a linear property.",
61 *str_ptr)
62 }
63
65 "Could not convert independent_variable neither to a Variable nor "
66 "to a std::string.");
67}
68
69Linear::Linear(std::string name,
70 PropertyDataType const& property_reference_value,
71 std::vector<IndependentVariable> const& vs)
73{
74 name_ = std::move(name);
75 value_ = property_reference_value;
76}
77
80 double const t, double const /*dt*/) const
81{
82 auto calculate_linearized_ratio =
83 [&variable_array, pos, t](double const initial_linearized_ratio,
84 auto const& iv)
85 {
86 double const x = iv.valueClamped(variable_array, pos, t);
87
88 return initial_linearized_ratio +
89 std::get<double>(iv.slope) *
90 (x - std::get<double>(iv.reference_condition));
91 };
92
93 double const linearized_ratio_to_reference_value =
94 std::accumulate(independent_variables_.begin(),
96 1.0,
97 calculate_linearized_ratio);
98
99 return std::get<double>(value_) * linearized_ratio_to_reference_value;
100}
101
103 Variable const variable,
105 double const t, double const /*dt*/) const
106{
107 auto const independent_variable = std::find_if(
110 [&variable](auto const& iv) -> bool
111 {
112 if (auto const* var_ptr = std::get_if<Variable>(&iv.type))
113 {
114 return *var_ptr == variable;
115 }
116 return false;
117 });
118
119 auto const zero = decltype(value_){};
120 if (independent_variable == independent_variables_.end())
121 {
122 return zero;
123 }
124
125 auto const& iv = *independent_variable;
126
127 double const x = iv.valueUnclamped(variable_array, pos, t);
128
129 if (iv.min && x < *iv.min)
130 {
131 return zero;
132 }
133 if (iv.max && x > *iv.max)
134 {
135 return zero;
136 }
137
138 return std::get<double>(value_) * std::get<double>(iv.slope);
139}
140
142 Variable const /*pv1*/, Variable const /*pv2*/,
143 ParameterLib::SpatialPosition const& /*pos*/,
144 double const /*t*/, double const /*dt*/) const
145{
146 return decltype(value_){};
147}
148
149} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
std::vector< IndependentVariable > const independent_variables_
Definition Linear.h:72
PropertyDataType d2Value(VariableArray const &variable_array, Variable const pv1, Variable const pv2, ParameterLib::SpatialPosition const &, double const, double const) const override
Definition Linear.cpp:141
PropertyDataType dValue(VariableArray const &variable_array, Variable const variable, ParameterLib::SpatialPosition const &, double const, double const) const override
Definition Linear.cpp:102
Linear(std::string name, PropertyDataType const &property_reference_value, std::vector< IndependentVariable > const &vs)
Definition Linear.cpp:69
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
double valueClamped(VariableArray const &variable_array, ParameterLib::SpatialPosition const &pos, double const t) const
Definition Linear.cpp:17
std::optional< double > max
Definition Linear.h:24
std::optional< double > min
Definition Linear.h:23
double valueUnclamped(VariableArray const &variable_array, ParameterLib::SpatialPosition const &pos, double const t) const
Definition Linear.cpp:36