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
37int diag_init(diag_data* data, int Nmrk) {
38
39 if(data->diagorb_collect) {
40 data->diagorb.Nmrk = Nmrk;
41
42 switch(data->diagorb.record_mode) {
43
46 break;
47
50 break;
51
54 break;
55
58 break;
59
60 }
61 }
62 if(data->diagtrcof_collect) {
63 data->diagtrcof.Nmrk = Nmrk;
64 }
65
66 if(data->dist5D_collect) {
67 dist_5D_init(&data->dist5D);
68 }
69
70 if(data->dist6D_collect) {
71 dist_6D_init(&data->dist6D);
72 }
73
74 if(data->distrho5D_collect) {
76 }
77
78 if(data->distrho6D_collect) {
80 }
81
82 if(data->distCOM_collect) {
83 dist_COM_init(&data->distCOM);
84 }
85
86 if(data->diagorb_collect) {
87 diag_orb_init(&data->diagorb);
88 }
89
90 if(data->diagtrcof_collect) {
92 }
93
94 return 0;
95}
96
102void diag_free(diag_data* data) {
103 if(data->dist5D_collect) {
104 dist_5D_free(&data->dist5D);
105 }
106 if(data->dist6D_collect) {
107 dist_6D_free(&data->dist6D);
108 }
109 if(data->distrho5D_collect) {
111 }
112 if(data->distrho6D_collect) {
114 }
115 if(data->distCOM_collect) {
116 dist_COM_free(&data->distCOM);
117 }
118 if(data->diagorb_collect) {
119 diag_orb_free(&data->diagorb);
120 }
121 if(data->diagtrcof_collect) {
123 }
124}
125
132 if(data->dist5D_collect) {
133 dist_5D_offload(&data->dist5D);
134 }
135 if(data->dist6D_collect) {
136 dist_6D_offload(&data->dist6D);
137 }
138 if(data->distrho5D_collect) {
140 }
141 if(data->distrho6D_collect) {
143 }
144 if(data->distCOM_collect) {
146 }
147}
148
155 if(data->dist5D_collect) {
156 dist_5D_onload(&data->dist5D);
157 }
158 if(data->dist6D_collect) {
159 dist_6D_onload(&data->dist6D);
160 }
161 if(data->distrho5D_collect) {
163 }
164 if(data->distrho6D_collect) {
166 }
167 if(data->distCOM_collect) {
168 dist_COM_onload(&data->distCOM);
169 }
170}
171
183 particle_simd_fo* p_i) {
184 if(data->diagorb_collect) {
185 diag_orb_update_fo(&data->diagorb, p_f, p_i);
186 }
187 if(data->dist5D_collect) {
188 dist_5D_update_fo(&data->dist5D, p_f, p_i);
189 }
190 if(data->dist6D_collect) {
191 dist_6D_update_fo(&data->dist6D, p_f, p_i);
192 }
193 if(data->distrho5D_collect) {
194 dist_rho5D_update_fo(&data->distrho5D, p_f, p_i);
195 }
196 if(data->distrho6D_collect) {
197 dist_rho6D_update_fo(&data->distrho6D, p_f, p_i);
198 }
199 if(data->distCOM_collect){
200 dist_COM_update_fo(&data->distCOM, Bdata, p_f, p_i);
201 }
202 if(data->diagtrcof_collect){
203 diag_transcoef_update_fo(&data->diagtrcof, p_f, p_i);
204 }
205}
206
218 particle_simd_gc* p_i) {
219 if(data->diagorb_collect) {
220 diag_orb_update_gc(&data->diagorb, p_f, p_i);
221 }
222
223 if(data->dist5D_collect){
224 dist_5D_update_gc(&data->dist5D, p_f, p_i);
225 }
226
227 if(data->dist6D_collect){
228 dist_6D_update_gc(&data->dist6D, p_f, p_i);
229 }
230
231 if(data->distrho5D_collect){
232 dist_rho5D_update_gc(&data->distrho5D, p_f, p_i);
233 }
234
235 if(data->distrho6D_collect){
236 dist_rho6D_update_gc(&data->distrho6D, p_f, p_i);
237 }
238
239 if(data->distCOM_collect){
240 dist_COM_update_gc(&data->distCOM, Bdata, p_f, p_i);
241 }
242
243 if(data->diagtrcof_collect){
244 diag_transcoef_update_gc(&data->diagtrcof, p_f, p_i);
245 }
246}
247
260 particle_simd_ml* p_i) {
261 if(data->diagorb_collect) {
262 diag_orb_update_ml(&data->diagorb, p_f, p_i);
263 }
264
265 if(data->diagtrcof_collect){
266 diag_transcoef_update_ml(&data->diagtrcof, p_f, p_i);
267 }
268}
269
282void diag_sum(diag_data* data1, diag_data* data2) {
283 if(data1->diagorb_collect) {
284 }
285
286 if(data1->diagtrcof_collect) {
287 }
288
289 if(data1->dist5D_collect){
290 size_t stop = (size_t)(data1->dist5D.n_r) * (size_t)(data1->dist5D.n_z)
291 * (size_t)(data1->dist5D.n_ppara) * (size_t)(data1->dist5D.n_pperp)
292 * (size_t)(data1->dist5D.n_time) * (size_t)(data1->dist5D.n_q);
293 diag_arraysum(0, stop, data1->dist5D.histogram,
294 data2->dist5D.histogram);
295 }
296
297 if(data1->dist6D_collect){
298 size_t stop = (size_t)(data1->dist6D.n_r)
299 * (size_t)(data1->dist6D.n_phi)
300 * (size_t)(data1->dist6D.n_z) * (size_t)(data1->dist6D.n_pr)
301 * (size_t)(data1->dist6D.n_pphi) * (size_t)(data1->dist6D.n_pz)
302 * (size_t)(data1->dist6D.n_time) * (size_t)(data1->dist6D.n_q);
303 diag_arraysum(0, stop, data1->dist6D.histogram,
304 data2->dist6D.histogram);
305 }
306
307 if(data1->distrho5D_collect){
308 size_t stop = (size_t)(data1->distrho5D.n_rho)
309 * (size_t)(data1->distrho5D.n_theta)
310 * (size_t)(data1->distrho5D.n_phi)
311 * (size_t)(data1->distrho5D.n_ppara)
312 * (size_t)(data1->distrho5D.n_pperp)
313 * (size_t)(data1->distrho5D.n_time)
314 * (size_t)(data1->distrho5D.n_q);
315 diag_arraysum(0, stop, data1->distrho5D.histogram,
316 data2->distrho5D.histogram);
317 }
318
319 if(data1->distrho6D_collect){
320 size_t stop = (size_t)(data1->distrho6D.n_rho)
321 * (size_t)(data1->distrho6D.n_theta)
322 * (size_t)(data1->distrho6D.n_phi)
323 * (size_t)(data1->distrho6D.n_pr)
324 * (size_t)(data1->distrho6D.n_pphi)
325 * (size_t)(data1->distrho6D.n_pz)
326 * (size_t)(data1->distrho6D.n_time)
327 * (size_t)(data1->distrho6D.n_q);
328 diag_arraysum(0, stop, data1->distrho6D.histogram,
329 data2->distrho6D.histogram);
330 }
331
332 if(data1->distCOM_collect){
333 size_t stop = (size_t)(data1->distCOM.n_mu)
334 * (size_t)(data1->distCOM.n_Ekin) * (size_t)(data1->distCOM.n_Ptor);
335 diag_arraysum(0, stop, data1->dist6D.histogram,
336 data2->dist6D.histogram);
337 }
338}
339
351void diag_arraysum(size_t start, size_t stop, real* array1, real* array2) {
352 for(size_t i = start; i < stop; i++) {
353 array1[i] += array2[i];
354 }
355}
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:182
void diag_offload(diag_data *data)
Offload data to the accelerator.
Definition diag.c:131
void diag_onload(diag_data *data)
Onload data back to the host.
Definition diag.c:154
void diag_sum(diag_data *data1, diag_data *data2)
Sum offload data arrays as one.
Definition diag.c:282
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:351
int diag_init(diag_data *data, int Nmrk)
Initializes diagnostics data.
Definition diag.c:37
void diag_free(diag_data *data)
Free allocated resources.
Definition diag.c:102
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:259
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:217
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:211
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:624
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:417
void diag_orb_free(diag_orb_data *data)
Free allocated resources.
Definition diag_orb.c:119
void diag_orb_init(diag_orb_data *data)
Initializes orbit diagnostics data.
Definition diag_orb.c:26
Header file for diag_orb.c.
#define DIAG_ORB_HYBRIDFIELDS
Definition diag_orb.h:20
#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_init(diag_transcoef_data *data)
Initializes transport coefficient diagnostics data.
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 allocated resources.
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:194
void dist_5D_onload(dist_5D_data *data)
Onload data back to the host.
Definition dist_5D.c:79
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:96
void dist_5D_free(dist_5D_data *data)
Free allocated resources.
Definition dist_5D.c:59
int dist_5D_init(dist_5D_data *data)
Initializes distribution from offload data.
Definition dist_5D.c:35
void dist_5D_offload(dist_5D_data *data)
Offload data to the accelerator.
Definition dist_5D.c:68
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:95
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:186
void dist_6D_onload(dist_6D_data *data)
Onload data back to the host.
Definition dist_6D.c:78
int dist_6D_init(dist_6D_data *data)
Initializes distribution data.
Definition dist_6D.c:34
void dist_6D_free(dist_6D_data *data)
Free allocated resources.
Definition dist_6D.c:58
void dist_6D_offload(dist_6D_data *data)
Offload data to the accelerator.
Definition dist_6D.c:67
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:77
void dist_COM_free(dist_COM_data *data)
Free allocated resources.
Definition dist_com.c:45
void dist_COM_offload(dist_COM_data *data)
Offload data to the accelerator.
Definition dist_com.c:54
void dist_COM_onload(dist_COM_data *data)
Onload data back to the host.
Definition dist_com.c:63
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:157
int dist_COM_init(dist_COM_data *data)
Initializes distribution data.
Definition dist_com.c:29
Header file for dist_com.c.
int dist_rho5D_init(dist_rho5D_data *data)
Initializes distribution data.
Definition dist_rho5D.c:35
void dist_rho5D_free(dist_rho5D_data *data)
Free the allocated resources.
Definition dist_rho5D.c:59
void dist_rho5D_offload(dist_rho5D_data *data)
Offload data to the accelerator.
Definition dist_rho5D.c:68
void dist_rho5D_onload(dist_rho5D_data *data)
Onload data back to the host.
Definition dist_rho5D.c:79
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:201
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:96
Header file for dist_rho5D.c.
void dist_rho6D_onload(dist_rho6D_data *data)
Onload data back to the host.
Definition dist_rho6D.c:78
int dist_rho6D_init(dist_rho6D_data *data)
Initializes distribution data.
Definition dist_rho6D.c:34
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:192
void dist_rho6D_free(dist_rho6D_data *data)
Free allocated resources.
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:95
void dist_rho6D_offload(dist_rho6D_data *data)
Offload data to the accelerator.
Definition dist_rho6D.c:67
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:41
Diagnostics data struct.
Definition diag.h:21
dist_COM_data distCOM
Definition diag.h:35
int distrho5D_collect
Definition diag.h:25
int diagtrcof_collect
Definition diag.h:28
diag_transcoef_data diagtrcof
Definition diag.h:36
int distrho6D_collect
Definition diag.h:26
diag_orb_data diagorb
Definition diag.h:30
dist_rho6D_data distrho6D
Definition diag.h:34
dist_5D_data dist5D
Definition diag.h:31
int dist5D_collect
Definition diag.h:23
int dist6D_collect
Definition diag.h:24
int distCOM_collect
Definition diag.h:27
dist_6D_data dist6D
Definition diag.h:32
dist_rho5D_data distrho5D
Definition diag.h:33
int diagorb_collect
Definition diag.h:22
int record_mode
Definition diag_orb.h:76
int n_ppara
Definition dist_5D.h:28
int n_pperp
Definition dist_5D.h:32
real * histogram
Definition dist_5D.h:51
real * histogram
Definition dist_6D.h:56
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