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