version 0.4.1
strainconversions.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
14#pragma once
15#include "tags.hh"
16
17#include <unsupported/Eigen/MatrixFunctions>
18
19#include <Eigen/Core>
20
22
23namespace Ikarus {
24namespace Impl {
25 template <typename Derived>
26 decltype(auto) mayTransformFromVoigt(const Eigen::MatrixBase<Derived>& e, bool isStrain = true) {
27 if constexpr (Concepts::EigenVector<Derived>)
28 return fromVoigt(e.derived(), isStrain);
29 else
30 return e;
31 }
32} // namespace Impl
33
45template <StrainTags tag, typename Derived>
46auto createGreenLagrangianStrains(const Eigen::MatrixBase<Derived>& eMB) {
47 const auto& e = eMB.derived();
48 static_assert(Concepts::EigenMatrix33<Derived>);
49 if constexpr (tag == StrainTags::greenLagrangian)
50 return e;
51 else if constexpr (tag == StrainTags::deformationGradient)
52 return (0.5 * (e.transpose() * e - Derived::Identity())).eval();
53 else if constexpr (tag == StrainTags::displacementGradient)
54 return (0.5 * (e + e.transpose() + e.transpose() * e)).eval();
55 else if constexpr (tag == StrainTags::rightCauchyGreenTensor)
56 return (0.5 * (e - Derived::Identity())).eval();
57}
58
70template <StrainTags tag, typename Derived>
71decltype(auto) createDeformationGradient(const Eigen::MatrixBase<Derived>& eMB) {
72 const auto& e = eMB.derived();
73
74 static_assert(Concepts::EigenMatrix33<Derived>);
75 if constexpr (tag == StrainTags::greenLagrangian) {
76 // E = 0.5 * (F ^ 2 - I);
77 // 2*E = F ^ 2 - I;
78 // 2*E+I = F ^ 2;
79 // sqrt(2*E+I) = F;
80 return ((2 * e + Derived::Identity()).sqrt()).eval();
81 } else if constexpr (tag == StrainTags::deformationGradient)
82 return e;
83 else if constexpr (tag == StrainTags::displacementGradient)
84 return (e + Derived::Identity()).eval();
85 else if constexpr (tag == StrainTags::rightCauchyGreenTensor) {
86 return (e.sqrt()).eval(); // this looses information, since the rotation information from the original F is lost!
87 }
88}
89
101template <StrainTags tag, typename Derived>
102decltype(auto) createRightCauchyGreen(const Eigen::MatrixBase<Derived>& eMB) {
103 const auto& e = eMB.derived();
104 static_assert(Concepts::EigenMatrix33<Derived>);
105 if constexpr (tag == StrainTags::greenLagrangian) {
106 // E = 0.5 * (C - I);
107 // 2*E = C - I;
108 // 2*E+I = C;
109 return (2 * e + Derived::Identity()).eval();
110 } else if constexpr (tag == StrainTags::deformationGradient)
111 return (e.transpose() * e).eval();
112 else if constexpr (tag == StrainTags::displacementGradient) {
113 const auto F = e + Derived::Identity();
114 return (F.transpose() * F).eval();
115 } else if constexpr (tag == StrainTags::rightCauchyGreenTensor) {
116 return e;
117 }
118}
119
131template <StrainTags from, StrainTags to, typename Derived>
132decltype(auto) transformStrain(const Eigen::MatrixBase<Derived>& eRaw) {
133 static_assert((from == to) or (from != StrainTags::linear and to != StrainTags::linear),
134 "No useful transformation available for linear strains.");
135 decltype(auto) e = Impl::mayTransformFromVoigt(eRaw.eval(), true);
136 if constexpr (from == to)
137 return e;
138 else if constexpr (to == StrainTags::greenLagrangian)
139 return createGreenLagrangianStrains<from>(e);
140 else if constexpr (to == StrainTags::deformationGradient)
141 return createDeformationGradient<from>(e);
142 else if constexpr (to == StrainTags::rightCauchyGreenTensor) {
143 return createRightCauchyGreen<from>(e);
144 } else
147}
148} // namespace Ikarus
Helper for the Eigen::Tensor types.
Definition of several material related enums.
decltype(auto) createDeformationGradient(const Eigen::MatrixBase< Derived > &eMB)
Create the deformation gradient based on the input.
Definition: strainconversions.hh:71
auto createGreenLagrangianStrains(const Eigen::MatrixBase< Derived > &eMB)
Create Green-Lagrangian strain based on the input.
Definition: strainconversions.hh:46
decltype(auto) createRightCauchyGreen(const Eigen::MatrixBase< Derived > &eMB)
Create right Cauchy-Green tensor based on the input.
Definition: strainconversions.hh:102
decltype(auto) transformStrain(const Eigen::MatrixBase< Derived > &eRaw)
Transform strain from one type to another.
Definition: strainconversions.hh:132
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:271
Definition: assemblermanipulatorbuildingblocks.hh:22