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
160 particle_simd_fo* p_i) {
161 if(data->diagorb_collect) {
162 diag_orb_update_fo(&data->diagorb, p_f, p_i);
163 }
164 if(data->dist5D_collect) {
165 dist_5D_update_fo(&data->dist5D, p_f, p_i);
166 }
167 if(data->dist6D_collect) {
168 dist_6D_update_fo(&data->dist6D, p_f, p_i);
169 }
170 if(data->distrho5D_collect) {
171 dist_rho5D_update_fo(&data->distrho5D, p_f, p_i);
172 }
173 if(data->distrho6D_collect) {
174 dist_rho6D_update_fo(&data->distrho6D, p_f, p_i);
175 }
176 if(data->distCOM_collect){
177 dist_COM_update_fo(&data->distCOM, Bdata, p_f, p_i);
178 }
179 if(data->diagtrcof_collect){
180 diag_transcoef_update_fo(&data->diagtrcof, p_f, p_i);
181 }
182}
183
195 particle_simd_gc* p_i) {
196 if(data->diagorb_collect) {
197 diag_orb_update_gc(&data->diagorb, p_f, p_i);
198 }
199
200 if(data->dist5D_collect){
201 dist_5D_update_gc(&data->dist5D, p_f, p_i);
202 }
203
204 if(data->dist6D_collect){
205 dist_6D_update_gc(&data->dist6D, p_f, p_i);
206 }
207
208 if(data->distrho5D_collect){
209 dist_rho5D_update_gc(&data->distrho5D, p_f, p_i);
210 }
211
212 if(data->distrho6D_collect){
213 dist_rho6D_update_gc(&data->distrho6D, p_f, p_i);
214 }
215
216 if(data->distCOM_collect){
217 dist_COM_update_gc(&data->distCOM, Bdata, p_f, p_i);
218 }
219
220 if(data->diagtrcof_collect){
221 diag_transcoef_update_gc(&data->diagtrcof, p_f, p_i);
222 }
223}
224
237 particle_simd_ml* p_i) {
238 if(data->diagorb_collect) {
239 diag_orb_update_ml(&data->diagorb, p_f, p_i);
240 }
241
242 if(data->diagtrcof_collect){
243 diag_transcoef_update_ml(&data->diagtrcof, p_f, p_i);
244 }
245}
246
259void diag_sum(diag_data* data1, diag_data* data2) {
260 if(data1->diagorb_collect) {
261 }
262
263 if(data1->diagtrcof_collect) {
264 }
265
266 if(data1->dist5D_collect){
267 size_t stop = (size_t)(data1->dist5D.n_r) * (size_t)(data1->dist5D.n_z)
268 * (size_t)(data1->dist5D.n_ppara) * (size_t)(data1->dist5D.n_pperp)
269 * (size_t)(data1->dist5D.n_time) * (size_t)(data1->dist5D.n_q);
270 diag_arraysum(0, stop, data1->dist5D.histogram,
271 data2->dist5D.histogram);
272 }
273
274 if(data1->dist6D_collect){
275 size_t stop = (size_t)(data1->dist6D.n_r)
276 * (size_t)(data1->dist6D.n_phi)
277 * (size_t)(data1->dist6D.n_z) * (size_t)(data1->dist6D.n_pr)
278 * (size_t)(data1->dist6D.n_pphi) * (size_t)(data1->dist6D.n_pz)
279 * (size_t)(data1->dist6D.n_time) * (size_t)(data1->dist6D.n_q);
280 diag_arraysum(0, stop, data1->dist6D.histogram,
281 data2->dist6D.histogram);
282 }
283
284 if(data1->distrho5D_collect){
285 size_t stop = (size_t)(data1->distrho5D.n_rho)
286 * (size_t)(data1->distrho5D.n_theta)
287 * (size_t)(data1->distrho5D.n_phi)
288 * (size_t)(data1->distrho5D.n_ppara)
289 * (size_t)(data1->distrho5D.n_pperp)
290 * (size_t)(data1->distrho5D.n_time)
291 * (size_t)(data1->distrho5D.n_q);
292 diag_arraysum(0, stop, data1->distrho5D.histogram,
293 data2->distrho5D.histogram);
294 }
295
296 if(data1->distrho6D_collect){
297 size_t stop = (size_t)(data1->distrho6D.n_rho)
298 * (size_t)(data1->distrho6D.n_theta)
299 * (size_t)(data1->distrho6D.n_phi)
300 * (size_t)(data1->distrho6D.n_pr)
301 * (size_t)(data1->distrho6D.n_pphi)
302 * (size_t)(data1->distrho6D.n_pz)
303 * (size_t)(data1->distrho6D.n_time)
304 * (size_t)(data1->distrho6D.n_q);
305 diag_arraysum(0, stop, data1->distrho6D.histogram,
306 data2->distrho6D.histogram);
307 }
308
309 if(data1->distCOM_collect){
310 size_t stop = (size_t)(data1->distCOM.n_mu)
311 * (size_t)(data1->distCOM.n_Ekin) * (size_t)(data1->distCOM.n_Ptor);
312 diag_arraysum(0, stop, data1->dist6D.histogram,
313 data2->dist6D.histogram);
314 }
315}
316
328void diag_arraysum(size_t start, size_t stop, real* array1, real* array2) {
329 for(size_t i = start; i < stop; i++) {
330 array1[i] += array2[i];
331 }
332}
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:159
void diag_offload(diag_data *data)
Offload data to the accelerator.
Definition diag.c:131
void diag_sum(diag_data *data1, diag_data *data2)
Sum offload data arrays as one.
Definition diag.c:259
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:328
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:236
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:194
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:158
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:85
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:84
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:150
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:66
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_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:123
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_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:165
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:85
Header file for dist_rho5D.c.
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:157
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:84
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:33
@ simulate_mode_ml
Definition simulate.h:44
@ simulate_mode_gc
Definition simulate.h:36
@ simulate_mode_hybrid
Definition simulate.h:41
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