ASCOT5
|
3D wall collision checks More...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../ascot5.h"
#include "wall_3d.h"
#include "../list.h"
#include "../octree.h"
#include "../print.h"
Go to the source code of this file.
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 (wall_3d_data *w, wall_3d_offload_data *offload_data, real *offload_array, int *int_offload_array) |
Initialize wall data struct on target. | |
void | wall_3d_init_tree (wall_3d_data *w, real *offload_array) |
Construct wall octree iteratively. | |
void | wall_3d_init_octree (wall_3d_offload_data *w, real *offload_array, int **tree_array) |
Construct wall octree recursively. | |
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. | |
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. | |
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. | |
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. | |
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) | |
3D wall collision checks
3D wall model where wall consists of small triangles that form a surface mesh. A wall collision happens when a marker intersects a wall triangle's plane. During initialization, the computational model is divided into smaller cell using octree, and wall triangles are divided according to which cell(s) they inhabit. Collision checks are only made with respect to triangles that are in the same cell as the marker.
Definition in file wall_3d.c.
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.
offload_data | pointer to offload data struct |
offload_array | pointer to offload array |
int_offload_array | pointer to offload array containing integers |
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.
offload_data | pointer to offload data struct |
offload_array | pointer to offload array |
int_offload_array | pointer to offload array containing integers |
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.
w | pointer to data struct on target |
offload_data | pointer to offload data struct |
offload_array | offload array |
int_offload_array | offload array containing integers |
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.
w | pointer to wall data |
offload_array | offload array |
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
w | pointer to wall data |
offload_array | the offload array |
tree_array | pointer to array storing what octree cells contain which triangles |
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.
r1 | start point R coordinate [m] |
phi1 | start point phi coordinate [rad] |
z1 | start point z coordinate [rad] |
r2 | end point R coordinate [m] |
phi2 | end point phi coordinate [rad] |
z2 | end point z coordinate [rad] |
wdata | pointer to data struct on target |
w_coll | pointer for storing the parameter in P = P1 + w_coll * (P2-P1), where P is the point where the collision occurred. |
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.
r1 | start point R coordinate [m] |
phi1 | start point phi coordinate [rad] |
z1 | start point z coordinate [rad] |
r2 | end point R coordinate [m] |
phi2 | end point phi coordinate [rad] |
z2 | end point z coordinate [rad] |
wdata | pointer to data struct on target |
w_coll | pointer for storing the parameter in P = P1 + w_coll * (P2-P1), where P is the point where the collision occurred. |
Check if any part of a triangle is inside a box.
t1 | xyz coordinates of first triangle vertex [m] |
t2 | xyz coordinates of second triangle vertex [m] |
t3 | xyz coordinates of third triangle vertex [m] |
bb1 | bounding box minimum xyz coordinates [m] |
bb2 | bounding box maximum xyz coordinates [m] |
Check if a line segment intersects a triangle.
This routine implements the Möller-Trumbore algorithm.
q1 | line segment start point xyz coordinates [m] |
q2 | line segment end point xyz coordinates [m] |
t1 | xyz coordinates of first triangle vertex [m] |
t2 | xyz coordinates of second triangle vertex [m] |
t3 | xyz coordinates of third triangle vertex [m] |
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)
q1 | line segment start point xyz coordinates [m] |
q2 | line segment end point xyz coordinates [m] |
t1 | xyz coordinates of first quad vertex [m] |
t2 | xyz coordinates of second quad vertex [m] |
t3 | xyz coordinates of third quad vertex [m] |
t4 | xyz coordinates of fourth quad vertex [m] |