ASCOT5
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
wall_3d.h File Reference

Header file for wall_3d.c. More...

#include "../ascot5.h"
#include "../offload_acc_omp.h"

Go to the source code of this file.

Data Structures

struct  wall_3d_offload_data
 3D wall offload data More...
 
struct  wall_3d_data
 3D wall data parameters More...
 

Macros

#define WALL_EPSILON   1e-9
 

Functions

int wall_3d_init_offload (wall_3d_offload_data *offload_data, real **offload_array, int **int_offload_array)
 Initialize 3D wall data and check inputs.
 
void wall_3d_free_offload (wall_3d_offload_data *offload_data, real **offload_array, int **int_offload_array)
 Free offload array and reset parameters.
 
void wall_3d_init_octree (wall_3d_offload_data *w, real *offload_array, int **int_offload_array)
 Construct wall octree recursively.
 
void wall_3d_init (wall_3d_data *w, wall_3d_offload_data *offload_data, real *offload_array, int *int_offload_array)
 Initialize wall data struct on target.
 
int wall_3d_hit_wall (real r1, real phi1, real z1, real r2, real phi2, real z2, wall_3d_data *w, real *w_coll)
 Check if trajectory from (r1, phi1, z1) to (r2, phi2, z2) intersects the wall using the octree structure.
 
DECLARE_TARGET_END int wall_3d_hit_wall_full (real r1, real phi1, real z1, real r2, real phi2, real z2, wall_3d_data *w, real *w_coll)
 Check if trajectory from (r1, phi1, z1) to (r2, phi2, z2) intersects the wall against all triangles.
 
DECLARE_TARGET_END GPU_DECLARE_TARGET_SIMD double wall_3d_tri_collision (real q1[3], real q2[3], real t1[3], real t2[3], real t3[3])
 Check if a line segment intersects a triangle.
 
DECLARE_TARGET_END DECLARE_TARGET void wall_3d_init_tree (wall_3d_data *w, real *offload_array)
 Construct wall octree iteratively.
 
DECLARE_TARGET_END DECLARE_TARGET int wall_3d_tri_in_cube (real t1[3], real t2[3], real t3[3], real bb1[3], real bb2[3])
 Check if any part of a triangle is inside a box.
 
DECLARE_TARGET_END DECLARE_TARGET int wall_3d_quad_collision (real q1[3], real q2[3], real t1[3], real t2[3], real t3[3], real t4[3])
 Check if a line segment intersects a quad (assumed planar)
 

Detailed Description

Header file for wall_3d.c.

Definition in file wall_3d.h.

Macro Definition Documentation

◆ WALL_EPSILON

#define WALL_EPSILON   1e-9

Small value to check if x = 0 (i.e. abs(x) < WALL_EPSILON)

Definition at line 11 of file wall_3d.h.

Function Documentation

◆ wall_3d_init_offload()

int wall_3d_init_offload ( wall_3d_offload_data * offload_data,
real ** offload_array,
int ** int_offload_array )

Initialize 3D wall data and check inputs.

Before calling this function, the offload struct is expected to hold triangle positions as

[x1_1, y1_1, z1_1, x2_1, y2_1, z2_1, x3_1, y3_1, z3_1,... ],

where first index is for the triangle vertex and second for the triangle itself.

This function fill rest of the offload struct and constructs the octree, while also printing some values as sanity check.

The default octree depth is defined by macro WALL_OCTREE_DEPTH in wall_3d.h.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to offload array
int_offload_arraypointer to offload array containing integers
Returns
zero if initialization succeeded

Definition at line 44 of file wall_3d.c.

◆ wall_3d_free_offload()

void wall_3d_free_offload ( wall_3d_offload_data * offload_data,
real ** offload_array,
int ** int_offload_array )

Free offload array and reset parameters.

This function deallocates the offload_array.

This function is host only.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to offload array
int_offload_arraypointer to offload array containing integers

Definition at line 110 of file wall_3d.c.

◆ wall_3d_init_octree()

void wall_3d_init_octree ( wall_3d_offload_data * w,
real * offload_array,
int ** tree_array )

Construct wall octree recursively.

Constructs the octree array by iterating through all wall triangles and placing them into an octree structure

Parameters
wpointer to wall data
offload_arraythe offload array
tree_arraypointer to array storing what octree cells contain which triangles

Definition at line 242 of file wall_3d.c.

◆ wall_3d_init()

void wall_3d_init ( wall_3d_data * w,
wall_3d_offload_data * offload_data,
real * offload_array,
int * int_offload_array )

Initialize wall data struct on target.

This function copies the wall parameters from the offload struct to the struct on target and sets the wall data pointers to correct offsets in the offload array.

Parameters
wpointer to data struct on target
offload_datapointer to offload data struct
offload_arrayoffload array
int_offload_arrayoffload array containing integers

Definition at line 131 of file wall_3d.c.

◆ wall_3d_hit_wall()

int wall_3d_hit_wall ( real r1,
real phi1,
real z1,
real r2,
real phi2,
real z2,
wall_3d_data * wdata,
real * w_coll )

Check if trajectory from (r1, phi1, z1) to (r2, phi2, z2) intersects the wall using the octree structure.

Parameters
r1start point R coordinate [m]
phi1start point phi coordinate [rad]
z1start point z coordinate [rad]
r2end point R coordinate [m]
phi2end point phi coordinate [rad]
z2end point z coordinate [rad]
wdatapointer to data struct on target
w_collpointer for storing the parameter in P = P1 + w_coll * (P2-P1), where P is the point where the collision occurred.
Returns
id, which is the first element id if hit, zero otherwise

Definition at line 339 of file wall_3d.c.

◆ wall_3d_hit_wall_full()

DECLARE_TARGET_END int wall_3d_hit_wall_full ( real r1,
real phi1,
real z1,
real r2,
real phi2,
real z2,
wall_3d_data * wdata,
real * w_coll )

Check if trajectory from (r1, phi1, z1) to (r2, phi2, z2) intersects the wall against all triangles.

Parameters
r1start point R coordinate [m]
phi1start point phi coordinate [rad]
z1start point z coordinate [rad]
r2end point R coordinate [m]
phi2end point phi coordinate [rad]
z2end point z coordinate [rad]
wdatapointer to data struct on target
w_collpointer for storing the parameter in P = P1 + w_coll * (P2-P1), where P is the point where the collision occurred.
Returns
id is wall element id if hit, zero otherwise*

Definition at line 419 of file wall_3d.c.

◆ wall_3d_tri_collision()

DECLARE_TARGET_END GPU_DECLARE_TARGET_SIMD double wall_3d_tri_collision ( real q1[3],
real q2[3],
real t1[3],
real t2[3],
real t3[3] )

Check if a line segment intersects a triangle.

This routine implements the Möller-Trumbore algorithm.

Parameters
q1line segment start point xyz coordinates [m]
q2line segment end point xyz coordinates [m]
t1xyz coordinates of first triangle vertex [m]
t2xyz coordinates of second triangle vertex [m]
t3xyz coordinates of third triangle vertex [m]
Returns
A positive number w which is defined so that vector q1 + w*(q2-q1) is the intersection point. A negative number is returned if no there is no intersection

Definition at line 544 of file wall_3d.c.

◆ wall_3d_init_tree()

DECLARE_TARGET_END DECLARE_TARGET void wall_3d_init_tree ( wall_3d_data * w,
real * offload_array )

Construct wall octree iteratively.

Constructs the octree array by iterating through all wall triangles and octree grid to identify triangles belonging to each grid cell.

Slow, only for testing purposes.

Parameters
wpointer to wall data
offload_arrayoffload array

Definition at line 162 of file wall_3d.c.

◆ wall_3d_tri_in_cube()

DECLARE_TARGET_END DECLARE_TARGET int wall_3d_tri_in_cube ( real t1[3],
real t2[3],
real t3[3],
real bb1[3],
real bb2[3] )

Check if any part of a triangle is inside a box.

Parameters
t1xyz coordinates of first triangle vertex [m]
t2xyz coordinates of second triangle vertex [m]
t3xyz coordinates of third triangle vertex [m]
bb1bounding box minimum xyz coordinates [m]
bb2bounding box maximum xyz coordinates [m]
Returns
zero if not any part of the triangle is within the box

Definition at line 464 of file wall_3d.c.

◆ wall_3d_quad_collision()

DECLARE_TARGET_END DECLARE_TARGET int wall_3d_quad_collision ( real q1[3],
real q2[3],
real t1[3],
real t2[3],
real t3[3],
real t4[3] )

Check if a line segment intersects a quad (assumed planar)

Parameters
q1line segment start point xyz coordinates [m]
q2line segment end point xyz coordinates [m]
t1xyz coordinates of first quad vertex [m]
t2xyz coordinates of second quad vertex [m]
t3xyz coordinates of third quad vertex [m]
t4xyz coordinates of fourth quad vertex [m]
Returns
Zero if no intersection, positive number otherwise

Definition at line 619 of file wall_3d.c.