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->diagorb_collect) {
104 diag_orb_free(&data->diagorb);
105 }
106 if(data->diagtrcof_collect) {
108 }
109}
110
117 if(data->dist5D_collect) {
118 dist_5D_offload(&data->dist5D);
119 }
120 if(data->dist6D_collect) {
121 dist_6D_offload(&data->dist6D);
122 }
123 if(data->distrho5D_collect) {
125 }
126 if(data->distrho6D_collect) {
128 }
129 if(data->distCOM_collect) {
131 }
132}
133
145 particle_simd_fo* p_i) {
146 if(data->diagorb_collect) {
147 diag_orb_update_fo(&data->diagorb, p_f, p_i);
148 }
149 if(data->dist5D_collect) {
150 dist_5D_update_fo(&data->dist5D, p_f, p_i);
151 }
152 if(data->dist6D_collect) {
153 dist_6D_update_fo(&data->dist6D, p_f, p_i);
154 }
155 if(data->distrho5D_collect) {
156 dist_rho5D_update_fo(&data->distrho5D, p_f, p_i);
157 }
158 if(data->distrho6D_collect) {
159 dist_rho6D_update_fo(&data->distrho6D, p_f, p_i);
160 }
161 if(data->distCOM_collect){
162 dist_COM_update_fo(&data->distCOM, Bdata, p_f, p_i);
163 }
164 if(data->diagtrcof_collect){
165 diag_transcoef_update_fo(&data->diagtrcof, p_f, p_i);
166 }
167}
168
180 particle_simd_gc* p_i) {
181 if(data->diagorb_collect) {
182 diag_orb_update_gc(&data->diagorb, p_f, p_i);
183 }
184
185 if(data->dist5D_collect){
186 dist_5D_update_gc(&data->dist5D, p_f, p_i);
187 }
188
189 if(data->dist6D_collect){
190 dist_6D_update_gc(&data->dist6D, p_f, p_i);
191 }
192
193 if(data->distrho5D_collect){
194 dist_rho5D_update_gc(&data->distrho5D, p_f, p_i);
195 }
196
197 if(data->distrho6D_collect){
198 dist_rho6D_update_gc(&data->distrho6D, p_f, p_i);
199 }
200
201 if(data->distCOM_collect){
202 dist_COM_update_gc(&data->distCOM, Bdata, p_f, p_i);
203 }
204
205 if(data->diagtrcof_collect){
206 diag_transcoef_update_gc(&data->diagtrcof, p_f, p_i);
207 }
208}
209
222 particle_simd_ml* p_i) {
223 if(data->diagorb_collect) {
224 diag_orb_update_ml(&data->diagorb, p_f, p_i);
225 }
226
227 if(data->diagtrcof_collect){
228 diag_transcoef_update_ml(&data->diagtrcof, p_f, p_i);
229 }
230}
231
244void diag_sum(diag_data* data1, diag_data* data2) {
245 if(data1->diagorb_collect) {
246 }
247
248 if(data1->diagtrcof_collect) {
249 }
250
251 if(data1->dist5D_collect){
252 size_t stop = (size_t)(data1->dist5D.n_r) * (size_t)(data1->dist5D.n_z)
253 * (size_t)(data1->dist5D.n_ppara) * (size_t)(data1->dist5D.n_pperp)
254 * (size_t)(data1->dist5D.n_time) * (size_t)(data1->dist5D.n_q);
255 diag_arraysum(0, stop, data1->dist5D.histogram,
256 data2->dist5D.histogram);
257 }
258
259 if(data1->dist6D_collect){
260 size_t stop = (size_t)(data1->dist6D.n_r)
261 * (size_t)(data1->dist6D.n_phi)
262 * (size_t)(data1->dist6D.n_z) * (size_t)(data1->dist6D.n_pr)
263 * (size_t)(data1->dist6D.n_pphi) * (size_t)(data1->dist6D.n_pz)
264 * (size_t)(data1->dist6D.n_time) * (size_t)(data1->dist6D.n_q);
265 diag_arraysum(0, stop, data1->dist6D.histogram,
266 data2->dist6D.histogram);
267 }
268
269 if(data1->distrho5D_collect){
270 size_t stop = (size_t)(data1->distrho5D.n_rho)
271 * (size_t)(data1->distrho5D.n_theta)
272 * (size_t)(data1->distrho5D.n_phi)
273 * (size_t)(data1->distrho5D.n_ppara)
274 * (size_t)(data1->distrho5D.n_pperp)
275 * (size_t)(data1->distrho5D.n_time)
276 * (size_t)(data1->distrho5D.n_q);
277 diag_arraysum(0, stop, data1->distrho5D.histogram,
278 data2->distrho5D.histogram);
279 }
280
281 if(data1->distrho6D_collect){
282 size_t stop = (size_t)(data1->distrho6D.n_rho)
283 * (size_t)(data1->distrho6D.n_theta)
284 * (size_t)(data1->distrho6D.n_phi)
285 * (size_t)(data1->distrho6D.n_pr)
286 * (size_t)(data1->distrho6D.n_pphi)
287 * (size_t)(data1->distrho6D.n_pz)
288 * (size_t)(data1->distrho6D.n_time)
289 * (size_t)(data1->distrho6D.n_q);
290 diag_arraysum(0, stop, data1->distrho6D.histogram,
291 data2->distrho6D.histogram);
292 }
293
294 if(data1->distCOM_collect){
295 size_t stop = (size_t)(data1->distCOM.n_mu)
296 * (size_t)(data1->distCOM.n_Ekin) * (size_t)(data1->distCOM.n_Ptor);
297 diag_arraysum(0, stop, data1->dist6D.histogram,
298 data2->dist6D.histogram);
299 }
300}
301
313void diag_arraysum(size_t start, size_t stop, real* array1, real* array2) {
314 for(size_t i = start; i < stop; i++) {
315 array1[i] += array2[i];
316 }
317}
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:144
void diag_offload(diag_data *data)
Offload data to the accelerator.
Definition diag.c:116
void diag_sum(diag_data *data1, diag_data *data2)
Sum offload data arrays as one.
Definition diag.c:244
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:313
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:221
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:179
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:133
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:546
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:339
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:160
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:87
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:70
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:86
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:152
int dist_6D_init(dist_6D_data *data)
Initializes distribution data.
Definition dist_6D.c:34
void dist_6D_offload(dist_6D_data *data)
Offload data to the accelerator.
Definition dist_6D.c:69
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:67
void dist_COM_offload(dist_COM_data *data)
Offload data to the accelerator.
Definition dist_com.c:55
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:124
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_offload(dist_rho5D_data *data)
Offload data to the accelerator.
Definition dist_rho5D.c:70
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:167
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:87
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:159
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:86
void dist_rho6D_offload(dist_rho6D_data *data)
Offload data to the accelerator.
Definition dist_rho6D.c:69
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