v0.6.10
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 
8 #include "Tensor1_or_Tensor1.hpp"
10 #include "Tensor1_and_Tensor1.hpp"
11 #include "Tensor1_plus_generic.hpp"
16 #include "minus_Tensor1.hpp"
17 #include "dTensor1.hpp"
18 #include "ddTensor1.hpp"
19 #include "d_one_sided_Tensor1.hpp"
20 #include "diffusion_Tensor1.hpp"
21 #include "interpolate_Tensor1.hpp"
22 
23 template<class A, class T, int Dim, char i>
25 {
26  A iter;
27 public:
28  Tensor1_Expr(A &a): iter(a) {}
29  T operator()(const int N) const
30  {
31  return iter(N);
32  }
33 };
34 
35 template<class A, class T, int Tensor_Dim, int Dim, char i>
36 class Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i>
37 {
39 public:
41 
42  T & operator()(const int N)
43  {
44  return iter(N);
45  }
46  T operator()(const int N) const
47  {
48  return iter(N);
49  }
50 
51  /* Various assignment operators. I have to explicitly declare the
52  second operator= because otherwise the compiler will generate its
53  own and not use the template code. */
54 
55  template<class B, class U>
56  inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
57  operator=(const Tensor1_Expr<B,U,Dim,i> &result);
58 
59  const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
60  operator=(const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &result);
61 
62  template<class B, class U> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
63  operator+=(const Tensor1_Expr<B,U,Dim,i> &result);
64 
65  template<class B, class U> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
66  operator-=(const Tensor1_Expr<B,U,Dim,i> &result);
67 
68  /* General template assignment operators intended mostly for
69  doubles (type T), but could be applied to anything you want, like
70  complex, etc. All that is required is that T=B works (or T+=B,
71  etc.) */
72 
73  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
74  operator=(const B &d);
75  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
76  operator+=(const B &d);
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 
84  /** Assignments operators for ADOL-C
85  */
86 
87  template<class B, class U>
88  inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
89  operator<<=(const Tensor1_Expr<B,U,Dim,i> &result);
90 
91  const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
92  operator<<=(const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &result);
93 
94  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
95  operator<<=(const B &d);
96 
97  template<class B, class U>
98  inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
99  operator>>=(const Tensor1_Expr<B,U,Dim,i> &result);
100 
101  const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
102  operator>>=(const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &result);
103 
104  template<class B> inline const Tensor1_Expr<Tensor1<A,Tensor_Dim>,T,Dim,i> &
105  operator>>=(const B &d);
106 
107 };
108 
109 /* Specialized for Tensor2_number_rhs_0 (Tensor2{_symmetric} with the
110  first index explicitly given). */
111 
112 template<class A, class T, int Dim1, char i, int N>
113 class Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i>
114 {
115  A &iter;
116 public:
117  Tensor1_Expr(A &a): iter(a) {}
118  T & operator()(const int N1)
119  {
120  return iter(N,N1);
121  }
122  T operator()(const int N1) const
123  {
124  return iter(N,N1);
125  }
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>
133  operator=(const Tensor1_Expr<B,U,Dim1,i> &result);
134 
136  operator=(const Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i> &result);
137 
138  template<class B, class U>
140  operator+=(const Tensor1_Expr<B,U,Dim1,i> &result);
141 
143  operator+=(const Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i> &result);
144 
145  template<class B, class U>
147  operator-=(const Tensor1_Expr<B,U,Dim1,i> &result);
148 
150  operator-=(const Tensor1_Expr<Tensor2_number_rhs_0<A,T,N>,T,Dim1,i> &result);
151 
152  template<class B> inline
154  operator=(const B &result);
155 
156  template<class B> inline
158  operator+=(const B &result);
159 
160  template<class B> inline
162  operator-=(const B &result);
163 
164  template<class B> inline
166  operator*=(const B &result);
167 
168  template<class B> inline
170  operator/=(const B &result);
171 
172 };
173 
174 
175 /* Specialized for Tensor2_number_rhs_1 (Tensor2{_symmetric} with the
176  second index explicitly given). */
177 
178 template<class A, class T, int Dim1, char i, int N>
179 class Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i>
180 {
181  A &iter;
182 public:
183  Tensor1_Expr(A &a): iter(a) {}
184  T & operator()(const int N1)
185  {
186  return iter(N1,N);
187  }
188  T operator()(const int N1) const
189  {
190  return iter(N1,N);
191  }
192 
193  /* Various assignment operators. I have to explicitly declare the
194  second operator= because otherwise the compiler will generate its
195  own and not use the template code. */
196 
197  template<class B, class U>
199  operator=(const Tensor1_Expr<B,U,Dim1,i> &result);
200 
202  operator=(const Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i> &result);
203 
204  template<class B, class U>
206  operator+=(const Tensor1_Expr<B,U,Dim1,i> &result);
207 
209  operator+=(const Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i> &result);
210 
211  template<class B, class U>
213  operator-=(const Tensor1_Expr<B,U,Dim1,i> &result);
214 
216  operator-=(const Tensor1_Expr<Tensor2_number_rhs_1<A,T,N>,T,Dim1,i> &result);
217 
218  template<class B> inline
220  operator=(const B &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 };
239 
240 /* Specialized for Tensor3_dg_number_rhs_12 (A Tensor3_dg with
241  explicit numbers in the (first or second) and third slots). */
242 
243 template<class A, class T, int Dim, char i, int N1, int N2>
244 class Tensor1_Expr<Tensor3_dg_number_rhs_12<A,T,N1,N2>,T,Dim,i>
245 {
246  A &iter;
247 public:
248  Tensor1_Expr(A &a):iter(a) {}
249  T & operator()(const int N)
250  {
251  return iter(N,N1,N2);
252  }
253  T operator()(const int N) const
254  {
255  return iter(N,N1,N2);
256  }
257 
258  /* Various assignment operators. I have to explicitly declare the
259  second operator= because otherwise the compiler will generate its
260  own and not use the template code. */
261 
262  template<class B, class U>
264  operator=(const Tensor1_Expr<B,U,Dim,i> &result);
265 
268  &result);
269 };
270 
271 /* Specialized for Tensor3_dg_number_rhs_01 (A Tensor3_dg with
272  explicit numbers in the first and second slots). */
273 
274 template<class A, class T, int Dim, char i, int N1, int N2>
275 class Tensor1_Expr<Tensor3_dg_number_rhs_01<A,T,N1,N2>,T,Dim,i>
276 {
277  A &iter;
278 public:
279  Tensor1_Expr(A &a):iter(a) {}
280  T & operator()(const int N)
281  {
282  return iter(N1,N2,N);
283  }
284  T operator()(const int N) const
285  {
286  return iter(N1,N2,N);
287  }
288 
289  /* Various assignment operators. I have to explicitly declare the
290  second operator= because otherwise the compiler will generate its
291  own and not use the template code. */
292 
293  template<class B, class U>
295  operator=(const Tensor1_Expr<B,U,Dim,i> &result);
296 
299  &result);
300 };
301 
302 #include "Tensor1_Expr_equals.hpp"
T operator()(const int N) const
const A operator=(const Tensor1_Expr< Tensor1, 'i'> &result)
Definition: single.cpp:27
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:22
Tensor1_Expr(A &a)
const int N
Definition: speed_test.cpp:3