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