v0.14.0
Tensor4_Expr.hpp
Go to the documentation of this file.
1 /* Declare a wrapper class for generic rank 4 Tensor expressions. */
2 
3 #pragma once
4 
7 #include "Tensor4_or_Tensor4.hpp"
16 
17 #include "../permute.hpp"
18 
20 
21 namespace FTensor
22 {
23  template <class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i,
24  char j, char k, char l>
26  {
28 
29  public:
30  Tensor4_Expr(const A &a) : iter(a) {}
31  T operator()(const int N1, const int N2, const int N3, const int N4) const
32  {
33  return iter(N1, N2, N3, N4);
34  }
35  };
36 
37  template <class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i,
38  char j, char k, char l>
39  class Tensor4_Expr<Tensor4<A, Dim0, Dim1, Dim2, Dim3>, T, Dim0, Dim1, Dim2,
40  Dim3, i, j, k, l>
41  {
43 
44  public:
46  T &operator()(const int N1, const int N2, const int N3, const int N4)
47  {
48  return iter(N1, N2, N3, N4);
49  }
50  T operator()(const int N1, const int N2, const int N3, const int N4) const
51  {
52  return iter(N1, N2, N3, N4);
53  }
54 
55  /* Various assignment operators. I have to explicitly declare the
56  second operator= because otherwise the compiler will generate its
57  own and not use the template code. */
58 
59  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
60  char i_1, char j_1, char k_1, char l_1>
61  auto &equals(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1,
62  j_1, k_1, l_1> &rhs)
63  {
64  for(int ii = 0; ii < Dim0; ++ii)
65  for(int jj = 0; jj < Dim1; ++jj)
66  for(int kk = 0; kk < Dim2; ++kk)
67  for(int ll = 0; ll < Dim3; ++ll)
68  {
69  iter(ii, jj, kk, ll) = permute(*this, rhs, ii, jj, kk, ll);
70  }
71  return *this;
72  }
73 
74  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
75  char i_1, char j_1, char k_1, char l_1>
76  auto &operator=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
77  i_1, j_1, k_1, l_1> &rhs)
78  {
79  return equals(rhs);
80  }
81 
82  auto &
84  Dim1, Dim2, Dim3, i, j, k, l> &rhs)
85  {
86  return equals(rhs);
87  }
88 
89  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
90  char k_1, char l_1>
91  auto &
93  for(int ii = 0; ii != Dim01; ++ii)
94  for(int jj = 0; jj != Dim01; ++jj)
95  for(int kk = 0; kk != Dim23; ++kk)
96  for (int ll = 0; ll != Dim23; ++ll) {
97  iter(ii, jj, kk, ll) = permute(*this, rhs, ii, jj, kk, ll);
98  }
99  return *this;
100  }
101 
102  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
103  char k_1, char l_1>
104  auto &
106  return equals(rhs);
107  }
108 
109  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
110  char i_1, char j_1, char k_1, char l_1>
111  auto &operator+=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
112  i_1, j_1, k_1, l_1> &rhs)
113  {
114  for(int ii = 0; ii < Dim0; ++ii)
115  for(int jj = 0; jj < Dim1; ++jj)
116  for(int kk = 0; kk < Dim2; ++kk)
117  for(int ll = 0; ll < Dim3; ++ll)
118  {
119  iter(ii, jj, kk, ll) += permute(*this, rhs, ii, jj, kk, ll);
120  }
121  return *this;
122  }
123 
124  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
125  char i_1, char j_1, char k_1, char l_1>
126  auto &operator-=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
127  i_1, j_1, k_1, l_1> &rhs)
128  {
129  for(int ii = 0; ii < Dim0; ++ii)
130  for(int jj = 0; jj < Dim1; ++jj)
131  for(int kk = 0; kk < Dim2; ++kk)
132  for(int ll = 0; ll < Dim3; ++ll)
133  {
134  iter(ii, jj, kk, ll) += permute(*this, rhs, ii, jj, kk, ll);
135  }
136  return *this;
137  }
138 
139  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
140  char k_1, char l_1>
141  auto &
143  for (int ii = 0; ii != Dim01; ++ii)
144  for (int jj = 0; jj != Dim01; ++jj)
145  for (int kk = 0; kk != Dim23; ++kk)
146  for (int ll = 0; ll != Dim23; ++ll) {
147  iter(ii, jj, kk, ll) += rhs(ii, jj, kk, ll);
148  }
149  return *this;
150  }
151 
152  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
153  char k_1, char l_1>
154  auto &
156  for (int ii = 0; ii != Dim01; ++ii)
157  for (int jj = 0; jj != Dim01; ++jj)
158  for (int kk = 0; kk != Dim23; ++kk)
159  for (int ll = 0; ll != Dim23; ++ll) {
160  iter(ii, jj, kk, ll) -= rhs(ii, jj, kk, ll);
161  }
162  return *this;
163  }
164 
165  template <class U> auto &operator=(const U &d) {
166  for (int ii = 0; ii != Dim0; ++ii)
167  for (int jj = 0; jj != Dim1; ++jj)
168  for (int kk = 0; kk != Dim2; ++kk)
169  for (int ll = 0; ll != Dim3; ++ll)
170  iter(ii, jj, kk, ll) = d;
171  return *this;
172  }
173 
174  template <class U> auto &operator*=(const U &d) {
175  for (int ii = 0; ii != Dim0; ++ii)
176  for (int jj = 0; jj != Dim1; ++jj)
177  for (int kk = 0; kk != Dim2; ++kk)
178  for (int ll = 0; ll != Dim3; ++ll)
179  iter(ii, jj, kk, ll) *= d;
180  return *this;
181  }
182 
183  template <class U> auto &operator/=(const U &d) {
184  for (int ii = 0; ii != Dim0; ++ii)
185  for (int jj = 0; jj != Dim1; ++jj)
186  for (int kk = 0; kk != Dim2; ++kk)
187  for (int ll = 0; ll != Dim3; ++ll)
188  iter(ii, jj, kk, ll) /= d;
189  return *this;
190  }
191 
192  };
193 }
Tensor4_plus_Tensor4.hpp
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator+=
auto & operator+=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:111
FTensor::Tensor4_Expr::operator()
T operator()(const int N1, const int N2, const int N3, const int N4) const
Definition: Tensor4_Expr.hpp:31
FTensor::d
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: dTensor0.hpp:27
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::Tensor4_Expr
Tensor4_Expr(Tensor4< A, Dim0, Dim1, Dim2, Dim3 > &a)
Definition: Tensor4_Expr.hpp:45
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
FTensor::Tensor4_Expr::Tensor4_Expr
Tensor4_Expr(const A &a)
Definition: Tensor4_Expr.hpp:30
Tensor4_or_Tensor4.hpp
FTensor::permute
U permute(const Tensor2_Expr< A, T, Dim0_0, Dim0_1, i0, j0 > &, const Tensor2_Expr< B, U, Dim1_0, Dim1_1, i1, j1 > &rhs, const int N0, const int N1)
Definition: permute.hpp:11
FTensor::Ddg_Expr
Definition: Ddg_Expr.hpp:28
FTensor::Tensor4_Expr
Definition: Tensor4_Expr.hpp:25
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator()
T operator()(const int N1, const int N2, const int N3, const int N4) const
Definition: Tensor4_Expr.hpp:50
Tensor4_times_Tensor3_triple.hpp
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::equals
auto & equals(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:92
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator-=
auto & operator-=(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:155
a
constexpr double a
Definition: approx_sphere.cpp:30
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator()
T & operator()(const int N1, const int N2, const int N3, const int N4)
Definition: Tensor4_Expr.hpp:46
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator=
auto & operator=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:76
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator-=
auto & operator-=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:126
Tensor4_times_Tensor2_symmetric.hpp
Tensor4_times_Tensor2_double.hpp
Tensor4_times_Tensor3_double.hpp
FTensor::Tensor4_Expr::iter
A iter
Definition: Tensor4_Expr.hpp:27
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator+=
auto & operator+=(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:142
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator*=
auto & operator*=(const U &d)
Definition: Tensor4_Expr.hpp:174
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::equals
auto & equals(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:61
FTensor::Tensor4
Definition: Tensor4_value.hpp:18
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
Tensor4_minus_Tensor4.hpp
Tensor4_times_Tensor1.hpp
Tensor4_times_Tensor2_single.hpp
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator=
auto & operator=(const U &d)
Definition: Tensor4_Expr.hpp:165
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator=
auto & operator=(const Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l > &rhs)
Definition: Tensor4_Expr.hpp:83
Tensor4_times_generic.hpp
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::iter
Tensor4< A, Dim0, Dim1, Dim2, Dim3 > & iter
Definition: Tensor4_Expr.hpp:42
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator=
auto & operator=(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
Definition: Tensor4_Expr.hpp:105
EshelbianPlasticity::U
@ U
Definition: EshelbianContact.cpp:197
FTensor::Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l >::operator/=
auto & operator/=(const U &d)
Definition: Tensor4_Expr.hpp:183
l
FTensor::Index< 'l', 3 > l
Definition: matrix_function.cpp:21
Tensor4_times_Tensor4_double.hpp
Tensor4 times Tensor4 yields Tensor4.
Tensor4_times_Dg_double.hpp