version 0.4
interface.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
18
19namespace Ikarus {
20
21#ifndef DOXYGEN
22 template <class MaterialImpl>
23 struct Material;
24
25 template <auto stressIndexPair, typename MaterialImpl>
26 struct VanishingStress;
27#endif
28
37 template <typename Material, typename Strains>
38 consteval bool hasCorrectSize() {
39 if constexpr (Concepts::EigenVector6<Strains> or Concepts::EigenMatrix33<Strains>) return true;
41 return Strains::RowsAtCompileTime == Material::freeStrains;
42 } else
43 return false;
44 }
45
52 template <typename Material, typename Strains>
53 concept CorrectStrainSize = hasCorrectSize<Material, Strains>();
54
74 template <class MaterialImpl>
75 struct Material {
76 using MaterialImplType = MaterialImpl;
77
81 static constexpr bool isReduced = traits::isSpecializationNonTypeAndTypes<VanishingStress, MaterialImpl>::value;
82
88 constexpr const MaterialImpl& impl() const { return static_cast<MaterialImpl const&>(*this); }
89
95 constexpr MaterialImpl& impl() { return static_cast<MaterialImpl&>(*this); }
96
102 [[nodiscard]] constexpr std::string name() const { return impl().nameImpl(); }
103
114 template <StrainTags tag, typename Derived>
116 [[nodiscard]] auto storedEnergy(const Eigen::MatrixBase<Derived>& Eraw) const {
117 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
118 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
119
120 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
121 if constexpr (MaterialImpl::energyAcceptsVoigt)
122 return impl().storedEnergyImpl(toVoigt(E));
123 else
124 return impl().storedEnergyImpl(E);
125 } else
126 return impl().storedEnergyImpl(E);
127 }
128
138 template <StrainTags tag, bool voigt = true, typename Derived>
140 [[nodiscard]] auto stresses(const Eigen::MatrixBase<Derived>& Eraw) const {
141 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
142 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
143 if constexpr (voigt and MaterialImpl::stressToVoigt == false)
144 // user requests a Voigt shaped return but material is not able to. Therefore, we transform it here.
145 return toVoigt(stressesMaybeTransformInputToVoigt<false>(E), false);
146 else
147 return stressesMaybeTransformInputToVoigt<voigt>(E);
148 }
149
159 template <StrainTags tag, bool voigt = true, typename Derived>
161 [[nodiscard]] auto tangentModuli(const Eigen::MatrixBase<Derived>& Eraw) const {
162 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
163 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
164 if constexpr (voigt and MaterialImpl::moduliToVoigt == false)
165 // user request a Voigt shaped return but material is not able to. Therefore, we transform it here.
166 return toVoigt(tangentModuliMaybeTransformInputToVoigt<false>(E));
167 else
168 return tangentModuliMaybeTransformInputToVoigt<voigt>(E);
169 }
170
179 template <typename ScalarTypeOther>
180 auto rebind() const {
181 return impl().template rebind<ScalarTypeOther>();
182 }
183
184 private:
185 template <bool voigt = true, typename Derived>
186 auto stressesMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
187 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means Voigt notation
188 if constexpr (MaterialImpl::stressAcceptsVoigt)
189 return impl().template stressesImpl<voigt>(E);
190 else // material is not able to accept Voigt shaped Input. Therefore, we transform it before.
191 return impl().template stressesImpl<voigt>(fromVoigt(E.derived()));
192 } else
193 return impl().template stressesImpl<voigt>(E.derived());
194 }
195
196 template <bool voigt = true, typename Derived>
197 auto tangentModuliMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
198 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
199 if constexpr (MaterialImpl::moduliAcceptsVoigt)
200 return impl().template tangentModuliImpl<voigt>(E);
201 else
202 return impl().template tangentModuliImpl<voigt>(fromVoigt(E.derived()));
203 } else
204 return impl().template tangentModuliImpl<voigt>(E.derived());
205 }
206 };
207
208} // namespace Ikarus
Several concepts.
Contains stl-like type traits.
Helper for the autodiff library.
Material property functions and conversion utilities.
Implementation of strain-related functions.
Definition of several material related enums.
auto fromVoigt(const Eigen::Vector< ST, size > &EVoigt, bool isStrain=true)
Converts a vector given in Voigt notation to a matrix.
Definition: tensorutils.hh:256
constexpr Eigen::Index toVoigt(Eigen::Index i, Eigen::Index j) noexcept
Converts 2D indices to Voigt notation index.
Definition: tensorutils.hh:167
Definition: simpleassemblers.hh:21
consteval bool hasCorrectSize()
Template function for checking if the strain size is correct.
Definition: interface.hh:38
Interface classf or materials.
Definition: interface.hh:75
constexpr const MaterialImpl & impl() const
Const accessor to the underlying material (CRTP).
Definition: interface.hh:88
auto tangentModuli(const Eigen::MatrixBase< Derived > &Eraw) const
Get the tangentModuli of the material.
Definition: interface.hh:161
auto storedEnergy(const Eigen::MatrixBase< Derived > &Eraw) const
Return the stored potential energy of the material.
Definition: interface.hh:116
constexpr MaterialImpl & impl()
Accessor to the underlying material (CRTP).
Definition: interface.hh:95
static constexpr bool isReduced
Static constant for determining if the material has vanishing stress components (is reduced).
Definition: interface.hh:81
MaterialImpl MaterialImplType
Type of material implementation.
Definition: interface.hh:76
constexpr std::string name() const
Get the name of the implemented material.
Definition: interface.hh:102
auto stresses(const Eigen::MatrixBase< Derived > &Eraw) const
Get the stresses of the material.
Definition: interface.hh:140
auto rebind() const
Rebind material to a different scalar type.
Definition: interface.hh:180
Template concept for ensuring correct strain size.
Definition: interface.hh:53
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:381