OGS
VariableType.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <BaseLib/Algorithm.h>
16#include <BaseLib/Error.h>
17
18#include <Eigen/Core>
19#include <array>
20#include <string>
21#include <variant>
22
23namespace MaterialPropertyLib
24{
25
59
60static const std::array<std::string,
61 static_cast<int>(Variable::number_of_variables)>
62 variable_enum_to_string{{"capillary_pressure",
63 "concentration",
64 "deformation_gradient",
65 "density",
66 "effective_pore_pressure",
67 "enthalpy",
68 "enthalpy_of_evaporation",
69 "equivalent_plastic_strain",
70 "fracture_aperture",
71 "grain_compressibility",
72 "liquid_phase_pressure",
73 "liquid_saturation",
74 "mechanical_strain",
75 "molar_mass",
76 "molar_mass_derivative",
77 "molar_fraction",
78 "gas_phase_pressure",
79 "porosity",
80 "solid_grain_pressure",
81 "stress",
82 "temperature",
83 "total_strain",
84 "total_stress",
85 "transport_porosity",
86 "vapour_pressure",
87 "volumetric_strain"}};
88
91using VariableType = std::variant<std::monostate,
92 double,
93 Eigen::Vector<double, 4>,
94 Eigen::Vector<double, 5>,
95 Eigen::Vector<double, 6>,
96 Eigen::Vector<double, 9>>;
97
99{
100public:
101 using Scalar = double;
102 using KelvinVector = std::variant<std::monostate,
103 Eigen::Vector<double, 4>,
104 Eigen::Vector<double, 6>>;
105 // Compare to GMatrixPolicy::GradientVectorType. The 1d case = Vector<3>
106 // is not used so far.
107 using DeformationGradient = std::variant<std::monostate,
108 Eigen::Vector<double, 5>,
109 Eigen::Vector<double, 9>>;
110
112 variant<Scalar const*, KelvinVector const*, DeformationGradient const*>;
113
115
117 std::variant<Scalar*, KelvinVector*, DeformationGradient*>;
118
119 template <typename Visitor>
120 auto visitVariable(Visitor&& visitor, Variable const variable)
121 {
122 return std::visit(
124 std::forward<Visitor>(visitor),
125 []<typename T>(T*)
126 {
127 static_assert(!std::is_same_v<T, T>,
128 "Non-exhaustive visitor! The variable type "
129 "must be one of the VariableArray::{Scalar, "
130 "KelvinVector, DeformationGradient}.");
131 }},
132 address_of(variable));
133 }
134
135 template <typename Visitor>
136 auto visitVariable(Visitor&& visitor, Variable const variable) const
137 {
138 return std::visit(
140 std::forward<Visitor>(visitor),
141 []<typename T>(T const*)
142 {
143 static_assert(!std::is_same_v<T, T>,
144 "Non-exhaustive visitor! The variable type "
145 "must be one of the VariableArray::{Scalar, "
146 "KelvinVector, DeformationGradient}.");
147 }},
148 address_of(variable));
149 }
150
153 VariableType operator[](Variable const variable) const
154 {
155 auto identity = [](auto const& arg) -> VariableType { return arg; };
156
157 return visitVariable(
159 [](Scalar const* ptr) -> VariableType { return *ptr; },
160 [&identity](KelvinVector const* ptr) -> VariableType
161 { return std::visit(identity, *ptr); },
162 [&identity](DeformationGradient const* ptr) -> VariableType
163 { return std::visit(identity, *ptr); }},
164 variable);
165 }
166
167private:
169
170public:
174 double density = nan_;
176 double enthalpy = nan_;
184 double molar_mass = nan_;
188 double porosity = nan_;
197
198 bool is2D() const;
199 bool is3D() const;
200
201private:
202 static constexpr auto nan_ = std::numeric_limits<double>::signaling_NaN();
203};
204
206
209Variable convertStringToVariable(std::string const& string);
210} // namespace MaterialPropertyLib
DeformationGradient deformation_gradient
std::variant< Scalar *, KelvinVector *, DeformationGradient * > VariablePointer
VariableType operator[](Variable const variable) const
std::variant< std::monostate, Eigen::Vector< double, 5 >, Eigen::Vector< double, 9 > > DeformationGradient
std:: variant< Scalar const *, KelvinVector const *, DeformationGradient const * > VariablePointerConst
std::variant< std::monostate, Eigen::Vector< double, 4 >, Eigen::Vector< double, 6 > > KelvinVector
VariablePointerConst address_of(Variable const v) const
auto visitVariable(Visitor &&visitor, Variable const variable) const
auto visitVariable(Visitor &&visitor, Variable const variable)
std::variant< std::monostate, double, Eigen::Vector< double, 4 >, Eigen::Vector< double, 5 >, Eigen::Vector< double, 6 >, Eigen::Vector< double, 9 > > VariableType
static const VariableArray EmptyVariableArray
static const std::array< std::string, static_cast< int >(Variable::number_of_variables)> variable_enum_to_string
@ concentration
used to specify decay rate of a substance.
Variable convertStringToVariable(std::string const &string)