version 0.4.1
finiteelements/mechanics/materials/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
22template <class MImpl>
23struct Material;
24
25template <auto stressIndexPair, typename MImpl>
26struct VanishingStress;
27
28template <auto strainIndexPair, typename MImpl>
29struct VanishingStrain;
30#endif
31
40template <typename MAT, typename S>
41consteval bool hasCorrectSize() {
42 if constexpr (Concepts::EigenVector6<S> or Concepts::EigenMatrix33<S>)
43 return true;
44 if constexpr (MAT::isReduced and Concepts::EigenVector<S>) {
45 return S::RowsAtCompileTime == MAT::freeStrains;
46 } else
47 return false;
48}
49
56template <typename MAT, typename S>
57concept CorrectStrainSize = hasCorrectSize<MAT, S>();
58
78template <class MI>
80{
81 using MaterialImpl = MI;
82
86 static constexpr bool isReduced = traits::isSpecializationNonTypeAndTypes<VanishingStress, MaterialImpl>::value or
87 traits::isSpecializationNonTypeAndTypes<VanishingStrain, MaterialImpl>::value;
88
94 constexpr const MaterialImpl& impl() const { return static_cast<const MaterialImpl&>(*this); }
95
101 constexpr MaterialImpl& impl() { return static_cast<MaterialImpl&>(*this); }
102
108 [[nodiscard]] constexpr static std::string name() { return MI::nameImpl(); }
109
114 [[nodiscard]] auto materialParameters() const { return impl().materialParametersImpl(); }
115
122 static constexpr double derivativeFactor = MI::derivativeFactorImpl;
123
134 template <StrainTags tag, typename Derived>
136 [[nodiscard]] auto storedEnergy(const Eigen::MatrixBase<Derived>& Eraw) const {
137 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
138 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
139
140 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
141 if constexpr (MaterialImpl::energyAcceptsVoigt)
142 return impl().storedEnergyImpl(toVoigt(E));
143 else
144 return impl().storedEnergyImpl(E);
145 } else
146 return impl().storedEnergyImpl(E);
147 }
148
158 template <StrainTags tag, bool voigt = true, typename Derived>
160 [[nodiscard]] auto stresses(const Eigen::MatrixBase<Derived>& Eraw) const {
161 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
162 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
163 if constexpr (voigt and MaterialImpl::stressToVoigt == false)
164 // user requests a Voigt shaped return but material is not able to. Therefore, we transform it here.
165 return toVoigt(stressesMaybeTransformInputToVoigt<false>(E), false);
166 else
167 return stressesMaybeTransformInputToVoigt<voigt>(E);
168 }
169
179 template <StrainTags tag, bool voigt = true, typename Derived>
181 [[nodiscard]] auto tangentModuli(const Eigen::MatrixBase<Derived>& Eraw) const {
182 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
183 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
184 if constexpr (voigt and MaterialImpl::moduliToVoigt == false)
185 // user request a Voigt shaped return but material is not able to. Therefore, we transform it here.
186 return toVoigt(tangentModuliMaybeTransformInputToVoigt<false>(E));
187 else
188 return tangentModuliMaybeTransformInputToVoigt<voigt>(E);
189 }
190
199 template <typename STO>
200 auto rebind() const {
201 return impl().template rebind<STO>();
202 }
203
204private:
205 template <bool voigt = true, typename Derived>
206 auto stressesMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
207 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means Voigt notation
208 if constexpr (MaterialImpl::stressAcceptsVoigt)
209 return impl().template stressesImpl<voigt>(E);
210 else // material is not able to accept Voigt shaped Input. Therefore, we transform it before.
211 return impl().template stressesImpl<voigt>(fromVoigt(E.derived()));
212 } else
213 return impl().template stressesImpl<voigt>(E.derived());
214 }
215
216 template <bool voigt = true, typename Derived>
217 auto tangentModuliMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
218 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
219 if constexpr (MaterialImpl::moduliAcceptsVoigt)
220 return impl().template tangentModuliImpl<voigt>(E);
221 else
222 return impl().template tangentModuliImpl<voigt>(fromVoigt(E.derived()));
223 } else
224 return impl().template tangentModuliImpl<voigt>(E.derived());
225 }
226};
227
228} // namespace Ikarus
Contains stl-like type traits.
Helper for the autodiff library.
Several concepts.
Material property functions and conversion utilities.
Implementation of strain-related functions.
Definition of several material related enums.
constexpr Eigen::Index toVoigt(Eigen::Index i, Eigen::Index j) noexcept
Converts 2D indices to Voigt notation index.
Definition: tensorutils.hh:166
auto fromVoigt(const Eigen::Matrix< ST, size, 1, Options, maxSize, 1 > &EVoigt, bool isStrain=true)
Converts a vector given in Voigt notation to a matrix.
Definition: tensorutils.hh:271
Definition: assemblermanipulatorbuildingblocks.hh:22
consteval bool hasCorrectSize()
Template function for checking if the strain size is correct.
Definition: finiteelements/mechanics/materials/interface.hh:41
Interface classf or materials.
Definition: finiteelements/mechanics/materials/interface.hh:80
constexpr const MaterialImpl & impl() const
Const accessor to the underlying material (CRTP).
Definition: finiteelements/mechanics/materials/interface.hh:94
auto tangentModuli(const Eigen::MatrixBase< Derived > &Eraw) const
Get the tangentModuli of the material.
Definition: finiteelements/mechanics/materials/interface.hh:181
auto rebind() const
Rebind material to a different scalar type.
Definition: finiteelements/mechanics/materials/interface.hh:200
static constexpr double derivativeFactor
This factor denotes the differences between the returned stresses and moduli and the passed strain.
Definition: finiteelements/mechanics/materials/interface.hh:122
MI MaterialImpl
Type of material implementation.
Definition: finiteelements/mechanics/materials/interface.hh:81
static constexpr bool isReduced
Static constant for determining if the material has vanishing stress or strain components (is reduced...
Definition: finiteelements/mechanics/materials/interface.hh:86
static constexpr std::string name()
Get the name of the implemented material.
Definition: finiteelements/mechanics/materials/interface.hh:108
auto storedEnergy(const Eigen::MatrixBase< Derived > &Eraw) const
Return the stored potential energy of the material.
Definition: finiteelements/mechanics/materials/interface.hh:136
constexpr MaterialImpl & impl()
Accessor to the underlying material (CRTP).
Definition: finiteelements/mechanics/materials/interface.hh:101
auto stresses(const Eigen::MatrixBase< Derived > &Eraw) const
Get the stresses of the material.
Definition: finiteelements/mechanics/materials/interface.hh:160
auto materialParameters() const
Returns the material parameters stored in the implemented material.
Definition: finiteelements/mechanics/materials/interface.hh:114
Template concept for ensuring correct strain size.
Definition: finiteelements/mechanics/materials/interface.hh:57
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:355