OGS
VariableType.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 "VariableType.h"
5
6#include <boost/algorithm/string/predicate.hpp>
7
8#include "BaseLib/Error.h"
9
11template <int Rows>
12static bool maybeHasSize(const auto& arg)
13{
14 return std::holds_alternative<std::monostate>(arg) ||
15 std::holds_alternative<Eigen::Matrix<double, Rows, 1>>(arg);
16}
17
18namespace MaterialPropertyLib
19{
20Variable convertStringToVariable(std::string const& string)
21{
22 for (int i = 0; i < static_cast<int>(Variable::number_of_variables); ++i)
23 {
24 if (boost::iequals(string, variable_enum_to_string[i]))
25 {
26 return static_cast<Variable>(i);
27 }
28 }
29
31 "The variable name '{:s}' does not correspond to any known variable",
32 string);
33}
34
36 Variable const v) const
37{
38 switch (v)
39 {
41 return &capillary_pressure;
43 return &concentration;
47 return &density;
51 return &enthalpy;
57 return &fracture_aperture;
61 return &ice_volume_fraction;
65 return &liquid_saturation;
67 return &mechanical_strain;
69 return &molar_mass;
73 return &molar_fraction;
75 return &gas_phase_pressure;
77 return &porosity;
81 return &stress;
83 return &temperature;
85 return &total_strain;
87 return &total_stress;
89 return &transport_porosity;
91 return &vapour_pressure;
95 return &volumetric_strain;
96 default:
98 "No conversion to VariableType is provided for variable "
99 "{:d}",
100 static_cast<int>(v));
101 };
102}
103
105 VariableArray::VariablePointerConst const const_pointer)
106{
107 return std::visit(
108 []<typename T>(T const* ptr) -> VariableArray::VariablePointer
109 { return const_cast<T*>(ptr); },
110 const_pointer);
111}
112
114{
115 return dropConst(const_cast<const VariableArray&>(*this).address_of(v));
116}
117
126
135
136} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:19
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)