GMatElastoPlasticQPot 0.18.3
Loading...
Searching...
No Matches
Cartesian3d.h
Go to the documentation of this file.
1
7#ifndef GMATELASTIC_CARTESIAN3D_H
8#define GMATELASTIC_CARTESIAN3D_H
9
11
12#include "config.h"
13#include "version.h"
14
15namespace GMatElastic {
16
20namespace Cartesian3d {
21
32template <class T>
33inline auto Epseq(const T& A) -> typename GMatTensor::allocate<xt::get_rank<T>::value - 2, T>::type
34{
35 GMATELASTIC_ASSERT(A.dimension() >= 2);
36 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
37 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
38
39 return xt::eval(std::sqrt(2.0 / 3.0) * GMatTensor::Cartesian3d::Norm_deviatoric(A));
40}
41
48template <class T, class U>
49inline void epseq(const T& A, U& ret)
50{
51 GMATELASTIC_ASSERT(A.dimension() >= 2);
52 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
53 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
54 GMATELASTIC_ASSERT(xt::has_shape(A, ret.shape()));
55
57 ret *= std::sqrt(2.0 / 3.0);
58}
59
70template <class T>
71inline auto Sigeq(const T& A) -> typename GMatTensor::allocate<xt::get_rank<T>::value - 2, T>::type
72{
73 GMATELASTIC_ASSERT(A.dimension() >= 2);
74 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
75 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
76
77 return xt::eval(std::sqrt(1.5) * GMatTensor::Cartesian3d::Norm_deviatoric(A));
78}
79
86template <class T, class U>
87inline void sigeq(const T& A, U& ret)
88{
89 GMATELASTIC_ASSERT(A.dimension() >= 2);
90 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
91 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
92 GMATELASTIC_ASSERT(xt::has_shape(A, ret.shape()));
93
95 ret *= std::sqrt(1.5);
96}
97
102template <size_t N>
104protected:
110
118
119public:
121
122 Elastic() = default;
123
129 template <class T>
130 Elastic(const T& K, const T& G)
131 {
132 this->init_Elastic(K, G);
133 }
134
135protected:
141 template <class T>
142 void init_Elastic(const T& K, const T& G)
143 {
144 GMATELASTIC_ASSERT(K.dimension() == N);
145 GMATELASTIC_ASSERT(xt::has_shape(K, G.shape()));
146 std::copy(K.shape().cbegin(), K.shape().cend(), m_shape.begin());
147 this->init(m_shape);
148
149 m_K = K;
150 m_G = G;
151 m_Eps = xt::zeros<double>(m_shape_tensor2);
152 m_Sig = xt::zeros<double>(m_shape_tensor2);
153 m_C = xt::empty<double>(m_shape_tensor4);
154
155#pragma omp parallel
156 {
157 auto C = xt::adapt(m_C.data(), {m_ndim, m_ndim, m_ndim, m_ndim});
158 double K;
159 double G;
162
163#pragma omp for
164 for (size_t i = 0; i < m_size; ++i) {
165 C.reset_buffer(&m_C.flat(i * m_stride_tensor4), m_stride_tensor4);
166 K = m_K.flat(i);
167 G = m_G.flat(i);
168 C = K * II + 2.0 * G * I4d;
169 }
170 }
171 }
172
173public:
179 {
180 return m_K;
181 }
182
188 {
189 return m_G;
190 }
191
198 template <class T>
199 void set_Eps(const T& arg)
200 {
201 GMATELASTIC_ASSERT(xt::has_shape(arg, m_shape_tensor2));
202 std::copy(arg.cbegin(), arg.cend(), m_Eps.begin());
203 this->refresh();
204 }
205
213 template <class T>
214 void set_Eps(const T& arg, bool compute_tangent)
215 {
216 GMATELASTIC_ASSERT(xt::has_shape(arg, m_shape_tensor2));
217 std::copy(arg.cbegin(), arg.cend(), m_Eps.begin());
218 this->refresh(compute_tangent);
219 }
220
242 virtual void refresh(bool compute_tangent = true)
243 {
244 (void)(compute_tangent);
245
246#pragma omp parallel for
247 for (size_t i = 0; i < m_size; ++i) {
248
249 double K = m_K.flat(i);
250 double G = m_G.flat(i);
251
252 const double* Eps = &m_Eps.flat(i * m_stride_tensor2);
253 double* Sig = &m_Sig.flat(i * m_stride_tensor2);
254
256
257 Sig[0] = (3.0 * K - 2.0 * G) * epsm + 2.0 * G * Eps[0];
258 Sig[1] = 2.0 * G * Eps[1];
259 Sig[2] = 2.0 * G * Eps[2];
260 Sig[3] = 2.0 * G * Eps[3];
261 Sig[4] = (3.0 * K - 2.0 * G) * epsm + 2.0 * G * Eps[4];
262 Sig[5] = 2.0 * G * Eps[5];
263 Sig[6] = 2.0 * G * Eps[6];
264 Sig[7] = 2.0 * G * Eps[7];
265 Sig[8] = (3.0 * K - 2.0 * G) * epsm + 2.0 * G * Eps[8];
266 }
267 }
268
274 {
275 return m_Eps;
276 }
277
284 {
285 return m_Eps;
286 }
287
293 {
294 return m_Sig;
295 }
296
302 {
303 return m_C;
304 }
305
311 {
312 array_type::tensor<double, N> ret = xt::empty<double>(m_shape);
314
315#pragma omp parallel for
316 for (size_t i = 0; i < m_size; ++i) {
317
318 double K = m_K.flat(i);
319 double G = m_G.flat(i);
320
321 const double* Eps = &m_Eps.flat(i * m_stride_tensor2);
322
323 std::array<double, m_stride_tensor2> Epsd;
324 double epsm = GT::Hydrostatic_deviatoric(Eps, &Epsd[0]);
325 double epsd = std::sqrt(0.5 * GT::A2s_ddot_B2s(&Epsd[0], &Epsd[0]));
326
327 double U = 3.0 * K * std::pow(epsm, 2.0);
328 double V = 2.0 * G * std::pow(epsd, 2.0);
329
330 ret.flat(i) = U + V;
331 }
332
333 return ret;
334 }
335};
336
337} // namespace Cartesian3d
338} // namespace GMatElastic
339
340#endif
Array of material points with a linear elastic constitutive response.
Definition: Cartesian3d.h:103
const array_type::tensor< double, N > & G() const
Shear modulus per item.
Definition: Cartesian3d.h:187
const array_type::tensor< double, N+2 > & Eps() const
Strain tensor per item.
Definition: Cartesian3d.h:273
const array_type::tensor< double, N > & K() const
Bulk modulus per item.
Definition: Cartesian3d.h:178
array_type::tensor< double, N+4 > m_C
Tangent per item.
Definition: Cartesian3d.h:109
void init_Elastic(const T &K, const T &G)
Construct system.
Definition: Cartesian3d.h:142
const array_type::tensor< double, N+2 > & Sig() const
Stress tensor per item.
Definition: Cartesian3d.h:292
array_type::tensor< double, N > m_G
Shear modulus per item.
Definition: Cartesian3d.h:106
virtual array_type::tensor< double, N > energy() const
Potential energy per item.
Definition: Cartesian3d.h:310
virtual void refresh(bool compute_tangent=true)
Recompute stress from strain.
Definition: Cartesian3d.h:242
array_type::tensor< double, N+2 > m_Sig
Stress tensor per item.
Definition: Cartesian3d.h:108
const array_type::tensor< double, N+4 > & C() const
Tangent tensor per item.
Definition: Cartesian3d.h:301
void set_Eps(const T &arg, bool compute_tangent)
Set strain tensors.
Definition: Cartesian3d.h:214
Elastic(const T &K, const T &G)
Construct system.
Definition: Cartesian3d.h:130
array_type::tensor< double, N > m_K
Bulk modulus per item.
Definition: Cartesian3d.h:105
void set_Eps(const T &arg)
Set strain tensors.
Definition: Cartesian3d.h:199
array_type::tensor< double, N+2 > m_Eps
Strain tensor per item.
Definition: Cartesian3d.h:107
array_type::tensor< double, N+2 > & Eps()
Strain tensor per item.
Definition: Cartesian3d.h:283
array_type::tensor< double, N+4 > I4d() const
Array of Cartesian3d::I4d()
std::array< size_t, N+4 > m_shape_tensor4
Shape of an array of 4th-order tensors == [m_shape, 3, 3, 3, 3].
Definition: Cartesian3d.h:712
static constexpr size_t m_stride_tensor4
Storage stride for 4th-order tensors ( ).
Definition: Cartesian3d.h:700
static constexpr size_t m_ndim
Number of dimensions of tensors.
Definition: Cartesian3d.h:694
std::array< size_t, N > m_shape
Shape of the array (of scalars).
Definition: Cartesian3d.h:706
array_type::tensor< double, N+4 > II() const
Array of Cartesian3d::II()
void init(const std::array< size_t, N > &shape)
Constructor 'alias'.
std::array< size_t, N+2 > m_shape_tensor2
Shape of an array of 2nd-order tensors == [m_shape, 3, 3].
Definition: Cartesian3d.h:709
static constexpr std::size_t rank
Rank of the array (the actual rank is increased with the tensor-rank).
Definition: Cartesian3d.h:597
size_t m_size
Size of the array (of scalars) == prod(m_shape).
Definition: Cartesian3d.h:703
static constexpr size_t m_stride_tensor2
Storage stride for 2nd-order tensors ( ).
Definition: Cartesian3d.h:697
#define GMATELASTIC_ASSERT(expr)
All assertions are implementation as:
Definition: config.h:32
void sigeq(const T &A, U &ret)
Same as Sigeq(), but writes to externally allocated output.
Definition: Cartesian3d.h:87
auto Epseq(const T &A) -> typename GMatTensor::allocate< xt::get_rank< T >::value - 2, T >::type
Von Mises equivalent strain: norm of strain deviator.
Definition: Cartesian3d.h:33
void epseq(const T &A, U &ret)
Same as epseq(), but writes to externally allocated output.
Definition: Cartesian3d.h:49
auto Sigeq(const T &A) -> typename GMatTensor::allocate< xt::get_rank< T >::value - 2, T >::type
Von Mises equivalent stress: norm of strain deviator.
Definition: Cartesian3d.h:71
xt::xtensor< T, N > tensor
Fixed (static) rank array.
Definition: config.h:59
Linear elastic material model.
Definition: Cartesian3d.h:15
API for individual tensors with pointer-only input.
Definition: Cartesian3d.h:724
T Hydrostatic(const T *A)
See Cartesian3d::Hydrostatic()
array_type::tensor< double, 4 > II()
Result of the dyadic product of two 2nd-order identity tensors (see I2()).
Definition: Cartesian3d.hpp:54
array_type::tensor< double, 4 > I4d()
Fourth order deviatoric projection.
Definition: Cartesian3d.hpp:82
auto Norm_deviatoric(const T &A)
Norm of the tensor's deviator:
void norm_deviatoric(const T &A, R &ret)
Same as Norm_deviatoric() but writes to externally allocated output.
Helper to allocate 'output' which is of the same type of some 'input', but of a different rank.
Definition: config.h:107