OGS
MFrontGeneric.cpp
Go to the documentation of this file.
1
10#include "MFrontGeneric.h"
11
13{
14const char* varTypeToString(int v)
15{
16 using V = mgis::behaviour::Variable;
17 if (v == V::SCALAR)
18 return "SCALAR";
19 if (v == V::VECTOR)
20 return "VECTOR";
21 if (v == V::STENSOR)
22 return "STENSOR";
23 if (v == V::TENSOR)
24 return "TENSOR";
25
26 OGS_FATAL("Unknown variable type {}.", v);
27}
28
29int getEquivalentPlasticStrainOffset(mgis::behaviour::Behaviour const& b)
30{
31 return mgis::behaviour::contains(b.isvs, "EquivalentPlasticStrain")
32 ? mgis::behaviour::getVariableOffset(
33 b.isvs, "EquivalentPlasticStrain", b.hypothesis)
34 : -1;
35}
36
37template <int DisplacementDim>
39 std::vector<double> const& mfront_data,
40 std::optional<
42 mgis::behaviour::Behaviour const& behaviour)
43{
44 using VT = mgis::behaviour::Variable::Type;
47
48 std::vector<double> ogs_data(mfront_data.size());
49
50 std::size_t offset = 0;
51 constexpr auto kv_size =
53
54 for (auto const& [var1, var2] : behaviour.to_blocks)
55 {
56 std::size_t size;
57
58 auto const* const d_in = mfront_data.data() + offset;
59 auto* const d_out = ogs_data.data() + offset;
60
61 if (var1.type == VT::SCALAR && var2.type == VT::SCALAR)
62 {
63 size = 1;
64 *d_out = *d_in;
65 }
66 else if (var1.type == VT::SCALAR && var2.type == VT::STENSOR)
67 {
68 assert(getVariableSize(var2, behaviour.hypothesis) == kv_size);
69 size = kv_size;
70
71 if (Q)
72 {
74 "Coordinate frame rotation not yet implemented for "
75 "dScalar/dSTensor.");
76 }
77
78 Eigen::Map<KV>{d_out} = eigenSwap45View(Eigen::Map<const KV>{d_in});
79 }
80 else if (var1.type == VT::STENSOR && var2.type == VT::SCALAR)
81 {
82 assert(getVariableSize(var1, behaviour.hypothesis) == kv_size);
83 size = kv_size;
84
85 if (Q)
86 {
88 "Coordinate frame rotation not yet implemented for "
89 "dSTensor/dScalar.");
90 }
91
92 Eigen::Map<KV>{d_out} = eigenSwap45View(Eigen::Map<const KV>{d_in});
93 }
94 else if (var1.type == VT::STENSOR && var2.type == VT::STENSOR)
95 {
96 assert(getVariableSize(var1, behaviour.hypothesis) == kv_size);
97 assert(getVariableSize(var2, behaviour.hypothesis) == kv_size);
98 size = kv_size * kv_size;
99
100 if (Q)
101 {
102 Eigen::Map<KM>{d_out} =
103 *Q * eigenSwap45View(Eigen::Map<const KM>{d_in}) *
104 Q->transpose();
105 }
106 else
107 {
108 Eigen::Map<KM>{d_out} =
109 eigenSwap45View(Eigen::Map<const KM>{d_in});
110 }
111 }
112 else
113 {
114 OGS_FATAL("unsupported variable type combination");
115 }
116
117 offset += size;
118 }
119
120 return {std::move(ogs_data)};
121}
122
124 std::vector<double> const& mfront_data,
125 std::optional<MathLib::KelvinVector::KelvinMatrixType<2>> const& Q,
126 mgis::behaviour::Behaviour const& behaviour);
128 std::vector<double> const& mfront_data,
129 std::optional<MathLib::KelvinVector::KelvinMatrixType<3>> const& Q,
130 mgis::behaviour::Behaviour const& behaviour);
131
132} // namespace MaterialLib::Solids::MFront
#define OGS_FATAL(...)
Definition Error.h:26
OGSMFrontTangentOperatorData tangentOperatorDataMFrontToOGS(std::vector< double > const &mfront_data, std::optional< MathLib::KelvinVector::KelvinMatrixType< DisplacementDim > > const &Q, mgis::behaviour::Behaviour const &behaviour)
template OGSMFrontTangentOperatorData tangentOperatorDataMFrontToOGS< 3 >(std::vector< double > const &mfront_data, std::optional< MathLib::KelvinVector::KelvinMatrixType< 3 > > const &Q, mgis::behaviour::Behaviour const &behaviour)
template OGSMFrontTangentOperatorData tangentOperatorDataMFrontToOGS< 2 >(std::vector< double > const &mfront_data, std::optional< MathLib::KelvinVector::KelvinMatrixType< 2 > > const &Q, mgis::behaviour::Behaviour const &behaviour)
constexpr auto eigenSwap45View(Eigen::MatrixBase< Derived > const &matrix)
const char * varTypeToString(int v)
int getEquivalentPlasticStrainOffset(mgis::behaviour::Behaviour const &b)
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), kelvin_vector_dimensions(DisplacementDim), Eigen::RowMajor > KelvinMatrixType
Used for disambiguation with MFront's thermodynamic forces data.