version 0.4.1
easvariants.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
10#pragma once
11
15
16namespace Ikarus::EAS {
17namespace Impl {
26 template <typename GEO>
27 struct Variants
28 {
29 static constexpr int worldDim = GEO::coorddimension;
30 static_assert((worldDim == 2) or (worldDim == 3), "EAS variants are only available 2D and 3D elements.");
31
33 using EAS2D = std::variant<E0<GEO>, Q1E4<GEO>, Q1E5<GEO>, Q1E7<GEO>>;
34
36 using EAS3D = std::variant<E0<GEO>, H1E9<GEO>, H1E21<GEO>>;
37
39 using type = std::conditional_t<worldDim == 2, EAS2D, EAS3D>;
40 };
41
46 template <typename Geometry>
47 struct EASVariant
48 {
49 using Variant = Impl::Variants<Geometry>::type;
50
56 template <typename F>
57 void operator()(F&& f) const {
58 std::visit(
59 [&]<typename EAST>(const EAST& easFunction) {
60 if constexpr (EAST::enhancedStrainSize != 0)
61 f(easFunction);
62 },
63 var_);
64 }
65
66 auto numberOfEASParameters() const {
67 return std::visit([]<typename EAST>(const EAST&) -> int { return EAST::enhancedStrainSize; }, var_);
68 }
69 bool isDisplacmentBased() const { return numberOfEASParameters() == 0; }
70 void setEASType(int numberOfEASParameters) {
71 numberOfEASParameters_ = numberOfEASParameters;
72 if (geometry_)
73 createEASType();
74 }
75 void bind(const Geometry& geometry) {
76 geometry_ = std::make_optional<Geometry>(geometry);
77 createEASType();
78 }
79
80 private:
81 void createEASType() {
82 if (numberOfEASParameters_ == 0) {
83 var_ = E0(geometry_.value());
84 return;
85 }
86
87 if constexpr (Geometry::mydimension == 2) {
88 switch (numberOfEASParameters_) {
89 case 4:
90 var_ = Q1E4(geometry_.value());
91 break;
92 case 5:
93 var_ = Q1E5(geometry_.value());
94 break;
95 case 7:
96 var_ = Q1E7(geometry_.value());
97 break;
98 default:
99 DUNE_THROW(Dune::NotImplemented, "The given EAS parameters are not available for the 2D case.");
100 }
101 } else if constexpr (Geometry::mydimension == 3) {
102 switch (numberOfEASParameters_) {
103 case 9:
104 var_ = H1E9(geometry_.value());
105 break;
106 case 21:
107 var_ = H1E21(geometry_.value());
108 break;
109 default:
110 DUNE_THROW(Dune::NotImplemented, "The given EAS parameters are not available for the 3D case.");
111 }
112 }
113 }
114 std::optional<Geometry> geometry_;
115 Variant var_;
116 int numberOfEASParameters_;
117 };
118} // namespace Impl
119} // namespace Ikarus::EAS
Helper for the Eigen::Tensor types.
Definition of the types of EAS formulations for 2D elements.
Definition of the types of EAS formulations for 3D elements.
Definition: eas2d.hh:14