ASCOT5
Loading...
Searching...
No Matches
wall_2d.c File Reference

2D wall collision checks More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../ascot5.h"
#include "../print.h"
#include "wall_2d.h"

Go to the source code of this file.

Functions

int wall_2d_init (wall_2d_data *data, int nelements, real *r, real *z)
 Load 2D wall data and prepare parameters.
 
void wall_2d_free (wall_2d_data *data)
 Free allocated resources.
 
void wall_2d_offload (wall_2d_data *data)
 Offload data to the accelerator.
 
int wall_2d_inside (real r, real z, wall_2d_data *w)
 Check if coordinates are within 2D polygon wall.
 
int wall_2d_hit_wall (real r1, real phi1, real z1, real r2, real phi2, real z2, wall_2d_data *w, real *w_coll)
 Check if trajectory from (r1, phi1, z1) to (r2, phi2, z2) intersects the wall.
 
int wall_2d_find_intersection (real r1, real z1, real r2, real z2, wall_2d_data *w, real *w_coll)
 Find intersection between the wall element and line segment.
 

Detailed Description

2D wall collision checks

Definition in file wall_2d.c.

Function Documentation

◆ wall_2d_init()

int wall_2d_init ( wall_2d_data * data,
int nelements,
real * r,
real * z )

Load 2D wall data and prepare parameters.

Parameters
datapointer to the data struct
nelementsnumber of elements in the wall polygon
rR coordinates for the wall polygon points
zz coordinates for the wall polygon points
Returns
zero to indicate success

Definition at line 22 of file wall_2d.c.

◆ wall_2d_free()

void wall_2d_free ( wall_2d_data * data)

Free allocated resources.

Parameters
datapointer to the data struct

Definition at line 50 of file wall_2d.c.

◆ wall_2d_offload()

void wall_2d_offload ( wall_2d_data * data)

Offload data to the accelerator.

Parameters
datapointer to the data struct

Definition at line 60 of file wall_2d.c.

◆ wall_2d_inside()

int wall_2d_inside ( real r,
real z,
wall_2d_data * w )

Check if coordinates are within 2D polygon wall.

This function checks if the given coordinates are within the walls defined by a 2D polygon using a modified axis crossing method [1]. Origin is moved to the coordinates and the number of wall segments crossing the positive r-axis are calculated. If this is odd, the point is inside the polygon.

[1] D.G. Alciatore, R. Miranda. A Winding Number and Point-in-Polygon Algorithm. Technical report, Colorado State University, 1995. https://www.engr.colostate.edu/~dga/documents/papers/point_in_polygon.pdf

Parameters
rr coordinate [m]
zz coordinate [m]
w2D wall data structure

Definition at line 83 of file wall_2d.c.

◆ wall_2d_hit_wall()

int wall_2d_hit_wall ( real r1,
real phi1,
real z1,
real r2,
real phi2,
real z2,
wall_2d_data * w,
real * w_coll )

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

Parameters
r1start point R coordinate [m]
phi1start point phi coordinate [rad]
z1start point z coordinate [m]
r2end point R coordinate [m]
phi2end point phi coordinate [rad]
z2end point z coordinate [m]
wpointer 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
wall element ID if hit, zero otherwise

Definition at line 124 of file wall_2d.c.

◆ wall_2d_find_intersection()

int wall_2d_find_intersection ( real r1,
real z1,
real r2,
real z2,
wall_2d_data * w,
real * w_coll )

Find intersection between the wall element and line segment.

If there are multiple intersections, the one that is closest to P1 is returned.

Parameters
r1R1 coordinate of the line segment [P1,P2] [m]
z1z1 coordinate of the line segment [P1,P2] [m]
r2R2 coordinate of the line segment [P1,P2] [m]
z2z2 coordinate of the line segment [P1,P2] [m]
wpointer to the wall data
w_collpointer for storing the parameter in P = P1 + w_coll * (P2-P1), where P is the point where the collision occurred.
Returns
int wall element id if hit, zero otherwise

Definition at line 149 of file wall_2d.c.