OGS
MaterialLib/MPL/Property.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 "Property.h"
5
6#include <string>
7
8#include "Component.h"
9#include "Medium.h"
10#include "Phase.h"
11
12namespace MaterialPropertyLib
13{
14PropertyDataType fromVector(std::vector<double> const& values)
15{
16 switch (values.size())
17 {
18 case 1:
19 {
20 return values[0];
21 }
22 case 2:
23 {
24 return Eigen::Vector2d{values[0], values[1]};
25 }
26 case 3:
27 {
28 return Eigen::Vector3d{values[0], values[1], values[2]};
29 }
30 case 4:
31 {
32 using M = Eigen::Matrix2d;
33 // the values vector is in row major order
34 using MRM = Eigen::Matrix<double, 2, 2, Eigen::RowMajor>;
35 return M{Eigen::Map<MRM const>{values.data(), 2, 2}};
36 }
37 case 6:
38 {
39 // Symmetric Tensor - xx, yy, zz, xy, xz, yz
40 using M = Eigen::Matrix<double, 6, 1>;
41 return M{Eigen::Map<M const>{values.data(), 6}};
42 }
43 case 9:
44 {
45 using M = Eigen::Matrix3d;
46 // the values vector is in row major order
47 using MRM = Eigen::Matrix<double, 3, 3, Eigen::RowMajor>;
48 return M{Eigen::Map<MRM const>{values.data(), 3, 3}};
49 }
50 default:
51 {
53 "Conversion of a {:d}-vector to PropertyDataType is not "
54 "implemented.",
55 values.size());
56 }
57 }
58}
59
61 ParameterLib::SpatialPosition const& pos, double const t) const
62{
63 return value(EmptyVariableArray, pos, t,
64 std::numeric_limits<double>::quiet_NaN());
65}
66
68{
69#ifndef NDEBUG
70 property_used = true;
71#endif
72 return value_;
73}
74
76 VariableArray const& /*variable_array_prev*/,
77 ParameterLib::SpatialPosition const& /*pos*/,
78 double const /*t*/, double const /*dt*/) const
79{
80#ifndef NDEBUG
81 property_used = true;
82#endif
83 return value_;
84}
85
88 double const t, double const dt) const
89{
90#ifndef NDEBUG
91 property_used = true;
92#endif
93 return value(variable_array, EmptyVariableArray, pos, t, dt);
94}
95
97 VariableArray const& /*variable_array_prev*/,
98 Variable const /*variable*/,
99 ParameterLib::SpatialPosition const& /*pos*/,
100 double const /*t*/, double const /*dt*/) const
101{
102#ifndef NDEBUG
103 property_used = true;
104#endif
105 return dvalue_;
106}
107
111 Variable const variable,
113 double const t, double const dt) const
114{
115#ifndef NDEBUG
116 property_used = true;
117#endif
118 return dValue(variable_array, EmptyVariableArray, variable, pos, t, dt);
119}
120
123 Variable const /*variable*/,
124 Variable const /*variable*/,
125 ParameterLib::SpatialPosition const& /*pos*/,
126 double const /*t*/,
127 double const /*dt*/) const
128{
129#ifndef NDEBUG
130 property_used = true;
131#endif
132 return 0.0;
133}
134
137 std::vector<std::unique_ptr<Phase>> const& /*phases*/)
138{
139 // empty
140}
141
142std::string Property::description() const
143{
144 return "property '" + name_ + "' defined for " +
145 std::visit(
146 [](auto&& scale) -> std::string
147 {
148 if (scale == nullptr)
149 {
150 return "unknown scale";
151 }
152 return scale->description();
153 },
154 scale_);
155}
156} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:19
virtual void setProperties(std::vector< std::unique_ptr< Phase > > const &phases)
Default implementation:
virtual PropertyDataType d2Value(VariableArray const &variable_array, Variable const variable1, Variable const variable2, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
Default implementation: 2nd derivative of any constant property is zero.
PropertyDataType value_
The single value of a property.
virtual PropertyDataType value() const
std::variant< Medium *, Phase *, Component * > scale_
virtual PropertyDataType initialValue(ParameterLib::SpatialPosition const &pos, double const t) const
virtual PropertyDataType dValue(VariableArray const &variable_array, VariableArray const &variable_array_prev, Variable const variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const
PropertyDataType fromVector(std::vector< double > const &values)
static const VariableArray EmptyVariableArray
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