slm: OpenCL code base  0.1
Functions
Utility functions

Functions used frequently by kernels. More...

Functions

static float2 speed_interpolator (float2 vec, __global const float2 *uv_array)
 Bilinearly interpolate a velocity vector (choice of row-major or column-major arrays). More...
 
static uint get_array_idx (float2 vec)
 Compute the array index of the padded grid pixel pointed to by a float2 grid position vector (choice of row-major or column-major arrays). More...
 
static char2 compress (float2 raw_vector)
 Squish a float vector into a byte vector for O(<1 pixel) trajectory steps Achieved through scaling by TRAJECTORY_RESOLUTION, e.g. More...
 
static float2 uncompress (char2 compressed_vector)
 Unsquish a byte vector back to a float vector. More...
 
static float2 approximate (float2 raw_position)
 Approximate a float vector at the resolution provided by a scaled byte vector. More...
 
static float dt_to_nearest_edge (float x, float u)
 In Euler streamline integration (which is the last step), this function provides the delta time required to reach the boundary precisely in one hop. More...
 
static uint lehmer_rand_uint (uint *rng_state)
 Generate a Lehmer (linear congruential) integer random variate. More...
 
static float2 lehmer_rand_vec (uint *rng_state)
 Generate a Lehmer RNG float2 vector random variate \([-0.5,0.5)\times 2\). More...
 

Detailed Description

Functions used frequently by kernels.

Function Documentation

◆ approximate()

static float2 approximate ( float2  raw_position)
static

Approximate a float vector at the resolution provided by a scaled byte vector.

Do this by compressing and then uncompressing at the TRAJECTORY_RESOLUTION, which is usually 128. This function is useful in trajectory step integration to make sure that the progressively recorded, total trajectory length matches the reduced resolution trajectory step sequence.

Parameters
[in]raw_position(float2): vector (trajectory step) to be approximated
Return values
float2reduced-resolution vector

Definition at line 164 of file essentials.cl.

◆ compress()

static char2 compress ( float2  raw_vector)
static

Squish a float vector into a byte vector for O(<1 pixel) trajectory steps Achieved through scaling by TRAJECTORY_RESOLUTION, e.g.

x128, and being content with 1/TRAJECTORY_RESOLUTION resolution.

Parameters
[in]raw_vector(float2): vector (trajectory step) to be compressed
Return values
char2vector (trajectory step) in compressed (byte,byte) form

Definition at line 131 of file essentials.cl.

◆ dt_to_nearest_edge()

static float dt_to_nearest_edge ( float  x,
float  u 
)
inlinestatic

In Euler streamline integration (which is the last step), this function provides the delta time required to reach the boundary precisely in one hop.

Parameters
[in]x(float): position vector (the current point on the trajectory)
[in]u(float): flow speed vector (to be integrated to the grid boundary)
Return values
floatdelta time that will integrate the flow vector onto the boundary

Definition at line 181 of file essentials.cl.

◆ get_array_idx()

static uint get_array_idx ( float2  vec)
inlinestatic

Compute the array index of the padded grid pixel pointed to by a float2 grid position vector (choice of row-major or column-major arrays).

#ifdef C_ORDER: Assumes a C-order, row-major, last-index-fastest array type.

Parameters
[in]vec(float2 *, RO): real-valued vector position (x,y)
Returns
padded grid array index at position vec (x,y)

#ifdef F_ORDER: Assumes a Fortran-order, column-major, first-index-fastest array type.

Parameters
[in]vec(float2 *, RO): real-valued vector position (x,y)
Returns
padded grid array index at position vec (x,y)

Definition at line 62 of file essentials.cl.

◆ lehmer_rand_uint()

static uint lehmer_rand_uint ( uint *  rng_state)
static

Generate a Lehmer (linear congruential) integer random variate.

The revised Park & Miller (1998) version is implemented here. Refer to the Wikipedia page about this RNG for more information.

The passed-in rng_state variable acts as a seed and a container to return the subsequent state of the RNG aka the 32-bit unsigned integer random variate. 64-bit arithmetic required to avoid overflow, although more labored 32-bit versions exist. The generator parameter used here is the prime modulus \(2^{32}-5\).

Parameters
[in,out]rng_statepointer to the RNG state which is also the current integer variate
Return values
uintvalue of random 32-bit integer aka RNG state

Definition at line 37 of file rng.cl.

◆ lehmer_rand_vec()

static float2 lehmer_rand_vec ( uint *  rng_state)
static

Generate a Lehmer RNG float2 vector random variate \([-0.5,0.5)\times 2\).

The passed-in rng_state variable acts as a seed and a container to return the subsequent state of the RNG. The float2 vector random variate is returned explicitly.

Parameters
[in,out]rng_statepointer to the RNG state which is also the current integer variate
Return values
float2two random 32-bit float values each \([-0.5,0.5)\) as a float2 vector

Definition at line 62 of file rng.cl.

◆ speed_interpolator()

static float2 speed_interpolator ( float2  vec,
__global const float2 *  uv_array 
)
static

Bilinearly interpolate a velocity vector (choice of row-major or column-major arrays).

Perform a fast, simple bilinear interpolation at arbitrary position vector from regular grid of velocity vectors in global uv_array with ordering type set by macro definitions C_ORDER or F_ORDER.

#ifdef C_ORDER: Assumes a C-order, row-major, last-index-fastest array type.

Parameters
[in]vec(float2 *, RO): real-valued vector position (x,y) onto which to interpolate (u,v)
[in]uv_array(float *, RO): gridded velocity vector components (u,v)
Returns
normalized velocity vector (u,v) sampled at position vec (x,y)

#ifdef F_ORDER: Assumes a Fortran-order, column-major, first-index-fastest array type.

Parameters
[in]vec(float2 *, RO): real-valued vector position (x,y) onto which to interpolate (u,v)
[in]uv_array(float *, RO): gridded velocity vector components (u,v)
Returns
normalized velocity vector (u,v) at position vec (x,y)

Definition at line 28 of file essentials.cl.

◆ uncompress()

static float2 uncompress ( char2  compressed_vector)
static

Unsquish a byte vector back to a float vector.

Used in connect_channels() to unpack a streamline trajectory.

Parameters
[in]compressed_vector(char2): vector (trajectory step) in compressed (byte,byte) form
Return values
float2uncompressed vector (trajectory step)

Definition at line 146 of file essentials.cl.