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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/vs/vector.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
vector.H
Go to the documentation of this file.
1#ifndef VS_VECTOR_H
2#define VS_VECTOR_H
3
4#include "AMReX_Gpu.H"
6
7namespace amr_wind::vs {
8
11template <typename T>
12struct VectorT
13{
14 amrex::GpuArray<T, 3> vv = {Traits::zero(), Traits::zero(), Traits::zero()};
15
17 static constexpr int ncomp = 3;
18 using size_type = int;
19 using value_type = T;
20 using reference = T&;
21 using iterator = T*;
22 using const_iterator = const T*;
25
27 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT() = default;
28
31 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
32 VectorT(const T& x, const T& y, const T& z)
33 : vv{x, y, z}
34 {}
35
36 ~VectorT() = default;
37 VectorT(const VectorT&) = default;
38 VectorT(VectorT&&) = default;
39 VectorT& operator=(const VectorT&) & = default;
40 VectorT& operator=(const VectorT&) && = delete;
41 VectorT& operator=(VectorT&&) & = default;
42 VectorT& operator=(VectorT&&) && = delete;
43
45 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr VectorT<T> zero()
46 {
47 return VectorT<T>{Traits::zero(), Traits::zero(), Traits::zero()};
48 }
49
50 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr VectorT<T> one()
51 {
52 return VectorT<T>{Traits::one(), Traits::one(), Traits::one()};
53 }
54
59 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr VectorT<T>
60 ihat(const T& x = Traits::one())
61 {
62 return VectorT<T>{x, Traits::zero(), Traits::zero()};
63 }
64
69 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr VectorT<T>
70 jhat(const T& y = Traits::one())
71 {
72 return VectorT<T>{Traits::zero(), y, Traits::zero()};
73 }
74
79 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static constexpr VectorT<T>
80 khat(const T& z = Traits::one())
81 {
82 return VectorT<T>{Traits::zero(), Traits::zero(), z};
83 }
84
86 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>& normalize();
87
89 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> sqrt(const VectorT&);
90
92 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> unit() const
93 {
94 return VectorT<T>(*this).normalize();
95 }
96
97 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& x() & noexcept { return vv[0]; }
98 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& y() & noexcept { return vv[1]; }
99 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& z() & noexcept { return vv[2]; }
100 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& x() const& noexcept
101 {
102 return vv[0];
103 }
104 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& y() const& noexcept
105 {
106 return vv[1];
107 }
108 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& z() const& noexcept
109 {
110 return vv[2];
111 }
112
113 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> operator-() const;
114
115 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> operator*=(const T val);
116
117 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
118 operator*=(const VectorT<T>& valvec);
119
120 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> operator/=(const T val);
121
122 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& operator[](size_type pos) &
123 {
124 return vv[pos];
125 }
126 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T&
128 {
129 return vv[pos];
130 }
131
132 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T* data() noexcept
133 {
134 return vv.data();
135 }
136 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T* data() const noexcept
137 {
138 return vv.data();
139 }
140
141 iterator begin() noexcept { return vv.begin(); }
142 iterator end() noexcept { return vv.end(); }
143 const_iterator cbegin() const noexcept { return vv.cbegin(); }
144 const_iterator cend() const noexcept { return vv.cend(); }
145 size_type size() const noexcept { return ncomp; }
146};
147
149
150} // namespace amr_wind::vs
151
153
154#endif /* VS_VECTOR_H */
Definition tensor.H:8
Definition vstraits.H:11
Definition vector.H:13
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT(const T &x, const T &y, const T &z)
Definition vector.H:32
const T * const_iterator
Definition vector.H:22
VectorT(const VectorT &)=default
size_type size() const noexcept
Definition vector.H:145
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT()=default
Construct a default vector, all components set to zero.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator/=(const T val)
Definition vectorI.H:39
VectorT & operator=(const VectorT &) &=default
VectorT & operator=(const VectorT &) &&=delete
VectorT & operator=(VectorT &&) &&=delete
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr VectorT< T > one()
Definition vector.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & z() &noexcept
Definition vector.H:99
const_iterator cend() const noexcept
Definition vector.H:144
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & x() &noexcept
Definition vector.H:97
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & z() const &noexcept
Definition vector.H:108
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator*=(const T val)
Definition vectorI.H:19
static constexpr int ncomp
Number of components.
Definition vector.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > unit() const
Return the unit vector parallel to this vector.
Definition vector.H:92
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * data() const noexcept
Definition vector.H:136
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & y() &noexcept
Definition vector.H:98
int size_type
Definition vector.H:18
VectorT(VectorT &&)=default
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr VectorT< T > jhat(const T &y=Traits::one())
Definition vector.H:70
iterator end() noexcept
Definition vector.H:142
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > & normalize()
Normalize the vector to unit vector.
Definition vectorI.H:126
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * data() noexcept
Definition vector.H:132
T value_type
Definition vector.H:19
const_iterator cbegin() const noexcept
Definition vector.H:143
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & operator[](size_type pos) const &
Definition vector.H:127
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & x() const &noexcept
Definition vector.H:100
T * iterator
Definition vector.H:21
T & reference
Definition vector.H:20
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > sqrt(const VectorT &)
Sqrt of each component.
iterator begin() noexcept
Definition vector.H:141
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr VectorT< T > zero()
Zero vector.
Definition vector.H:45
VectorT & operator=(VectorT &&) &=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & y() const &noexcept
Definition vector.H:104
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr VectorT< T > khat(const T &z=Traits::one())
Definition vector.H:80
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator-() const
Definition vectorI.H:12
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr VectorT< T > ihat(const T &x=Traits::one())
Definition vector.H:60
amrex::GpuArray< T, 3 > vv
Definition vector.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & operator[](size_type pos) &
Definition vector.H:122