10#if !defined(MiniTensor_Tensor4_h)
11#define MiniTensor_Tensor4_h
25template<
typename T, Index N>
31template<
typename T, Index N = DYNAMIC>
148 Index const l)
const;
187template<
typename S,
typename T, Index N>
198template<
typename S,
typename T, Index N>
207template<
typename T, Index N>
216template<
typename T, Index N>
225template<
typename T, Index N>
236template<
typename S,
typename T, Index N>
247template<
typename S,
typename T, Index N>
258template<
typename S,
typename T, Index N>
269template<
typename S,
typename T, Index N>
277template<
typename T, Index N>
286template<
typename T, Index N>
299template<
typename T, Index N>
308template<
typename T, Index N>
321template<
typename T, Index N>
330template<
typename T, Index N>
343template<
typename T, Index N>
351template<
typename T, Index N>
361template<
typename T, Index N>
369template<
typename T, Index N>
379template<
typename T, Index N>
387template<
typename T, Index N>
397template<
typename T, Index N>
406template<
typename T, Index N>
417template<
typename S,
typename T, Index N>
428template<
typename S,
typename T, Index N>
439template<
typename S,
typename T, Index N>
450template<
typename S,
typename T, Index N>
461template<
typename S,
typename T, Index N>
472template<
typename S,
typename T, Index N>
483template<
typename S,
typename T, Index N>
494template<
typename S,
typename T, Index N>
505template<
typename S,
typename T, Index N>
516template<
typename S,
typename T, Index N>
527template<
typename S,
typename T, Index N>
538template<
typename S,
typename T, Index N>
549template<
typename S,
typename T, Index N>
560template<
typename S,
typename T, Index N>
571template<
typename S,
typename T, Index N>
582template<
typename S,
typename T, Index N>
593template<
typename S,
typename T, Index N>
604template<
typename S,
typename T, Index N>
617template<
typename S,
typename T, Index N>
628template<
typename S,
typename T, Index N>
639template<
typename T, Index N>
649template<
typename T, Index N>
661template<
typename T, Index N>
670template<
typename T, Index N>
681template<
typename T, Index N>
689template<
typename T, Index N>
700template<
typename T, Index N>
708template<
typename T, Index N>
719template<
typename T, Index N>
735second_to_fourth_dimension(
Index const dimension_2nd)
740 switch (dimension_2nd) {
764 return dimension_4th;
769template<
typename T, Index N>
774 dimension_2nd = A.get_dimension();
777 dimension_4th = second_to_fourth_dimension(dimension_2nd);
785 number_components = dimension_2nd * dimension_2nd;
787 for (
Index i = 0; i < number_components; ++i) {
796template<
typename T, Index N>
806template<
typename T, Index N>
817template<
typename T, Index N>
829template<
typename S,
typename T, Index N>
845template<
typename S,
typename T, Index N>
847Tensor4<typename Promote<S, T>::type, N>
861template<
typename T, Index N>
877template<
typename T, Index N>
888template<
typename T, Index N>
899template<
typename S,
typename T, Index N>
901typename lazy_disable_if< order_1234<S>, apply_tensor4< Promote<S,T>, N>>::type
915template<
typename S,
typename T, Index N>
917typename lazy_disable_if< order_1234<S>, apply_tensor4< Promote<S,T>, N>>::type
931template<
typename S,
typename T, Index N>
933Tensor4<typename Promote<S, T>::type, N>
947template<
typename S,
typename T, Index N>
949Tensor4<typename Promote<S, T>::type, N>
967template<
typename T, Index N>
979 return self[((i * dimension + j) * dimension + k) * dimension + l];
989template<
typename T, Index N>
1001 return self[((i * dimension + j) * dimension + k) * dimension + l];
1007template<
typename T, Index N>
1020template<
typename T, Index N>
1022void ones_in_ikjl(Tensor4<T, N> & A)
1026 dimension = A.get_dimension();
1028 for (
Index i = 0; i < dimension; ++i) {
1029 for (
Index j = 0; j < dimension; ++j) {
1030 for (
Index k = 0; k < dimension; ++k) {
1031 for (
Index l = 0; l < dimension; ++l) {
1032 if (i == k && j == l) {
1043template<
typename T, Index N>
1045void ones_in_iljk(Tensor4<T, N> & A)
1049 dimension = A.get_dimension();
1051 for (
Index i = 0; i < dimension; ++i) {
1052 for (
Index j = 0; j < dimension; ++j) {
1053 for (
Index k = 0; k < dimension; ++k) {
1054 for (
Index l = 0; l < dimension; ++l) {
1055 if (i == l && j == k) {
1066template<
typename T, Index N>
1068void ones_in_ijkl(Tensor4<T, N> & A)
1072 dimension = A.get_dimension();
1074 for (
Index i = 0; i < dimension; ++i) {
1075 for (
Index j = 0; j < dimension; ++j) {
1076 for (
Index k = 0; k < dimension; ++k) {
1077 for (
Index l = 0; l < dimension; ++l) {
1078 if (i == j && k == l) {
1089template<
typename T, Index N>
1091void fill_levi_civita(Tensor4<T, N> & A)
1094 dimension = A.get_dimension();
1096 for (
Index i = 0; i < dimension; ++i) {
1097 for (
Index j = 0; j < dimension; ++j) {
1098 for (
Index k = 0; k < dimension; ++k) {
1099 for (
Index l = 0; l < dimension; ++l) {
1100 A(i, j, k, l) = levi_civita<T>(i, j, k, l);
1115template<
typename T, Index N>
1127const Tensor4<T, DYNAMIC>
1138template<
typename T, Index N>
1143 if (N !=
DYNAMIC) assert(dimension == N);
1154template<
typename T, Index N>
1166const Tensor4<T, DYNAMIC>
1177template<
typename T, Index N>
1182 if (N !=
DYNAMIC) assert(dimension == N);
1193template<
typename T, Index N>
1205const Tensor4<T, DYNAMIC>
1216template<
typename T, Index N>
1229template<
typename T, Index N>
1237 fill_levi_civita(A);
1247Tensor4<T, DYNAMIC>
const
1253 fill_levi_civita(A);
1261template<
typename T, Index N>
1266 if (N !=
DYNAMIC) assert(dimension == N);
1271 fill_levi_civita(A);
1279template<
typename T, Index N>
1284 return levi_civita_4<T, N>();
1292Tensor4<T, DYNAMIC>
const
1295 return levi_civita_4<T>(dimension);
1301template<
typename T, Index N>
1306 return levi_civita_4<T, N>(dimension);
1312template<
typename T, Index N>
1317 return levi_civita_4<T, N>();
1325Tensor4<T, DYNAMIC>
const
1328 return levi_civita_4<T>(dimension);
1335template<
typename T, Index N>
1340 return levi_civita_4<T, N>(dimension);
1347template<
typename T, Index N>
1358 for (
Index i = 0; i < dimension; ++i) {
1359 for (
Index j = 0; j < dimension; ++j) {
1360 for (
Index k = 0; k < dimension; ++k) {
1361 for (
Index l = 0; l < dimension; ++l) {
1362 B(i, j, k, l) = A(k, l, i, j);
1377template<
typename S,
typename T, Index N>
1379Tensor3<typename Promote<S, T>::type, N>
1390 for (
Index i = 0; i < dimension; ++i) {
1391 for (
Index j = 0; j < dimension; ++j) {
1392 for (
Index k = 0; k < dimension; ++k) {
1394 typename Promote<S, T>::type
1397 for (
Index p = 0; p < dimension; ++p) {
1398 s += A(i,j,k,p) * u(p);
1414template<
typename S,
typename T, Index N>
1416Tensor3<typename Promote<S, T>::type, N>
1427 for (
Index i = 0; i < dimension; ++i) {
1428 for (
Index j = 0; j < dimension; ++j) {
1429 for (
Index k = 0; k < dimension; ++k) {
1431 typename Promote<S, T>::type
1434 for (
Index p = 0; p < dimension; ++p) {
1435 s += u(p) * A(p,i,j,k);
1451template<
typename S,
typename T, Index N>
1453Tensor3<typename Promote<S, T>::type, N>
1464 for (
Index i = 0; i < dimension; ++i) {
1465 for (
Index j = 0; j < dimension; ++j) {
1466 for (
Index k = 0; k < dimension; ++k) {
1468 typename Promote<S, T>::type
1471 for (
Index p = 0; p < dimension; ++p) {
1472 s += A(i,j,p,k) * u(p);
1488template<
typename S,
typename T, Index N>
1490Tensor3<typename Promote<S, T>::type, N>
1501 for (
Index i = 0; i < dimension; ++i) {
1502 for (
Index j = 0; j < dimension; ++j) {
1503 for (
Index k = 0; k < dimension; ++k) {
1505 typename Promote<S, T>::type
1508 for (
Index p = 0; p < dimension; ++p) {
1509 s += u(p) * A(i,p,j,k);
1522template<
typename S,
typename T, Index N>
1524Tensor<typename Promote<S, T>::type, N>
1535 for (
Index i = 0; i < dimension; ++i) {
1536 for (
Index j = 0; j < dimension; ++j) {
1538 typename Promote<S, T>::type
1541 for (
Index p = 0; p < dimension; ++p) {
1542 for (
Index q = 0; q < dimension; ++q) {
1543 s += A(i,j,p,q) * B(p,q);
1556template<
typename S,
typename T, Index N>
1558Tensor<typename Promote<S, T>::type, N>
1569 for (
Index i = 0; i < dimension; ++i) {
1570 for (
Index j = 0; j < dimension; ++j) {
1572 typename Promote<S, T>::type
1575 for (
Index p = 0; p < dimension; ++p) {
1576 for (
Index q = 0; q < dimension; ++q) {
1577 s += B(p,q) * A(p,q,i,j);
1590template<
typename S,
typename T, Index N>
1592Tensor4<typename Promote<S, T>::type, N>
1603 for (
Index i = 0; i < dimension; ++i) {
1604 for (
Index j = 0; j < dimension; ++j) {
1605 for (
Index k = 0; k < dimension; ++k) {
1606 for (
Index l = 0; l < dimension; ++l) {
1608 typename Promote<S, T>::type
1611 for (
Index p = 0; p < dimension; ++p) {
1612 for (
Index q = 0; q < dimension; ++q) {
1613 s += A(i,j,p,q) * B(p,q,k,l);
1628template<
typename S,
typename T, Index N>
1630Tensor4<typename Promote<S, T>::type, N>
1641 for (
Index i = 0; i < dimension; ++i) {
1642 for (
Index j = 0; j < dimension; ++j) {
1643 for (
Index k = 0; k < dimension; ++k) {
1644 for (
Index l = 0; l < dimension; ++l) {
1645 C(i,j,k,l) = A(i,j) * B(k,l);
1657template<
typename S,
typename T, Index N>
1659Tensor4<typename Promote<S, T>::type, N>
1670 for (
Index i = 0; i < dimension; ++i) {
1671 for (
Index j = 0; j < dimension; ++j) {
1672 for (
Index k = 0; k < dimension; ++k) {
1673 for (
Index l = 0; l < dimension; ++l) {
1674 C(i,j,k,l) = A(i,k) * B(j,l);
1686template<
typename S,
typename T, Index N>
1688Tensor4<typename Promote<S, T>::type, N>
1699 for (
Index i = 0; i < dimension; ++i) {
1700 for (
Index j = 0; j < dimension; ++j) {
1701 for (
Index k = 0; k < dimension; ++k) {
1702 for (
Index l = 0; l < dimension; ++l) {
1703 C(i,j,k,l) = A(i,l) * B(k,j);
1715template<
typename S,
typename T, Index N>
1717Tensor4<typename Promote<S, T>::type, N>
1728 for (
Index i = 0; i < dimension; ++i) {
1729 for (
Index j = 0; j < dimension; ++j) {
1730 for (
Index k = 0; k < dimension; ++k) {
1731 for (
Index l = 0; l < dimension; ++l) {
1733 typename Promote<S, T>::type
1736 for (
Index p = 0; p < dimension; ++p) {
1737 s += A(i,j,k,p) * B(p,l);
1751template<
typename S,
typename T, Index N>
1753Tensor4<typename Promote<S, T>::type, N>
1764 for (
Index i = 0; i < dimension; ++i) {
1765 for (
Index j = 0; j < dimension; ++j) {
1766 for (
Index k = 0; k < dimension; ++k) {
1767 for (
Index l = 0; l < dimension; ++l) {
1769 typename Promote<S, T>::type
1772 for (
Index p = 0; p < dimension; ++p) {
1773 s += A(i,j,k,p) * B(l,p);
1791template<
typename S,
typename T, Index N>
1793Tensor4<typename Promote<S, T>::type, N>
1804 for (
Index i = 0; i < dimension; ++i) {
1805 for (
Index j = 0; j < dimension; ++j) {
1806 for (
Index k = 0; k < dimension; ++k) {
1807 for (
Index l = 0; l < dimension; ++l) {
1809 typename Promote<S, T>::type
1812 for (
Index p = 0; p < dimension; ++p) {
1813 s += A(i,p) * B(p,j,k,l);
1827template<
typename S,
typename T, Index N>
1829Tensor4<typename Promote<S, T>::type, N>
1840 for (
Index i = 0; i < dimension; ++i) {
1841 for (
Index j = 0; j < dimension; ++j) {
1842 for (
Index k = 0; k < dimension; ++k) {
1843 for (
Index l = 0; l < dimension; ++l) {
1845 typename Promote<S, T>::type
1848 for (
Index p = 0; p < dimension; ++p) {
1849 s += A(p,i) * B(p,j,k,l);
1863template<
typename S,
typename T, Index N>
1865Tensor4<typename Promote<S, T>::type, N>
1876 for (
Index i = 0; i < dimension; ++i) {
1877 for (
Index j = 0; j < dimension; ++j) {
1878 for (
Index k = 0; k < dimension; ++k) {
1879 for (
Index l = 0; l < dimension; ++l) {
1881 typename Promote<S, T>::type
1884 for (
Index p = 0; p < dimension; ++p) {
1885 s += A(i,j,p,l) * B(p,k);
1899template<
typename S,
typename T, Index N>
1901Tensor4<typename Promote<S, T>::type, N>
1912 for (
Index i = 0; i < dimension; ++i) {
1913 for (
Index j = 0; j < dimension; ++j) {
1914 for (
Index k = 0; k < dimension; ++k) {
1915 for (
Index l = 0; l < dimension; ++l) {
1917 typename Promote<S, T>::type
1920 for (
Index p = 0; p < dimension; ++p) {
1921 s += A(i,j,p,l) * B(k,p);
1935template<
typename S,
typename T, Index N>
1937Tensor4<typename Promote<S, T>::type, N>
1948 for (
Index i = 0; i < dimension; ++i) {
1949 for (
Index j = 0; j < dimension; ++j) {
1950 for (
Index k = 0; k < dimension; ++k) {
1951 for (
Index l = 0; l < dimension; ++l) {
1953 typename Promote<S, T>::type
1956 for (
Index p = 0; p < dimension; ++p) {
1957 s += A(j,p) * B(i,p,k,l);
1971template<
typename S,
typename T, Index N>
1973Tensor4<typename Promote<S, T>::type, N>
1984 for (
Index i = 0; i < dimension; ++i) {
1985 for (
Index j = 0; j < dimension; ++j) {
1986 for (
Index k = 0; k < dimension; ++k) {
1987 for (
Index l = 0; l < dimension; ++l) {
1989 typename Promote<S, T>::type
1992 for (
Index p = 0; p < dimension; ++p) {
1993 s += A(p,j) * B(i,p,k,l);
2012template<
typename S,
typename T, Index N>
2014Tensor4<typename Promote<S, T>::type, N>
2025 for (
Index i = 0; i < dimension; ++i) {
2026 for (
Index j = 0; j < dimension; ++j) {
2027 for (
Index k = 0; k < dimension; ++k) {
2028 for (
Index l = 0; l < dimension; ++l) {
2029 C(i,j,k,l) = 0.5 * (A(i,k) * B(j,l) + A(i,l) * B(j,k));
2041template<
typename S,
typename T, Index N>
2043Tensor4<typename Promote<S, T>::type, N>
2054 for (
Index i = 0; i < dimension; ++i) {
2055 for (
Index j = 0; j < dimension; ++j) {
2056 for (
Index k = 0; k < dimension; ++k) {
2057 for (
Index l = 0; l < dimension; ++l) {
2059 typename Promote<S, T>::type
2065 for (
Index p = 0; p < dimension; ++p) {
2066 for (
Index q = 0; q < dimension; ++q) {
2067 for (
Index m = 0; m < dimension; ++m) {
2068 for (
Index n = 0; n < dimension; ++n) {
2069 s += A(p,i) * A(q,j) * A(m,k) * A(n,l) * B(p,q,m,n);
2089template<
typename T, Index N>
2096 for (
Index i = 0; i < dimension; ++i) {
2097 for (
Index j = 0; j < dimension; ++j) {
2098 for (
Index k = 0; k < dimension; ++k) {
2099 for (
Index l = 0; l < dimension; ++l) {
2115template<
typename T, Index N>
2122 if (dimension == 0) {
2126 os << std::scientific << std::setprecision(17);
2128 for (
Index i = 0; i < dimension; ++i) {
2130 for (
Index j = 0; j < dimension; ++j) {
2132 for (
Index k = 0; k < dimension; ++k) {
2134 os << std::setw(24) << A(i,j,k,0);
2136 for (
Index l = 1; l < dimension; ++l) {
2138 os <<
"," << std::setw(24) << A(i,j,k,l);
#define KOKKOS_INLINE_FUNCTION
#define MT_ERROR_EXIT(...)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > operator+(Matrix< S, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Tensor4< typename Promote< S, T >::type, N > kronecker(Tensor< S, N > const &A, Tensor4< T, N > const &B)
KOKKOS_INLINE_FUNCTION void minus(TensorBase< T, ST > const &A, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > operator-(Matrix< S, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Tensor4< T, N > const levi_civita_4()
std::ostream & operator<<(std::ostream &os, Matrix< T, M, N > const &A)
KOKKOS_INLINE_FUNCTION void add(TensorBase< R, SR > const &A, TensorBase< S, SS > const &B, TensorBase< T, ST > &C)
KOKKOS_INLINE_FUNCTION Tensor4< typename Promote< S, T >::type, N > tensor2(Tensor< S, N > const &A, Tensor< T, N > const &B)
KOKKOS_INLINE_FUNCTION Tensor4(Index const dimension, T const *data_ptr)
KOKKOS_INLINE_FUNCTION T const & operator()(Index const i, Index const j, Index const k, Index const l) const
std::istream & operator>>(std::istream &is, Matrix< T, M, N > &A)
virtual KOKKOS_INLINE_FUNCTION ~Tensor4()
KOKKOS_INLINE_FUNCTION Tensor4(T const *data_ptr)
KOKKOS_INLINE_FUNCTION Tensor4(Tensor4< T, N > const &A)
KOKKOS_INLINE_FUNCTION Tensor4(Tensor< T, dimension_square< N >::value > const &A)
KOKKOS_INLINE_FUNCTION Tensor4(Index const dimension, Filler const value)
KOKKOS_INLINE_FUNCTION Tensor4< typename Promote< S, T >::type, N > odot(Tensor< S, N > const &A, Tensor< T, N > const &B)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > operator/(Matrix< T, M, N > const &A, S const &s)
KOKKOS_INLINE_FUNCTION Vector< typename Promote< S, T >::type, M > operator*(Matrix< T, M, N > const &A, Vector< S, N > const &u)
KOKKOS_INLINE_FUNCTION Promote< S, T >::type dotdot(Matrix< S, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Tensor4< typename Promote< S, T >::type, N > tensor3(Tensor< S, N > const &A, Tensor< T, N > const &B)
KOKKOS_INLINE_FUNCTION bool equal(TensorBase< T, ST > const &A, TensorBase< T, ST > const &B)
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Index get_dimension(Index const order) const
KOKKOS_INLINE_FUNCTION void set_dimension(Index const dimension)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > dot_t(Matrix< S, M, P > const &A, Matrix< T, N, P > const &B)
KOKKOS_INLINE_FUNCTION void scale(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION bool operator!=(Matrix< T, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Tensor4()
KOKKOS_INLINE_FUNCTION Tensor4< T, N > const permutation_4()
KOKKOS_INLINE_FUNCTION Tensor4< typename Promote< S, T >::type, N > dot2_t(Tensor4< T, N > const &A, Tensor< S, N > const &B)
KOKKOS_INLINE_FUNCTION bool operator==(Matrix< T, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Vector< typename Promote< S, T >::type, M > dot(Matrix< T, M, N > const &A, Vector< S, N > const &u)
static KOKKOS_INLINE_FUNCTION constexpr Index get_order()
KOKKOS_INLINE_FUNCTION Tensor4< T, N > const alternator_4()
KOKKOS_INLINE_FUNCTION void split(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
static constexpr Index ORDER
static constexpr bool IS_DYNAMIC
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > t_dot(Matrix< S, P, M > const &A, Matrix< T, P, N > const &B)
KOKKOS_INLINE_FUNCTION Tensor< typename Promote< S, T >::type, N > tensor(Vector< S, N > const &u, Vector< T, N > const &v)
KOKKOS_INLINE_FUNCTION Tensor4< T, N > const identity_2()
KOKKOS_INLINE_FUNCTION Tensor4< T, N > const identity_3()
KOKKOS_INLINE_FUNCTION bool not_equal(TensorBase< T, ST > const &A, TensorBase< T, ST > const &B)
KOKKOS_INLINE_FUNCTION Tensor4(Filler const value)
KOKKOS_INLINE_FUNCTION Tensor4< T, N > const identity_1()
KOKKOS_INLINE_FUNCTION void set_dimension(Index const dimension, Index const order)
KOKKOS_INLINE_FUNCTION T & operator()(Index const i, Index const j, Index const k, Index const l)
KOKKOS_INLINE_FUNCTION Tensor4(Index const dimension)
KOKKOS_INLINE_FUNCTION Tensor4< typename Promote< S, T >::type, N > t_dot2(Tensor< S, N > const &A, Tensor4< T, N > const &B)
KOKKOS_INLINE_FUNCTION Matrix< T, M, N > transpose(Matrix< T, N, M > const &A)
KOKKOS_INLINE_FUNCTION void divide(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION Tensor< typename Promote< S, T >::type, N > dot2(Tensor3< T, N > const &A, Vector< S > const &u)
KOKKOS_INLINE_FUNCTION void subtract(TensorBase< R, SR > const &A, TensorBase< S, SS > const &B, TensorBase< T, ST > &C)
KOKKOS_INLINE_FUNCTION Tensor< T, N > inverse(Tensor< T, N > const &A)
uint32_t Index
Indexing type.
constexpr Index DYNAMIC
Indicator for dynamic storage.
Integer square for manipulations between 2nd and 4rd-order tensors.