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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/vs/vectorI.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
vectorI.H
Go to the documentation of this file.
1#ifndef VS_VECTORI_H
2#define VS_VECTORI_H
3
4#include <ostream>
5#include <cmath>
7
8namespace amr_wind::vs {
9
10template <typename T>
11AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
13{
14 return VectorT<T>{-vv[0], -vv[1], -vv[2]};
15}
16
17template <typename T>
18AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
20{
21 vv[0] *= fac;
22 vv[1] *= fac;
23 vv[2] *= fac;
24 return *this;
25}
26
27template <typename T>
28AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
30{
31 vv[0] *= vin.x();
32 vv[1] *= vin.y();
33 vv[2] *= vin.z();
34 return *this;
35}
36
37template <typename T>
38AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
40{
41 vv[0] /= fac;
42 vv[1] /= fac;
43 vv[2] /= fac;
44 return *this;
45}
46
47template <typename T, typename OStream>
48OStream& operator<<(OStream& out, const VectorT<T>& vec)
49{
50 out << "(" << vec.x() << " " << vec.y() << " " << vec.z() << ")";
51 return out;
52}
53
54template <typename T>
55AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
56operator+(const VectorT<T>& v1, const VectorT<T>& v2)
57{
58 return VectorT<T>{v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()};
59}
60
61template <typename T>
62AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
63operator-(const VectorT<T>& v1, const VectorT<T>& v2)
64{
65 return VectorT<T>{v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()};
66}
67
68template <typename T1, typename T2>
69AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T1>
70operator*(const VectorT<T1>& inp, const T2 fac)
71{
72 return VectorT<T1>{inp.x() * fac, inp.y() * fac, inp.z() * fac};
73}
74
75template <typename T1, typename T2>
76AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T1>
77operator*(const T2 fac, const VectorT<T1>& inp)
78{
79 return VectorT<T1>{inp.x() * fac, inp.y() * fac, inp.z() * fac};
80}
81
82template <typename T1, typename T2>
83AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T1>
84operator/(const VectorT<T1>& inp, const T2 fac)
85{
86 return VectorT<T1>{inp.x() / fac, inp.y() / fac, inp.z() / fac};
87}
88
89template <typename T>
90AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T
91operator&(const VectorT<T>& v1, const VectorT<T>& v2)
92{
93 return (v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z());
94}
95
96template <typename T>
97AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
98operator^(const VectorT<T>& v1, const VectorT<T>& v2)
99{
100 return VectorT<T>{
101 (v1.y() * v2.z() - v1.z() * v2.y()),
102 (v1.z() * v2.x() - v1.x() * v2.z()),
103 (v1.x() * v2.y() - v1.y() * v2.x())};
104}
105
106template <typename T>
107AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>
108operator*(const VectorT<T>& v1, const VectorT<T>& v2)
109{
110 return VectorT<T>{v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z()};
111}
112
113template <typename T>
114AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T mag_sqr(const VectorT<T>& v)
116 return (v.x() * v.x() + v.y() * v.y() + v.z() * v.z());
117}
119template <typename T>
120AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T mag(const VectorT<T>& v)
121{
122 return std::sqrt(mag_sqr(v));
123}
124
125template <typename T>
126AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T>& VectorT<T>::normalize()
127{
128 T vmag = mag(*this);
129
130 if (vmag < Traits::eps()) {
131 *this = VectorT<T>::zero();
132 } else {
133 *this /= vmag;
134 }
135 return *this;
136}
137
138template <typename T>
139AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT<T> sqrt(const VectorT<T>& v)
140{
141 return VectorT<T>{std::sqrt(v.x()), std::sqrt(v.y()), std::sqrt(v.z())};
142}
143
144} // namespace amr_wind::vs
145
146#endif /* VS_VECTORI_H */
Definition tensor.H:8
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T mag(const TensorT< T > &t)
Definition tensorI.H:182
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T1 > operator*(const VectorT< T1 > &inp, const T2 fac)
Definition vectorI.H:70
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator&(const TensorT< T > &t, const VectorT< T > &v)
Definition tensorI.H:103
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T1 > operator/(const VectorT< T1 > &inp, const T2 fac)
Definition vectorI.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TensorT< T > operator-(const TensorT< T > &t1, const TensorT< T > &t2)
Definition tensorI.H:156
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator^(const VectorT< T > &v1, const VectorT< T > &v2)
Definition vectorI.H:98
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TensorT< T > operator+(const TensorT< T > &t1, const TensorT< T > &t2)
Definition tensorI.H:146
OStream & operator<<(OStream &out, const TensorT< T > &t)
Definition tensorI.H:91
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T mag_sqr(const TensorT< T > &t)
Definition tensorI.H:175
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > sqrt(const VectorT< T > &v)
Definition vectorI.H:139
Definition vector.H:13
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator/=(const T val)
Definition vectorI.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & z() &noexcept
Definition vector.H:99
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & x() &noexcept
Definition vector.H:97
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator*=(const T val)
Definition vectorI.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & y() &noexcept
Definition vector.H:98
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > & normalize()
Normalize the vector to unit vector.
Definition vectorI.H:126
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr VectorT< T > zero()
Zero vector.
Definition vector.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE VectorT< T > operator-() const
Definition vectorI.H:12