v0.14.0
Tensor3_Expr.hpp
Go to the documentation of this file.
1 /* Declare a wrapper class for generic rank 3 Tensor expressions.
2  There isn't a Tensor3 class yet. I only use Tensor3_Expr as an
3  intermediate expression which immediately get contracted with
4  something to make a Tensor2 or Tensor1. */
5 
6 #pragma once
7 
9 #include "Tensor3_or_Tensor3.hpp"
10 #include "Tensor3_plus_Tensor3.hpp"
11 #include "Tensor3_times_Dg.hpp"
17 
18 #include "../Tensor4/Tensor4_number.hpp"
19 
20 namespace FTensor
21 {
22  template <class A, class T, int Dim0, int Dim1, int Dim2, char i, char j,
23  char k>
25  {
27 
28  public:
29  Tensor3_Expr(const A &a) : iter(a) {}
30  T operator()(const int N1, const int N2, const int N3) const
31  {
32  return iter(N1, N2, N3);
33  }
34  };
35 
36  template <class A, class T, int Tensor_Dim0, int Tensor_Dim1, int Tensor_Dim2,
37  int Dim0, int Dim1, int Dim2, char i, char j, char k>
38  class Tensor3_Expr<Tensor3<A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2>, T,
39  Dim0, Dim1, Dim2, i, j, k>
40  {
42 
43  public:
45  : iter(a)
46  {}
47  T &operator()(const int N1, const int N2, const int N3)
48  {
49  return iter(N1, N2, N3);
50  }
51  T operator()(const int N1, const int N2, const int N3) const
52  {
53  return iter(N1, N2, N3);
54  }
55 
56  /* Various assignment operators. I have to explicitly declare the
57  second operator= because otherwise the compiler will generate its
58  own and not use the template code. */
59 
60  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, char i_1,
61  char j_1, char k_1>
62  auto &
64  {
65  for(int ii = 0; ii < Dim0; ++ii)
66  for(int jj = 0; jj < Dim1; ++jj)
67  for(int kk = 0; kk < Dim2; ++kk)
68  {
69  iter(ii, jj, kk) = permute(*this, rhs, ii, jj, kk);
70  }
71  return *this;
72  }
73 
74  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, char i_1,
75  char j_1, char k_1>
76  auto &operator=(
78  {
79  return equals(rhs);
80  }
81 
82  auto &operator=(
84  Dim0, Dim1, Dim2, i, j, k> &rhs)
85  {
86  return equals(rhs);
87  }
88 
89  template <class U>
91  Dim1, Dim2, i, j, k> &
92  operator=(const U &u)
93  {
94  for(int ii = 0; ii < Dim0; ++ii)
95  for(int jj = 0; jj < Dim1; ++jj)
96  for(int kk = 0; kk < Dim2; ++kk)
97  {
98  iter(ii, jj, kk) = u;
99  }
100  return *this;
101  }
102 
103  template <class U>
105  Dim1, Dim2, i, j, k> &
106  operator*=(const U &u)
107  {
108  for(int ii = 0; ii < Dim0; ++ii)
109  for(int jj = 0; jj < Dim1; ++jj)
110  for(int kk = 0; kk < Dim2; ++kk)
111  {
112  iter(ii, jj, kk) *= u;
113  }
114  return *this;
115  }
116 
117  template <class U>
119  Dim1, Dim2, i, j, k> &
120  operator/=(const U &u)
121  {
122  for(int ii = 0; ii < Dim0; ++ii)
123  for(int jj = 0; jj < Dim1; ++jj)
124  for(int kk = 0; kk < Dim2; ++kk)
125  {
126  iter(ii, jj, kk) /= u;
127  }
128  return *this;
129  }
130 
131  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, char i_1,
132  char j_1, char k_1>
133  auto &operator+=(
135  for (int ii = 0; ii < Dim0; ++ii)
136  for (int jj = 0; jj < Dim1; ++jj)
137  for (int kk = 0; kk < Dim2; ++kk) {
138  iter(ii, jj, kk) += permute(*this, rhs, ii, jj, kk);
139  }
140  return *this;
141  }
142 
143  auto &operator+=(
145  Dim0, Dim1, Dim2, i, j, k> &rhs) {
146  for (int ii = 0; ii < Dim0; ++ii)
147  for (int jj = 0; jj < Dim1; ++jj)
148  for (int kk = 0; kk < Dim2; ++kk) {
149  iter(ii, jj, kk) += permute(*this, rhs, ii, jj, kk);
150  }
151  return *this;
152  }
153 
154  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, char i_1,
155  char j_1, char k_1>
156  auto &operator-=(
158 
159  for (int ii = 0; ii < Dim0; ++ii)
160  for (int jj = 0; jj < Dim1; ++jj)
161  for (int kk = 0; kk < Dim2; ++kk) {
162  iter(ii, jj, kk) -= permute(*this, rhs, ii, jj, kk);
163  }
164  return *this;
165  }
166 
167  auto &operator-=(
169  Dim0, Dim1, Dim2, i, j, k> &rhs) {
170  for (int ii = 0; ii < Dim0; ++ii)
171  for (int jj = 0; jj < Dim1; ++jj)
172  for (int kk = 0; kk < Dim2; ++kk) {
173  iter(ii, jj, kk) -= permute(*this, rhs, ii, jj, kk);
174  }
175  return *this;
176  }
177 
178  template <class B, class U, int Dim1_01, int Dim1_2, char i_1, char j_1,
179  char k_1>
181 
182  for (int ii = 0; ii < Dim0; ++ii)
183  for (int jj = 0; jj < Dim1; ++jj)
184  for (int kk = 0; kk < Dim2; ++kk) {
185  iter(ii, jj, kk) = permute(*this, rhs, ii, jj, kk);
186  }
187  return *this;
188  }
189 
190  template <class B, class U, int Dim1_01, int Dim1_2, char i_1, char j_1,
191  char k_1>
193 
194  for (int ii = 0; ii < Dim0; ++ii)
195  for (int jj = 0; jj < Dim1; ++jj)
196  for (int kk = 0; kk < Dim2; ++kk) {
197  iter(ii, jj, kk) += permute(*this, rhs, ii, jj, kk);
198  }
199  return *this;
200  }
201 
202  template <class B, class U, int Dim1_01, int Dim1_2, char i_1, char j_1,
203  char k_1>
205 
206  for (int ii = 0; ii < Dim0; ++ii)
207  for (int jj = 0; jj < Dim1; ++jj)
208  for (int kk = 0; kk < Dim2; ++kk) {
209  iter(ii, jj, kk) -= permute(*this, rhs, ii, jj, kk);
210  }
211  return *this;
212  }
213  };
214 
215  /* Specialized for Tensor4_number_rhs_2 */
216 
217  template <class A, class T, int Dim0, int Dim1, int Dim2, char i, char j,
218  char k, int N>
219  class Tensor3_Expr<Tensor4_number_rhs_2<A, T, N>, T, Dim0, Dim1, Dim2, i, j,
220  k> {
221  A &iter;
222 
223  public:
225  T &operator()(const int N0, const int N1, const int N2) {
226  return iter(N0, N1, N2, N);
227  }
228  T operator()(const int N0, const int N1, const int N2) const {
229  return iter(N0, N1, N2, N);
230  }
231 
232  /* Various assignment operators. I have to explicitly declare the
233  second operator= because otherwise the compiler will generate its
234  own and not use the template code. */
235 
236  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, char i_1,
237  char j_1, char k_1>
238  auto &operator=(
240  for (int ii = 0; ii < Dim0; ++ii)
241  for (int jj = 0; jj < Dim1; ++jj)
242  for (int kk = 0; kk < Dim2; ++kk) {
243  iter(ii, jj, N, kk) = permute(*this, rhs, ii, jj, kk);
244  }
245  return *this;
246  }
247 
249  Dim1, Dim2, i, j, k> &result) {
250  return operator=<Tensor4_number_rhs_2<A, T, N>, T>(result);
251  }
252 
253  };
254 
255  /* Specialized for Tensor4_number_rhs_3 */
256 
257  template <class A, class T, int Dim0, int Dim1, int Dim2, char i, char j,
258  char k, int N>
259  class Tensor3_Expr<Tensor4_number_rhs_3<A, T, N>, T, Dim0, Dim1, Dim2, i, j,
260  k> {
261  A &iter;
262 
263  public:
265  T &operator()(const int N0, const int N1, const int N2) {
266  return iter(N0, N1, N2, N);
267  }
268  T operator()(const int N0, const int N1, const int N2) const {
269  return iter(N0, N1, N2, N);
270  }
271 
272  /* Various assignment operators. I have to explicitly declare the
273  second operator= because otherwise the compiler will generate its
274  own and not use the template code. */
275 
276  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, char i_1,
277  char j_1, char k_1>
278  auto &operator=(
280 
281  for (int ii = 0; ii < Dim0; ++ii)
282  for (int jj = 0; jj < Dim1; ++jj)
283  for (int kk = 0; kk < Dim2; ++kk) {
284  iter(ii, jj, kk, N) = permute(*this, rhs, ii, jj, kk);
285  }
286  return *this;
287  }
288 
290  Dim1, Dim2, i, j, k> &result) {
291  return operator=<Tensor4_number_rhs_3<A, T, N>, T>(result);
292  }
293 
294  };
295 
296  template <class A, class T, int Dim0, int Dim1, int Dim2, char i, char j,
297  char k>
300 
301  public:
302  T operator()(const int N1, const int N2, const int N3) const
303  {
304  return -iterA(N1, N2, N3);
305  }
306 
308  : iterA(a) {}
309  };
310 
311  template <class A, class T, int Dim0, int Dim1, int Dim2, char i, char j,
312  char k>
313  Tensor3_Expr<minus_Tensor3<A, T, Dim0, Dim1, Dim2, i, j, k>, T, Dim0, Dim1,
314  Dim2, i, j, k>
318  TensorExpr(a));
319  }
320 }
FTensor::Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::iter
A & iter
Definition: Tensor3_Expr.hpp:261
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator/=
Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k > & operator/=(const U &u)
Definition: Tensor3_Expr.hpp:120
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::Tensor3_Expr::Tensor3_Expr
Tensor3_Expr(const A &a)
Definition: Tensor3_Expr.hpp:29
Tensor3_times_generic.hpp
FTensor::Tensor4_number_rhs_3
Definition: Tensor4_number.hpp:39
FTensor::Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k > &result)
Definition: Tensor3_Expr.hpp:248
FTensor::Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::iter
A & iter
Definition: Tensor3_Expr.hpp:221
FTensor::Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator()
T operator()(const int N0, const int N1, const int N2) const
Definition: Tensor3_Expr.hpp:268
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
FTensor::minus_Tensor3::minus_Tensor3
minus_Tensor3(const Tensor3_Expr< A, T, Dim0, Dim1, Dim2, i, j, k > &a)
Definition: Tensor3_Expr.hpp:307
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k > &rhs)
Definition: Tensor3_Expr.hpp:82
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::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator*=
Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k > & operator*=(const U &u)
Definition: Tensor3_Expr.hpp:106
FTensor::Tensor3_Expr::iter
A iter
Definition: Tensor3_Expr.hpp:26
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::Tensor3_Expr
Tensor3_Expr(Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 > &a)
Definition: Tensor3_Expr.hpp:44
FTensor::minus_Tensor3::operator()
T operator()(const int N1, const int N2, const int N3) const
Definition: Tensor3_Expr.hpp:302
FTensor::minus_Tensor3
Definition: Tensor3_Expr.hpp:298
FTensor::Tensor3
Definition: Tensor3_value.hpp:12
a
constexpr double a
Definition: approx_sphere.cpp:30
Tensor3_times_Tensor2_symmetric.hpp
Tensor3_times_Tensor2.hpp
FTensor::Tensor4_number_rhs_2
Definition: Tensor4_number.hpp:23
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator()
T operator()(const int N1, const int N2, const int N3) const
Definition: Tensor3_Expr.hpp:51
Tensor3_plus_Tensor3.hpp
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator+=
auto & operator+=(const Dg_Expr< B, U, Dim1_01, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:192
Tensor3_minus_Tensor3.hpp
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::iter
Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 > & iter
Definition: Tensor3_Expr.hpp:41
FTensor::Tensor3_Expr
Definition: Tensor3_Expr.hpp:24
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator-=
auto & operator-=(const Dg_Expr< B, U, Dim1_01, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:204
FTensor::Tensor3_Expr::operator()
T operator()(const int N1, const int N2, const int N3) const
Definition: Tensor3_Expr.hpp:30
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::minus_Tensor3::iterA
Tensor3_Expr< A, T, Dim0, Dim1, Dim2, i, j, k > iterA
Definition: Tensor3_Expr.hpp:299
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator()
T & operator()(const int N1, const int N2, const int N3)
Definition: Tensor3_Expr.hpp:47
N
const int N
Definition: speed_test.cpp:3
Tensor3_times_Dg.hpp
Tensor3_times_Tensor3.hpp
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k > & operator=(const U &u)
Definition: Tensor3_Expr.hpp:92
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Tensor3_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:76
FTensor::Dg_Expr
Definition: Dg_Expr.hpp:25
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator-=
auto & operator-=(const Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k > &rhs)
Definition: Tensor3_Expr.hpp:167
FTensor::Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator()
T & operator()(const int N0, const int N1, const int N2)
Definition: Tensor3_Expr.hpp:265
FTensor::operator-
Ddg_Expr< Ddg_minus_Ddg< A, B, T, U, Dim01, Dim23, i, j, k, l >, typename promote< T, U >::V, Dim01, Dim23, i, j, k, l > operator-(const Ddg_Expr< A, T, Dim01, Dim23, i, j, k, l > &a, const Ddg_Expr< B, U, Dim01, Dim23, i, j, k, l > &b)
Definition: Ddg_minus_Ddg.hpp:33
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator-=
auto & operator-=(const Tensor3_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:156
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator+=
auto & operator+=(const Tensor3_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:133
FTensor::Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::Tensor3_Expr
Tensor3_Expr(A &a)
Definition: Tensor3_Expr.hpp:224
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Dg_Expr< B, U, Dim1_01, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:180
FTensor::Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Tensor3_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:278
FTensor::Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::Tensor3_Expr
Tensor3_Expr(A &a)
Definition: Tensor3_Expr.hpp:264
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::equals
auto & equals(const Tensor3_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:63
Tensor3_times_Tensor1.hpp
FTensor::Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator()
T & operator()(const int N0, const int N1, const int N2)
Definition: Tensor3_Expr.hpp:225
FTensor::Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Tensor3_Expr< Tensor4_number_rhs_3< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k > &result)
Definition: Tensor3_Expr.hpp:289
FTensor::Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator=
auto & operator=(const Tensor3_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, i_1, j_1, k_1 > &rhs)
Definition: Tensor3_Expr.hpp:238
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
FTensor::Tensor3_Expr< Tensor4_number_rhs_2< A, T, N >, T, Dim0, Dim1, Dim2, i, j, k >::operator()
T operator()(const int N0, const int N1, const int N2) const
Definition: Tensor3_Expr.hpp:228
FTensor::Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k >::operator+=
auto & operator+=(const Tensor3_Expr< Tensor3< A, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 >, T, Dim0, Dim1, Dim2, i, j, k > &rhs)
Definition: Tensor3_Expr.hpp:143
EshelbianPlasticity::U
@ U
Definition: EshelbianContact.cpp:197
Tensor3_or_Tensor3.hpp