/home/runner/work/amr-wind/amr-wind/amr-wind/core/vs/tensor.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/vs/tensor.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
tensor.H
Go to the documentation of this file.
1#ifndef VS_TENSOR_H
2#define VS_TENSOR_H
3
4#include "AMReX_Gpu.H"
7
8namespace amr_wind::vs {
9
12template <typename T>
13struct TensorT
14{
15 amrex::GpuArray<T, 9> vv = {Traits::zero(), Traits::zero(), Traits::zero(),
16 Traits::zero(), Traits::zero(), Traits::zero(),
17 Traits::zero(), Traits::zero(), Traits::zero()};
18
19 static constexpr int ncomp = 9;
20 using size_type = int;
21 using value_type = T;
22 using reference = T&;
23 using iterator = T*;
24 using const_iterator = const T*;
26
27 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr TensorT() = default;
28
29 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr TensorT(
30 const T& xx,
31 const T& xy,
32 const T& xz,
33 const T& yx,
34 const T& yy,
35 const T& yz,
36 const T& zx,
37 const T& zy,
38 const T& zz)
39 : vv{xx, xy, xz, yx, yy, yz, zx, zy, zz}
40 {}
41
42 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TensorT(
43 const VectorT<T>& x,
44 const VectorT<T>& y,
45 const VectorT<T>& z,
46 const bool transpose = false);
47
48 ~TensorT() = default;
49 TensorT(const TensorT&) = default;
50 TensorT(TensorT&&) = default;
51 TensorT& operator=(const TensorT&) & = default;
52 TensorT& operator=(const TensorT&) && = delete;
53 TensorT& operator=(TensorT&&) & = default;
54 TensorT& operator=(TensorT&&) && = delete;
55
56 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr TensorT<T>
57 zero() noexcept
58 {
59 return TensorT<T>{Traits::zero(), Traits::zero(), Traits::zero(),
60 Traits::zero(), Traits::zero(), Traits::zero(),
61 Traits::zero(), Traits::zero(), Traits::zero()};
62 }
63
64 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr TensorT<T>
65 identity() noexcept
66 {
67 return TensorT{Traits::one(), Traits::zero(), Traits::zero(),
68 Traits::zero(), Traits::one(), Traits::zero(),
69 Traits::zero(), Traits::zero(), Traits::one()};
70 }
71
72 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rows(
73 const VectorT<T>& x, const VectorT<T>& y, const VectorT<T>& z) noexcept;
74 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void cols(
75 const VectorT<T>& x, const VectorT<T>& y, const VectorT<T>& z) noexcept;
76
77 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> x() const noexcept;
78 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> y() const noexcept;
79 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> z() const noexcept;
80
81 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> cx() const noexcept;
82 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> cy() const noexcept;
83 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> cz() const noexcept;
84
85 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& xx() & noexcept
86 {
87 return vv[0];
88 }
89 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& xy() & noexcept
90 {
91 return vv[1];
92 }
93 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& xz() & noexcept
94 {
95 return vv[2];
96 }
97
98 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& yx() & noexcept
99 {
100 return vv[3];
101 }
102 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& yy() & noexcept
103 {
104 return vv[4];
105 }
106 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& yz() & noexcept
107 {
108 return vv[5];
109 }
110
111 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& zx() & noexcept
112 {
113 return vv[6];
114 }
115 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& zy() & noexcept
116 {
117 return vv[7];
118 }
119 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& zz() & noexcept
120 {
121 return vv[8];
122 }
123
124 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& xx() const& noexcept
125 {
126 return vv[0];
127 }
128 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& xy() const& noexcept
129 {
130 return vv[1];
131 }
132 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& xz() const& noexcept
133 {
134 return vv[2];
135 }
136
137 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& yx() const& noexcept
138 {
139 return vv[3];
140 }
141 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& yy() const& noexcept
142 {
143 return vv[4];
144 }
145 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& yz() const& noexcept
146 {
147 return vv[5];
148 }
149
150 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& zx() const& noexcept
151 {
152 return vv[6];
153 }
154 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& zy() const& noexcept
155 {
156 return vv[7];
157 }
158 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& zz() const& noexcept
159 {
160 return vv[8];
161 }
162
163 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& operator[](size_type pos) &
164 {
165 return vv[pos];
166 }
167 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T&
169 {
170 return vv[pos];
171 }
172
173 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T* data() noexcept
174 {
175 return vv.data();
176 }
177 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T* data() const noexcept
178 {
179 return vv.data();
180 }
181
182 iterator begin() noexcept { return vv.begin(); }
183 iterator end() noexcept { return vv.end(); }
184 const_iterator cbegin() const noexcept { return vv.cbegin(); }
185 const_iterator cend() const noexcept { return vv.cend(); }
186 size_type size() const noexcept { return ncomp; }
187};
188
190
191} // namespace amr_wind::vs
192
194
195#endif /* VS_TENSOR_H */
Definition tensor.H:8
Definition vstraits.H:11
Definition tensor.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & xz() const &noexcept
Definition tensor.H:132
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * data() const noexcept
Definition tensor.H:177
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr TensorT< T > identity() noexcept
Definition tensor.H:65
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & zy() &noexcept
Definition tensor.H:115
const T * const_iterator
Definition tensor.H:24
TensorT(const TensorT &)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > y() const noexcept
Definition tensorI.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & zz() &noexcept
Definition tensor.H:119
const_iterator cbegin() const noexcept
Definition tensor.H:184
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & zx() &noexcept
Definition tensor.H:111
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & yy() &noexcept
Definition tensor.H:102
TensorT & operator=(TensorT &&) &=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & yz() const &noexcept
Definition tensor.H:145
int size_type
Definition tensor.H:20
static constexpr int ncomp
Definition tensor.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr TensorT()=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > z() const noexcept
Definition tensorI.H:63
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > cz() const noexcept
Definition tensorI.H:84
T & reference
Definition tensor.H:22
iterator end() noexcept
Definition tensor.H:183
TensorT & operator=(const TensorT &) &&=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & zx() const &noexcept
Definition tensor.H:150
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > x() const noexcept
Definition tensorI.H:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void cols(const VectorT< T > &x, const VectorT< T > &y, const VectorT< T > &z) noexcept
Definition tensorI.H:36
TensorT & operator=(TensorT &&) &&=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & xx() &noexcept
Definition tensor.H:85
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & zz() const &noexcept
Definition tensor.H:158
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > cy() const noexcept
Definition tensorI.H:77
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & yx() &noexcept
Definition tensor.H:98
iterator begin() noexcept
Definition tensor.H:182
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rows(const VectorT< T > &x, const VectorT< T > &y, const VectorT< T > &z) noexcept
Definition tensorI.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & xy() const &noexcept
Definition tensor.H:128
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & zy() const &noexcept
Definition tensor.H:154
T * iterator
Definition tensor.H:23
TensorT & operator=(const TensorT &) &=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr TensorT(const T &xx, const T &xy, const T &xz, const T &yx, const T &yy, const T &yz, const T &zx, const T &zy, const T &zz)
Definition tensor.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & xx() const &noexcept
Definition tensor.H:124
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & xz() &noexcept
Definition tensor.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > cx() const noexcept
Definition tensorI.H:70
amrex::GpuArray< T, 9 > vv
Definition tensor.H:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & yy() const &noexcept
Definition tensor.H:141
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & yx() const &noexcept
Definition tensor.H:137
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & operator[](size_type pos) const &
Definition tensor.H:168
TensorT(TensorT &&)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * data() noexcept
Definition tensor.H:173
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr TensorT< T > zero() noexcept
Definition tensor.H:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & operator[](size_type pos) &
Definition tensor.H:163
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & xy() &noexcept
Definition tensor.H:89
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & yz() &noexcept
Definition tensor.H:106
size_type size() const noexcept
Definition tensor.H:186
const_iterator cend() const noexcept
Definition tensor.H:185
T value_type
Definition tensor.H:21
Definition vector.H:13