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
58
59static const std::array<std::string,
60 static_cast<int>(Variable::number_of_variables)>
61 variable_enum_to_string{{"capillary_pressure",
62 "concentration",
63 "deformation_gradient",
64 "density",
65 "effective_pore_pressure",
66 "enthalpy",
67 "enthalpy_of_evaporation",
68 "equivalent_plastic_strain",
69 "grain_compressibility",
70 "liquid_phase_pressure",
71 "liquid_saturation",
72 "mechanical_strain",
73 "molar_mass",
74 "molar_mass_derivative",
75 "molar_fraction",
76 "gas_phase_pressure",
77 "porosity",
78 "solid_grain_pressure",
79 "stress",
80 "temperature",
81 "total_strain",
82 "total_stress",
83 "transport_porosity",
84 "vapour_pressure",
85 "volumetric_strain"}};
86
89using VariableType = std::variant<std::monostate,
90 double,
91 Eigen::Vector<double, 4>,
92 Eigen::Vector<double, 5>,
93 Eigen::Vector<double, 6>,
94 Eigen::Vector<double, 9>>;
95
97{
98public:
99 using Scalar = double;
100 using KelvinVector = std::variant<std::monostate,
101 Eigen::Vector<double, 4>,
102 Eigen::Vector<double, 6>>;
103 // Compare to GMatrixPolicy::GradientVectorType. The 1d case = Vector<3>
104 // is not used so far.
105 using DeformationGradient = std::variant<std::monostate,
106 Eigen::Vector<double, 5>,
107 Eigen::Vector<double, 9>>;
108
110 variant<Scalar const*, KelvinVector const*, DeformationGradient const*>;
111
113
115 std::variant<Scalar*, KelvinVector*, DeformationGradient*>;
116
117 template <typename Visitor>
118 auto visitVariable(Visitor&& visitor, Variable const variable)
119 {
120 return std::visit(
122 std::forward<Visitor>(visitor),
123 []<typename T>(T*)
124 {
125 static_assert(!std::is_same_v<T, T>,
126 "Non-exhaustive visitor! The variable type "
127 "must be one of the VariableArray::{Scalar, "
128 "KelvinVector, DeformationGradient}.");
129 }},
130 address_of(variable));
131 }
132
133 template <typename Visitor>
134 auto visitVariable(Visitor&& visitor, Variable const variable) const
135 {
136 return std::visit(
138 std::forward<Visitor>(visitor),
139 []<typename T>(T const*)
140 {
141 static_assert(!std::is_same_v<T, T>,
142 "Non-exhaustive visitor! The variable type "
143 "must be one of the VariableArray::{Scalar, "
144 "KelvinVector, DeformationGradient}.");
145 }},
146 address_of(variable));
147 }
148
151 VariableType operator[](Variable const variable) const
152 {
153 auto identity = [](auto const& arg) -> VariableType { return arg; };
154
155 return visitVariable(
157 [](Scalar const* ptr) -> VariableType { return *ptr; },
158 [&identity](KelvinVector const* ptr) -> VariableType
159 { return std::visit(identity, *ptr); },
160 [&identity](DeformationGradient const* ptr) -> VariableType
161 { return std::visit(identity, *ptr); }},
162 variable);
163 }
164
165private:
167
168public:
172 double density = nan_;
174 double enthalpy = nan_;
181 double molar_mass = nan_;
185 double porosity = nan_;
194
195 bool is2D() const;
196 bool is3D() const;
197
198private:
199 static constexpr auto nan_ = std::numeric_limits<double>::signaling_NaN();
200};
201
203
206Variable convertStringToVariable(std::string const& string);
207} // 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)