version 0.4.7
finiteelements/mechanics/materials/interface.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
20
21namespace Ikarus::Materials {
22
23#ifndef DOXYGEN
24template <class MImpl>
25struct Material;
26
27template <auto stressIndexPair, typename MImpl>
28struct VanishingStress;
29
30template <auto strainIndexPair, typename MImpl>
31struct VanishingStrain;
32#endif
33
42template <typename MAT, typename S>
43consteval bool hasCorrectSize() {
44 if constexpr (Concepts::EigenVector6<S> or Concepts::EigenMatrix33<S>)
45 return true;
46 if constexpr (MAT::isReduced and Concepts::EigenVector<S>) {
47 return S::RowsAtCompileTime == MAT::freeStrains;
48 } else
49 return false;
50}
51
58template <typename MAT, typename S>
59concept CorrectStrainSize = hasCorrectSize<MAT, S>();
60
65template <typename MAT, bool isReduced = MAT::isReduced>
67
68template <typename MAT>
69struct UnderlyingMaterial<MAT, true>
70{
71 using type = MAT::Underlying;
72 static auto material(const MAT& mat) { return mat.underlying(); }
73};
74
75template <typename MAT>
76struct UnderlyingMaterial<MAT, false>
77{
78 using type = MAT;
79 static auto material(const MAT& mat) { return mat; }
80};
81
83template <typename MAT>
85
87template <typename MAT>
88auto underlyingMaterial(const MAT& mat) {
90}
91
111template <class MI>
113{
114 using MaterialImpl = MI;
115
116 static constexpr bool isStrainVanished =
117 traits::isSpecializationNonTypeAndTypes<VanishingStrain, MaterialImpl>::value;
118 static constexpr bool isStressVanished =
119 traits::isSpecializationNonTypeAndTypes<VanishingStress, MaterialImpl>::value;
120
124 static constexpr bool isReduced = isStrainVanished or isStressVanished;
125
126 static constexpr bool isLinear = MI::strainTag == StrainTags::linear;
127
128 static constexpr bool isHyperelastic = [] {
129 if constexpr (isReduced) {
130 return requires {
131 typename MI::Underlying::DeviatoricType;
132 typename MI::Underlying::VolumetricType;
133 };
134 } else {
135 return requires {
136 typename MI::DeviatoricType;
137 typename MI::VolumetricType;
138 };
139 }
140 }();
141
147 constexpr const MaterialImpl& impl() const { return static_cast<const MaterialImpl&>(*this); }
148
154 constexpr MaterialImpl& impl() { return static_cast<MaterialImpl&>(*this); }
155
161 [[nodiscard]] constexpr static std::string name() { return MI::nameImpl(); }
162
167 [[nodiscard]] auto materialParameters() const { return impl().materialParametersImpl(); }
168
175 static constexpr double derivativeFactor = MI::derivativeFactorImpl;
176
187 template <StrainTags tag, typename Derived>
189 [[nodiscard]] auto storedEnergy(const Eigen::MatrixBase<Derived>& Eraw) const {
190 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
191 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
192
193 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
194 if constexpr (MaterialImpl::energyAcceptsVoigt)
195 return impl().storedEnergyImpl(toVoigt(E));
196 else
197 return impl().storedEnergyImpl(E);
198 } else
199 return impl().storedEnergyImpl(E);
200 }
201
211 template <StrainTags tag, bool voigt = true, typename Derived>
213 [[nodiscard]] auto stresses(const Eigen::MatrixBase<Derived>& Eraw) const {
214 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
215 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
216 if constexpr (voigt and MaterialImpl::stressToVoigt == false)
217 // user requests a Voigt shaped return but material is not able to. Therefore, we transform it here.
218 return toVoigt(stressesMaybeTransformInputToVoigt<false>(E), false);
219 else
220 return stressesMaybeTransformInputToVoigt<voigt>(E);
221 }
222
232 template <StrainTags tag, bool voigt = true, typename Derived>
234 [[nodiscard]] auto tangentModuli(const Eigen::MatrixBase<Derived>& Eraw) const {
235 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
236 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
237 if constexpr (voigt and MaterialImpl::moduliToVoigt == false)
238 // user request a Voigt shaped return but material is not able to. Therefore, we transform it here.
239 return toVoigt(tangentModuliMaybeTransformInputToVoigt<false>(E));
240 else
241 return tangentModuliMaybeTransformInputToVoigt<voigt>(E);
242 }
243
264 template <StrainTags tag, bool voigt = true, bool useNumeric = false, typename Derived>
266 [[nodiscard]] auto materialInversion(const Eigen::MatrixBase<Derived>& Sraw,
267 const Eigen::MatrixBase<Derived>& EstartRaw = Derived::Zero().eval(),
268 const double tol = 1e-12, const int maxIter = 20) const {
269 const auto S = Impl::maybeFromVoigt(Sraw.derived(), false).eval();
270
271 auto [D, Eraw] = [&]() {
272 if constexpr (requires { impl().materialInversionImpl(S); } and not useNumeric)
273 return impl().materialInversionImpl(S);
274 else {
275 const auto Estart = Impl::maybeFromVoigt(EstartRaw.derived(), true).eval();
276 return numericalMaterialInversion(impl(), S, Estart, tol, maxIter);
277 }
278 }();
279
280 const auto E = transformStrain<MaterialImpl::strainTag, tag>(Eraw).eval();
281 if constexpr (voigt)
282 return std::make_pair(D, toVoigt(E));
283 else
284 return std::make_pair(fromVoigt(D), E);
285 }
286
295 template <typename STO>
296 auto rebind() const {
297 return impl().template rebind<STO>();
298 }
299
300private:
301 template <bool voigt = true, typename Derived>
302 auto stressesMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
303 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means Voigt notation
304 if constexpr (MaterialImpl::stressAcceptsVoigt)
305 return impl().template stressesImpl<voigt>(E);
306 else // material is not able to accept Voigt shaped Input. Therefore, we transform it before.
307 return impl().template stressesImpl<voigt>(fromVoigt(E.derived()));
308 } else
309 return impl().template stressesImpl<voigt>(E.derived());
310 }
311
312 template <bool voigt = true, typename Derived>
313 auto tangentModuliMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
314 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
315 if constexpr (MaterialImpl::moduliAcceptsVoigt)
316 return impl().template tangentModuliImpl<voigt>(E);
317 else
318 return impl().template tangentModuliImpl<voigt>(fromVoigt(E.derived()));
319 } else
320 return impl().template tangentModuliImpl<voigt>(E.derived());
321 }
322};
323
324} // namespace Ikarus::Materials
Contains stl-like type traits.
Helper for the autodiff library.
Implementation of the numerical scheme for material inverison for generic hyperelastic material model...
helper functions used by material model implementations.
Definition of several material related enums.
Implementation of transformations for different strain measures.
Material property functions and conversion utilities.
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:296
constexpr Eigen::Index toVoigt(Eigen::Index i, Eigen::Index j) noexcept
Converts 2D indices to Voigt notation index.
Definition: tensorutils.hh:182
Definition: decomposehyperelastic.hh:15
auto numericalMaterialInversion(const Material &mat, const Eigen::MatrixBase< Derived > &S, const Eigen::MatrixBase< Derived > &Estart=Derived::Zero().eval(), const double tol=1e-12, const int maxIter=20)
Computes numerically an approximation of the complementary strain energy function and returns the mat...
Definition: numericalmaterialinversion.hh:34
auto underlyingMaterial(const MAT &mat)
Helper function to access the underlying material model.
Definition: finiteelements/mechanics/materials/interface.hh:88
consteval bool hasCorrectSize()
Template function for checking if the strain size is correct.
Definition: finiteelements/mechanics/materials/interface.hh:43
typename UnderlyingMaterial< MAT >::type UnderlyingMaterial_t
Type alias for the underlying material model.
Definition: finiteelements/mechanics/materials/interface.hh:84
A helper struct to access the underling material model if reduced (or vanished).
Definition: finiteelements/mechanics/materials/interface.hh:66
static auto material(const MAT &mat)
Definition: finiteelements/mechanics/materials/interface.hh:72
MAT::Underlying type
Definition: finiteelements/mechanics/materials/interface.hh:71
static auto material(const MAT &mat)
Definition: finiteelements/mechanics/materials/interface.hh:79
MAT type
Definition: finiteelements/mechanics/materials/interface.hh:78
Interface classf or materials.
Definition: finiteelements/mechanics/materials/interface.hh:113
static constexpr std::string name()
Get the name of the implemented material.
Definition: finiteelements/mechanics/materials/interface.hh:161
auto materialParameters() const
Returns the material parameters stored in the implemented material.
Definition: finiteelements/mechanics/materials/interface.hh:167
constexpr const MaterialImpl & impl() const
Const accessor to the underlying material (CRTP).
Definition: finiteelements/mechanics/materials/interface.hh:147
auto rebind() const
Rebind material to a different scalar type.
Definition: finiteelements/mechanics/materials/interface.hh:296
MI MaterialImpl
Type of material implementation.
Definition: finiteelements/mechanics/materials/interface.hh:114
auto materialInversion(const Eigen::MatrixBase< Derived > &Sraw, const Eigen::MatrixBase< Derived > &EstartRaw=Derived::Zero().eval(), const double tol=1e-12, const int maxIter=20) const
Computes the corresponding strain measure and inverse material tangent for a given stress state.
Definition: finiteelements/mechanics/materials/interface.hh:266
auto tangentModuli(const Eigen::MatrixBase< Derived > &Eraw) const
Get the tangentModuli of the material.
Definition: finiteelements/mechanics/materials/interface.hh:234
static constexpr bool isHyperelastic
Definition: finiteelements/mechanics/materials/interface.hh:128
auto stresses(const Eigen::MatrixBase< Derived > &Eraw) const
Get the stresses of the material.
Definition: finiteelements/mechanics/materials/interface.hh:213
auto storedEnergy(const Eigen::MatrixBase< Derived > &Eraw) const
Return the stored potential energy of the material.
Definition: finiteelements/mechanics/materials/interface.hh:189
static constexpr bool isStrainVanished
Definition: finiteelements/mechanics/materials/interface.hh:116
static constexpr bool isStressVanished
Definition: finiteelements/mechanics/materials/interface.hh:118
static constexpr bool isLinear
Definition: finiteelements/mechanics/materials/interface.hh:126
constexpr MaterialImpl & impl()
Accessor to the underlying material (CRTP).
Definition: finiteelements/mechanics/materials/interface.hh:154
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:175
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:124
Template concept for ensuring correct strain size.
Definition: finiteelements/mechanics/materials/interface.hh:59
Concept defining the requirements for Eigen vectors.
Definition: utils/concepts.hh:365
Several concepts.