version 0.4.1
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#endif
28
37template <typename MAT, typename S>
38consteval bool hasCorrectSize() {
39 if constexpr (Concepts::EigenVector6<S> or Concepts::EigenMatrix33<S>)
40 return true;
41 if constexpr (MAT::isReduced and Concepts::EigenVector<S>) {
42 return S::RowsAtCompileTime == MAT::freeStrains;
43 } else
44 return false;
45}
46
53template <typename MAT, typename S>
54concept CorrectStrainSize = hasCorrectSize<MAT, S>();
55
75template <class MI>
77{
78 using MaterialImpl = MI;
79
83 static constexpr bool isReduced = traits::isSpecializationNonTypeAndTypes<VanishingStress, MaterialImpl>::value;
84
90 constexpr const MaterialImpl& impl() const { return static_cast<const MaterialImpl&>(*this); }
91
97 constexpr MaterialImpl& impl() { return static_cast<MaterialImpl&>(*this); }
98
104 [[nodiscard]] constexpr std::string name() const { return impl().nameImpl(); }
105
116 template <StrainTags tag, typename Derived>
118 [[nodiscard]] auto storedEnergy(const Eigen::MatrixBase<Derived>& Eraw) const {
119 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
120 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
121
122 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
123 if constexpr (MaterialImpl::energyAcceptsVoigt)
124 return impl().storedEnergyImpl(toVoigt(E));
125 else
126 return impl().storedEnergyImpl(E);
127 } else
128 return impl().storedEnergyImpl(E);
129 }
130
140 template <StrainTags tag, bool voigt = true, typename Derived>
142 [[nodiscard]] auto stresses(const Eigen::MatrixBase<Derived>& Eraw) const {
143 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
144 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
145 if constexpr (voigt and MaterialImpl::stressToVoigt == false)
146 // user requests a Voigt shaped return but material is not able to. Therefore, we transform it here.
147 return toVoigt(stressesMaybeTransformInputToVoigt<false>(E), false);
148 else
149 return stressesMaybeTransformInputToVoigt<voigt>(E);
150 }
151
161 template <StrainTags tag, bool voigt = true, typename Derived>
163 [[nodiscard]] auto tangentModuli(const Eigen::MatrixBase<Derived>& Eraw) const {
164 decltype(auto) Ev = enlargeIfReduced<Material>(Eraw);
165 decltype(auto) E = transformStrain<tag, MaterialImpl::strainTag>(Ev);
166 if constexpr (voigt and MaterialImpl::moduliToVoigt == false)
167 // user request a Voigt shaped return but material is not able to. Therefore, we transform it here.
168 return toVoigt(tangentModuliMaybeTransformInputToVoigt<false>(E));
169 else
170 return tangentModuliMaybeTransformInputToVoigt<voigt>(E);
171 }
172
181 template <typename STO>
182 auto rebind() const {
183 return impl().template rebind<STO>();
184 }
185
186private:
187 template <bool voigt = true, typename Derived>
188 auto stressesMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
189 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means Voigt notation
190 if constexpr (MaterialImpl::stressAcceptsVoigt)
191 return impl().template stressesImpl<voigt>(E);
192 else // material is not able to accept Voigt shaped Input. Therefore, we transform it before.
193 return impl().template stressesImpl<voigt>(fromVoigt(E.derived()));
194 } else
195 return impl().template stressesImpl<voigt>(E.derived());
196 }
197
198 template <bool voigt = true, typename Derived>
199 auto tangentModuliMaybeTransformInputToVoigt(const Eigen::MatrixBase<Derived>& E) const {
200 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means voigt notation
201 if constexpr (MaterialImpl::moduliAcceptsVoigt)
202 return impl().template tangentModuliImpl<voigt>(E);
203 else
204 return impl().template tangentModuliImpl<voigt>(fromVoigt(E.derived()));
205 } else
206 return impl().template tangentModuliImpl<voigt>(E.derived());
207 }
208};
209
210} // 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:166
Definition: simpleassemblers.hh:22
consteval bool hasCorrectSize()
Template function for checking if the strain size is correct.
Definition: interface.hh:38
Interface classf or materials.
Definition: interface.hh:77
constexpr const MaterialImpl & impl() const
Const accessor to the underlying material (CRTP).
Definition: interface.hh:90
auto tangentModuli(const Eigen::MatrixBase< Derived > &Eraw) const
Get the tangentModuli of the material.
Definition: interface.hh:163
auto rebind() const
Rebind material to a different scalar type.
Definition: interface.hh:182
MI MaterialImpl
Type of material implementation.
Definition: interface.hh:78
static constexpr bool isReduced
Static constant for determining if the material has vanishing stress components (is reduced).
Definition: interface.hh:83
constexpr std::string name() const
Get the name of the implemented material.
Definition: interface.hh:104
auto storedEnergy(const Eigen::MatrixBase< Derived > &Eraw) const
Return the stored potential energy of the material.
Definition: interface.hh:118
constexpr MaterialImpl & impl()
Accessor to the underlying material (CRTP).
Definition: interface.hh:97
auto stresses(const Eigen::MatrixBase< Derived > &Eraw) const
Get the stresses of the material.
Definition: interface.hh:142
Template concept for ensuring correct strain size.
Definition: interface.hh:54
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:353