v0.13.1
Loading...
Searching...
No Matches
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
11#include "Tensor0/ddTensor0.hpp"
13
14namespace 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 {
105 return *this;
106 }
107 template <class U> const Tensor0 &operator-=(const U &d)
108 {
110 return *this;
111 }
112 template <class U> const Tensor0 &operator*=(const U &d)
113 {
115 return *this;
116 }
117 template <class U> const Tensor0 &operator/=(const U &d)
118 {
120 return *this;
121 }
122
123 /* Assignments operator for ADOL-C */
124 template <class U> const Tensor0 &operator>>=(U &d)
125 {
127 return *this;
128 }
129
130 template <class U> const Tensor0 &operator<<=(const U d)
131 {
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
static Index< 'I', 3 > I
constexpr double a
const Tensor0 & operator++() const
Definition: Tensor0.hpp:148
const Tensor0 & operator<<=(const U d)
Definition: Tensor0.hpp:130
const Tensor0 & operator>>=(U &d)
Definition: Tensor0.hpp:124
const Tensor0 & operator=(const U &d)
Definition: Tensor0.hpp:98
const Tensor0 & operator+=(const U &d)
Definition: Tensor0.hpp:102
const Tensor0 & operator/=(const U &d)
Definition: Tensor0.hpp:117
const Tensor0 & operator-=(const U &d)
Definition: Tensor0.hpp:107
const Tensor0 & operator*=(const U &d)
Definition: Tensor0.hpp:112
const Tensor0 & operator++() const
Definition: Tensor0.hpp:85
const Tensor0 & operator+=(const U &d)
Definition: Tensor0.hpp:40
const Tensor0 & operator=(const Tensor0 &a)
Definition: Tensor0.hpp:29
const Tensor0 & operator=(const U &d)
Definition: Tensor0.hpp:35
const T * operator&() const
Definition: Tensor0.hpp:79
Tensor0(T *d, const int i=1)
Definition: Tensor0.hpp:27
const Tensor0 & operator>>=(U &d)
Definition: Tensor0.hpp:62
const Tensor0 & operator<<=(const U d)
Definition: Tensor0.hpp:68
const Tensor0 & operator*=(const U &d)
Definition: Tensor0.hpp:50
const Tensor0 & operator/=(const U &d)
Definition: Tensor0.hpp:55
const Tensor0 & operator-=(const U &d)
Definition: Tensor0.hpp:45
FTensor::Index< 'i', SPACE_DIM > i
const double T
Tensors class implemented by Walter Landry.
Definition: FTensor.hpp:51
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