v0.16.0
Loading...
Searching...
No Matches
EshelbianAux.hpp
Go to the documentation of this file.
1/**
2 * @file EshelbianAux.hpp
3 * @brief Auxilary functions for Eshelbian plasticity
4 * @date 2024-08-30
5 *
6 * @copyright Copyright (c) 2024
7 *
8 */
9
10#include <Lie.hpp>
11
12namespace EshelbianPlasticity {
13
14inline auto diff_deviator(FTensor::Ddg<double, 3, 3> &&t_diff_stress) {
15 FTensor::Index<'i', 3> i;
16 FTensor::Index<'j', 3> j;
17 FTensor::Index<'k', 3> k;
18 FTensor::Index<'l', 3> l;
19
20 FTensor::Ddg<double, 3, 3> t_diff_deviator;
21 t_diff_deviator(i, j, k, l) = t_diff_stress(i, j, k, l);
22
23 constexpr double third = boost::math::constants::third<double>();
24
25 t_diff_deviator(0, 0, 0, 0) -= third;
26 t_diff_deviator(0, 0, 1, 1) -= third;
27
28 t_diff_deviator(1, 1, 0, 0) -= third;
29 t_diff_deviator(1, 1, 1, 1) -= third;
30
31 t_diff_deviator(2, 2, 0, 0) -= third;
32 t_diff_deviator(2, 2, 1, 1) -= third;
33
34 t_diff_deviator(0, 0, 2, 2) -= third;
35 t_diff_deviator(1, 1, 2, 2) -= third;
36 t_diff_deviator(2, 2, 2, 2) -= third;
37
38 return t_diff_deviator;
39}
40
41constexpr static auto size_symm = (3 * (3 + 1)) / 2;
42
43inline auto diff_tensor() {
44 FTensor::Index<'i', 3> i;
45 FTensor::Index<'j', 3> j;
46 FTensor::Index<'k', 3> k;
47 FTensor::Index<'l', 3> l;
50 t_diff(i, j, k, l) = (t_kd(i, k) ^ t_kd(j, l)) / 4.;
51 return t_diff;
52};
53
54inline auto symm_L_tensor() {
55 FTensor::Index<'i', 3> i;
56 FTensor::Index<'j', 3> j;
59 t_L(i, j, L) = 0;
60 t_L(0, 0, 0) = 1;
61 t_L(1, 1, 3) = 1;
62 t_L(2, 2, 5) = 1;
63 t_L(1, 0, 1) = 1;
64 t_L(2, 0, 2) = 1;
65 t_L(2, 1, 4) = 1;
66 return t_L;
67}
68
69inline auto voigt_to_symm() {
73 t_L(L, M) = 0;
74 t_L(0, 0) = 1;
75 t_L(1, 3) = 1;
76 t_L(2, 5) = 1;
77 t_L(3, 1) = 1;
78 t_L(4, 2) = 1;
79 t_L(5, 4) = 1;
80 return t_L;
81}
82
83inline auto diff_symmetrize() {
84
89
91
92 t_diff(i, j, k, l) = 0;
93 t_diff(0, 0, 0, 0) = 1;
94 t_diff(1, 1, 1, 1) = 1;
95
96 t_diff(1, 0, 1, 0) = 0.5;
97 t_diff(1, 0, 0, 1) = 0.5;
98
99 t_diff(0, 1, 0, 1) = 0.5;
100 t_diff(0, 1, 1, 0) = 0.5;
101
102 if constexpr (SPACE_DIM == 3) {
103 t_diff(2, 2, 2, 2) = 1;
104
105 t_diff(2, 0, 2, 0) = 0.5;
106 t_diff(2, 0, 0, 2) = 0.5;
107 t_diff(0, 2, 0, 2) = 0.5;
108 t_diff(0, 2, 2, 0) = 0.5;
109
110 t_diff(2, 1, 2, 1) = 0.5;
111 t_diff(2, 1, 1, 2) = 0.5;
112 t_diff(1, 2, 1, 2) = 0.5;
113 t_diff(1, 2, 2, 1) = 0.5;
114 }
115
116 return t_diff;
117}
118
119template <class T> struct TensorTypeExtractor {
120 typedef typename std::remove_pointer<T>::type Type;
121};
122template <class T, int I> struct TensorTypeExtractor<FTensor::PackPtr<T, I>> {
123 typedef typename std::remove_pointer<T>::type Type;
124};
125
126inline bool is_eq(const double &a, const double &b) {
127 const double eps = std::sqrt(std::numeric_limits<double>::epsilon());
128 const auto abs_max = std::max(1., std::max(std::abs(a), std::abs(b)));
129 return std::abs(a - b) <= eps * abs_max;
130}
131
132template <int DIM> inline auto get_uniq_nb(double *ptr) {
133 std::array<double, DIM> tmp;
134 std::copy(ptr, ptr + DIM, tmp.begin());
135 std::sort(tmp.begin(), tmp.end());
136 return std::distance(tmp.begin(),
137 std::unique(tmp.begin(), tmp.end(), is_eq));
138}
139
140template <typename A, typename B>
141inline auto sort_eigen_vals(A &eig, B &eigen_vec) {
142
143 constexpr int dim = 3;
144
145 int i = 0, j = 1, k = 2;
146
147 if (is_eq(eig(0), eig(1))) {
148 i = 0;
149 j = 2;
150 k = 1;
151 } else if (is_eq(eig(0), eig(2))) {
152 i = 0;
153 j = 1;
154 k = 2;
155 } else if (is_eq(eig(1), eig(2))) {
156 i = 1;
157 j = 0;
158 k = 2;
159 }
160
162 eigen_vec(i, 0), eigen_vec(i, 1), eigen_vec(i, 2),
163
164 eigen_vec(j, 0), eigen_vec(j, 1), eigen_vec(j, 2),
165
166 eigen_vec(k, 0), eigen_vec(k, 1), eigen_vec(k, 2)};
167
168 auto ave = (eig(i) + eig(k)) / 2.;
169 FTensor::Tensor1<double, 3> eig_c{ave, eig(j), ave};
170
171 {
172 FTENSOR_INDEX(dim, i);
173 FTENSOR_INDEX(dim, j);
174 eig(i) = eig_c(i);
175 eigen_vec(i, j) = eigen_vec_c(i, j);
176 }
177}
178}
constexpr double third
Lie algebra implementation.
#define FTENSOR_INDEX(DIM, I)
constexpr double a
static const double eps
constexpr int SPACE_DIM
Kronecker Delta class symmetric.
constexpr auto t_kd
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
auto get_uniq_nb(double *ptr)
auto diff_deviator(FTensor::Ddg< double, 3, 3 > &&t_diff_stress)
auto sort_eigen_vals(A &eig, B &eigen_vec)
bool is_eq(const double &a, const double &b)
static constexpr auto size_symm
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51
constexpr AssemblyType A
std::remove_pointer< T >::type Type