version 0.4.1
resultevaluators.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
13#include <dune/common/math.hh>
14
15#include <Eigen/Geometry>
16
19
21
29{
37 template <typename R>
38 double operator()(const R& resultArray, [[maybe_unused]] const auto& pos, [[maybe_unused]] const auto& fe,
39 [[maybe_unused]] const int comp) const {
40 auto sigma = fromVoigt(resultArray, false);
41
42 auto I2 = 1.0 / 2.0 * (sigma.squaredNorm() - 1.0 / 3.0 * Dune::power(sigma.trace(), 2));
43 return std::sqrt(3.0 * I2);
44 }
45
50 constexpr static std::string name() { return "VonMises"; }
51
56 constexpr static int ncomps() { return 1; }
57};
58
66{
74 template <typename R>
75 double operator()(const R& resultArray, [[maybe_unused]] const auto& pos, [[maybe_unused]] const auto& fe,
76 [[maybe_unused]] const int comp) const {
77 const auto sigma = fromVoigt(resultArray, false);
78 return 1.0 / sigma.rows() * sigma.trace();
79 }
80
85 constexpr static std::string name() { return "HydrostaticStress"; }
86
91 constexpr static int ncomps() { return 1; }
92};
93
101template <int dim>
102requires(dim == 2 or dim == 3)
104{
111 double operator()(const auto& resultArray, [[maybe_unused]] const auto& pos, [[maybe_unused]] const auto& fe,
112 const int comp) const {
113 auto mat = fromVoigt(resultArray, false);
114 Eigen::SelfAdjointEigenSolver<decltype(mat)> eigensolver(mat, Eigen::EigenvaluesOnly);
115 return eigensolver.eigenvalues().reverse()[comp];
116 }
117
122 constexpr static std::string name() { return "PrincipalStress"; }
123
128 constexpr static int ncomps() { return dim; }
129};
130
138{
146 template <typename R>
147 double operator()(const R& resultArray, [[maybe_unused]] const auto& pos, [[maybe_unused]] const auto& fe,
148 [[maybe_unused]] const int comp) const {
149 auto sigeq = VonMises{}(resultArray, pos, fe, 0);
150 auto sigm = HydrostaticStress{}(resultArray, pos, fe, 0);
151 return sigm / sigeq;
152 }
157 constexpr static std::string name() { return "Triaxiality"; }
158
163 constexpr static int ncomps() { return 1; }
164};
165
172{
174 : origin_(origin) {}
175
183 template <typename R>
184 double operator()(const R& resultArray, const auto& pos, const auto& fe, const int comp) const {
185 static_assert(R::CompileTimeTraits::RowsAtCompileTime == 3, "PolarStress is only valid for 2D.");
186 if (comp > 2)
187 DUNE_THROW(Dune::RangeError, "PolarStress: Comp out of range.");
188
189 // Offset to center the coordinate system in the reference geometry
190 Dune::FieldVector<double, 2> posGlobal = fe.geometry().global(pos) - origin_;
191 auto theta = std::atan2(posGlobal[1], posGlobal[0]);
192
193 const auto sigma = fromVoigt(resultArray, false);
194 Eigen::Rotation2D<double> r(theta);
195
196 // deliberately not evaluating this that it stays an expression for below
197 auto polarStress = r.inverse() * sigma * r;
198 switch (comp) {
199 case 0:
200 return polarStress(0, 0);
201 case 1:
202 return polarStress(1, 1);
203 case 2:
204 return polarStress(1, 0);
205 default:
206 __builtin_unreachable();
207 }
208 }
209
214 constexpr static std::string name() { return "PolarStress"; }
215
220 constexpr static int ncomps() { return 3; }
221
222private:
224};
225
226} // namespace Ikarus::ResultEvaluators
Helper for the Eigen::Tensor types.
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: resultevaluators.hh:20
Struct for calculating von Mises stress.
Definition: resultevaluators.hh:29
double operator()(const R &resultArray, const auto &pos, const auto &fe, const int comp) const
Calculate the result quantity (von Mises stress)
Definition: resultevaluators.hh:38
static constexpr int ncomps()
Get the number of components in the result (always 1 for VonMises)
Definition: resultevaluators.hh:56
static constexpr std::string name()
Get the name of the result type.
Definition: resultevaluators.hh:50
Struct for calculating hydrostatic stress.
Definition: resultevaluators.hh:66
static constexpr std::string name()
Get the name of the result type.
Definition: resultevaluators.hh:85
double operator()(const R &resultArray, const auto &pos, const auto &fe, const int comp) const
Calculate the result quantity (hydrostatic stress).
Definition: resultevaluators.hh:75
static constexpr int ncomps()
Get the number of components in the result (always 1 for hydrostatic stress)
Definition: resultevaluators.hh:91
Struct for calculating principal stresses.
Definition: resultevaluators.hh:104
static constexpr std::string name()
Get the name of the result type.
Definition: resultevaluators.hh:122
static constexpr int ncomps()
Get the number of components in the result.
Definition: resultevaluators.hh:128
double operator()(const auto &resultArray, const auto &pos, const auto &fe, const int comp) const
Calculate the result quantity (principal stress)
Definition: resultevaluators.hh:111
Struct for calculating stress triaxiality.
Definition: resultevaluators.hh:138
static constexpr std::string name()
Get the name of the result type.
Definition: resultevaluators.hh:157
double operator()(const R &resultArray, const auto &pos, const auto &fe, const int comp) const
Calculate the result quantity (stress triaxiality)
Definition: resultevaluators.hh:147
static constexpr int ncomps()
Get the number of components in the result (always 1 for stress triaxiality)
Definition: resultevaluators.hh:163
Struct for calculating the 2d polar stress. The center of the coordinate system is to be passed to th...
Definition: resultevaluators.hh:172
double operator()(const R &resultArray, const auto &pos, const auto &fe, const int comp) const
Calculate the result quantity (von Mises stress)
Definition: resultevaluators.hh:184
static constexpr int ncomps()
Get the number of components in the result.
Definition: resultevaluators.hh:220
PolarStress(const Dune::FieldVector< double, 2 > &origin)
Definition: resultevaluators.hh:173
static constexpr std::string name()
Get the name of the result type.
Definition: resultevaluators.hh:214
Header file for material models in Ikarus finite element mechanics.