version 0.4.1
neohooke.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
14
15namespace Ikarus {
16
35template <typename ST>
36struct NeoHookeT : public Material<NeoHookeT<ST>>
37{
38 using ScalarType = ST;
39 static constexpr int worldDimension = 3;
40 using StrainMatrix = Eigen::Matrix<ScalarType, worldDimension, worldDimension>;
43
45 static constexpr auto stressTag = StressTags::PK2;
47 static constexpr bool energyAcceptsVoigt = false;
48 static constexpr bool stressToVoigt = false;
49 static constexpr bool stressAcceptsVoigt = false;
50 static constexpr bool moduliToVoigt = false;
51 static constexpr bool moduliAcceptsVoigt = false;
52 static constexpr double derivativeFactorImpl = 2;
53
54 [[nodiscard]] constexpr static std::string nameImpl() noexcept { return "NeoHooke"; }
55
60 explicit NeoHookeT(const MaterialParameters& mpt)
61 : materialParameter_{mpt} {}
62
66 MaterialParameters materialParametersImpl() const { return materialParameter_; }
67
74 template <typename Derived>
75 ScalarType storedEnergyImpl(const Eigen::MatrixBase<Derived>& C) const {
76 static_assert(Concepts::EigenMatrixOrVoigtNotation3<Derived>);
77 if constexpr (!Concepts::EigenVector<Derived>) {
78 const auto traceC = C.trace();
79 const auto detC = C.determinant();
80 checkPositiveDetC(detC);
81 const auto logdetF = log(sqrt(detC));
82 return materialParameter_.mu / 2.0 * (traceC - 3 - 2 * logdetF) +
83 materialParameter_.lambda / 2.0 * logdetF * logdetF;
84 } else
85 static_assert(!Concepts::EigenVector<Derived>,
86 "NeoHooke energy can only be called with a matrix and not a vector in Voigt notation");
87 }
88
96 template <bool voigt, typename Derived>
97 auto stressesImpl(const Eigen::MatrixBase<Derived>& C) const {
98 static_assert(Concepts::EigenMatrixOrVoigtNotation3<Derived>);
99 if constexpr (!voigt) {
100 if constexpr (!Concepts::EigenVector<Derived>) {
101 const auto detC = C.determinant();
102 checkPositiveDetC(detC);
103 const auto logdetF = log(sqrt(detC));
104 const auto invC = C.inverse().eval();
105 return (materialParameter_.mu * (StrainMatrix::Identity() - invC) + materialParameter_.lambda * logdetF * invC)
106 .eval();
107 } else
108 static_assert(!Concepts::EigenVector<Derived>,
109 "NeoHooke can only be called with a matrix and not a vector in Voigt notation");
110 } else
111 static_assert(voigt == false, "NeoHooke does not support returning stresses in Voigt notation");
112 }
113
121 template <bool voigt, typename Derived>
122 auto tangentModuliImpl(const Eigen::MatrixBase<Derived>& C) const {
123 static_assert(Concepts::EigenMatrixOrVoigtNotation3<Derived>);
124 if constexpr (!voigt) {
125 const auto invC = C.inverse().eval();
126 const auto detC = C.determinant();
127 checkPositiveDetC(detC);
128 const auto logdetF = log(sqrt(detC));
129 const auto CTinv = tensorView(invC, std::array<Eigen::Index, 2>({3, 3}));
130 static_assert(Eigen::TensorFixedSize<ScalarType, Eigen::Sizes<3, 3>>::NumIndices == 2);
131 Eigen::TensorFixedSize<ScalarType, Eigen::Sizes<3, 3, 3, 3>> moduli =
132 (materialParameter_.lambda * dyadic(CTinv, CTinv) +
133 2 * (materialParameter_.mu - materialParameter_.lambda * logdetF) *
134 symTwoSlots(fourthOrderIKJL(invC, invC), {2, 3}))
135 .eval();
136 return moduli;
137 } else
138 static_assert(voigt == false, "NeoHooke does not support returning tangent moduli in Voigt notation");
139 }
140
146 template <typename STO>
147 auto rebind() const {
148 return NeoHookeT<STO>(materialParameter_);
149 }
150
151private:
152 MaterialParameters materialParameter_;
153
154 void checkPositiveDetC(ScalarType detC) const {
155 if (Dune::FloatCmp::le(static_cast<double>(detC), 0.0, 1e-10))
156 DUNE_THROW(Dune::InvalidStateException,
157 "Determinant of right Cauchy Green tensor C must be greater than zero. detC = " +
158 std::to_string(static_cast<double>(detC)));
159 }
160};
161
166
167} // namespace Ikarus
Helper for the Eigen::Tensor types.
Eigen::Tensor< typename Derived::Scalar, rank > tensorView(const Eigen::EigenBase< Derived > &matrix, const std::array< T, rank > &dims)
View an Eigen matrix as an Eigen Tensor with specified dimensions.
Definition: tensorutils.hh:32
auto fourthOrderIKJL(const Eigen::MatrixBase< AType > &A, const Eigen::MatrixBase< BType > &B)
Computes the IKJL product of two matrices.
Definition: tensorutils.hh:122
auto dyadic(const auto &A_ij, const auto &B_kl)
Computes the dyadic product of two Eigen tensors.
Definition: tensorutils.hh:47
auto symTwoSlots(const Eigen::TensorFixedSize< ScalarType, Eigen::Sizes< dim, dim, dim, dim > > &t, const std::array< size_t, 2 > &slots)
Creates a symmetric fourth-order tensor in the two specified slots of the input tensor.
Definition: tensorutils.hh:145
Definition: assemblermanipulatorbuildingblocks.hh:22
Interface classf or materials.
Definition: finiteelements/mechanics/materials/interface.hh:80
Implementation of the Neo-Hookean material model.The energy is computed as.
Definition: neohooke.hh:37
static constexpr bool energyAcceptsVoigt
Definition: neohooke.hh:47
Eigen::Matrix< ScalarType, worldDimension, worldDimension > StrainMatrix
Definition: neohooke.hh:40
LamesFirstParameterAndShearModulus MaterialParameters
Definition: neohooke.hh:42
StrainMatrix StressMatrix
Definition: neohooke.hh:41
auto tangentModuliImpl(const Eigen::MatrixBase< Derived > &C) const
Computes the tangent moduli in the Neo-Hookean material model.
Definition: neohooke.hh:122
ScalarType storedEnergyImpl(const Eigen::MatrixBase< Derived > &C) const
Computes the stored energy in the Neo-Hookean material model.
Definition: neohooke.hh:75
static constexpr auto strainTag
Definition: neohooke.hh:44
static constexpr auto tangentModuliTag
Definition: neohooke.hh:46
static constexpr bool stressToVoigt
Definition: neohooke.hh:48
MaterialParameters materialParametersImpl() const
Returns the material parameters stored in the material.
Definition: neohooke.hh:66
static constexpr int worldDimension
Definition: neohooke.hh:39
static constexpr auto stressTag
Definition: neohooke.hh:45
static constexpr bool moduliAcceptsVoigt
Definition: neohooke.hh:51
auto rebind() const
Rebinds the material to a different scalar type.
Definition: neohooke.hh:147
static constexpr std::string nameImpl() noexcept
Definition: neohooke.hh:54
static constexpr double derivativeFactorImpl
Definition: neohooke.hh:52
static constexpr bool stressAcceptsVoigt
Definition: neohooke.hh:49
ST ScalarType
Definition: neohooke.hh:38
NeoHookeT(const MaterialParameters &mpt)
Constructor for NeoHookeT.
Definition: neohooke.hh:60
static constexpr bool moduliToVoigt
Definition: neohooke.hh:50
auto stressesImpl(const Eigen::MatrixBase< Derived > &C) const
Computes the stresses in the Neo-Hookean material model.
Definition: neohooke.hh:97
Definition: physicshelper.hh:54
double lambda
Definition: physicshelper.hh:55
double mu
Definition: physicshelper.hh:56
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:355
Contains the Material interface class and related template functions for material properties.