v0.14.0
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  {
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:
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>
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>
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>
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>
154  operator=(const B &result);
155 
156  template <class B>
158  operator+=(const B &result);
159 
160  template <class B>
162  operator-=(const B &result);
163 
164  template <class B>
166  operator*=(const B &result);
167 
168  template <class B>
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:
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>
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>
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>
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>
213  operator=(const B &result);
214 
215  template <class B>
217  operator+=(const B &result);
218 
219  template <class B>
221  operator-=(const B &result);
222 
223  template <class B>
225  operator*=(const B &result);
226 
227  template <class B>
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:
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:
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"
FTensor::Tensor1_Expr< Dg_number_rhs_12< A, T, N1, N2 >, T, Dim, i >::operator()
T operator()(const int N) const
Definition: Tensor1_Expr.hpp:243
dTensor1.hpp
FTensor::Tensor1_Expr< Dg_number_rhs_12< A, T, N1, N2 >, T, Dim, i >::iter
A & iter
Definition: Tensor1_Expr.hpp:238
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
Tensor1_and_Tensor1.hpp
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
Tensor1_divide_generic.hpp
FTensor::Tensor1_Expr< Tensor1< A, Tensor_Dim >, T, Dim, i >::operator()
T operator()(const int N) const
Definition: Tensor1_Expr.hpp:45
FTensor::Tensor1_Expr::Tensor1_Expr
Tensor1_Expr(const A &a)
Definition: Tensor1_Expr.hpp:32
FTensor::Tensor2_number_rhs_1
Definition: Tensor2_number.hpp:29
FTensor::Tensor1_Expr< Tensor1< A, Tensor_Dim >, T, Dim, i >::operator()
T & operator()(const int N)
Definition: Tensor1_Expr.hpp:44
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
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
FTensor::Tensor1_Expr< Tensor2_number_rhs_0< A, T, N >, T, Dim1, i >::operator()
T & operator()(const int N1)
Definition: Tensor1_Expr.hpp:124
FTensor::Tensor1_Expr< Dg_number_rhs_01< A, T, N1, N2 >, T, Dim, i >::Tensor1_Expr
Tensor1_Expr(A &a)
Definition: Tensor1_Expr.hpp:266
Tensor1_minus_Tensor1.hpp
Tensor1_or_Tensor1.hpp
FTensor::Tensor1_Expr< Tensor1< A, Tensor_Dim >, T, Dim, i >::iter
Tensor1< A, Tensor_Dim > & iter
Definition: Tensor1_Expr.hpp:39
FTensor::Tensor1_Expr< Dg_number_rhs_01< A, T, N1, N2 >, T, Dim, i >::operator()
T operator()(const int N) const
Definition: Tensor1_Expr.hpp:268
interpolate_Tensor1.hpp
FTensor::Tensor1_Expr< Tensor2_number_rhs_0< A, T, N >, T, Dim1, i >::Tensor1_Expr
Tensor1_Expr(A &a)
Definition: Tensor1_Expr.hpp:123
Tensor1_plus_generic.hpp
Tensor1_plus_Tensor1.hpp
FTensor::Tensor1_Expr
Definition: Tensor1_Expr.hpp:27
a
constexpr double a
Definition: approx_sphere.cpp:30
FTensor::Tensor1_Expr::iter
A iter
Definition: Tensor1_Expr.hpp:29
Tensor1_Expr_equals.hpp
Tensor1_times_Tensor1.hpp
FTensor::Tensor1_Expr< Dg_number_rhs_01< A, T, N1, N2 >, T, Dim, i >::iter
A & iter
Definition: Tensor1_Expr.hpp:263
Tensor1_carat_Tensor1.hpp
FTensor::Tensor1_Expr< Tensor2_number_rhs_0< A, T, N >, T, Dim1, i >::iter
A & iter
Definition: Tensor1_Expr.hpp:120
Tensor1_minus_generic.hpp
FTensor::Tensor1_Expr< Tensor2_number_rhs_1< A, T, N >, T, Dim1, i >::operator()
T & operator()(const int N1)
Definition: Tensor1_Expr.hpp:183
generic_minus_Tensor1.hpp
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
N
const int N
Definition: speed_test.cpp:3
diffusion_Tensor1.hpp
Tensor1_times_generic.hpp
FTensor::Tensor1_Expr< Tensor2_number_rhs_0< A, T, N >, T, Dim1, i >::operator()
T operator()(const int N1) const
Definition: Tensor1_Expr.hpp:125
FTensor::Tensor1_Expr< Dg_number_rhs_12< A, T, N1, N2 >, T, Dim, i >::Tensor1_Expr
Tensor1_Expr(A &a)
Definition: Tensor1_Expr.hpp:241
FTensor::Tensor1_Expr< Tensor2_number_rhs_1< A, T, N >, T, Dim1, i >::iter
A & iter
Definition: Tensor1_Expr.hpp:179
FTensor::Tensor1_Expr< Tensor1< A, Tensor_Dim >, T, Dim, i >::Tensor1_Expr
Tensor1_Expr(Tensor1< A, Tensor_Dim > &a)
Definition: Tensor1_Expr.hpp:42
d_one_sided_Tensor1.hpp
FTensor::Dg_number_rhs_01
Definition: Dg_number.hpp:62
FTensor::Tensor2_number_rhs_0
Definition: Tensor2_number.hpp:26
FTensor::Tensor1_Expr< Dg_number_rhs_12< A, T, N1, N2 >, T, Dim, i >::operator()
T & operator()(const int N)
Definition: Tensor1_Expr.hpp:242
FTensor::Dg_number_rhs_12
Definition: Dg_number.hpp:48
FTensor::Tensor1_Expr::operator()
T operator()(const int N) const
Definition: Tensor1_Expr.hpp:33
ddTensor1.hpp
FTensor::Tensor1_Expr< Dg_number_rhs_01< A, T, N1, N2 >, T, Dim, i >::operator()
T & operator()(const int N)
Definition: Tensor1_Expr.hpp:267
FTensor::Tensor1_Expr< Tensor2_number_rhs_1< A, T, N >, T, Dim1, i >::Tensor1_Expr
Tensor1_Expr(A &a)
Definition: Tensor1_Expr.hpp:182
FTensor::Tensor1_Expr< Tensor2_number_rhs_1< A, T, N >, T, Dim1, i >::operator()
T operator()(const int N1) const
Definition: Tensor1_Expr.hpp:184
minus_Tensor1.hpp