ASCOT5
Toggle main menu visibility
Loading...
Searching...
No Matches
diag
hist.c
Go to the documentation of this file.
1
9
#include <stdlib.h>
10
#include "
../ascot5.h
"
11
#include "
../math.h
"
12
#include "
../consts.h
"
13
#include "../offload.h"
14
#include "
../particle.h
"
15
#include "
hist.h
"
16
20
int
hist_init
(
histogram
* data,
int
dimensions,
hist_coordinate
* coordinates,
21
real
* binmin,
real
* binmax,
size_t
* nbin) {
22
data->
axes
[0].
name
=
R
;
23
data->
axes
[1].
name
=
PHI
;
24
data->
axes
[2].
name
=
Z
;
25
data->
axes
[3].
name
=
RHO
;
26
data->
axes
[4].
name
=
THETA
;
27
data->
axes
[5].
name
=
PPAR
;
28
data->
axes
[6].
name
=
PPERP
;
29
data->
axes
[7].
name
=
PR
;
30
data->
axes
[8].
name
=
PPHI
;
31
data->
axes
[9].
name
=
PZ
;
32
data->
axes
[10].
name
=
EKIN
;
33
data->
axes
[11].
name
=
XI
;
34
data->
axes
[12].
name
=
MU
;
35
data->
axes
[13].
name
=
PTOR
;
36
data->
axes
[14].
name
=
TIME
;
37
data->
axes
[15].
name
=
CHARGE
;
38
39
data->
nbin
= 1;
40
for
(
int
i = HIST_ALLDIM-1; i >= 0; i--) {
41
data->
axes
[i].
n
= 0;
42
data->
axes
[i].
min
= 0;
43
data->
axes
[i].
max
= 1;
44
for
(
int
k = 0; k < dimensions; k++) {
45
if
(coordinates[k] == data->
axes
[i].
name
) {
46
data->
axes
[i].
min
= binmin[k];
47
data->
axes
[i].
max
= binmax[k];
48
data->
axes
[i].
n
= nbin[k];
49
data->
nbin
*= nbin[k];
50
}
51
}
52
if
(i < HIST_ALLDIM-1) {
53
data->
strides
[i] = data->
axes
[i+1].
n
? data->
axes
[i+1].
n
: 1;
54
if
( i < HIST_ALLDIM-2) {
55
data->
strides
[i] *= data->
strides
[i+1];
56
}
57
}
58
}
59
data->
bins
= (
real
*) calloc(data->
nbin
,
sizeof
(
real
));
60
return
0;
61
}
62
66
void
hist_free
(
histogram
* data) {
67
free(data->
bins
);
68
data->
nbin
= 0;
69
}
70
74
void
hist_offload
(
histogram
* data) {
75
GPU_MAP_TO_DEVICE(
76
data->
axes
[0:HIST_ALLDIM], data->
bins
[0:data->
nbin
]
77
)
78
}
79
83
void
hist_update_fo
(
histogram
* hist,
particle_simd_fo
* p_f,
84
particle_simd_fo
* p_i) {
85
#ifdef GPU
86
size_t
index;
87
real
weight;
88
#else
89
size_t
index[
NSIMD
];
90
real
weight[
NSIMD
];
91
#endif
92
GPU_PARALLEL_LOOP_ALL_LEVELS
93
for
(
int
i = 0; i < p_f->
n_mrk
; i++) {
94
hist_axis
* axis;
95
96
real
phi =
fmod
(p_f->
phi
[i], 2*
CONST_PI
);
97
phi += (phi<0) * 2*
CONST_PI
;
98
99
real
theta =
fmod
(p_f->
theta
[i], 2*
CONST_PI
);
100
theta += (theta<0) * 2*
CONST_PI
;
101
102
real
ppar = ( p_f->
p_r
[i] * p_f->
B_r
[i]
103
+ p_f->
p_phi
[i] * p_f->
B_phi
[i]
104
+ p_f->
p_z
[i] * p_f->
B_z
[i])
105
/ sqrt( p_f->
B_r
[i] * p_f->
B_r
[i]
106
+ p_f->
B_phi
[i]* p_f->
B_phi
[i]
107
+ p_f->
B_z
[i] * p_f->
B_z
[i]);
108
109
real
pperp = sqrt(
110
p_f->
p_r
[i] * p_f->
p_r
[i]
111
+ p_f->
p_phi
[i] * p_f->
p_phi
[i]
112
+ p_f->
p_z
[i] * p_f->
p_z
[i]
113
- ppar * ppar);
114
115
axis = &hist->
axes
[15];
116
size_t
nq = axis->
n
;
117
size_t
i15 = 0;
118
119
axis = &hist->
axes
[14];
120
size_t
i14 =
math_bin_index
(
121
p_f->
time
[i], axis->
n
, axis->
min
, axis->
max
);
122
123
axis = &hist->
axes
[13];
124
size_t
nptor = axis->
n
;
125
size_t
i13 = 0;
126
127
axis = &hist->
axes
[12];
128
size_t
nmu = axis->
n
;
129
size_t
i12 = 0;
130
131
axis = &hist->
axes
[11];
132
size_t
nxi = axis->
n
;
133
size_t
i11 = 0;
134
135
axis = &hist->
axes
[10];
136
size_t
nekin = axis->
n
;
137
size_t
i10 = 0;
138
139
axis = &hist->
axes
[9];
140
size_t
i9 =
math_bin_index
(p_f->
p_z
[i], axis->
n
, axis->
min
, axis->
max
);
141
142
axis = &hist->
axes
[8];
143
size_t
i8 =
math_bin_index
(
144
p_f->
p_phi
[i], axis->
n
, axis->
min
, axis->
max
);
145
146
axis = &hist->
axes
[7];
147
size_t
i7 =
math_bin_index
(p_f->
p_r
[i], axis->
n
, axis->
min
, axis->
max
);
148
149
axis = &hist->
axes
[6];
150
size_t
i6 =
math_bin_index
(pperp, axis->
n
, axis->
min
, axis->
max
);
151
152
axis = &hist->
axes
[5];
153
size_t
i5 =
math_bin_index
(ppar, axis->
n
, axis->
min
, axis->
max
);
154
155
axis = &hist->
axes
[4];
156
size_t
i4 =
math_bin_index
(theta, axis->
n
, axis->
min
, axis->
max
);
157
158
axis = &hist->
axes
[3];
159
size_t
i3 =
math_bin_index
(p_f->
rho
[i], axis->
n
, axis->
min
, axis->
max
);
160
161
axis = &hist->
axes
[2];
162
size_t
i2 =
math_bin_index
(p_f->
z
[i], axis->
n
, axis->
min
, axis->
max
);
163
164
axis = &hist->
axes
[1];
165
size_t
i1 =
math_bin_index
(phi, axis->
n
, axis->
min
, axis->
max
);
166
167
axis = &hist->
axes
[0];
168
size_t
i0 =
math_bin_index
(p_f->
r
[i], axis->
n
, axis->
min
, axis->
max
);
169
170
#ifdef GPU
171
size_t
* n = hist->
strides
;
172
index = i0*n[0] + i1*n[1] + i2*n[2] + i3*n[3] + i4*n[4]
173
+ i5*n[5] + i6*n[6] + i7*n[7] + i8*n[8] + i9*n[9]
174
+ i10*n[10] + i11*n[11] + i12*n[12] + i13*n[13] + i14*n[14]
175
+ i15;
176
weight = p_f->
weight
[i];
177
GPU_ATOMIC
178
hist->
bins
[index] += p_f->
weight
[i];
179
#else
180
size_t
* n = hist->
strides
;
181
index[i] = i0*n[0] + i1*n[1] + i2*n[2] + i3*n[3] + i4*n[4]
182
+ i5*n[5] + i6*n[6] + i7*n[7] + i8*n[8] + i9*n[9]
183
+ i10*n[10] + i11*n[11] + i12*n[12] + i13*n[13] + i14*n[14]
184
+ i15;
185
weight[i] = p_f->
weight
[i];
186
#endif
187
}
188
#ifndef GPU
189
for
(
int
i = 0; i < p_f->
n_mrk
; i++) {
190
if
(p_f->
running
[i] && index[i] >= 0 && index[i] < hist->
nbin
) {
191
GPU_ATOMIC
192
hist->
bins
[index[i]] += weight[i];
193
}
194
}
195
#endif
196
}
197
201
void
hist_update_gc
(
histogram
* hist,
particle_simd_gc
* p_f,
202
particle_simd_gc
* p_i) {
203
//TODO
204
}
ascot5.h
Main header file for ASCOT5.
real
double real
Definition
ascot5.h:85
NSIMD
#define NSIMD
Number of particles simulated simultaneously in a particle group operations.
Definition
ascot5.h:91
consts.h
Header file containing physical and mathematical constants.
CONST_PI
#define CONST_PI
pi
Definition
consts.h:11
hist_update_fo
void hist_update_fo(histogram *hist, particle_simd_fo *p_f, particle_simd_fo *p_i)
Update the histogram in the particle picture.
Definition
hist.c:83
hist_offload
void hist_offload(histogram *data)
Offload the data to the accelerator.
Definition
hist.c:74
hist_init
int hist_init(histogram *data, int dimensions, hist_coordinate *coordinates, real *binmin, real *binmax, size_t *nbin)
Initialize the histogram object.
Definition
hist.c:20
hist_free
void hist_free(histogram *data)
Free allocated resources.
Definition
hist.c:66
hist_update_gc
void hist_update_gc(histogram *hist, particle_simd_gc *p_f, particle_simd_gc *p_i)
Update the histogram in the GC picture.
Definition
hist.c:201
hist.h
Header file for hist.c.
hist_coordinate
hist_coordinate
Quantities that can be used as histogram axis coordinates.
Definition
hist.h:17
R
@ R
Definition
hist.h:18
XI
@ XI
Definition
hist.h:29
THETA
@ THETA
Definition
hist.h:22
PZ
@ PZ
Definition
hist.h:27
PPHI
@ PPHI
Definition
hist.h:26
RHO
@ RHO
Definition
hist.h:21
PHI
@ PHI
Definition
hist.h:19
PPERP
@ PPERP
Definition
hist.h:24
PR
@ PR
Definition
hist.h:25
MU
@ MU
Definition
hist.h:30
PPAR
@ PPAR
Definition
hist.h:23
Z
@ Z
Definition
hist.h:20
EKIN
@ EKIN
Definition
hist.h:28
PTOR
@ PTOR
Definition
hist.h:31
TIME
@ TIME
Definition
hist.h:32
CHARGE
@ CHARGE
Definition
hist.h:33
fmod
real fmod(real x, real y)
Compute the modulus of two real numbers.
Definition
math.c:22
math.h
Header file for math.c.
math_bin_index
#define math_bin_index(x, nx, xmin, xmax)
Find the bin index on a uniform grid.
Definition
math.h:22
particle.h
Header file for particle.c.
hist_axis
Coordinate axis for the histogram.
Definition
hist.h:39
hist_axis::min
real min
Definition
hist.h:41
hist_axis::max
real max
Definition
hist.h:42
hist_axis::name
hist_coordinate name
Definition
hist.h:40
hist_axis::n
size_t n
Definition
hist.h:43
histogram
Histogram parameters.
Definition
hist.h:52
histogram::axes
hist_axis axes[HIST_ALLDIM]
Definition
hist.h:53
histogram::nbin
size_t nbin
Definition
hist.h:55
histogram::strides
size_t strides[HIST_ALLDIM-1]
Definition
hist.h:54
histogram::bins
real * bins
Definition
hist.h:56
particle_simd_fo
Struct representing NSIMD particle markers.
Definition
particle.h:210
particle_simd_fo::p_phi
real * p_phi
Definition
particle.h:216
particle_simd_fo::time
real * time
Definition
particle.h:220
particle_simd_fo::r
real * r
Definition
particle.h:212
particle_simd_fo::n_mrk
size_t n_mrk
Definition
particle.h:256
particle_simd_fo::weight
real * weight
Definition
particle.h:241
particle_simd_fo::rho
real * rho
Definition
particle.h:243
particle_simd_fo::B_phi
real * B_phi
Definition
particle.h:226
particle_simd_fo::p_z
real * p_z
Definition
particle.h:217
particle_simd_fo::B_z
real * B_z
Definition
particle.h:227
particle_simd_fo::B_r
real * B_r
Definition
particle.h:225
particle_simd_fo::theta
real * theta
Definition
particle.h:244
particle_simd_fo::p_r
real * p_r
Definition
particle.h:215
particle_simd_fo::running
integer * running
Definition
particle.h:252
particle_simd_fo::phi
real * phi
Definition
particle.h:213
particle_simd_fo::z
real * z
Definition
particle.h:214
particle_simd_gc
Struct representing NSIMD guiding center markers.
Definition
particle.h:275
Generated on
for ASCOT5 by
1.18.0