version 0.4.1
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
80template <class MI>
82{
83 using MaterialImpl = MI;
84
88 static constexpr bool isReduced = traits::isSpecializationNonTypeAndTypes<VanishingStress, MaterialImpl>::value or
89 traits::isSpecializationNonTypeAndTypes<VanishingStrain, MaterialImpl>::value;
90
91 static constexpr bool isLinear = MI::strainTag == StrainTags::linear;
92
98 constexpr const MaterialImpl& impl() const { return static_cast<const MaterialImpl&>(*this); }
99
105 constexpr MaterialImpl& impl() { return static_cast<MaterialImpl&>(*this); }
106
112 [[nodiscard]] constexpr static std::string name() { return MI::nameImpl(); }
113
118 [[nodiscard]] auto materialParameters() const { return impl().materialParametersImpl(); }
119
126 static constexpr double derivativeFactor = MI::derivativeFactorImpl;
127
138 template <StrainTags tag, typename Derived>
140 [[nodiscard]] auto storedEnergy(const Eigen::MatrixBase<Derived>& Eraw) const {
141 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
142 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
143
144 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
145 if constexpr (MaterialImpl::energyAcceptsVoigt)
146 return impl().storedEnergyImpl(toVoigt(E));
147 else
148 return impl().storedEnergyImpl(E);
149 } else
150 return impl().storedEnergyImpl(E);
151 }
152
162 template <StrainTags tag, bool voigt = true, typename Derived>
164 [[nodiscard]] auto stresses(const Eigen::MatrixBase<Derived>& Eraw) const {
165 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
166 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
167 if constexpr (voigt and MaterialImpl::stressToVoigt == false)
168 // user requests a Voigt shaped return but material is not able to. Therefore, we transform it here.
169 return toVoigt(stressesMaybeTransformInputToVoigt<false>(E), false);
170 else
171 return stressesMaybeTransformInputToVoigt<voigt>(E);
172 }
173
183 template <StrainTags tag, bool voigt = true, typename Derived>
185 [[nodiscard]] auto tangentModuli(const Eigen::MatrixBase<Derived>& Eraw) const {
186 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
187 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
188 if constexpr (voigt and MaterialImpl::moduliToVoigt == false)
189 // user request a Voigt shaped return but material is not able to. Therefore, we transform it here.
190 return toVoigt(tangentModuliMaybeTransformInputToVoigt<false>(E));
191 else
192 return tangentModuliMaybeTransformInputToVoigt<voigt>(E);
193 }
194
215 template <StrainTags tag, bool voigt = true, bool useNumeric = false, typename Derived>
217 [[nodiscard]] auto materialInversion(const Eigen::MatrixBase<Derived>& Sraw,
218 const Eigen::MatrixBase<Derived>& EstartRaw = Derived::Zero().eval(),
219 const double tol = 1e-12, const int maxIter = 20) const {
220 const auto S = Impl::maybeFromVoigt(Sraw.derived(), false).eval();
221
222 auto [D, Eraw] = [&]() {
223 if constexpr (requires { impl().materialInversionImpl(S); } and not useNumeric)
224 return impl().materialInversionImpl(S);
225 else {
226 const auto Estart = Impl::maybeFromVoigt(EstartRaw.derived(), true).eval();
227 return numericalMaterialInversion(impl(), S, Estart, tol, maxIter);
228 }
229 }();
230
231 const auto E = transformStrain<MaterialImpl::strainTag, tag>(Eraw).eval();
232 if constexpr (voigt)
233 return std::make_pair(D, toVoigt(E));
234 else
235 return std::make_pair(fromVoigt(D), E);
236 }
237
246 template <typename STO>
247 auto rebind() const {
248 return impl().template rebind<STO>();
249 }
250
251private:
252 template <bool voigt = true, typename Derived>
253 auto stressesMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
254 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means Voigt notation
255 if constexpr (MaterialImpl::stressAcceptsVoigt)
256 return impl().template stressesImpl<voigt>(E);
257 else // material is not able to accept Voigt shaped Input. Therefore, we transform it before.
258 return impl().template stressesImpl<voigt>(fromVoigt(E.derived()));
259 } else
260 return impl().template stressesImpl<voigt>(E.derived());
261 }
262
263 template <bool voigt = true, typename Derived>
264 auto tangentModuliMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
265 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
266 if constexpr (MaterialImpl::moduliAcceptsVoigt)
267 return impl().template tangentModuliImpl<voigt>(E);
268 else
269 return impl().template tangentModuliImpl<voigt>(fromVoigt(E.derived()));
270 } else
271 return impl().template tangentModuliImpl<voigt>(E.derived());
272 }
273};
274
275} // namespace Ikarus::Materials
Contains stl-like type traits.
Helper for the autodiff library.
Definition of several material related enums.
helper functions used by material model implementations.
Implementation of the numerical scheme for material inverison for generic hyperelastic material model...
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: arrudaboyce.hh:27
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
consteval bool hasCorrectSize()
Template function for checking if the strain size is correct.
Definition: finiteelements/mechanics/materials/interface.hh:43
Interface classf or materials.
Definition: finiteelements/mechanics/materials/interface.hh:82
static constexpr std::string name()
Get the name of the implemented material.
Definition: finiteelements/mechanics/materials/interface.hh:112
auto materialParameters() const
Returns the material parameters stored in the implemented material.
Definition: finiteelements/mechanics/materials/interface.hh:118
constexpr const MaterialImpl & impl() const
Const accessor to the underlying material (CRTP).
Definition: finiteelements/mechanics/materials/interface.hh:98
auto rebind() const
Rebind material to a different scalar type.
Definition: finiteelements/mechanics/materials/interface.hh:247
MI MaterialImpl
Type of material implementation.
Definition: finiteelements/mechanics/materials/interface.hh:83
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:217
auto tangentModuli(const Eigen::MatrixBase< Derived > &Eraw) const
Get the tangentModuli of the material.
Definition: finiteelements/mechanics/materials/interface.hh:185
auto stresses(const Eigen::MatrixBase< Derived > &Eraw) const
Get the stresses of the material.
Definition: finiteelements/mechanics/materials/interface.hh:164
auto storedEnergy(const Eigen::MatrixBase< Derived > &Eraw) const
Return the stored potential energy of the material.
Definition: finiteelements/mechanics/materials/interface.hh:140
static constexpr bool isLinear
Definition: finiteelements/mechanics/materials/interface.hh:91
constexpr MaterialImpl & impl()
Accessor to the underlying material (CRTP).
Definition: finiteelements/mechanics/materials/interface.hh:105
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:126
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:88
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:362
Several concepts.