v0.8.4
Tensor0.hpp
Go to the documentation of this file.
1 /* A Tensor0 class that really just ends up being an alias for a
2  pointer to a templated type T. Note that the T * is mutable, so the
3  pointer can change, allowing iterating over a array. Also note
4  that diffusion and interpolate are included at the end of this
5  file, because it needs the full definition of Tensor0. */
6 
7 #pragma once
8 
9 #include "Tensor0/dTensor0.hpp"
11 #include "Tensor0/ddTensor0.hpp"
13 
14 namespace FTensor
15 {
16  template <class T> class Tensor0
17  {};
18 
19  template <class T, int I> class Tensor0<PackPtr<T *, I>>
20  {
21  mutable T *restrict data;
22 
23  public:
24  Tensor0(T *d) : data(d) {}
25 
26  const Tensor0 &operator=(const Tensor0 &a)
27  {
28  *data = *(a.data);
29  return *this;
30  }
31 
32  template <class U> const Tensor0<PackPtr<T *, I>> &operator=(const U &d)
33  {
34  *data = d;
35  return *this;
36  }
37  template <class U> const Tensor0<PackPtr<T *, I>> &operator+=(const U &d)
38  {
39  *data += d;
40  return *this;
41  }
42  template <class U> const Tensor0<PackPtr<T *, I>> &operator-=(const U &d)
43  {
44  *data -= d;
45  return *this;
46  }
47  template <class U> const Tensor0<PackPtr<T *, I>> &operator*=(const U &d)
48  {
49  *data *= d;
50  return *this;
51  }
52  template <class U> const Tensor0<PackPtr<T *, I>> &operator/=(const U &d)
53  {
54  *data /= d;
55  return *this;
56  }
57 
58  /* Assignments operator for ADOL-C */
59  template <class U> const Tensor0<PackPtr<T *, I>> &operator>>=(U &d)
60  {
61  d >>= *data;
62  return *this;
63  }
64 
65  template <class U> const Tensor0<PackPtr<T *, I>> &operator<<=(const U &d)
66  {
67  *data <<= d;
68  return *this;
69  }
70 
71  /* Note that the conversion operator& to T * only works on
72  consts, so it doesn't allow you to change the value of *data.
73  You have to use the = operators to change that. The idea is that
74  operator& is only used for stencils and such. */
75 
76  const T *operator&() const { return data; }
77  operator T() const { return *data; }
78 
79  /* The ++ operator increments the pointer, not the number that the
80  pointer points to. This allows iterating over a grid. */
81 
83  {
84  data += I;
85  return *this;
86  }
87  };
88 
89  template <class T> class Tensor0<T *>
90  {
91  const int inc;
92  mutable T *restrict data;
93 
94  public:
95  Tensor0(T *d, const int i = 1) : inc(i), data(d) {}
96 
97  const Tensor0 &operator=(const Tensor0 &a)
98  {
99  *data = *(a.data);
100  return *this;
101  }
102 
103  template <class U> const Tensor0<T *> &operator=(const U &d)
104  {
105  *data = d;
106  return *this;
107  }
108  template <class U> const Tensor0<T *> &operator+=(const U &d)
109  {
110  *data += d;
111  return *this;
112  }
113  template <class U> const Tensor0<T *> &operator-=(const U &d)
114  {
115  *data -= d;
116  return *this;
117  }
118  template <class U> const Tensor0<T *> &operator*=(const U &d)
119  {
120  *data *= d;
121  return *this;
122  }
123  template <class U> const Tensor0<T *> &operator/=(const U &d)
124  {
125  *data /= d;
126  return *this;
127  }
128 
129  /* Assignments operator for ADOL-C */
130  template <class U> const Tensor0<T *> &operator>>=(U &d)
131  {
132  d >>= *data;
133  return *this;
134  }
135 
136  template <class U> const Tensor0<T *> &operator<<=(const U d)
137  {
138  *data <<= d;
139  return *this;
140  }
141 
142  /* Note that the conversion operator& to T * only works on
143  consts, so it doesn't allow you to change the value of *data.
144  You have to use the = operators to change that. The idea is that
145  operator& is only used for stencils and such. */
146 
147  const T *operator&() const { return data; }
148  operator T() const { return *data; }
149 
150  /* The ++ operator increments the pointer, not the number that the
151  pointer points to. This allows iterating over a grid. */
152 
153  const Tensor0<T *> &operator++() const
154  {
155  data += inc;
156  return *this;
157  }
158  };
159 }
160 
const Tensor0< PackPtr< T *, I > > & operator+=(const U &d)
Definition: Tensor0.hpp:37
const Tensor0< T * > & operator++() const
Definition: Tensor0.hpp:153
const Tensor0< T * > & operator+=(const U &d)
Definition: Tensor0.hpp:108
const Tensor0< PackPtr< T *, I > > & operator*=(const U &d)
Definition: Tensor0.hpp:47
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
const Tensor0< PackPtr< T *, I > > & operator=(const U &d)
Definition: Tensor0.hpp:32
Ddg_Expr< Ddg_and_Tensor2_symmetric< A, B, T, U, Dim01_0, Dim23_0, Dim_1, i0, j0, k0, l0, i1, j1 >, typename promote< T, U >::V, Dim01_0, Dim23_0, i0, j0, k0, l0 > operator &(const Ddg_Expr< A, T, Dim01_0, Dim23_0, i0, j0, k0, l0 > &a, const Tensor2_symmetric_Expr< B, U, Dim_1, i1, j1 > &b)
Fully Antisymmetric Levi-Civita Tensor.
Tensor0(T *d, const int i=1)
Definition: Tensor0.hpp:95
const Tensor0 & operator=(const Tensor0 &a)
Definition: Tensor0.hpp:26
const Tensor0< PackPtr< T *, I > > & operator++() const
Definition: Tensor0.hpp:82
const Tensor0< PackPtr< T *, I > > & operator-=(const U &d)
Definition: Tensor0.hpp:42
const Tensor0< T * > & operator<<=(const U d)
Definition: Tensor0.hpp:136
const Tensor0 & operator=(const Tensor0 &a)
Definition: Tensor0.hpp:97
const Tensor0< T * > & operator*=(const U &d)
Definition: Tensor0.hpp:118
const Tensor0< T * > & operator>>=(U &d)
Definition: Tensor0.hpp:130
const Tensor0< PackPtr< T *, I > > & operator>>=(U &d)
Definition: Tensor0.hpp:59
const Tensor0< PackPtr< T *, I > > & operator/=(const U &d)
Definition: Tensor0.hpp:52
const Tensor0< PackPtr< T *, I > > & operator<<=(const U &d)
Definition: Tensor0.hpp:65
const Tensor0< T * > & operator-=(const U &d)
Definition: Tensor0.hpp:113
const Tensor0< T * > & operator=(const U &d)
Definition: Tensor0.hpp:103
const Tensor0< T * > & operator/=(const U &d)
Definition: Tensor0.hpp:123