v0.5.86
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 #include "Tensor0/dTensor0.hpp"
8 #include "Tensor0/ddTensor0.hpp"
11 
12 template <class T>
13 class Tensor0
14 {};
15 
16 template <class T>
17 class Tensor0<T*>
18 {
19  mutable int inc;
20  mutable T * restrict data;
21 public:
22  Tensor0(T *d,const int i = 1): inc(i),data(d) {}
23 
24  const Tensor0 & operator=(const Tensor0 &a)
25  {
26  *data=*(a.data);
27  return *this;
28  }
29 
30  template<class U>
31  const Tensor0<T*> & operator=(const U &d)
32  {
33  *data=d;
34  return *this;
35  }
36  template<class U>
37  const Tensor0<T*> & operator+=(const U &d)
38  {
39  *data+=d;
40  return *this;
41  }
42  template<class U>
43  const Tensor0<T*> & operator-=(const U &d)
44  {
45  *data-=d;
46  return *this;
47  }
48  template<class U>
49  const Tensor0<T*> & operator*=(const U &d)
50  {
51  *data*=d;
52  return *this;
53  }
54  template<class U>
55  const Tensor0<T*> & operator/=(const U &d)
56  {
57  *data/=d;
58  return *this;
59  }
60 
61  #ifdef ADOLC_ADOUBLE_H
62 
63  /*
64  Assignments operator for ADOL-C
65  */
66  template<class U>
67  const Tensor0<T*> & operator>>=(U &d)
68  {
69  d >>= *data;
70  return *this;
71  }
72 
73  template<class U>
74  const Tensor0<T*> & operator<<=(const U d)
75  {
76  *data<<=d;
77  return *this;
78  }
79 
80  #endif
81 
82  /* Note that the conversion operator& to T * only works on
83  consts, so it doesn't allow you to change the value of *data.
84  You have to use the = operators to change that. The idea is that
85  operator& is only used for stencils and such. */
86 
87  const T * operator&() const
88  {
89  return data;
90  }
91  operator T() const
92  {
93  return *data;
94  }
95 
96  /* The ++ operator increments the pointer, not the number that the
97  pointer points to. This allows iterating over a grid. */
98 
99  const Tensor0<T*> & operator++() const
100  {
101  data+=inc;
102  return *this;
103  }
104 };
105 
106 #ifdef ADOLC_ADOUBLE_H
107 
108 #endif
109 
Tensor0(T *d, const int i=1)
Definition: Tensor0.hpp:22
const Tensor0< T * > & operator+=(const U &d)
Definition: Tensor0.hpp:37
T *restrict data
Definition: Tensor0.hpp:20
const Tensor0 & operator=(const Tensor0 &a)
Definition: Tensor0.hpp:24
const Tensor0< T * > & operator*=(const U &d)
Definition: Tensor0.hpp:49
const Tensor1_Expr< const Tensor1_and_Tensor1< A, B, T, U, Dim, i >, typename promote< T, U >::V, Dim, i > operator &(const Tensor1_Expr< A, T, Dim, i > &a, const Tensor1_Expr< B, U, Dim, i > &b)
const Tensor0< T * > & operator-=(const U &d)
Definition: Tensor0.hpp:43
const Tensor0< T * > & operator=(const U &d)
Definition: Tensor0.hpp:31
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
const Tensor0< T * > & operator/=(const U &d)
Definition: Tensor0.hpp:55
const Tensor0< T * > & operator++() const
Definition: Tensor0.hpp:99