v0.7.24
Tensor1_Expr.hpp
Go to the documentation of this file.
1 /* Declares a wrapper class for rank 1 Tensor expressions. Note that
2  Tensor1_Expr_equals is included at the end, since it needs the
3  definition of the class in order to compile. */
4 
5 #pragma once
6 
12 #include "Tensor1_or_Tensor1.hpp"
13 #include "Tensor1_plus_Tensor1.hpp"
14 #include "Tensor1_plus_generic.hpp"
17 #include "dTensor1.hpp"
18 #include "d_one_sided_Tensor1.hpp"
19 #include "ddTensor1.hpp"
20 #include "diffusion_Tensor1.hpp"
22 #include "interpolate_Tensor1.hpp"
23 #include "minus_Tensor1.hpp"
24 
25 namespace FTensor
26 {
27  template <class A, class T, int Dim, char i> class Tensor1_Expr
28  {
29  A iter;
30 
31  public:
32  Tensor1_Expr(const A &a) : iter(a) {}
33  T operator()(const int N) const { return iter(N); }
34  };
35 
36  template <class A, class T, int Tensor_Dim, int Dim, char i>
37  class Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i>
38  {
40 
41  public:
43 
44  T &operator()(const int N) { return iter(N); }
45  T operator()(const int N) const { return iter(N); }
46 
47  /* Various assignment operators. I have to explicitly declare the
48  second operator= because otherwise the compiler will generate its
49  own and not use the template code. */
50 
51  template <class B, class U>
52  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
53  operator=(const Tensor1_Expr<B, U, Dim, i> &result);
54 
55  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
56  operator=(const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &result);
57 
58  template <class B, class U>
59  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
60  operator+=(const Tensor1_Expr<B, U, Dim, i> &result);
61 
62  template <class B, class U>
63  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
64  operator-=(const Tensor1_Expr<B, U, Dim, i> &result);
65 
66  /* General template assignment operators intended mostly for
67  doubles (type T), but could be applied to anything you want, like
68  complex, etc. All that is required is that T=B works (or T+=B,
69  etc.) */
70 
71  template <class B>
72  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
73  operator=(const B &d);
74  template <class B>
75  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
76  operator+=(const B &d);
77  template <class B>
78  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
79  operator-=(const B &d);
80  template <class B>
81  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
82  operator*=(const B &d);
83  template <class B>
84  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
85  operator/=(const B &d);
86 
87 
88  /** Assignments operators for ADOL-C
89  */
90 
91  template <class B, class U>
92  inline const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
93  operator<<=(const Tensor1_Expr<B, U, Dim, i> &result);
94 
95  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
96  operator<<=(const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &result);
97 
98  template <class B>
99  inline const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
100  operator<<=(const B &d);
101 
102  template <class B, class U>
103  inline const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
104  operator>>=(const Tensor1_Expr<B, U, Dim, i> &result);
105 
106  const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
107  operator>>=(const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &result);
108 
109  template <class B>
110  inline const Tensor1_Expr<Tensor1<A, Tensor_Dim>, T, Dim, i> &
111  operator>>=(const B &d);
112  };
113 
114  /* Specialized for Tensor2_number_rhs_0 (Tensor2{_symmetric} with the
115  first index explicitly given). */
116 
117  template <class A, class T, int Dim1, char i, int N>
118  class Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i>
119  {
120  A &iter;
121 
122  public:
123  Tensor1_Expr(A &a) : iter(a) {}
124  T &operator()(const int N1) { return iter(N, N1); }
125  T operator()(const int N1) const { return iter(N, N1); }
126 
127  /* Various assignment operators. I have to explicitly declare the
128  second operator= because otherwise the compiler will generate its
129  own and not use the template code. */
130 
131  template <class B, class U>
132  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
133  operator=(const Tensor1_Expr<B, U, Dim1, i> &result);
134 
135  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &operator=(
136  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &result);
137 
138  template <class B, class U>
139  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
140  operator+=(const Tensor1_Expr<B, U, Dim1, i> &result);
141 
142  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &operator+=(
143  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &result);
144 
145  template <class B, class U>
146  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
147  operator-=(const Tensor1_Expr<B, U, Dim1, i> &result);
148 
149  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &operator-=(
150  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &result);
151 
152  template <class B>
153  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
154  operator=(const B &result);
155 
156  template <class B>
157  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
158  operator+=(const B &result);
159 
160  template <class B>
161  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
162  operator-=(const B &result);
163 
164  template <class B>
165  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
166  operator*=(const B &result);
167 
168  template <class B>
169  const Tensor1_Expr<Tensor2_number_rhs_0<A, T, N>, T, Dim1, i> &
170  operator/=(const B &result);
171  };
172 
173  /* Specialized for Tensor2_number_rhs_1 (Tensor2{_symmetric} with the
174  second index explicitly given). */
175 
176  template <class A, class T, int Dim1, char i, int N>
177  class Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i>
178  {
179  A &iter;
180 
181  public:
182  Tensor1_Expr(A &a) : iter(a) {}
183  T &operator()(const int N1) { return iter(N1, N); }
184  T operator()(const int N1) const { return iter(N1, N); }
185 
186  /* Various assignment operators. I have to explicitly declare the
187  second operator= because otherwise the compiler will generate its
188  own and not use the template code. */
189 
190  template <class B, class U>
191  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
192  operator=(const Tensor1_Expr<B, U, Dim1, i> &result);
193 
194  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &operator=(
195  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &result);
196 
197  template <class B, class U>
198  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
199  operator+=(const Tensor1_Expr<B, U, Dim1, i> &result);
200 
201  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &operator+=(
202  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &result);
203 
204  template <class B, class U>
205  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
206  operator-=(const Tensor1_Expr<B, U, Dim1, i> &result);
207 
208  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &operator-=(
209  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &result);
210 
211  template <class B>
212  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
213  operator=(const B &result);
214 
215  template <class B>
216  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
217  operator+=(const B &result);
218 
219  template <class B>
220  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
221  operator-=(const B &result);
222 
223  template <class B>
224  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
225  operator*=(const B &result);
226 
227  template <class B>
228  const Tensor1_Expr<Tensor2_number_rhs_1<A, T, N>, T, Dim1, i> &
229  operator/=(const B &result);
230  };
231 
232  /* Specialized for Dg_number_rhs_12 (A Dg with
233  explicit numbers in the (first or second) and third slots). */
234 
235  template <class A, class T, int Dim, char i, int N1, int N2>
236  class Tensor1_Expr<Dg_number_rhs_12<A, T, N1, N2>, T, Dim, i>
237  {
238  A &iter;
239 
240  public:
241  Tensor1_Expr(A &a) : iter(a) {}
242  T &operator()(const int N) { return iter(N, N1, N2); }
243  T operator()(const int N) const { return iter(N, N1, N2); }
244 
245  /* Various assignment operators. I have to explicitly declare the
246  second operator= because otherwise the compiler will generate its
247  own and not use the template code. */
248 
249  template <class B, class U>
251  operator=(const Tensor1_Expr<B, U, Dim, i> &result);
252 
253  const Tensor1_Expr<Dg_number_rhs_12<A, T, N1, N2>, T, Dim, i> &operator=(
254  const Tensor1_Expr<Dg_number_rhs_12<A, T, N1, N2>, T, Dim, i> &result);
255  };
256 
257  /* Specialized for Dg_number_rhs_01 (A Dg with
258  explicit numbers in the first and second slots). */
259 
260  template <class A, class T, int Dim, char i, int N1, int N2>
261  class Tensor1_Expr<Dg_number_rhs_01<A, T, N1, N2>, T, Dim, i>
262  {
263  A &iter;
264 
265  public:
266  Tensor1_Expr(A &a) : iter(a) {}
267  T &operator()(const int N) { return iter(N1, N2, N); }
268  T operator()(const int N) const { return iter(N1, N2, N); }
269 
270  /* Various assignment operators. I have to explicitly declare the
271  second operator= because otherwise the compiler will generate its
272  own and not use the template code. */
273 
274  template <class B, class U>
276  operator=(const Tensor1_Expr<B, U, Dim, i> &result);
277 
278  const Tensor1_Expr<Dg_number_rhs_01<A, T, N1, N2>, T, Dim, i> &operator=(
279  const Tensor1_Expr<Dg_number_rhs_01<A, T, N1, N2>, T, Dim, i> &result);
280  };
281 }
282 
283 #include "Tensor1_Expr_equals.hpp"
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
Fully Antisymmetric Levi-Civita Tensor.
T operator()(const int N) const
const int N
Definition: speed_test.cpp:3
Tensor1_Expr(const A &a)