ASCOT5
Loading...
Searching...
No Matches
diag.c
Go to the documentation of this file.
1
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include "ascot5.h"
17#include "simulate.h"
18#include "B_field.h"
19#include "diag.h"
20#include "diag/diag_orb.h"
21#include "diag/dist_5D.h"
22#include "diag/dist_6D.h"
23#include "diag/dist_rho5D.h"
24#include "diag/dist_rho6D.h"
25#include "diag/dist_com.h"
26#include "diag/diag_transcoef.h"
27#include "particle.h"
28
29void diag_arraysum(size_t start, size_t stop, real* array1, real* array2);
30
40int diag_init_offload(diag_offload_data* data, real** offload_array, int Nmrk){
41 /* Determine how long array we need and allocate it */
42 size_t n = 0;
43
44 if(data->dist5D_collect) {
45 data->offload_dist5D_index = n;
46 n += (size_t)(data->dist5D.n_r) * (size_t)(data->dist5D.n_phi)
47 * (size_t)(data->dist5D.n_z) * (size_t)(data->dist5D.n_ppara)
48 * (size_t)(data->dist5D.n_pperp) * (size_t)(data->dist5D.n_time)
49 * (size_t)(data->dist5D.n_q);
50 }
51
52 if(data->dist6D_collect) {
53 data->offload_dist6D_index = n;
54 n += (size_t)(data->dist6D.n_r) * (size_t)(data->dist6D.n_phi)
55 * (size_t)(data->dist6D.n_z) * (size_t)(data->dist6D.n_pr)
56 * (size_t)(data->dist6D.n_pphi) * (size_t)(data->dist6D.n_pz)
57 * (size_t)(data->dist6D.n_time) * (size_t)(data->dist6D.n_q);
58 }
59
60 if(data->distrho5D_collect) {
62 n += (size_t)(data->distrho5D.n_rho) * (size_t)(data->distrho5D.n_theta)
63 * (size_t)(data->distrho5D.n_phi) * (size_t)(data->distrho5D.n_ppara)
64 * (size_t)(data->distrho5D.n_pperp)
65 * (size_t)(data->distrho5D.n_time) * (size_t)(data->distrho5D.n_q);
66 }
67
68 if(data->distrho6D_collect) {
70 n += (size_t)(data->distrho6D.n_rho) * (size_t)(data->distrho6D.n_theta)
71 * (size_t)(data->distrho6D.n_phi) * (size_t)(data->distrho6D.n_pr)
72 * (size_t)(data->distrho6D.n_pphi) * (size_t)(data->distrho6D.n_pz)
73 * (size_t)(data->distrho6D.n_time) * (size_t)(data->distrho6D.n_q);
74 }
75
76 if(data->distCOM_collect) {
77 data->offload_distCOM_index = n;
78 n += (size_t)(data->distCOM.n_mu) * (size_t)(data->distCOM.n_Ekin)
79 * (size_t)(data->distCOM.n_Ptor);
80 }
81
82 data->offload_dist_length = n;
83
84 if(data->diagorb_collect) {
85 data->offload_diagorb_index = n;
86 data->diagorb.Nmrk = Nmrk;
87
88 switch(data->diagorb.record_mode) {
89
92 break;
93
96 break;
97
100 break;
101
104 break;
105
106 }
107
108 if(data->diagorb.mode == DIAG_ORB_POINCARE) {
109 n += (size_t)(data->diagorb.Nfld+2)
110 * (size_t)(data->diagorb.Nmrk) * (size_t)(data->diagorb.Npnt);
111 }
112 else if(data->diagorb.mode == DIAG_ORB_INTERVAL) {
113 n += (size_t)(data->diagorb.Nfld)
114 * (size_t)(data->diagorb.Nmrk) * (size_t)(data->diagorb.Npnt);
115 }
116 }
117 if(data->diagtrcof_collect) {
118 data->offload_diagtrcof_index = n;
119 data->diagtrcof.Nmrk = Nmrk;
120 n += (size_t)(3*data->diagtrcof.Nmrk);
121 }
122
123 data->offload_array_length = n;
124 *offload_array = malloc(n * sizeof(real));
125 if(*offload_array == NULL) {
126 return 1;
127 }
128
129 memset(*offload_array, 0, n * sizeof(real));
130
131 return 0;
132}
133
140void diag_free_offload(diag_offload_data* data, real** offload_array) {
141 free(*offload_array);
142 *offload_array = NULL;
143}
144
152void diag_init(diag_data* data, diag_offload_data* offload_data,
153 real* offload_array) {
154 data->diagorb_collect = offload_data->diagorb_collect;
155 data->dist5D_collect = offload_data->dist5D_collect;
156 data->dist6D_collect = offload_data->dist6D_collect;
157 data->distrho5D_collect = offload_data->distrho5D_collect;
158 data->distrho6D_collect = offload_data->distrho6D_collect;
159 data->distCOM_collect = offload_data->distCOM_collect;
160 data->diagtrcof_collect = offload_data->diagtrcof_collect;
161
162 if(data->dist5D_collect) {
163 dist_5D_init(&data->dist5D, &offload_data->dist5D,
164 &offload_array[offload_data->offload_dist5D_index]);
165 }
166
167 if(data->dist6D_collect) {
168 dist_6D_init(&data->dist6D, &offload_data->dist6D,
169 &offload_array[offload_data->offload_dist6D_index]);
170 }
171
172 if(data->distrho5D_collect) {
173 dist_rho5D_init(&data->distrho5D, &offload_data->distrho5D,
174 &offload_array[offload_data->offload_distrho5D_index]);
175 }
176
177 if(data->distrho6D_collect) {
178 dist_rho6D_init(&data->distrho6D, &offload_data->distrho6D,
179 &offload_array[offload_data->offload_distrho6D_index]);
180 }
181
182 if(data->distCOM_collect) {
183 dist_COM_init(&data->distCOM, &offload_data->distCOM,
184 &offload_array[offload_data->offload_distCOM_index]);
185 }
186
187 if(data->diagorb_collect) {
188 diag_orb_init(&data->diagorb, &offload_data->diagorb,
189 &offload_array[offload_data->offload_diagorb_index]);
190 }
191
192 if(data->diagtrcof_collect) {
194 &data->diagtrcof, &offload_data->diagtrcof,
195 &offload_array[offload_data->offload_diagtrcof_index]);
196 }
197}
198
204void diag_free(diag_data* data) {
205 if(data->diagorb_collect) {
206 diag_orb_free(&data->diagorb);
207 }
208 if(data->diagtrcof_collect) {
210 }
211}
212
224 particle_simd_fo* p_i) {
225 if(data->diagorb_collect) {
226 diag_orb_update_fo(&data->diagorb, p_f, p_i);
227 }
228 if(data->dist5D_collect) {
229 dist_5D_update_fo(&data->dist5D, p_f, p_i);
230 }
231 if(data->dist6D_collect) {
232 dist_6D_update_fo(&data->dist6D, p_f, p_i);
233 }
234 if(data->distrho5D_collect) {
235 dist_rho5D_update_fo(&data->distrho5D, p_f, p_i);
236 }
237 if(data->distrho6D_collect) {
238 dist_rho6D_update_fo(&data->distrho6D, p_f, p_i);
239 }
240 if(data->distCOM_collect){
241 dist_COM_update_fo(&data->distCOM, Bdata, p_f, p_i);
242 }
243 if(data->diagtrcof_collect){
244 diag_transcoef_update_fo(&data->diagtrcof, p_f, p_i);
245 }
246}
247
259 particle_simd_gc* p_i) {
260 if(data->diagorb_collect) {
261 diag_orb_update_gc(&data->diagorb, p_f, p_i);
262 }
263
264 if(data->dist5D_collect){
265 dist_5D_update_gc(&data->dist5D, p_f, p_i);
266 }
267
268 if(data->dist6D_collect){
269 dist_6D_update_gc(&data->dist6D, p_f, p_i);
270 }
271
272 if(data->distrho5D_collect){
273 dist_rho5D_update_gc(&data->distrho5D, p_f, p_i);
274 }
275
276 if(data->distrho6D_collect){
277 dist_rho6D_update_gc(&data->distrho6D, p_f, p_i);
278 }
279
280 if(data->distCOM_collect){
281 dist_COM_update_gc(&data->distCOM, Bdata, p_f, p_i);
282 }
283
284 if(data->diagtrcof_collect){
285 diag_transcoef_update_gc(&data->diagtrcof, p_f, p_i);
286 }
287}
288
301 particle_simd_ml* p_i) {
302 if(data->diagorb_collect) {
303 diag_orb_update_ml(&data->diagorb, p_f, p_i);
304 }
305
306 if(data->diagtrcof_collect){
307 diag_transcoef_update_ml(&data->diagtrcof, p_f, p_i);
308 }
309}
310
323void diag_sum(diag_offload_data* data, real* array1, real* array2) {
324 if(data->diagorb_collect) {
325 size_t arr_start = data->offload_diagorb_index;
326 size_t arr_length = (size_t)(data->diagorb.Nfld)
327 * (size_t)(data->diagorb.Nmrk) * (size_t)(data->diagorb.Npnt);
328
329 memcpy(&(array1[arr_start+arr_length]),
330 &(array2[arr_start]),
331 arr_length*sizeof(real));
332 }
333
334 if(data->diagtrcof_collect) {
335 size_t arr_start = data->offload_diagtrcof_index;
336 size_t arr_length = (size_t)(3 * data->diagtrcof.Nmrk);
337
338 memcpy(&(array1[arr_start+arr_length]),
339 &(array2[arr_start]),
340 arr_length*sizeof(real));
341 }
342
343 if(data->dist5D_collect){
344 size_t start = data->offload_dist5D_index;
345 size_t stop = start + (size_t)(data->dist5D.n_r)
346 * (size_t)(data->dist5D.n_z) * (size_t)(data->dist5D.n_ppara)
347 * (size_t)(data->dist5D.n_pperp) * (size_t)(data->dist5D.n_time)
348 * (size_t)(data->dist5D.n_q);
349 diag_arraysum(start, stop, array1, array2);
350 }
351
352 if(data->dist6D_collect){
353 size_t start = data->offload_dist6D_index;
354 size_t stop = start + (size_t)(data->dist6D.n_r)
355 * (size_t)(data->dist6D.n_phi)
356 * (size_t)(data->dist6D.n_z) * (size_t)(data->dist6D.n_pr)
357 * (size_t)(data->dist6D.n_pphi) * (size_t)(data->dist6D.n_pz)
358 * (size_t)(data->dist6D.n_time) * (size_t)(data->dist6D.n_q);
359 diag_arraysum(start, stop, array1, array2);
360 }
361
362 if(data->distrho5D_collect){
363 size_t start = data->offload_distrho5D_index;
364 size_t stop = start + (size_t)(data->distrho5D.n_rho)
365 * (size_t)(data->distrho5D.n_theta)
366 * (size_t)(data->distrho5D.n_phi)
367 * (size_t)(data->distrho5D.n_ppara)
368 * (size_t)(data->distrho5D.n_pperp)
369 * (size_t)(data->distrho5D.n_time)
370 * (size_t)(data->distrho5D.n_q);
371 diag_arraysum(start, stop, array1, array2);
372 }
373
374 if(data->distrho6D_collect){
375 size_t start = data->offload_distrho6D_index;
376 size_t stop = start + (size_t)(data->distrho6D.n_rho)
377 * (size_t)(data->distrho6D.n_theta)
378 * (size_t)(data->distrho6D.n_phi) * (size_t)(data->distrho6D.n_pr)
379 * (size_t)(data->distrho6D.n_pphi) * (size_t)(data->distrho6D.n_pz)
380 * (size_t)(data->distrho6D.n_time) * (size_t)(data->distrho6D.n_q);
381 diag_arraysum(start, stop, array1, array2);
382 }
383
384 if(data->distCOM_collect){
385 size_t start = data->offload_distCOM_index;
386 size_t stop = start + (size_t)(data->distCOM.n_mu)
387 * (size_t)(data->distCOM.n_Ekin) * (size_t)(data->distCOM.n_Ptor);
388 diag_arraysum(start, stop, array1, array2);
389 }
390}
391
403void diag_arraysum(size_t start, size_t stop, real* array1, real* array2) {
404 for(size_t i = start; i < stop; i++) {
405 array1[i] += array2[i];
406 }
407}
Header file for B_field.c.
Main header file for ASCOT5.
double real
Definition ascot5.h:85
void diag_update_fo(diag_data *data, B_field_data *Bdata, particle_simd_fo *p_f, particle_simd_fo *p_i)
Collects diagnostics when marker represents a particle.
Definition diag.c:223
void diag_sum(diag_offload_data *data, real *array1, real *array2)
Sum offload data arrays as one.
Definition diag.c:323
void diag_free_offload(diag_offload_data *data, real **offload_array)
Frees the offload array.
Definition diag.c:140
int diag_init_offload(diag_offload_data *data, real **offload_array, int Nmrk)
Initializes offload array from offload data.
Definition diag.c:40
void diag_init(diag_data *data, diag_offload_data *offload_data, real *offload_array)
Initializes diagnostics from offload data.
Definition diag.c:152
void diag_arraysum(size_t start, size_t stop, real *array1, real *array2)
Simple helper function for summing elements of two arrays of same size.
Definition diag.c:403
void diag_free(diag_data *data)
Free diagnostics data.
Definition diag.c:204
void diag_update_ml(diag_data *data, particle_simd_ml *p_f, particle_simd_ml *p_i)
Collects diagnostics when marker represents a magnetic field line.
Definition diag.c:300
void diag_update_gc(diag_data *data, B_field_data *Bdata, particle_simd_gc *p_f, particle_simd_gc *p_i)
Collects diagnostics when marker represents a guiding center.
Definition diag.c:258
Header file for diag.c.
void diag_orb_update_fo(diag_orb_data *data, particle_simd_fo *p_f, particle_simd_fo *p_i)
Collects orbit diagnostics when marker represents a particle.
Definition diag_orb.c:161
void diag_orb_init(diag_orb_data *data, diag_orb_offload_data *offload_data, real *offload_array)
Initializes orbit diagnostics offload data.
Definition diag_orb.c:28
void diag_orb_update_ml(diag_orb_data *data, particle_simd_ml *p_f, particle_simd_ml *p_i)
Collects orbit diagnostics when marker represents a field line.
Definition diag_orb.c:574
void diag_orb_update_gc(diag_orb_data *data, particle_simd_gc *p_f, particle_simd_gc *p_i)
Collects orbit diagnostics when marker represents a guiding center.
Definition diag_orb.c:367
void diag_orb_free(diag_orb_data *data)
Free orbit diagnostics data.
Definition diag_orb.c:147
Header file for diag_orb.c.
#define DIAG_ORB_POINCARE
Definition diag_orb.h:13
#define DIAG_ORB_HYBRIDFIELDS
Definition diag_orb.h:20
#define DIAG_ORB_INTERVAL
Definition diag_orb.h:14
#define DIAG_ORB_GCFIELDS
Definition diag_orb.h:18
#define DIAG_ORB_FOFIELDS
Definition diag_orb.h:17
#define DIAG_ORB_MLFIELDS
Definition diag_orb.h:19
void diag_transcoef_update_ml(diag_transcoef_data *data, particle_simd_ml *p_f, particle_simd_ml *p_i)
Collect transport diagnostics for ml simulation.
void diag_transcoef_update_gc(diag_transcoef_data *data, particle_simd_gc *p_f, particle_simd_gc *p_i)
Collect transport diagnostics for gc simulation.
void diag_transcoef_update_fo(diag_transcoef_data *data, particle_simd_fo *p_f, particle_simd_fo *p_i)
Collect transport diagnostics for fo simulation.
void diag_transcoef_free(diag_transcoef_data *data)
Free transport coefficient data on target.
void diag_transcoef_init(diag_transcoef_data *data, diag_transcoef_offload_data *offload_data, real *offload_array)
Initializes orbit diagnostics offload data.
Header file for diag_transcoef.c.
void dist_5D_update_gc(dist_5D_data *dist, particle_simd_gc *p_f, particle_simd_gc *p_i)
Update the histogram from guiding center markers.
Definition dist_5D.c:190
void dist_5D_init(dist_5D_data *dist_data, dist_5D_offload_data *offload_data, real *offload_array)
Initializes distribution from offload data.
Definition dist_5D.c:60
void dist_5D_update_fo(dist_5D_data *dist, particle_simd_fo *p_f, particle_simd_fo *p_i)
Update the histogram from full-orbit particles.
Definition dist_5D.c:117
Header file for dist_5D.c.
void dist_6D_update_fo(dist_6D_data *dist, particle_simd_fo *p_f, particle_simd_fo *p_i)
Update the histogram from full-orbit particles.
Definition dist_6D.c:121
void dist_6D_init(dist_6D_data *dist_data, dist_6D_offload_data *offload_data, real *offload_array)
Initializes distribution from offload data.
Definition dist_6D.c:58
void dist_6D_update_gc(dist_6D_data *dist, particle_simd_gc *p_f, particle_simd_gc *p_i)
Update the histogram from guiding-center particles.
Definition dist_6D.c:187
Header file for dist_6D.c.
void dist_COM_update_fo(dist_COM_data *dist, B_field_data *Bdata, particle_simd_fo *p_f, particle_simd_fo *p_i)
Update the histogram from full-orbit markers.
Definition dist_com.c:78
void dist_COM_init(dist_COM_data *dist_data, dist_COM_offload_data *offload_data, real *offload_array)
Initializes distribution from offload data.
Definition dist_com.c:48
void dist_COM_update_gc(dist_COM_data *dist, B_field_data *Bdata, particle_simd_gc *p_f, particle_simd_gc *p_i)
Update the histogram from guiding center markers.
Definition dist_com.c:135
Header file for dist_com.c.
void dist_rho5D_update_gc(dist_rho5D_data *dist, particle_simd_gc *p_f, particle_simd_gc *p_i)
Update the histogram from guiding center markers.
Definition dist_rho5D.c:198
void dist_rho5D_init(dist_rho5D_data *dist_data, dist_rho5D_offload_data *offload_data, real *offload_array)
Initializes distribution from offload data.
Definition dist_rho5D.c:60
void dist_rho5D_update_fo(dist_rho5D_data *dist, particle_simd_fo *p_f, particle_simd_fo *p_i)
Update the histogram from full-orbit particles.
Definition dist_rho5D.c:118
Header file for dist_rho5D.c.
void dist_rho6D_update_gc(dist_rho6D_data *dist, particle_simd_gc *p_f, particle_simd_gc *p_i)
Update the histogram from guiding-center particles.
Definition dist_rho6D.c:195
void dist_rho6D_init(dist_rho6D_data *dist_data, dist_rho6D_offload_data *offload_data, real *offload_array)
Initializes distribution from offload data.
Definition dist_rho6D.c:58
void dist_rho6D_update_fo(dist_rho6D_data *dist, particle_simd_fo *p_f, particle_simd_fo *p_i)
Update the histogram from full-orbit particles.
Definition dist_rho6D.c:122
Header file for dist_rho6D.c.
Header file for particle.c.
Header file for simulate.c.
@ simulate_mode_fo
Definition simulate.h:34
@ simulate_mode_ml
Definition simulate.h:45
@ simulate_mode_gc
Definition simulate.h:37
@ simulate_mode_hybrid
Definition simulate.h:42
Magnetic field simulation data.
Definition B_field.h:63
Diagnostics data struct.
Definition diag.h:54
dist_COM_data distCOM
Definition diag.h:68
int distrho5D_collect
Definition diag.h:58
int diagtrcof_collect
Definition diag.h:61
diag_transcoef_data diagtrcof
Definition diag.h:69
int distrho6D_collect
Definition diag.h:59
diag_orb_data diagorb
Definition diag.h:63
dist_rho6D_data distrho6D
Definition diag.h:67
dist_5D_data dist5D
Definition diag.h:64
int dist5D_collect
Definition diag.h:56
int dist6D_collect
Definition diag.h:57
int distCOM_collect
Definition diag.h:60
dist_6D_data dist6D
Definition diag.h:65
dist_rho5D_data distrho5D
Definition diag.h:66
int diagorb_collect
Definition diag.h:55
Diagnostics offload data struct.
Definition diag.h:21
dist_rho5D_offload_data distrho5D
Definition diag.h:33
size_t offload_distCOM_index
Definition diag.h:42
int distrho6D_collect
Definition diag.h:26
size_t offload_dist_length
Definition diag.h:46
int diagtrcof_collect
Definition diag.h:28
diag_transcoef_offload_data diagtrcof
Definition diag.h:36
int distCOM_collect
Definition diag.h:27
dist_5D_offload_data dist5D
Definition diag.h:31
size_t offload_distrho6D_index
Definition diag.h:41
size_t offload_distrho5D_index
Definition diag.h:40
size_t offload_dist6D_index
Definition diag.h:39
size_t offload_diagtrcof_index
Definition diag.h:44
int distrho5D_collect
Definition diag.h:25
dist_6D_offload_data dist6D
Definition diag.h:32
int dist5D_collect
Definition diag.h:23
dist_rho6D_offload_data distrho6D
Definition diag.h:34
size_t offload_dist5D_index
Definition diag.h:38
int diagorb_collect
Definition diag.h:22
size_t offload_array_length
Definition diag.h:47
int dist6D_collect
Definition diag.h:24
dist_COM_offload_data distCOM
Definition diag.h:35
size_t offload_diagorb_index
Definition diag.h:43
diag_orb_offload_data diagorb
Definition diag.h:30
Struct representing NSIMD particle markers.
Definition particle.h:210
Struct representing NSIMD guiding center markers.
Definition particle.h:275
Struct representing NSIMD field line markers.
Definition particle.h:342