version 0.4.4
easvariants.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2025 The Ikarus Developers ikarus@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
10#pragma once
11
16
17namespace Ikarus::EAS {
18namespace Impl {
19 template <typename GEO, int myDim, typename EASFunction>
20 struct EASType;
21 template <typename GEO>
22 struct EASType<GEO, 3, EAS::LinearStrain>
23 {
24 using type = std::variant<E0<GEO>, E9<GEO>, E21<GEO>>;
25 };
26 template <typename GEO>
27 struct EASType<GEO, 2, EAS::LinearStrain>
28 {
29 using type = std::variant<E0<GEO>, E4<GEO>, E5<GEO>, E7<GEO>, E11<GEO>>;
30 };
31 template <typename GEO, int myDim>
32 struct EASType<GEO, myDim, EAS::GreenLagrangeStrain>
33 {
34 using type = EASType<GEO, myDim, EAS::LinearStrain>::type;
35 };
36 template <typename GEO>
37 struct EASType<GEO, 2, EAS::DisplacementGradient>
38 {
39 using type = std::variant<H0<GEO>, H4<GEO>>;
40 };
41 template <typename GEO>
42 struct EASType<GEO, 3, EAS::DisplacementGradient>
43 {
44 using type = std::variant<H0<GEO>, H9<GEO>>;
45 };
46 template <typename GEO, int myDim>
47 struct EASType<GEO, myDim, EAS::DisplacementGradientTransposed>
48 {
49 using type = EASType<GEO, myDim, EAS::DisplacementGradient>::type;
50 };
51} // namespace Impl
52
58template <typename EASFunction, typename GEO>
60{
61 static constexpr int myDim = GEO::mydimension;
62 using Variant = Impl::EASType<GEO, myDim, EASFunction>::type;
63 static_assert((myDim == 2) or (myDim == 3), "EAS variants are only available for 2D and 3D elements.");
64
70 template <typename F>
71 void operator()(F&& f) const {
72 std::visit([&]<typename EAST>(const EAST& easFunction) { f(easFunction); }, var_);
73 }
74
80 return std::visit([]<typename EAST>(const EAST&) -> int { return EAST::enhancedStrainSize; }, var_);
81 }
82
88 bool isDisplacmentBased() const { return numberOfInternalVariables() == 0; }
89
91 numberOfEASParameters_ = numberOfInternalVariables;
92 if (geometry_)
93 createEASType();
94 }
95 void bind(const GEO& geometry) {
96 geometry_ = std::make_optional<GEO>(geometry);
97 createEASType();
98 }
99
100private:
101 void createEASType() {
102 const std::string& errorMessage = "The given EAS parameters are not available for enhancing " +
103 EASFunction::name() + " strain measure for the " + std::to_string(myDim) +
104 "D case.";
105
106 if constexpr (std::same_as<EASFunction, EAS::LinearStrain> or std::same_as<EASFunction, EAS::GreenLagrangeStrain>) {
107 if (numberOfEASParameters_ == 0) {
108 var_ = E0(geometry_.value());
109 return;
110 }
111 if constexpr (myDim == 2) {
112 switch (numberOfEASParameters_) {
113 case 4:
114 var_ = E4(geometry_.value());
115 break;
116 case 5:
117 var_ = E5(geometry_.value());
118 break;
119 case 7:
120 var_ = E7(geometry_.value());
121 break;
122 case 11:
123 var_ = E11(geometry_.value());
124 break;
125 default:
126 DUNE_THROW(Dune::NotImplemented, errorMessage);
127 }
128 } else if constexpr (myDim == 3) {
129 switch (numberOfEASParameters_) {
130 case 9:
131 var_ = E9(geometry_.value());
132 break;
133 case 21:
134 var_ = E21(geometry_.value());
135 break;
136 default:
137 DUNE_THROW(Dune::NotImplemented, errorMessage);
138 }
139 }
140 }
141 if constexpr (std::same_as<EASFunction, EAS::DisplacementGradient> or
142 std::same_as<EASFunction, EAS::DisplacementGradientTransposed>) {
143 if (numberOfEASParameters_ == 0) {
144 var_ = H0(geometry_.value());
145 return;
146 }
147 if constexpr (myDim == 2) {
148 switch (numberOfEASParameters_) {
149 case 4:
150 var_ = H4(geometry_.value());
151 break;
152 default:
153 DUNE_THROW(Dune::NotImplemented, errorMessage);
154 }
155 } else if constexpr (myDim == 3) {
156 switch (numberOfEASParameters_) {
157 case 9:
158 var_ = H9(geometry_.value());
159 break;
160 default:
161 DUNE_THROW(Dune::NotImplemented, errorMessage);
162 }
163 }
164 }
165 }
166 std::optional<GEO> geometry_;
167 Variant var_;
168 int numberOfEASParameters_;
169};
170} // namespace Ikarus::EAS
Helper for the Eigen::Tensor types.
Header file for various EAS functions.
Definition of the types of EAS formulations for 2D and 3D linear solid elements, where linear and Gre...
Definition: easfunctions/displacementgradient.hh:21
Wrapper around the EAS variant, contains helper functions.
Definition: easvariants.hh:60
void bind(const GEO &geometry)
Definition: easvariants.hh:95
auto numberOfInternalVariables() const
A helper function to get the number of EAS parameters.
Definition: easvariants.hh:79
Impl::EASType< GEO, myDim, EASFunction >::type Variant
Definition: easvariants.hh:62
bool isDisplacmentBased() const
A helper function to identify if the formulation is purely displacement-based, i.e....
Definition: easvariants.hh:88
void operator()(F &&f) const
Executes a function F on the variant, if enhancedStrainSize is not zero.
Definition: easvariants.hh:71
void setEASType(int numberOfInternalVariables)
Definition: easvariants.hh:90
static constexpr int myDim
Definition: easvariants.hh:61
Dummy struct for displacement-based EAS elements, i.e. 0 enhanced modes.
Definition: linearandglstrains.hh:46
Definition of the types of EAS formulations for 2D and 3D linear solid elements, where the displaceme...