v0.7.2
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 
10 #include "Tensor1_or_Tensor1.hpp"
12 #include "Tensor1_and_Tensor1.hpp"
13 #include "Tensor1_plus_generic.hpp"
18 #include "minus_Tensor1.hpp"
19 #include "dTensor1.hpp"
20 #include "ddTensor1.hpp"
21 #include "d_one_sided_Tensor1.hpp"
22 #include "diffusion_Tensor1.hpp"
23 #include "interpolate_Tensor1.hpp"
24 
25 namespace FTensor
26 {
27  template<class A, class T, int Dim, char i>
29  {
30  A iter;
31  public:
32  Tensor1_Expr(A &a): iter(a) {}
33  T operator()(const int N) const
34  {
35  return iter(N);
36  }
37  };
38 
39  template<class A, class T, int Tensor_Dim, int Dim, char i>
40  class Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i>
41  {
43  public:
45 
46  T & operator()(const int N)
47  {
48  return iter(N);
49  }
50  T operator()(const int N) const
51  {
52  return iter(N);
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>
60  inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
61  operator=(const Tensor1_Expr<B,U,Dim,i> &result);
62 
63  const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
64  operator=(const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &result);
65 
66  template<class B, class U> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
67  operator+=(const Tensor1_Expr<B,U,Dim,i> &result);
68 
69  template<class B, class U> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
70  operator-=(const Tensor1_Expr<B,U,Dim,i> &result);
71 
72  /* General template assignment operators intended mostly for
73  doubles (type T), but could be applied to anything you want, like
74  complex, etc. All that is required is that T=B works (or T+=B,
75  etc.) */
76 
77  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
78  operator=(const B &d);
79  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
80  operator+=(const B &d);
81  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
82  operator-=(const B &d);
83  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
84  operator*=(const B &d);
85  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
86  operator/=(const B &d);
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  public:
122  Tensor1_Expr(A &a): iter(a) {}
123  T & operator()(const int N1)
124  {
125  return iter(N,N1);
126  }
127  T operator()(const int N1) const
128  {
129  return iter(N,N1);
130  }
131 
132  /* Various assignment operators. I have to explicitly declare the
133  second operator= because otherwise the compiler will generate its
134  own and not use the template code. */
135 
136  template<class B, class U>
138  operator=(const Tensor1_Expr<B,U,Dim1,i> &result);
139 
141  operator=(const Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i> &result);
142 
143  template<class B, class U>
145  operator+=(const Tensor1_Expr<B,U,Dim1,i> &result);
146 
148  operator+=(const Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i> &result);
149 
150  template<class B, class U>
152  operator-=(const Tensor1_Expr<B,U,Dim1,i> &result);
153 
155  operator-=(const Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i> &result);
156 
157  template<class B> inline
159  operator=(const B &result);
160 
161  template<class B> inline
163  operator+=(const B &result);
164 
165  template<class B> inline
167  operator-=(const B &result);
168 
169  template<class B> inline
171  operator*=(const B &result);
172 
173  template<class B> inline
175  operator/=(const B &result);
176  };
177 
178 
179  /* Specialized for Tensor2_number_rhs_1 (Tensor2{_symmetric} with the
180  second index explicitly given). */
181 
182  template<class A, class T, int Dim1, char i, int N>
183  class Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i>
184  {
185  A &iter;
186  public:
187  Tensor1_Expr(A &a): iter(a) {}
188  T & operator()(const int N1)
189  {
190  return iter(N1,N);
191  }
192  T operator()(const int N1) const
193  {
194  return iter(N1,N);
195  }
196 
197  /* Various assignment operators. I have to explicitly declare the
198  second operator= because otherwise the compiler will generate its
199  own and not use the template code. */
200 
201  template<class B, class U>
203  operator=(const Tensor1_Expr<B,U,Dim1,i> &result);
204 
206  operator=(const Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i> &result);
207 
208  template<class B, class U>
210  operator+=(const Tensor1_Expr<B,U,Dim1,i> &result);
211 
213  operator+=(const Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i> &result);
214 
215  template<class B, class U>
217  operator-=(const Tensor1_Expr<B,U,Dim1,i> &result);
218 
220  operator-=(const Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i> &result);
221 
222  template<class B> inline
224  operator=(const B &result);
225 
226  template<class B> inline
228  operator+=(const B &result);
229 
230  template<class B> inline
232  operator-=(const B &result);
233 
234  template<class B> inline
236  operator*=(const B &result);
237 
238  template<class B> inline
240  operator/=(const B &result);
241 
242  };
243 
244  /* Specialized for Dg_number_rhs_12 (A Dg with
245  explicit numbers in the (first or second) and third slots). */
246 
247  template<class A, class T, int Dim, char i, int N1, int N2>
248  class Tensor1_Expr<Dg_number_rhs_12<A,T,N1,N2>,T,Dim,i>
249  {
250  A &iter;
251  public:
252  Tensor1_Expr(A &a):iter(a) {}
253  T & operator()(const int N)
254  {
255  return iter(N,N1,N2);
256  }
257  T operator()(const int N) const
258  {
259  return iter(N,N1,N2);
260  }
261 
262  /* Various assignment operators. I have to explicitly declare the
263  second operator= because otherwise the compiler will generate its
264  own and not use the template code. */
265 
266  template<class B, class U>
268  operator=(const Tensor1_Expr<B,U,Dim,i> &result);
269 
271  operator=(const Tensor1_Expr<Dg_number_rhs_12<A,T,N1,N2>,T,Dim,i>
272  &result);
273  };
274 
275  /* Specialized for Dg_number_rhs_01 (A Dg with
276  explicit numbers in the first and second slots). */
277 
278  template<class A, class T, int Dim, char i, int N1, int N2>
279  class Tensor1_Expr<Dg_number_rhs_01<A,T,N1,N2>,T,Dim,i>
280  {
281  A &iter;
282  public:
283  Tensor1_Expr(A &a):iter(a) {}
284  T & operator()(const int N)
285  {
286  return iter(N1,N2,N);
287  }
288  T operator()(const int N) const
289  {
290  return iter(N1,N2,N);
291  }
292 
293  /* Various assignment operators. I have to explicitly declare the
294  second operator= because otherwise the compiler will generate its
295  own and not use the template code. */
296 
297  template<class B, class U>
299  operator=(const Tensor1_Expr<B,U,Dim,i> &result);
300 
302  operator=(const Tensor1_Expr<Dg_number_rhs_01<A,T,N1,N2>,T,Dim,i>
303  &result);
304  };
305 }
306 
307 #include "Tensor1_Expr_equals.hpp"
308 
JSON compatible output.
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:26
T operator()(const int N) const
const int N
Definition: speed_test.cpp:3