/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 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> zero()
57 {
58 return TensorT<T>{Traits::zero(), Traits::zero(), Traits::zero(),
59 Traits::zero(), Traits::zero(), Traits::zero(),
60 Traits::zero(), Traits::zero(), Traits::zero()};
61 }
62
63 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr TensorT<T>
65 {
66 return TensorT{Traits::one(), Traits::zero(), Traits::zero(),
67 Traits::zero(), Traits::one(), Traits::zero(),
68 Traits::zero(), Traits::zero(), Traits::one()};
69 }
70
71 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void
72 rows(const VectorT<T>& x, const VectorT<T>& y, const VectorT<T>& z);
73 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void
74 cols(const VectorT<T>& x, const VectorT<T>& y, const VectorT<T>& z);
75
76 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> x() const;
77 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> y() const;
78 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> z() const;
79
80 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> cx() const;
81 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> cy() const;
82 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> cz() const;
83
84 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& xx() & { return vv[0]; }
85 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& xy() & { return vv[1]; }
86 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& xz() & { return vv[2]; }
87
88 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& yx() & { return vv[3]; }
89 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& yy() & { return vv[4]; }
90 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& yz() & { return vv[5]; }
91
92 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& zx() & { return vv[6]; }
93 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& zy() & { return vv[7]; }
94 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& zz() & { return vv[8]; }
95
96 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& xx() const&
97 {
98 return vv[0];
99 }
100 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& xy() const&
101 {
102 return vv[1];
103 }
104 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& xz() const&
105 {
106 return vv[2];
107 }
108
109 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& yx() const&
110 {
111 return vv[3];
112 }
113 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& yy() const&
114 {
115 return vv[4];
116 }
117 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& yz() const&
118 {
119 return vv[5];
120 }
121
122 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& zx() const&
123 {
124 return vv[6];
125 }
126 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& zy() const&
127 {
128 return vv[7];
129 }
130 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& zz() const&
131 {
132 return vv[8];
133 }
134
135 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& operator[](size_type pos) &
136 {
137 return vv[pos];
138 }
139 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T&
141 {
142 return vv[pos];
143 }
144
145 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T* data() { return vv.data(); }
146 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T* data() const
147 {
148 return vv.data();
149 }
150
151 iterator begin() { return vv.begin(); }
152 iterator end() { return vv.end(); }
153 [[nodiscard]] const_iterator cbegin() const { return vv.cbegin(); }
154 [[nodiscard]] const_iterator cend() const { return vv.cend(); }
155 [[nodiscard]] size_type size() const { return ncomp; }
156};
157
159
160} // namespace amr_wind::vs
161
163
164#endif /* VS_TENSOR_H */
Definition tensor.H:8
TensorT< amrex::Real > Tensor
Definition tensor.H:158
Definition vstraits.H:10
Definition tensor.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & xz() const &
Definition tensor.H:104
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * data()
Definition tensor.H:145
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr TensorT< T > zero()
Definition tensor.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & zz() const &
Definition tensor.H:130
const T * const_iterator
Definition tensor.H:24
TensorT(const TensorT &)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > cy() const
Definition tensorI.H:77
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TensorT(const VectorT< T > &x, const VectorT< T > &y, const VectorT< T > &z, bool transpose=false)
Definition tensorI.H:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & zy() &
Definition tensor.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & zz() &
Definition tensor.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > cz() const
Definition tensorI.H:84
TensorT & operator=(TensorT &&) &=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< amrex::Real > x() const
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
size_type size() const
Definition tensor.H:155
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & xz() &
Definition tensor.H:86
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< amrex::Real > z() const
T & reference
Definition tensor.H:22
TensorT & operator=(const TensorT &) &&=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void cols(const VectorT< T > &x, const VectorT< T > &y, const VectorT< T > &z)
Definition tensorI.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & yy() &
Definition tensor.H:89
TensorT & operator=(TensorT &&) &&=delete
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & zx() &
Definition tensor.H:92
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & yz() const &
Definition tensor.H:117
T * iterator
Definition tensor.H:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & xx() &
Definition tensor.H:84
TensorT & operator=(const TensorT &) &=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & yy() const &
Definition tensor.H:113
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * data() const
Definition tensor.H:146
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
DTraits< T > Traits
Definition tensor.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > cx() const
Definition tensorI.H:70
amrex::GpuArray< amrex::Real, 9 > vv
Definition tensor.H:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & yx() const &
Definition tensor.H:109
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr TensorT< T > identity()
Definition tensor.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & yx() &
Definition tensor.H:88
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rows(const VectorT< T > &x, const VectorT< T > &y, const VectorT< T > &z)
Definition tensorI.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & yz() &
Definition tensor.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & operator[](size_type pos) const &
Definition tensor.H:140
TensorT(TensorT &&)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & xy() const &
Definition tensor.H:100
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & operator[](size_type pos) &
Definition tensor.H:135
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & zx() const &
Definition tensor.H:122
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< amrex::Real > y() const
iterator end()
Definition tensor.H:152
iterator begin()
Definition tensor.H:151
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & xx() const &
Definition tensor.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real & xy() &
Definition tensor.H:85
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & zy() const &
Definition tensor.H:126
const_iterator cend() const
Definition tensor.H:154
const_iterator cbegin() const
Definition tensor.H:153
T value_type
Definition tensor.H:21
Definition vector.H:13