version 0.4.4
stressconversions.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2025 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
11#pragma once
12#include "tags.hh"
13
14#include <Eigen/Core>
15
18
19namespace Ikarus {
20
32template <StressTags tag, typename Derived>
33Derived createPK2Stress(const Eigen::MatrixBase<Derived>& sMB, const Eigen::MatrixBase<Derived>& F) {
34 const auto& S = sMB.derived();
35
36 static_assert(Concepts::EigenMatrix33<Derived> or Concepts::EigenMatrix22<Derived>);
37 if constexpr (tag == StressTags::Cauchy) {
38 auto J = F.determinant();
39 auto invF = F.inverse().eval();
40 return (J * invF * S * invF.transpose()).eval();
41 } else if constexpr (tag == StressTags::Kirchhoff) {
42 auto invF = F.inverse().eval();
43 return (invF * S * invF.transpose()).eval();
44 } else if constexpr (tag == StressTags::PK1)
45 return (F.inverse() * S).eval();
46 else if constexpr (tag == StressTags::PK2)
47 return S;
48}
49
61template <StressTags tag, typename Derived>
62Derived createPK1Stress(const Eigen::MatrixBase<Derived>& sMB, const Eigen::MatrixBase<Derived>& F) {
63 const auto& S = sMB.derived();
64
65 static_assert(Concepts::EigenMatrix33<Derived> or Concepts::EigenMatrix22<Derived>);
66 if constexpr (tag == StressTags::Cauchy)
67 return (F.determinant() * S * F.inverse().transpose()).eval();
68 else if constexpr (tag == StressTags::Kirchhoff)
69 return (S * F.inverse().transpose()).eval();
70 else if constexpr (tag == StressTags::PK1)
71 return S;
72 else if constexpr (tag == StressTags::PK2)
73 return (F * S).eval();
74}
75
87template <StressTags tag, typename Derived>
88Derived createKirchhoffStress(const Eigen::MatrixBase<Derived>& sMB, const Eigen::MatrixBase<Derived>& F) {
89 const auto& S = sMB.derived();
90
91 static_assert(Concepts::EigenMatrix33<Derived> or Concepts::EigenMatrix22<Derived>);
92 if constexpr (tag == StressTags::Cauchy)
93 return (F.determinant() * S).eval();
94 else if constexpr (tag == StressTags::Kirchhoff)
95 return S;
96 else if constexpr (tag == StressTags::PK1)
97 return (S * F.transpose()).eval();
98 else if constexpr (tag == StressTags::PK2)
99 return (F * S * F.transpose()).eval();
100}
101
113template <StressTags tag, typename Derived>
114Derived createCauchyStress(const Eigen::MatrixBase<Derived>& sMB, const Eigen::MatrixBase<Derived>& F) {
115 const auto& S = sMB.derived();
116 const auto invJ = 1.0 / F.determinant();
117
118 static_assert(Concepts::EigenMatrix33<Derived> or Concepts::EigenMatrix22<Derived>);
119 if constexpr (tag == StressTags::Cauchy)
120 return S;
121 else if constexpr (tag == StressTags::Kirchhoff)
122 return (invJ * S).eval();
123 else if constexpr (tag == StressTags::PK1)
124 return (invJ * S * F.transpose()).eval();
125 else if constexpr (tag == StressTags::PK2)
126 return (invJ * F * S * F.transpose()).eval();
127}
128
141template <StressTags from, StressTags to, typename DerivedS, typename DerivedF>
142auto transformStress(const Eigen::MatrixBase<DerivedS>& sRaw, const Eigen::MatrixBase<DerivedF>& F) {
143 static_assert((from == to) or (from != StressTags::linear and to != StressTags::linear),
144 "No useful transformation available for linear stresses.");
145 static_assert(Concepts::EigenMatrix33<DerivedF> or Concepts::EigenMatrix22<DerivedF>);
146
147 const auto S = Impl::maybeFromVoigt(sRaw.derived(), false);
148
149 if constexpr (from == to)
150 return S;
151 else if constexpr (to == StressTags::PK2)
152 return createPK2Stress<from>(S, F);
153 else if constexpr (to == StressTags::PK1)
154 return createPK1Stress<from>(S, F);
155 else if constexpr (to == StressTags::Kirchhoff)
156 return createKirchhoffStress<from>(S, F);
157 else if constexpr (to == StressTags::Cauchy)
158 return createCauchyStress<from>(S, F);
159 else
160 static_assert(to == StressTags::PK2 or to == StressTags::PK1 or to == StressTags::Kirchhoff or
161 to == StressTags::Cauchy);
162}
163} // namespace Ikarus
Helper for the Eigen::Tensor types.
Definition of several material related enums.
helper functions used by material model implementations.
Definition: assemblermanipulatorbuildingblocks.hh:22
auto transformStress(const Eigen::MatrixBase< DerivedS > &sRaw, const Eigen::MatrixBase< DerivedF > &F)
Transform stress measures from one type to another.
Definition: stressconversions.hh:142
Derived createPK2Stress(const Eigen::MatrixBase< Derived > &sMB, const Eigen::MatrixBase< Derived > &F)
Create PK2 stress matrix based on the input.
Definition: stressconversions.hh:33
Derived createKirchhoffStress(const Eigen::MatrixBase< Derived > &sMB, const Eigen::MatrixBase< Derived > &F)
Create Kirchhoff stress matrix based on the input.
Definition: stressconversions.hh:88
Derived createPK1Stress(const Eigen::MatrixBase< Derived > &sMB, const Eigen::MatrixBase< Derived > &F)
Create PK1 stress matrix based on the input.
Definition: stressconversions.hh:62
Derived createCauchyStress(const Eigen::MatrixBase< Derived > &sMB, const Eigen::MatrixBase< Derived > &F)
Create Cauchy stress matrix based on the input.
Definition: stressconversions.hh:114