Loading [MathJax]/jax/output/HTML-CSS/config.js
OGS
Curve.cpp
Go to the documentation of this file.
1
11#include "Curve.h"
12
13namespace MaterialPropertyLib
14{
15Curve::Curve(std::string name,
16 StringOrVariable const independent_variable,
18 : independent_variable_(independent_variable), curve_(curve)
19{
20 name_ = std::move(name);
21}
22
25 double const t, double const /*dt*/) const
26{
27 double x = 0.0;
28 if (Variable const* const independent_variable =
29 std::get_if<Variable>(&independent_variable_))
30 {
31 x = std::get<double>(variable_array[*independent_variable]);
32 }
33 else if (std::string const* const str_ptr =
34 std::get_if<std::string>(&independent_variable_))
35 {
36 if (*str_ptr == "t")
37 {
38 x = t;
39 }
40 else if (*str_ptr == "x")
41 {
42 x = pos.getCoordinates().value()[0];
43 }
44 else if (*str_ptr == "y")
45 {
46 x = pos.getCoordinates().value()[1];
47 }
48 else if (*str_ptr == "z")
49 {
50 x = pos.getCoordinates().value()[2];
51 }
52 else
53 {
54 OGS_FATAL("Unknown independent_variable {:s} for curve property.",
55 *str_ptr)
56 }
57 }
58 else
59 {
61 "Could not convert independent_variable neither to a Variable nor "
62 "to a std::string.");
63 }
64 return curve_.getValue(x);
65}
66
68 Variable const variable,
69 ParameterLib::SpatialPosition const& /*pos*/,
70 double const /*t*/, double const /*dt*/) const
71{
72 Variable const* const independent_variable =
73 std::get_if<Variable>(&independent_variable_);
74 if (independent_variable == nullptr)
75 {
76 return 0.0;
77 }
78 if (variable != *independent_variable)
79 {
80 return 0.0;
81 }
82 auto const x = std::get<double>(variable_array[*independent_variable]);
83 return curve_.getDerivative(x);
84}
85} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
StringOrVariable const independent_variable_
The variable type that the curve property depends on.
Definition Curve.h:47
PropertyDataType dValue(VariableArray const &variable_array, Variable const variable, ParameterLib::SpatialPosition const &, double const, double const) const override
Definition Curve.cpp:67
MathLib::PiecewiseLinearInterpolation const & curve_
The curve used by the property.
Definition Curve.h:49
Curve(std::string name, StringOrVariable const independent_variable, MathLib::PiecewiseLinearInterpolation const &curve)
Definition Curve.cpp:15
virtual PropertyDataType value() const
Definition Property.cpp:76
double getDerivative(double const pnt_to_interpolate) const
Calculates derivative using quadratic interpolation and central difference quotient.
double getValue(double pnt_to_interpolate) const
Calculates the interpolation value.
std::optional< MathLib::Point3d > const getCoordinates() const
std::variant< std::string, Variable > StringOrVariable
Definition Curve.h:18
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