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;
64 return &fracture_aperture;
70 return &liquid_saturation;
72 return &mechanical_strain;
74 return &molar_mass;
78 return &molar_fraction;
80 return &gas_phase_pressure;
82 return &porosity;
86 return &stress;
88 return &temperature;
90 return &total_strain;
92 return &total_stress;
94 return &transport_porosity;
96 return &vapour_pressure;
98 return &volumetric_strain;
99 default:
100 OGS_FATAL(
101 "No conversion to VariableType is provided for variable "
102 "{:d}",
103 static_cast<int>(v));
104 };
105}
106
108 VariableArray::VariablePointerConst const const_pointer)
109{
110 return std::visit(
111 []<typename T>(T const* ptr) -> VariableArray::VariablePointer
112 { return const_cast<T*>(ptr); },
113 const_pointer);
114}
115
117{
118 return dropConst(const_cast<const VariableArray&>(*this).address_of(v));
119}
120
129
138
139} // 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)