Contains various functions for common mathematical operations.
More...
#include <cmath>
#include <tuple>
#include "../global/global.h"
#include "../global/global_cuda.h"
#include "../utils/basic_structs.h"
#include "../utils/gpu.hpp"
Go to the source code of this file.
|
| template<typename T > |
| std::tuple< T, T, T > | math_utils::rotateCoords (Real const &x_1, Real const &x_2, Real const &x_3, Real const &pitch, Real const &yaw) |
| | Rotate cartesian coordinates. All arguments are cast to double then rotated. If the type is 'int' then the value is rounded to the nearest int.
|
| |
| __device__ __host__ Real | math_utils::dotProduct (Real const &a1, Real const &a2, Real const &a3, Real const &b1, Real const &b2, Real const &b3) |
| | Compute the dot product of a and b.
|
| |
| __device__ __host__ Real | math_utils::SquareMagnitude (Real const &v1, Real const &v2, Real const &v3) |
| | Compute the magnitude of a vector.
|
| |
| __device__ __host__ void | math_utils::Cyclic_Permute_Once (hydro_utilities::VectorXYZ< Real > &vec) |
| | Cyclically permute a Vector once. i.e. (x,y,z) becomes (y,z,x)
|
| |
| __device__ __host__ void | math_utils::Cyclic_Permute_Twice (hydro_utilities::VectorXYZ< Real > &vec) |
| | Cyclically permute a Vector twice. i.e. (x,y,z) becomes (z,x,y)
|
| |
| template<typename T > |
| __device__ __host__ T | math_utils::clamp (T val, T lo, T hi) |
| | When val lies within the inclusive range [lo, hi], returns val. Otherwise, return the closest value in the range.
|
| |
Contains various functions for common mathematical operations.
- Author
- Robert 'Bob' Caddy (rvc@p.nosp@m.itt..nosp@m.edu)
◆ clamp()
template<typename T >
| __device__ __host__ T math_utils::clamp |
( |
T |
val, |
|
|
T |
lo, |
|
|
T |
hi |
|
) |
| |
When val lies within the inclusive range [lo, hi], returns val. Otherwise, return the closest value in the range.
- Warning
- The behavior is undefined when
lo>hi or any of the values are std::nan.
- Note
- Instead of using this implementation, we may be able to use
std::clamp (unclear if supported by CUDA/Rocm). We could also consider using CUDA/Rocm intrinsics to speed this up
◆ Cyclic_Permute_Once()
Cyclically permute a Vector once. i.e. (x,y,z) becomes (y,z,x)
- Parameters
-
| [in,out] | vec | The vector to permute |
◆ Cyclic_Permute_Twice()
Cyclically permute a Vector twice. i.e. (x,y,z) becomes (z,x,y)
- Parameters
-
| [in,out] | vec | The vector to permute |
◆ dotProduct()
| __device__ __host__ Real math_utils::dotProduct |
( |
Real const & |
a1, |
|
|
Real const & |
a2, |
|
|
Real const & |
a3, |
|
|
Real const & |
b1, |
|
|
Real const & |
b2, |
|
|
Real const & |
b3 |
|
) |
| |
|
inline |
Compute the dot product of a and b.
- Parameters
-
| [in] | a1 | The first element of a |
| [in] | a2 | The second element of a |
| [in] | a3 | The third element of a |
| [in] | b1 | The first element of b |
| [in] | b2 | The second element of b |
| [in] | b3 | The third element of b |
- Returns
- Real The dot product of a and b
◆ rotateCoords()
template<typename T >
| std::tuple< T, T, T > math_utils::rotateCoords |
( |
Real const & |
x_1, |
|
|
Real const & |
x_2, |
|
|
Real const & |
x_3, |
|
|
Real const & |
pitch, |
|
|
Real const & |
yaw |
|
) |
| |
|
inline |
Rotate cartesian coordinates. All arguments are cast to double then rotated. If the type is 'int' then the value is rounded to the nearest int.
Rotation such that when pitch=90 and yaw=0 x1_rot = -x3 and when pitch=0 and yaw=90 x1_rot = -x2
- Template Parameters
-
- Parameters
-
| [in] | x_1 | x1 coordinate |
| [in] | x_2 | x2 coordinate |
| [in] | x_3 | x3 coordinate |
| [in] | pitch | Pitch angle in radians |
| [in] | yaw | Yaw angle in radians |
- Returns
- std::tuple<T, T, T> The new, rotated, coordinates in the order <x1, x2, x2>. Intended to be captured with structured binding
◆ SquareMagnitude()
| __device__ __host__ Real math_utils::SquareMagnitude |
( |
Real const & |
v1, |
|
|
Real const & |
v2, |
|
|
Real const & |
v3 |
|
) |
| |
|
inline |
Compute the magnitude of a vector.
- Parameters
-
| [in] | v1 | The first element of the vector |
| [in] | v2 | The second element of the vector |
| [in] | v3 | The third element of the vector |
- Returns
- Real The dot product of a and b