Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
Functions
math_utilities.h File Reference

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"
Include dependency graph for math_utilities.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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.
 

Detailed Description

Contains various functions for common mathematical operations.

Author
Robert 'Bob' Caddy (rvc@p.nosp@m.itt..nosp@m.edu)

Function Documentation

◆ clamp()

template<typename T >
__device__ __host__ T math_utils::clamp ( val,
lo,
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()

__device__ __host__ void math_utils::Cyclic_Permute_Once ( hydro_utilities::VectorXYZ< Real > &  vec)
inline

Cyclically permute a Vector once. i.e. (x,y,z) becomes (y,z,x)

Parameters
[in,out]vecThe vector to permute

◆ Cyclic_Permute_Twice()

__device__ __host__ void math_utils::Cyclic_Permute_Twice ( hydro_utilities::VectorXYZ< Real > &  vec)
inline

Cyclically permute a Vector twice. i.e. (x,y,z) becomes (z,x,y)

Parameters
[in,out]vecThe 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]a1The first element of a
[in]a2The second element of a
[in]a3The third element of a
[in]b1The first element of b
[in]b2The second element of b
[in]b3The 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
TThe return type
Parameters
[in]x_1x1 coordinate
[in]x_2x2 coordinate
[in]x_3x3 coordinate
[in]pitchPitch angle in radians
[in]yawYaw 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]v1The first element of the vector
[in]v2The second element of the vector
[in]v3The third element of the vector
Returns
Real The dot product of a and b