OGS
VariableType.cpp
Go to the documentation of this file.
1
11#include "VariableType.h"
12
13#include <boost/algorithm/string/predicate.hpp>
14
15#include "BaseLib/Error.h"
16
18template <int Rows>
19static bool maybeHasSize(const auto& arg)
20{
21 return std::holds_alternative<std::monostate>(arg) ||
22 std::holds_alternative<Eigen::Matrix<double, Rows, 1>>(arg);
23}
24
25namespace MaterialPropertyLib
26{
27Variable convertStringToVariable(std::string const& string)
28{
29 for (int i = 0; i < static_cast<int>(Variable::number_of_variables); ++i)
30 {
31 if (boost::iequals(string, variable_enum_to_string[i]))
32 {
33 return static_cast<Variable>(i);
34 }
35 }
36
38 "The variable name '{:s}' does not correspond to any known variable",
39 string);
40}
41
43 Variable const v) const
44{
45 switch (v)
46 {
48 return &capillary_pressure;
50 return &concentration;
54 return &density;
58 return &enthalpy;
68 return &liquid_saturation;
70 return &mechanical_strain;
72 return &molar_mass;
76 return &molar_fraction;
78 return &gas_phase_pressure;
80 return &porosity;
84 return &stress;
86 return &temperature;
88 return &total_strain;
90 return &total_stress;
92 return &transport_porosity;
94 return &vapour_pressure;
96 return &volumetric_strain;
97 default:
99 "No conversion to VariableType is provided for variable "
100 "{:d}",
101 static_cast<int>(v));
102 };
103}
104
106 VariableArray::VariablePointerConst const const_pointer)
107{
108 return std::visit(
109 []<typename T>(T const* ptr) -> VariableArray::VariablePointer
110 { return const_cast<T*>(ptr); },
111 const_pointer);
112}
113
115{
116 return dropConst(const_cast<const VariableArray&>(*this).address_of(v));
117}
118
120{
121 return maybeHasSize<5>(deformation_gradient) && //
122 maybeHasSize<4>(mechanical_strain) && //
123 maybeHasSize<4>(stress) && //
124 maybeHasSize<4>(total_strain) && //
125 maybeHasSize<4>(total_stress);
126}
127
129{
130 return maybeHasSize<9>(deformation_gradient) && //
131 maybeHasSize<6>(mechanical_strain) && //
132 maybeHasSize<6>(stress) && //
133 maybeHasSize<6>(total_strain) && //
134 maybeHasSize<6>(total_stress);
135}
136
137} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
static bool maybeHasSize(const auto &arg)
Returns true if the argument is uninitialized or has Rows number of rows.
DeformationGradient deformation_gradient
std::variant< Scalar *, KelvinVector *, DeformationGradient * > VariablePointer
std:: variant< Scalar const *, KelvinVector const *, DeformationGradient const * > VariablePointerConst
VariablePointerConst address_of(Variable const v) const
static VariableArray::VariablePointer dropConst(VariableArray::VariablePointerConst const const_pointer)
static const std::array< std::string, static_cast< int >(Variable::number_of_variables)> variable_enum_to_string
Variable convertStringToVariable(std::string const &string)