v0.14.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, I) {}
97 
98  template <class U> const Tensor0 &operator=(const U &d) {
100  return *this;
101  }
102  template <class U> const Tensor0 &operator+=(const U &d)
103  {
104  *Tensor0<T *>::data += d;
105  return *this;
106  }
107  template <class U> const Tensor0 &operator-=(const U &d)
108  {
109  *Tensor0<T *>::data -= d;
110  return *this;
111  }
112  template <class U> const Tensor0 &operator*=(const U &d)
113  {
114  *Tensor0<T *>::data *= d;
115  return *this;
116  }
117  template <class U> const Tensor0 &operator/=(const U &d)
118  {
119  *Tensor0<T *>::data /= d;
120  return *this;
121  }
122 
123  /* Assignments operator for ADOL-C */
124  template <class U> const Tensor0 &operator>>=(U &d)
125  {
126  d >>= *Tensor0<T *>::data;
127  return *this;
128  }
129 
130  template <class U> const Tensor0 &operator<<=(const U d)
131  {
132  *Tensor0<T *>::data <<= d;
133  return *this;
134  }
135 
136 
137  /* Note that the conversion operator& to T * only works on
138  consts, so it doesn't allow you to change the value of *data.
139  You have to use the = operators to change that. The idea is that
140  operator& is only used for stencils and such. */
141 
142  const T *operator&() const { return Tensor0<T *>::data; }
143  operator T() const { return *Tensor0<T *>::data; }
144 
145  /* The ++ operator increments the pointer, not the number that the
146  pointer points to. This allows iterating over a grid. */
147 
148  const Tensor0 &operator++() const {
150  return *this;
151  }
152  };
153 }
154 
d_boundary_Tensor0.hpp
FTensor::Tensor0< T * >::operator=
const Tensor0 & operator=(const U &d)
Definition: Tensor0.hpp:35
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::Tensor0< T * >::operator++
const Tensor0 & operator++() const
Definition: Tensor0.hpp:85
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
FTensor::Tensor0< PackPtr< T *, I > >::operator<<=
const Tensor0 & operator<<=(const U d)
Definition: Tensor0.hpp:130
diffusion_Tensor0.hpp
FTensor::Tensor0< PackPtr< T *, I > >::operator=
const Tensor0 & operator=(const U &d)
Definition: Tensor0.hpp:98
d_one_sided_Tensor0.hpp
FTensor::Tensor0< T * >::inc
const int inc
Definition: Tensor0.hpp:21
I
constexpr IntegrationType I
Definition: operators_tests.cpp:31
FTensor::Tensor0< PackPtr< T *, I > >::Tensor0
Tensor0(T *d)
Definition: Tensor0.hpp:96
FTensor::Tensor0< PackPtr< T *, I > >::operator*=
const Tensor0 & operator*=(const U &d)
Definition: Tensor0.hpp:112
dd_boundary_Tensor0.hpp
FTensor::Tensor0< T * >::operator/=
const Tensor0 & operator/=(const U &d)
Definition: Tensor0.hpp:55
FTensor::Tensor0< PackPtr< T *, I > >::operator+=
const Tensor0 & operator+=(const U &d)
Definition: Tensor0.hpp:102
a
constexpr double a
Definition: approx_sphere.cpp:30
ddTensor0.hpp
FTensor::Tensor0< T * >
Definition: Tensor0.hpp:19
FTensor::Tensor0< T * >::operator-=
const Tensor0 & operator-=(const U &d)
Definition: Tensor0.hpp:45
FTensor::Tensor0< PackPtr< T *, I > >::operator>>=
const Tensor0 & operator>>=(U &d)
Definition: Tensor0.hpp:124
FTensor::Tensor0< T * >::operator=
const Tensor0 & operator=(const Tensor0 &a)
Definition: Tensor0.hpp:29
FTensor::Tensor0< T * >::operator+=
const Tensor0 & operator+=(const U &d)
Definition: Tensor0.hpp:40
FTensor::Tensor0< PackPtr< T *, I > >::operator&
const T * operator&() const
Definition: Tensor0.hpp:142
FTensor::Tensor0< T * >::operator*=
const Tensor0 & operator*=(const U &d)
Definition: Tensor0.hpp:50
FTensor::PackPtr
Definition: FTensor.hpp:54
dTensor0.hpp
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Tensor0< PackPtr< T *, I > >::operator/=
const Tensor0 & operator/=(const U &d)
Definition: Tensor0.hpp:117
FTensor::Tensor0< T * >::data
T *restrict data
Definition: Tensor0.hpp:24
FTensor::Tensor0
Definition: Tensor0.hpp:16
FTensor::Tensor0< PackPtr< T *, I > >::operator-=
const Tensor0 & operator-=(const U &d)
Definition: Tensor0.hpp:107
FTensor::Tensor0< T * >::operator>>=
const Tensor0 & operator>>=(U &d)
Definition: Tensor0.hpp:62
FTensor::Tensor0< T * >::Tensor0
Tensor0(T *d, const int i=1)
Definition: Tensor0.hpp:27
FTensor::Tensor0< T * >::operator<<=
const Tensor0 & operator<<=(const U d)
Definition: Tensor0.hpp:68
FTensor::Tensor0< T * >::operator&
const T * operator&() const
Definition: Tensor0.hpp:79
EshelbianPlasticity::U
@ U
Definition: EshelbianContact.cpp:193
FTensor::Tensor0< PackPtr< T *, I > >::operator++
const Tensor0 & operator++() const
Definition: Tensor0.hpp:148
interpolate_Tensor0.hpp