v0.9.0
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> class Tensor0<T *>
20  {
21  const int inc;
22 
23  protected:
24  mutable T *restrict data;
25 
26  public:
27  Tensor0(T *d, const int i = 1) : inc(i), data(d) {}
28 
29  const Tensor0 &operator=(const Tensor0 &a)
30  {
31  *data = *(a.data);
32  return *this;
33  }
34 
35  template <class U> const Tensor0 &operator=(const U &d)
36  {
37  *data = d;
38  return *this;
39  }
40  template <class U> const Tensor0 &operator+=(const U &d)
41  {
42  *data += d;
43  return *this;
44  }
45  template <class U> const Tensor0 &operator-=(const U &d)
46  {
47  *data -= d;
48  return *this;
49  }
50  template <class U> const Tensor0 &operator*=(const U &d)
51  {
52  *data *= d;
53  return *this;
54  }
55  template <class U> const Tensor0 &operator/=(const U &d)
56  {
57  *data /= d;
58  return *this;
59  }
60 
61  /* Assignments operator for ADOL-C */
62  template <class U> const Tensor0 &operator>>=(U &d)
63  {
64  d >>= *data;
65  return *this;
66  }
67 
68  template <class U> const Tensor0 &operator<<=(const U d)
69  {
70  *data <<= d;
71  return *this;
72  }
73 
74  /* Note that the conversion operator& to T * only works on
75  consts, so it doesn't allow you to change the value of *data.
76  You have to use the = operators to change that. The idea is that
77  operator& is only used for stencils and such. */
78 
79  const T *operator&() const { return data; }
80  operator T() const { return *data; }
81 
82  /* The ++ operator increments the pointer, not the number that the
83  pointer points to. This allows iterating over a grid. */
84 
85  const Tensor0 &operator++() const
86  {
87  data += inc;
88  return *this;
89  }
90  };
91 
92  template <class T, int I>
93  class Tensor0<PackPtr<T *, I>> : public Tensor0<T *> {
94 
95  public:
96  Tensor0(T *d) : Tensor0<T *>(d) {}
97 
98  template <class U> const Tensor0 &operator=(const U &d)
99  {
101  return *this;
102  }
103  template <class U> const Tensor0 &operator+=(const U &d)
104  {
105  *Tensor0<T *>::data += d;
106  return *this;
107  }
108  template <class U> const Tensor0 &operator-=(const U &d)
109  {
110  *Tensor0<T *>::data -= d;
111  return *this;
112  }
113  template <class U> const Tensor0 &operator*=(const U &d)
114  {
115  *Tensor0<T *>::data *= d;
116  return *this;
117  }
118  template <class U> const Tensor0 &operator/=(const U &d)
119  {
120  *Tensor0<T *>::data /= d;
121  return *this;
122  }
123 
124  /* Assignments operator for ADOL-C */
125  template <class U> const Tensor0 &operator>>=(U &d)
126  {
127  d >>= *Tensor0<T *>::data;
128  return *this;
129  }
130 
131  template <class U> const Tensor0 &operator<<=(const U d)
132  {
133  *Tensor0<T *>::data <<= d;
134  return *this;
135  }
136 
137 
138  /* Note that the conversion operator& to T * only works on
139  consts, so it doesn't allow you to change the value of *data.
140  You have to use the = operators to change that. The idea is that
141  operator& is only used for stencils and such. */
142 
143  const T *operator&() const { return Tensor0<T *>::data; }
144  operator T() const { return *Tensor0<T *>::data; }
145 
146  /* The ++ operator increments the pointer, not the number that the
147  pointer points to. This allows iterating over a grid. */
148 
149  const Tensor0 &operator++() const {
150  Tensor0<T *>::data += I;
151  return *this;
152  }
153  };
154 }
155 
const Tensor0 & operator-=(const U &d)
Definition: Tensor0.hpp:108
const Tensor0 & operator>>=(U &d)
Definition: Tensor0.hpp:62
const Tensor0 & operator++() const
Definition: Tensor0.hpp:149
const Tensor0 & operator<<=(const U d)
Definition: Tensor0.hpp:131
const Tensor0 & operator++() const
Definition: Tensor0.hpp:85
const Tensor0 & operator>>=(U &d)
Definition: Tensor0.hpp:125
Fully Antisymmetric Levi-Civita Tensor.
Tensor0(T *d, const int i=1)
Definition: Tensor0.hpp:27
const Tensor0 & operator/=(const U &d)
Definition: Tensor0.hpp:55
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 & operator=(const Tensor0 &a)
Definition: Tensor0.hpp:29
const Tensor0 & operator+=(const U &d)
Definition: Tensor0.hpp:103
const Tensor0 & operator=(const U &d)
Definition: Tensor0.hpp:35
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)
const Tensor0 & operator<<=(const U d)
Definition: Tensor0.hpp:68
const Tensor0 & operator/=(const U &d)
Definition: Tensor0.hpp:118
const Tensor0 & operator+=(const U &d)
Definition: Tensor0.hpp:40
const Tensor0 & operator-=(const U &d)
Definition: Tensor0.hpp:45
const Tensor0 & operator=(const U &d)
Definition: Tensor0.hpp:98