GMatElastic 0.5.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 using return_type = typename GMatTensor::allocate<xt::get_rank<T>::value - 2, T>::type;
41 ret *= std::sqrt(2.0 / 3.0);
42 return ret;
43}
44
51template <class T, class U>
52inline void epseq(const T& A, U& ret)
53{
54 GMATELASTIC_ASSERT(A.dimension() >= 2);
55 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
56 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
57 GMATELASTIC_ASSERT(xt::has_shape(A, ret.shape()));
58
60 ret *= std::sqrt(2.0 / 3.0);
61}
62
73template <class T>
74inline auto Sigeq(const T& A) -> typename GMatTensor::allocate<xt::get_rank<T>::value - 2, T>::type
75{
76 GMATELASTIC_ASSERT(A.dimension() >= 2);
77 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
78 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
79
80 using return_type = typename GMatTensor::allocate<xt::get_rank<T>::value - 2, T>::type;
82 ret *= std::sqrt(1.5);
83 return ret;
84}
85
92template <class T, class U>
93inline void sigeq(const T& A, U& ret)
94{
95 GMATELASTIC_ASSERT(A.dimension() >= 2);
96 GMATELASTIC_ASSERT(A.shape(A.dimension() - 1) == 3);
97 GMATELASTIC_ASSERT(A.shape(A.dimension() - 2) == 3);
98 GMATELASTIC_ASSERT(xt::has_shape(A, ret.shape()));
99
101 ret *= std::sqrt(1.5);
102}
103
108template <size_t N>
110protected:
116
124
125public:
127
128 Elastic() = default;
129
135 template <class T>
136 Elastic(const T& K, const T& G)
137 {
138 this->init_Elastic(K, G);
139 }
140
141protected:
147 template <class T>
148 void init_Elastic(const T& K, const T& G)
149 {
150 GMATELASTIC_ASSERT(K.dimension() == N);
151 GMATELASTIC_ASSERT(xt::has_shape(K, G.shape()));
152 std::copy(K.shape().cbegin(), K.shape().cend(), m_shape.begin());
153 this->init(m_shape);
154
155 m_K = K;
156 m_G = G;
157 m_Eps = xt::zeros<double>(m_shape_tensor2);
158 m_Sig = xt::zeros<double>(m_shape_tensor2);
159 m_C = xt::empty<double>(m_shape_tensor4);
160
161#pragma omp parallel
162 {
163 auto C = xt::adapt(m_C.data(), {m_ndim, m_ndim, m_ndim, m_ndim});
164 double K;
165 double G;
168
169#pragma omp for
170 for (size_t i = 0; i < m_size; ++i) {
171 C.reset_buffer(&m_C.flat(i * m_stride_tensor4), m_stride_tensor4);
172 K = m_K.flat(i);
173 G = m_G.flat(i);
174 C = K * II + 2.0 * G * I4d;
175 }
176 }
177 }
178
179public:
185 {
186 return m_K;
187 }
188
194 {
195 return m_G;
196 }
197
204 template <class T>
205 void set_Eps(const T& arg)
206 {
207 GMATELASTIC_ASSERT(xt::has_shape(arg, m_shape_tensor2));
208 std::copy(arg.cbegin(), arg.cend(), m_Eps.begin());
209 this->refresh();
210 }
211
219 template <class T>
220 void set_Eps(const T& arg, bool compute_tangent)
221 {
222 GMATELASTIC_ASSERT(xt::has_shape(arg, m_shape_tensor2));
223 std::copy(arg.cbegin(), arg.cend(), m_Eps.begin());
224 this->refresh(compute_tangent);
225 }
226
248 virtual void refresh(bool compute_tangent = true)
249 {
250 (void)(compute_tangent);
251
252#pragma omp parallel for
253 for (size_t i = 0; i < m_size; ++i) {
254
255 double K = m_K.flat(i);
256 double G = m_G.flat(i);
257
258 const double* Eps = &m_Eps.flat(i * m_stride_tensor2);
259 double* Sig = &m_Sig.flat(i * m_stride_tensor2);
260
262
263 Sig[0] = (3.0 * K - 2.0 * G) * epsm + 2.0 * G * Eps[0];
264 Sig[1] = 2.0 * G * Eps[1];
265 Sig[2] = 2.0 * G * Eps[2];
266 Sig[3] = 2.0 * G * Eps[3];
267 Sig[4] = (3.0 * K - 2.0 * G) * epsm + 2.0 * G * Eps[4];
268 Sig[5] = 2.0 * G * Eps[5];
269 Sig[6] = 2.0 * G * Eps[6];
270 Sig[7] = 2.0 * G * Eps[7];
271 Sig[8] = (3.0 * K - 2.0 * G) * epsm + 2.0 * G * Eps[8];
272 }
273 }
274
280 {
281 return m_Eps;
282 }
283
290 {
291 return m_Eps;
292 }
293
299 {
300 return m_Sig;
301 }
302
308 {
309 return m_C;
310 }
311
317 {
318 array_type::tensor<double, N> ret = xt::empty<double>(m_shape);
320
321#pragma omp parallel for
322 for (size_t i = 0; i < m_size; ++i) {
323
324 double K = m_K.flat(i);
325 double G = m_G.flat(i);
326
327 const double* Eps = &m_Eps.flat(i * m_stride_tensor2);
328
329 std::array<double, m_stride_tensor2> Epsd;
330 double epsm = GT::Hydrostatic_deviatoric(Eps, &Epsd[0]);
331 double epsd = std::sqrt(0.5 * GT::A2s_ddot_B2s(&Epsd[0], &Epsd[0]));
332
333 double U = 3.0 * K * std::pow(epsm, 2.0);
334 double V = 2.0 * G * std::pow(epsd, 2.0);
335
336 ret.flat(i) = U + V;
337 }
338
339 return ret;
340 }
341};
342
343} // namespace Cartesian3d
344} // namespace GMatElastic
345
346#endif
Array of material points with a linear elastic constitutive response.
Definition: Cartesian3d.h:109
const array_type::tensor< double, N > & G() const
Shear modulus per item.
Definition: Cartesian3d.h:193
const array_type::tensor< double, N+2 > & Eps() const
Strain tensor per item.
Definition: Cartesian3d.h:279
const array_type::tensor< double, N > & K() const
Bulk modulus per item.
Definition: Cartesian3d.h:184
array_type::tensor< double, N+4 > m_C
Tangent per item.
Definition: Cartesian3d.h:115
void init_Elastic(const T &K, const T &G)
Construct system.
Definition: Cartesian3d.h:148
const array_type::tensor< double, N+2 > & Sig() const
Stress tensor per item.
Definition: Cartesian3d.h:298
array_type::tensor< double, N > m_G
Shear modulus per item.
Definition: Cartesian3d.h:112
virtual array_type::tensor< double, N > energy() const
Potential energy per item.
Definition: Cartesian3d.h:316
virtual void refresh(bool compute_tangent=true)
Recompute stress from strain.
Definition: Cartesian3d.h:248
array_type::tensor< double, N+2 > m_Sig
Stress tensor per item.
Definition: Cartesian3d.h:114
const array_type::tensor< double, N+4 > & C() const
Tangent tensor per item.
Definition: Cartesian3d.h:307
void set_Eps(const T &arg, bool compute_tangent)
Set strain tensors.
Definition: Cartesian3d.h:220
Elastic(const T &K, const T &G)
Construct system.
Definition: Cartesian3d.h:136
array_type::tensor< double, N > m_K
Bulk modulus per item.
Definition: Cartesian3d.h:111
void set_Eps(const T &arg)
Set strain tensors.
Definition: Cartesian3d.h:205
array_type::tensor< double, N+2 > m_Eps
Strain tensor per item.
Definition: Cartesian3d.h:113
array_type::tensor< double, N+2 > & Eps()
Strain tensor per item.
Definition: Cartesian3d.h:289
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
void sigeq(const T &A, U &ret)
Same as Sigeq(), but writes to externally allocated output.
Definition: Cartesian3d.h:93
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:52
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:74
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
#define GMATELASTIC_ASSERT(expr)
All assertions are implementation as:
Definition: config.h:32