7#ifndef GMATTENSOR_CARTESIAN2D_H
8#define GMATTENSOR_CARTESIAN2D_H
10#include <xtensor/xadapt.hpp>
11#include <xtensor/xnoalias.hpp>
12#include <xtensor/xrandom.hpp>
13#include <xtensor/xtensor.hpp>
14#include <xtensor/xview.hpp>
26namespace Cartesian2d {
47 std::fill(ret, ret + 4, T(0));
58 std::fill(ret, ret + 16, T(0));
83 std::fill(ret, ret + 16, T(0));
85 for (
size_t i = 0; i < 2; ++i) {
86 for (
size_t j = 0; j < 2; ++j) {
87 for (
size_t k = 0; k < 2; ++k) {
88 for (
size_t l = 0; l < 2; ++l) {
89 if (i == j && k == l) {
90 ret[i * 8 + j * 4 + k * 2 + l] = 1.0;
104inline void I4(T* ret)
106 std::fill(ret, ret + 16, T(0));
108 for (
size_t i = 0; i < 2; ++i) {
109 for (
size_t j = 0; j < 2; ++j) {
110 for (
size_t k = 0; k < 2; ++k) {
111 for (
size_t l = 0; l < 2; ++l) {
112 if (i == l && j == k) {
113 ret[i * 8 + j * 4 + k * 2 + l] = 1.0;
129 std::fill(ret, ret + 16, T(0));
131 for (
size_t i = 0; i < 2; ++i) {
132 for (
size_t j = 0; j < 2; ++j) {
133 for (
size_t k = 0; k < 2; ++k) {
134 for (
size_t l = 0; l < 2; ++l) {
135 if (i == k && j == l) {
136 ret[i * 8 + j * 4 + k * 2 + l] = 1.0;
154 std::array<double, 16> i4rt;
157 std::transform(ret, ret + 16, &i4rt[0], ret, std::plus<T>());
159 std::transform(ret, ret + 16, ret, std::bind(std::multiplies<T>(), std::placeholders::_1, 0.5));
172 std::array<double, 16> ii;
176 &ii[0], &ii[0] + 16, &ii[0], std::bind(std::multiplies<T>(), std::placeholders::_1, 0.5));
178 std::transform(ret, ret + 16, &ii[0], ret, std::minus<T>());
202 return T(0.5) *
Trace(A);
212inline void sym(
const T* A, T* ret)
215 ret[1] = 0.5 * (A[1] + A[2]);
250 return (A[0] - m) * (A[0] - m) + (A[3] - m) * (A[3] - m) + T(2) * A[1] * A[2];
275 return A[0] * B[0] + A[3] * B[3] + A[1] * B[2] + A[2] * B[1];
288 return A[0] * B[0] + A[3] * B[3] + T(2) * A[1] * B[1];
301 for (
size_t i = 0; i < 2; ++i) {
302 for (
size_t j = 0; j < 2; ++j) {
303 for (
size_t k = 0; k < 2; ++k) {
304 for (
size_t l = 0; l < 2; ++l) {
305 ret[i * 8 + j * 4 + k * 2 + l] = A[i * 2 + j] * B[k * 2 + l];
322 ret[0] = A[1] * B[2] + A[0] * B[0];
323 ret[1] = A[0] * B[1] + A[1] * B[3];
324 ret[2] = A[2] * B[0] + A[3] * B[2];
325 ret[3] = A[2] * B[1] + A[3] * B[3];
338 std::fill(ret, ret + 4, T(0));
340 for (
size_t i = 0; i < 2; i++) {
341 for (
size_t j = 0; j < 2; j++) {
342 for (
size_t k = 0; k < 2; k++) {
343 for (
size_t l = 0; l < 2; l++) {
344 ret[i * 2 + j] += A[i * 8 + j * 4 + k * 2 + l] * B[l * 2 + k];
382 return xt::zeros<double>({2, 2});
392 return xt::zeros<double>({2, 2, 2, 2});
554 return detail::impl_A2<T, 2>::ret0(A, [](
const auto& a) {
return pointer::Trace(a); });
563template <
class T,
class R>
564inline void trace(
const T& A, R& ret)
566 detail::impl_A2<T, 2>::ret0(A, ret, [](
const auto& a) {
return pointer::Trace(a); });
592template <
class T,
class R>
616 return detail::impl_A2<T, 2>::B2_ret0(
627template <
class T,
class R>
630 detail::impl_A2<T, 2>::B2_ret0(
647 return detail::impl_A2<T, 2>::B2_ret0(
658template <
class T,
class R>
661 detail::impl_A2<T, 2>::B2_ret0(
678 return detail::impl_A2<T, 2>::ret0(
688template <
class T,
class R>
708 return detail::impl_A2<T, 2>::ret2(
718template <
class T,
class R>
721 detail::impl_A2<T, 2>::ret2(
740inline auto Sym(
const T& A)
742 return detail::impl_A2<T, 2>::ret2(
743 A, [](
const auto& a,
const auto& r) {
return pointer::sym(a, r); });
752template <
class T,
class R>
753inline void sym(
const T& A, R& ret)
755 detail::impl_A2<T, 2>::ret2(
756 A, ret, [](
const auto& a,
const auto& r) {
return pointer::sym(a, r); });
777 return detail::impl_A2<T, 2>::B2_ret2(A, B, [](
const auto& a,
const auto& b,
const auto& r) {
789template <
class T,
class R>
792 detail::impl_A2<T, 2>::B2_ret2(A, B, ret, [](
const auto& a,
const auto& b,
const auto& r) {
815 return detail::impl_A2<T, 2>::B2_ret4(A, B, [](
const auto& a,
const auto& b,
const auto& r) {
827template <
class T,
class R>
830 detail::impl_A2<T, 2>::B2_ret4(A, B, ret, [](
const auto& a,
const auto& b,
const auto& r) {
850template <
class T,
class U>
853 return detail::impl_A4<T, 2>::B2_ret2(A, B, [](
const auto& a,
const auto& b,
const auto& r) {
865template <
class T,
class U,
class R>
868 detail::impl_A4<T, 2>::B2_ret2(A, B, ret, [](
const auto& a,
const auto& b,
const auto& r) {
882 return detail::impl_A2<T, 2>::toSizeT0(A.shape());
894 return detail::impl_A4<T, 2>::toSizeT0(A.shape());
906 return detail::impl_A2<T, 2>::toShapeT0(A.shape());
918 return detail::impl_A4<T, 2>::toShapeT0(A.shape());
935 constexpr static std::size_t
rank = N;
939 virtual ~Array() =
default;
956 const std::array<size_t, N>&
shape()
const
1010#pragma omp parallel for
1011 for (
size_t i = 0; i <
m_size; ++i) {
1027#pragma omp parallel for
1028 for (
size_t i = 0; i <
m_size; ++i) {
1044#pragma omp parallel for
1045 for (
size_t i = 0; i <
m_size; ++i) {
1061#pragma omp parallel for
1062 for (
size_t i = 0; i <
m_size; ++i) {
1078#pragma omp parallel for
1079 for (
size_t i = 0; i <
m_size; ++i) {
1095#pragma omp parallel for
1096 for (
size_t i = 0; i <
m_size; ++i) {
array_type::tensor< double, N+4 > I4d() const
Array of Cartesian2d::I4d()
std::array< size_t, N+4 > m_shape_tensor4
Shape of an array of 4th-order tensors == [m_shape, 2, 2, 2, 2].
Array(const std::array< size_t, N > &shape)
Constructor.
array_type::tensor< double, N+4 > O4() const
Array of Cartesian2d::O4()
const std::array< size_t, N+2 > & shape_tensor2() const
Shape of the array of second-order tensors.
static constexpr size_t m_stride_tensor2
Storage stride for 2nd-order tensors ( ).
size_t m_size
Size of the array (of scalars) == prod(m_shape).
const std::array< size_t, N+4 > & shape_tensor4() const
Shape of the array of fourth-order tensors.
array_type::tensor< double, N+4 > II() const
Array of Cartesian2d::II()
static constexpr size_t m_stride_tensor4
Storage stride for 4th-order tensors ( ).
array_type::tensor< double, N+4 > I4s() const
Array of Cartesian2d::I4s()
std::array< size_t, N+2 > m_shape_tensor2
Shape of an array of 2nd-order tensors == [m_shape, 2, 2].
static constexpr size_t m_ndim
Number of dimensions of tensors.
array_type::tensor< double, N+4 > I4() const
Array of Cartesian2d::I4()
array_type::tensor< double, N+2 > I2() const
Array of Cartesian2d::I2()
void init(const std::array< size_t, N > &shape)
Constructor 'alias'.
array_type::tensor< double, N+4 > I4rt() const
Array of Cartesian2d::I4rt()
const std::array< size_t, N > & shape() const
Shape of the array (of scalars).
std::array< size_t, N > m_shape
Shape of the array (of scalars).
static constexpr std::size_t rank
Rank of the array (the actual rank is increased with the tensor-rank).
array_type::tensor< double, N+2 > O2() const
Array of Cartesian2d::O2()
Macros used in the library.
void I4d(T *ret)
See Cartesian2d::I4d()
void I4(T *ret)
See Cartesian2d::I4()
T Deviatoric_ddot_deviatoric(const T *A)
Double tensor contraction of the tensor's deviator.
void I2(T *ret)
See Cartesian2d::I2()
T A2_ddot_B2(const T *A, const T *B)
See Cartesian2d::A2_ddot_B2()
void I4rt(T *ret)
See Cartesian2d::I4rt()
T Trace(const T *A)
See Cartesian2d::Trace()
void A4_ddot_B2(const T *A, const T *B, T *ret)
See Cartesian2d::A4_ddot_B2()
void A2_dot_B2(const T *A, const T *B, T *ret)
See Cartesian2d::A2_dot_B2()
void A2_dyadic_B2(const T *A, const T *B, T *ret)
See Cartesian2d::A2_dyadic_B2()
void I4s(T *ret)
See Cartesian2d::I4s()
T A2s_ddot_B2s(const T *A, const T *B)
See Cartesian2d::A2s_ddot_B2s()
T Norm_deviatoric(const T *A)
See Cartesian2d::Norm_deviatoric()
void sym(const T *A, T *ret)
See Cartesian2d::Sym()
void II(T *ret)
See Cartesian2d::II()
T Hydrostatic_deviatoric(const T *A, T *ret)
Returns Cartesian2d::Hydrostatic() and computes Cartesian2d::Deviatoric()
T Hydrostatic(const T *A)
See Cartesian2d::Hydrostatic()
array_type::tensor< double, 4 > Random4()
Random 4th-order tensor (for example for use in testing).
array_type::tensor< double, 2 > O2()
2nd-order null tensor (all components equal to zero).
array_type::tensor< double, 2 > I2()
2nd-order identity tensor.
auto Deviatoric(const T &A)
Deviatoric part of a tensor:
auto Norm_deviatoric(const T &A)
Norm of the tensor's deviator:
auto Hydrostatic(const T &A)
Hydrostatic part of a tensor.
void hydrostatic(const T &A, R &ret)
Same as Hydrostatic() but writes to externally allocated output.
auto Sym(const T &A)
Symmetric part of a tensor:
size_t underlying_size_A2(const T &A)
Size of the underlying array.
array_type::tensor< double, 4 > II()
Result of the dyadic product of two 2nd-order identity tensors (see I2()).
void deviatoric(const T &A, R &ret)
Same as Deviatoric() but writes to externally allocated output.
array_type::tensor< double, 4 > I4()
Fourth order unit tensor.
auto A2_ddot_B2(const T &A, const T &B)
Double tensor contraction.
void sym(const T &A, R &ret)
Same as Sym() but writes to externally allocated output.
auto A4_ddot_B2(const T &A, const U &B)
Double tensor contraction.
void norm_deviatoric(const T &A, R &ret)
Same as Norm_deviatoric() but writes to externally allocated output.
void trace(const T &A, R &ret)
Same as Trace() but writes to externally allocated output.
array_type::tensor< double, 4 > I4s()
Fourth order symmetric projection.
auto Trace(const T &A)
Trace or 2nd-order tensor.
array_type::tensor< double, 2 > Random2()
Random 2nd-order tensor (for example for use in testing).
auto A2_dot_B2(const T &A, const T &B)
Dot-product (single tensor contraction)
array_type::tensor< double, 4 > O4()
4th-order null tensor (all components equal to zero).
array_type::tensor< double, 4 > I4rt()
Right-transposed fourth order unit tensor.
array_type::tensor< double, 4 > I4d()
Fourth order deviatoric projection.
size_t underlying_size_A4(const T &A)
Size of the underlying array.
auto underlying_shape_A2(const T &A) -> std::array< size_t, detail::impl_A2< T, 2 >::rank >
Shape of the underlying array.
auto underlying_shape_A4(const T &A) -> std::array< size_t, detail::impl_A4< T, 2 >::rank >
Shape of the underlying array.
auto A2s_ddot_B2s(const T &A, const T &B)
Same as A2_ddot_B2(const T& A, const T& B, R& ret) but for symmetric tensors.
auto A2_dyadic_B2(const T &A, const T &B)
Dyadic product.
xt::xtensor< T, N > tensor
Fixed (static) rank array.
Tensor products / operations.