ASCOT5
Loading...
Searching...
No Matches
wall.c
Go to the documentation of this file.
1
16#include <stdio.h>
17#include <math.h>
18#include "ascot5.h"
19#include "print.h"
20#include "wall.h"
21#include "wall/wall_2d.h"
22#include "wall/wall_3d.h"
23
42int wall_init_offload(wall_offload_data* offload_data, real** offload_array,
43 int** int_offload_array) {
44
45 int err = 0;
46
47 switch(offload_data->type) {
48
49 case wall_type_2D:
50 err = wall_2d_init_offload(&(offload_data->w2d), offload_array);
51 offload_data->offload_array_length =
52 offload_data->w2d.offload_array_length;
53 offload_data->int_offload_array_length = 0;
54 break;
55
56 case wall_type_3D:
57 err = wall_3d_init_offload(&(offload_data->w3d), offload_array,
58 int_offload_array);
59 offload_data->offload_array_length =
60 offload_data->w3d.offload_array_length;
61 offload_data->int_offload_array_length =
62 offload_data->w3d.int_offload_array_length;
63 break;
64
65 default:
66 /* Unregonized input. Produce error. */
67 print_err("Error: Unregonized electric field type.");
68 err = 1;
69 break;
70 }
71 if(!err) {
72 print_out(VERBOSE_IO, "Estimated memory usage %.1f MB\n",
73 offload_data->offload_array_length
74 * sizeof(real) / (1024.0*1024.0) );
75 }
76
77 return err;
78}
79
91void wall_free_offload(wall_offload_data* offload_data, real** offload_array,
92 int** int_offload_array) {
93 switch(offload_data->type) {
94 case wall_type_2D:
95 wall_2d_free_offload(&(offload_data->w2d), offload_array);
96 break;
97
98 case wall_type_3D:
99 wall_3d_free_offload(&(offload_data->w3d), offload_array,
100 int_offload_array);
101 break;
102 }
103}
104
120 real* offload_array, int* int_offload_array) {
121 int err = 0;
122 switch(offload_data->type) {
123 case wall_type_2D:
124 wall_2d_init(&(w->w2d), &(offload_data->w2d), offload_array);
125 break;
126
127 case wall_type_3D:
128 wall_3d_init(&(w->w3d), &(offload_data->w3d), offload_array,
129 int_offload_array);
130 break;
131 default:
132 /* Unregonized input. Produce error. */
133 err = 1;
134 break;
135 }
136 w->type = offload_data->type;
137
138 return err;
139}
140
163int wall_hit_wall(real r1, real phi1, real z1, real r2, real phi2, real z2,
164 wall_data* w, real* w_coll) {
165 int ret = 0;
166 switch(w->type) {
167 case wall_type_2D:
168 ret = wall_2d_hit_wall(r1, phi1, z1, r2, phi2, z2, &(w->w2d),
169 w_coll);
170 break;
171
172 case wall_type_3D:
173 ret = wall_3d_hit_wall(r1, phi1, z1, r2, phi2, z2, &(w->w3d),
174 w_coll);
175 break;
176 }
177 return ret;
178}
179
188 int ret = 0;
189 switch(w->type) {
190 case wall_type_2D:
191 ret = w->w2d.n;
192 break;
193
194 case wall_type_3D:
195 ret = w->w3d.n;
196 break;
197 }
198 return ret;
199}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Header file for math.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
#define print_err(...)
Print to standard error.
Definition print.h:42
int int_offload_array_length
Definition wall_3d.h:32
Wall model simulation data.
Definition wall.h:55
wall_type type
Definition wall.h:56
wall_3d_data w3d
Definition wall.h:58
wall_2d_data w2d
Definition wall.h:57
Wall model offload data.
Definition wall.h:38
int offload_array_length
Definition wall.h:42
int int_offload_array_length
Definition wall.h:43
wall_3d_offload_data w3d
Definition wall.h:41
wall_type type
Definition wall.h:39
wall_2d_offload_data w2d
Definition wall.h:40
int wall_hit_wall(real r1, real phi1, real z1, real r2, real phi2, real z2, wall_data *w, real *w_coll)
Check if a given directed line segment intersects the wall.
Definition wall.c:163
void wall_free_offload(wall_offload_data *offload_data, real **offload_array, int **int_offload_array)
Free offload array and reset parameters.
Definition wall.c:91
int wall_init_offload(wall_offload_data *offload_data, real **offload_array, int **int_offload_array)
Load wall data and prepare parameters.
Definition wall.c:42
int wall_init(wall_data *w, wall_offload_data *offload_data, real *offload_array, int *int_offload_array)
Initialize wall data struct on target.
Definition wall.c:119
int wall_get_n_elements(wall_data *w)
Return the number of wall elements.
Definition wall.c:187
Header file for wall.c.
@ wall_type_2D
Definition wall.h:25
@ wall_type_3D
Definition wall.h:26
void wall_2d_free_offload(wall_2d_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition wall_2d.c:62
void wall_2d_init(wall_2d_data *w, wall_2d_offload_data *offload_data, real *offload_array)
Initialize 2D wall data struct on target.
Definition wall_2d.c:78
int wall_2d_init_offload(wall_2d_offload_data *offload_data, real **offload_array)
Load 2D wall data and prepare parameters.
Definition wall_2d.c:29
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.
Definition wall_2d.c:142
Header file for wall_2d.c.
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.
Definition wall_3d.c:131
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.
Definition wall_3d.c:44
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 struct...
Definition wall_3d.c:339
void wall_3d_free_offload(wall_3d_offload_data *offload_data, real **offload_array, int **int_offload_array)
Free offload array and reset parameters.
Definition wall_3d.c:110
Header file for wall_3d.c.