/home/runner/work/amr-wind/amr-wind/amr-wind/utilities/tensor_ops.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/utilities/tensor_ops.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
tensor_ops.H
Go to the documentation of this file.
1#ifndef TENSOR_OPS_H
2#define TENSOR_OPS_H
3
4#include "AMReX_Gpu.H"
5
6namespace amr_wind::utils {
7
10template <typename T>
11AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T dot_prod(const T* x, const T* y)
12{
13 static_assert(
14 AMREX_SPACEDIM == 3, "Vector ops only defined for AMREX_SPACEDIM == 3");
15 return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]);
16}
17
20template <typename T>
21AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T vec_mag(const T* x)
22{
23 return std::sqrt(dot_prod(x, x));
24}
25
28template <typename T>
29AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void vec_normalize(T* x)
30{
31 static_assert(
32 AMREX_SPACEDIM == 3, "Vector ops only defined for AMREX_SPACEDIM == 3");
33 const T inv_mag = 1.0 / vec_mag(x);
34 x[0] *= inv_mag;
35 x[1] *= inv_mag;
36 x[2] *= inv_mag;
37}
38
39template <typename T>
40AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T
41dot_prod(const T* x, const T* y, const int ndim)
42{
43 T sum = 0.0;
44 for (int i = 0; i < ndim; ++i) {
45 sum += x[i] * y[i];
46 }
47 return sum;
48}
49
52template <typename T>
53AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void
54cross_prod(const T* a, const T* b, T* c)
55{
56 static_assert(
57 AMREX_SPACEDIM == 3, "Vector ops only defined for AMREX_SPACEDIM == 3");
58 c[0] = a[1] * b[2] - a[2] * b[1];
59 c[1] = a[2] * b[0] - a[0] * b[2];
60 c[2] = a[0] * b[1] - a[1] * b[0];
61}
62
65template <typename T>
66AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transform_vec(
67 const amrex::Array2D<T, 0, AMREX_SPACEDIM, 0, AMREX_SPACEDIM>& tmat,
68 const T* x,
69 T* y)
70{
71 static_assert(
72 AMREX_SPACEDIM == 3, "Vector ops only defined for AMREX_SPACEDIM == 3");
73 y[0] = tmat(0, 0) * x[0] + tmat(0, 1) * x[1] + tmat(0, 2) * x[2];
74 y[1] = tmat(1, 0) * x[0] + tmat(1, 1) * x[1] + tmat(1, 2) * x[2];
75 y[2] = tmat(2, 0) * x[0] + tmat(2, 1) * x[1] + tmat(2, 2) * x[2];
76}
77
80template <typename T>
81AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void inv_transform_vec(
82 const amrex::Array2D<T, 0, AMREX_SPACEDIM, 0, AMREX_SPACEDIM>& tmat,
83 const T* x,
84 T* y)
85{
86 static_assert(
87 AMREX_SPACEDIM == 3, "Vector ops only defined for AMREX_SPACEDIM == 3");
88 y[0] = tmat(0, 0) * x[0] + tmat(1, 0) * x[1] + tmat(2, 0) * x[2];
89 y[1] = tmat(0, 1) * x[0] + tmat(1, 1) * x[1] + tmat(2, 1) * x[2];
90 y[2] = tmat(0, 2) * x[0] + tmat(1, 2) * x[1] + tmat(2, 2) * x[2];
91}
92
93} // namespace amr_wind::utils
94
95#endif /* TENSOR_OPS_H */
Definition MultiParser.H:7
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void vec_normalize(T *x)
Definition tensor_ops.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T dot_prod(const T *x, const T *y)
Definition tensor_ops.H:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void cross_prod(const T *a, const T *b, T *c)
Definition tensor_ops.H:54
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T vec_mag(const T *x)
Definition tensor_ops.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void inv_transform_vec(const amrex::Array2D< T, 0, AMREX_SPACEDIM, 0, AMREX_SPACEDIM > &tmat, const T *x, T *y)
Definition tensor_ops.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transform_vec(const amrex::Array2D< T, 0, AMREX_SPACEDIM, 0, AMREX_SPACEDIM > &tmat, const T *x, T *y)
Definition tensor_ops.H:66