slm: OpenCL code base  0.1
Functions
Trajectory stepping and recording functions

Functions to carry out Runge-Kutta integration steps along streamlines & record them. More...

Functions

static void compute_step_vec (const float dt, const __global float2 *uv_array, float2 *dxy1_vec, float2 *dxy2_vec, float2 *uv1_vec, float2 *uv2_vec, const float2 vec, float2 *next_vec, uint *idx)
 Compute a 2nd-order Runge-Kutta integration step along a streamline. More...
 
static void compute_step_vec_jittered (const float dt, const __global float2 *uv_array, uint *rng_state, float2 *dxy1_vec, float2 *dxy2_vec, float2 *uv1_vec, float2 *uv2_vec, const float2 vec, float2 *next_vec, uint *idx)
 Compute a jittered 2nd-order Runge-Kutta integration step along a streamline. More...
 
static void update_record_trajectory_write_sl_data (const float dl, float *l_trajectory, const float2 vec, const float2 prev_vec, uint *n_steps, uint *idx, uint *prev_idx, __global char2 *trajectory_vec, __global const bool *mask_array, __global uint *slt_array, __global uint *slc_array)
 Update variables tracking trajectory length and integration step counter. More...
 
static void update_trajectory_write_sl_data (float dl, float *l_trajectory, float2 vec, float2 prev_vec, uint *n_steps, uint *idx, uint *prev_idx, __global const bool *mask_array, __global uint *slt_array, __global uint *slc_array)
 Update variables tracking trajectory length and integration step counter. More...
 
static void update_record_trajectory (float dl, float *l_trajectory, float2 vec, float2 prev_vec, uint *n_steps, __global char2 *trajectory_vec)
 Update variables tracking trajectory length and integration step counter. More...
 
static void update_record_private_trajectory (float dl, float *l_trajectory, float2 vec, float2 prev_vec, uint *n_steps, __private char2 *trajectory_vec)
 Update variables tracking trajectory length and integration step counter. More...
 
static void update_trajectory (float dl, float *l_trajectory, uint *n_steps)
 Update variables tracking trajectory length and integration step counter. More...
 
static void finalize_trajectory (const uint global_id, uint n_steps, float l_trajectory, __global ushort *traj_nsteps_array, __global float *traj_length_array)
 Record the (final) trajectory length and count of integration steps to global arrays traj_length_array and traj_nsteps_array respectively. More...
 
static void atomic_write_sl_data (__global uint *slt, __global uint *slc, const float l_trajectory)
 Add the current streamline length (l_trajectory) to the current pixel of the slt accumulation array. More...
 
static void check_atomic_write_sl_data (const uint idx, uint *prev_idx, const bool mask_flag, __global uint *slt, __global uint *slc, const float l_trajectory)
 Extended version of atomic_write_sl_data() to include testing whether the current pixel is masked, and an assignment of the previous pixel index to the current pixel index. More...
 

Detailed Description

Functions to carry out Runge-Kutta integration steps along streamlines & record them.

Function Documentation

◆ atomic_write_sl_data()

static void atomic_write_sl_data ( __global uint *  slt,
__global uint *  slc,
const float  l_trajectory 
)
inlinestatic

Add the current streamline length (l_trajectory) to the current pixel of the slt accumulation array.

Similarly, increment the streamline count at the current pixel of the slc accumulation array. Atomic operations are used since several kernel instances may need to write to the same pixel effectively simultaneously.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in,out]slcgrid recording accumulated count of streamline integration steps across each pixel (padded)
[in,out]sltgrid recording accumulated count of streamline segment lengths crossing each pixel (padded)
[in]l_trajectorytotal streamline distance so far
Returns
void

Definition at line 31 of file writearray.cl.

◆ check_atomic_write_sl_data()

static void check_atomic_write_sl_data ( const uint  idx,
uint *  prev_idx,
const bool  mask_flag,
__global uint *  slt,
__global uint *  slc,
const float  l_trajectory 
)
inlinestatic

Extended version of atomic_write_sl_data() to include testing whether the current pixel is masked, and an assignment of the previous pixel index to the current pixel index.

Add the current streamline length (l_trajectory) to the current pixel of the slt accumulation array. Similarly, increment the streamline count at the current pixel of the slc accumulation array. Atomic operations are used since several kernel instances may need to write to the same pixel effectively simultaneously.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]idxarray index of pixel at current (x,y) position
[in,out]prev_idxarray index of pixel at previous (x,y) position
[in]mask_flagwhether current pixel is masked or not
[in,out]slcgrid recording accumulated count of streamline integration steps across each pixel (padded)
[in,out]sltgrid recording accumulated count of streamline segment lengths crossing each pixel (padded)
[in]l_trajectorytotal streamline distance so far
Returns
void

Definition at line 71 of file writearray.cl.

◆ compute_step_vec()

static void compute_step_vec ( const float  dt,
const __global float2 *  uv_array,
float2 *  dxy1_vec,
float2 *  dxy2_vec,
float2 *  uv1_vec,
float2 *  uv2_vec,
const float2  vec,
float2 *  next_vec,
uint *  idx 
)
inlinestatic

Compute a 2nd-order Runge-Kutta integration step along a streamline.

Compiled if any of the following are defined:

  • KERNEL_INTEGRATE_TRAJECTORY
  • KERNEL_CONNECT_CHANNELS
  • KERNEL_MAP_CHANNEL_HEADS
  • KERNEL_COUNT_DOWNCHANNELS
  • KERNEL_LINK_HILLSLOPES
  • KERNEL_SEGMENT_HILLSLOPES
  • KERNEL_SUBSEGMENT_FLANKS
  • KERNEL_HILLSLOPE_LENGTHS
Parameters
[in]dtdelta time step
[in]uv_array(float *, RO): gridded velocity vector components (u,v)
[in,out]dxy1_vecR-K first order delta step vector
[in,out]dxy2_vecR-K second order delta step vector
[in,out]uv1_vecflow velocity vector at current coordinate (at vec)
[in,out]uv2_vecflow velocity vector at RK1 stepped coordinate (at vec + dxy1_vec)
[in]veccurrent (x,y) coordinate vector at tip of streamline trajectory
[in,out]next_vecnext (x,y) coordinate vector on streamline trajectory
[in,out]idxarray index of pixel at current (x,y) position
Returns
void

Definition at line 41 of file computestep.cl.

◆ compute_step_vec_jittered()

static void compute_step_vec_jittered ( const float  dt,
const __global float2 *  uv_array,
uint *  rng_state,
float2 *  dxy1_vec,
float2 *  dxy2_vec,
float2 *  uv1_vec,
float2 *  uv2_vec,
const float2  vec,
float2 *  next_vec,
uint *  idx 
)
inlinestatic

Compute a jittered 2nd-order Runge-Kutta integration step along a streamline.

Jittering is achieved by adding a uniform random vector to of the RK2 flow velocity vectors, then normalizing to provide two RK2 unit step vectors. The [0,1) uniform variates are scaled by JITTER_MAGNITUDE before addition to the unit flow vectors.

Compiled if KERNEL_INTEGRATE_TRAJECTORY and IS_RNG_AVAILABLE is defined.

Parameters
[in]dtdelta time step
[in]uv_array(float *, RO): gridded velocity vector components (u,v)
[in,out]rng_stateRNG state (thus initally the seed) and RNG variate
[in,out]dxy1_vecR-K first order delta step vector
[in,out]dxy2_vecR-K second order delta step vector
[in,out]uv1_vecflow velocity vector at current coordinate (at vec)
[in,out]uv2_vecflow velocity vector at RK1 stepped coordinate (at vec + dxy1_vec)
[in]veccurrent (x,y) coordinate vector at tip of streamline trajectory
[in,out]next_vecnext (x,y) coordinate vector on streamline trajectory
[in,out]idxarray index of pixel at current (x,y) position
Returns
void

Definition at line 85 of file computestep.cl.

◆ finalize_trajectory()

static void finalize_trajectory ( const uint  global_id,
uint  n_steps,
float  l_trajectory,
__global ushort *  traj_nsteps_array,
__global float *  traj_length_array 
)
inlinestatic

Record the (final) trajectory length and count of integration steps to global arrays traj_length_array and traj_nsteps_array respectively.

This action takes place at the end of streamline tracing in each integration kernel instance.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]global_idID of the kernel instance
[in]n_stepsnumber of integration steps so far in streamline trajectory
[in]l_trajectorytotal streamline distance so far
[out]traj_nsteps_arraylist of number of steps along each trajectory; one per seed_point_array vector
[out]traj_length_arraylist of lengths of each trajectory; one per seed_point_array vector
Returns
void

Definition at line 213 of file trajectoryfns.cl.

◆ update_record_private_trajectory()

static void update_record_private_trajectory ( float  dl,
float *  l_trajectory,
float2  vec,
float2  prev_vec,
uint *  n_steps,
__private char2 *  trajectory_vec 
)
inlinestatic

Update variables tracking trajectory length and integration step counter.

Record (to private array) a compressed version of the current trajectory step vector.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]dlstep distance
[in,out]l_trajectorytotal streamline distance so far
[in]veccurrent (x,y) coordinate vector at tip of streamline trajectory
[in]prev_vecprevious (x,y) coordinate vector on streamline trajectory
[in,out]n_stepsnumber of integration steps so far in streamline trajectory
[in,out]trajectory_vecstreamline trajectory record (2d array of compressed (x,y) vectors)
Returns
void

Definition at line 156 of file trajectoryfns.cl.

◆ update_record_trajectory()

static void update_record_trajectory ( float  dl,
float *  l_trajectory,
float2  vec,
float2  prev_vec,
uint *  n_steps,
__global char2 *  trajectory_vec 
)
inlinestatic

Update variables tracking trajectory length and integration step counter.

Record (to global array) a compressed version of the current trajectory step vector.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]dlstep distance
[in,out]l_trajectorytotal streamline distance so far
[in]veccurrent (x,y) coordinate vector at tip of streamline trajectory
[in]prev_vecprevious (x,y) coordinate vector on streamline trajectory
[in,out]n_stepsnumber of integration steps so far in streamline trajectory
[in,out]trajectory_vecstreamline trajectory record (2d array of compressed (x,y) vectors)
Returns
void

Definition at line 125 of file trajectoryfns.cl.

◆ update_record_trajectory_write_sl_data()

static void update_record_trajectory_write_sl_data ( const float  dl,
float *  l_trajectory,
const float2  vec,
const float2  prev_vec,
uint *  n_steps,
uint *  idx,
uint *  prev_idx,
__global char2 *  trajectory_vec,
__global const bool *  mask_array,
__global uint *  slt_array,
__global uint *  slc_array 
)
inlinestatic

Update variables tracking trajectory length and integration step counter.

Record (to global array) a compressed version of the current trajectory step vector. Write length and count data to global arrays.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]dlstep distance
[in,out]l_trajectorytotal streamline distance so far
[in,out]veccurrent (x,y) coordinate vector at tip of streamline trajectory
[in,out]prev_vecprevious (x,y) coordinate vector on streamline trajectory
[in,out]n_stepsnumber of integration steps so far in streamline trajectory
[in,out]idxarray index of pixel at current (x,y) position
[in,out]prev_idxarray index of pixel at previous (x,y) position
[in,out]trajectory_vecstreamline trajectory record (2d array of compressed (x,y) vectors)
[in]mask_arraygrid pixel mask (padded), with true = masked, false = good
[in,out]slc_arraygrid recording accumulated count of streamline integration steps across each pixel (padded)
[in,out]slt_arraygrid recording accumulated count of streamline segment lengths crossing each pixel (padded)
Returns
void

Definition at line 44 of file trajectoryfns.cl.

◆ update_trajectory()

static void update_trajectory ( float  dl,
float *  l_trajectory,
uint *  n_steps 
)
inlinestatic

Update variables tracking trajectory length and integration step counter.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]dlstep distance
[in,out]l_trajectorytotal streamline distance so far
[in,out]n_stepsnumber of integration steps so far in streamline trajectory
Returns
void

Definition at line 182 of file trajectoryfns.cl.

◆ update_trajectory_write_sl_data()

static void update_trajectory_write_sl_data ( float  dl,
float *  l_trajectory,
float2  vec,
float2  prev_vec,
uint *  n_steps,
uint *  idx,
uint *  prev_idx,
__global const bool *  mask_array,
__global uint *  slt_array,
__global uint *  slc_array 
)
inlinestatic

Update variables tracking trajectory length and integration step counter.

Write length and count data to global arrays.

Compiled if KERNEL_INTEGRATE_TRAJECTORY is defined.

Parameters
[in]dlstep distance
[in,out]l_trajectorytotal streamline distance so far
[in]veccurrent (x,y) coordinate vector at tip of streamline trajectory
[in]prev_vecprevious (x,y) coordinate vector on streamline trajectory
[in,out]n_stepsnumber of integration steps so far in streamline trajectory
[in,out]idxarray index of pixel at current (x,y) position
[in,out]prev_idxarray index of pixel at previous (x,y) position
[in]mask_arraygrid pixel mask (padded), with true = masked, false = good
[in,out]slc_arraygrid recording accumulated count of streamline integration steps across each pixel (padded)
[in,out]slt_arraygrid recording accumulated count of streamline segment lengths crossing each pixel (padded)
Returns
void

Definition at line 88 of file trajectoryfns.cl.