70 p_fo->
r = malloc(nmrk *
sizeof(p_fo->
r) );
71 p_fo->
phi = malloc(nmrk *
sizeof(p_fo->
phi) );
72 p_fo->
z = malloc(nmrk *
sizeof(p_fo->
z) );
73 p_fo->
p_r = malloc(nmrk *
sizeof(p_fo->
p_r) );
74 p_fo->
p_phi = malloc(nmrk *
sizeof(p_fo->
p_phi) );
75 p_fo->
p_z = malloc(nmrk *
sizeof(p_fo->
p_z) );
76 p_fo->
mass = malloc(nmrk *
sizeof(p_fo->
mass) );
78 p_fo->
time = malloc(nmrk *
sizeof(p_fo->
time) );
79 p_fo->
znum = malloc(nmrk *
sizeof(p_fo->
znum) );
80 p_fo->
anum = malloc(nmrk *
sizeof(p_fo->
anum) );
83 p_fo->
B_r = malloc(nmrk *
sizeof(p_fo->
B_r) );
84 p_fo->
B_phi = malloc(nmrk *
sizeof(p_fo->
B_phi) );
85 p_fo->
B_z = malloc(nmrk *
sizeof(p_fo->
B_z) );
100 p_fo->
rho = malloc(nmrk *
sizeof(p_fo->
rho) );
101 p_fo->
theta = malloc(nmrk *
sizeof(p_fo->
theta) );
103 p_fo->
id = malloc(nmrk *
sizeof(p_fo->
id) );
112 p_fo->
err = malloc(nmrk *
sizeof(p_fo->
err) );
113 p_fo->
index = malloc(nmrk *
sizeof(p_fo->
index));
182 p_gc->bounces[j] = 0;
185 p_gc->mileage[j] = 0;
188 p_gc->B_r_dphi[j] = 1;
192 p_gc->B_phi_dr[j] = 1;
193 p_gc->B_phi_dphi[j] = 1;
194 p_gc->B_phi_dz[j] = 1;
198 p_gc->B_z_dphi[j] = 1;
224 p_ml->mileage[j] = 0;
227 p_ml->B_r_dphi[j] = 1;
231 p_ml->B_phi_dr[j] = 1;
232 p_ml->B_phi_dphi[j] = 1;
233 p_ml->B_phi_dz[j] = 1;
237 p_ml->B_z_dphi[j] = 1;
273 for(
int i = 0; i < p->
n_mrk; i++) {
279 if(p->
id[i] < 0 && q->
next < q->
n) {
316 q->
p[i_prt], i_prt, p, i, Bdata);
320 q->
p[i_prt]->
err = err;
334 #pragma omp simd reduction(+:n_running)
335 for(
int i = 0; i < p->
n_mrk; i++) {
372 for(
int i = 0; i <
NSIMD; i++) {
378 if(p->id[i] < 0 && q->
next < q->
n) {
383 if(!p->running[i] && p->id[i] >= 0) {
410 q->
p[i_prt], i_prt, p, i, Bdata);
414 q->
p[i_prt]->
err = err;
428 #pragma omp simd reduction(+:n_running)
429 for(
int i = 0; i <
NSIMD; i++) {
430 n_running += p->running[i];
466 for(
int i = 0; i <
NSIMD; i++) {
472 if(p->id[i] < 0 && q->
next < q->
n) {
477 if(!p->running[i] && p->id[i] >= 0) {
504 q->
p[i_prt], i_prt, p, i, Bdata);
508 q->
p[i_prt]->
err = err;
522 #pragma omp simd reduction(+:n_running)
523 for(
int i = 0; i <
NSIMD; i++) {
524 n_running += p->running[i];
557 if(!err && p->
p.
r <= 0) {
560 if(!err && p->
p.
mass <= 0) {
566 if(!err && p->
p.
id <= 0) {
579 if(!err && p->
p_gc.
r <= 0) {
594 if(!err && p->
p_gc.
id <= 0) {
607 if(!err && p->
p_ml.
r <= 0) {
613 if(!err && p->
p_ml.
id <= 0) {
664 p_fo->
r[j] = p->
rprt;
666 p_fo->
z[j] = p->
zprt;
686 real B_dB[15], psi[1], rho[2];
700 p_fo->
rho[j] = rho[0];
702 p_fo->
B_r[j] = B_dB[0];
703 p_fo->
B_r_dr[j] = B_dB[1];
705 p_fo->
B_r_dz[j] = B_dB[3];
707 p_fo->
B_phi[j] = B_dB[4];
712 p_fo->
B_z[j] = B_dB[8];
713 p_fo->
B_z_dr[j] = B_dB[9];
715 p_fo->
B_z_dz[j] = B_dB[11];
748 p->
rprt = p_fo->
r[j];
750 p->
zprt = p_fo->
z[j];
769 real B_dB[15], psi[1], rho[2];
770 rho[0] = p_fo->
rho[j];
771 B_dB[0] = p_fo->
B_r[j];
772 B_dB[1] = p_fo->
B_r_dr[j];
774 B_dB[3] = p_fo->
B_r_dz[j];
775 B_dB[4] = p_fo->
B_phi[j];
779 B_dB[8] = p_fo->
B_z[j];
780 B_dB[9] = p_fo->
B_z_dr[j];
782 B_dB[11] = p_fo->
B_z_dz[j];
877 p_gc->phi[j] = p->
phi;
879 p_gc->ppar[j] = p->
ppar;
881 p_gc->zeta[j] = p->
zeta;
883 p_gc->mass[j] = p->
mass;
884 p_gc->charge[j] = p->
charge;
885 p_gc->time[j] = p->
time;
886 p_gc->bounces[j] = 0;
887 p_gc->weight[j] = p->
weight;
888 p_gc->rho[j] = p->
rho;
889 p_gc->theta[j] = p->
theta;
895 p_gc->B_r[j] = p->
B_r;
896 p_gc->B_r_dr[j] = p->
B_r_dr;
898 p_gc->B_r_dz[j] = p->
B_r_dz;
900 p_gc->B_phi[j] = p->
B_phi;
905 p_gc->B_z[j] = p->
B_z;
906 p_gc->B_z_dr[j] = p->
B_z_dr;
908 p_gc->B_z_dz[j] = p->
B_z_dz;
910 p_gc->running[j] = 1;
912 p_gc->running[j] = 0;
941 p->
phi = p_gc->phi[j];
943 p->
ppar = p_gc->ppar[j];
945 p->
zeta = p_gc->zeta[j];
947 p->
mass = p_gc->mass[j];
948 p->
charge = p_gc->charge[j];
949 p->
time = p_gc->time[j];
950 p->
weight = p_gc->weight[j];
953 p->
rho = p_gc->rho[j];
954 p->
theta = p_gc->theta[j];
959 p->
B_r = p_gc->B_r[j];
960 p->
B_r_dr = p_gc->B_r_dr[j];
962 p->
B_r_dz = p_gc->B_r_dz[j];
964 p->
B_phi = p_gc->B_phi[j];
969 p->
B_z = p_gc->B_z[j];
970 p->
B_z_dr = p_gc->B_z_dr[j];
972 p->
B_z_dz = p_gc->B_z_dz[j];
991 real pparprt, muprt, zetaprt;
1001 p->
phiprt, pparprt, muprt, zetaprt,
1013 a5err simerr = p_gc->err[j];
1058 p_ml->phi[j] = p->
phi;
1061 p_ml->pitch[j] = 2*(p->
ppar >= 0) - 1.0;
1062 p_ml->time[j] = p->
time;
1063 p_ml->weight[j] = p->
weight;
1064 p_ml->id[j] = p->
id;
1065 p_ml->cputime[j] = p->
cputime;
1066 p_ml->rho[j] = p->
rho;
1067 p_ml->theta[j] = p->
theta;
1068 p_ml->endcond[j] = p->
endcond;
1070 p_ml->mileage[j] = p->
mileage;
1072 p_ml->B_r[j] = p->
B_r;
1073 p_ml->B_r_dr[j] = p->
B_r_dr;
1075 p_ml->B_r_dz[j] = p->
B_r_dz;
1077 p_ml->B_phi[j] = p->
B_phi;
1082 p_ml->B_z[j] = p->
B_z;
1083 p_ml->B_z_dr[j] = p->
B_z_dr;
1085 p_ml->B_z_dz[j] = p->
B_z_dz;
1087 p_ml->running[j] = 1;
1089 p_ml->running[j] = 0;
1121 p->
rprt = p_ml->r[j];
1122 p->
phiprt = p_ml->phi[j];
1123 p->
zprt = p_ml->z[j];
1129 p->
phi = p_ml->phi[j];
1131 p->
ppar = p_ml->pitch[j];
1136 p->
time = p_ml->time[j];
1137 p->
weight = p_ml->weight[j];
1138 p->
id = p_ml->id[j];
1139 p->
cputime = p_ml->cputime[j];
1140 p->
rho = p_ml->rho[j];
1141 p->
theta = p_ml->theta[j];
1142 p->
endcond = p_ml->endcond[j];
1144 p->
mileage = p_ml->mileage[j];
1145 p->
err = p_ml->err[j];
1147 p->
B_r = p_ml->B_r[j];
1148 p->
B_r_dr = p_ml->B_r_dr[j];
1150 p->
B_r_dz = p_ml->B_r_dz[j];
1152 p->
B_phi = p_ml->B_phi[j];
1157 p->
B_z = p_ml->B_z[j];
1158 p->
B_z_dr = p_ml->B_z_dr[j];
1160 p->
B_z_dz = p_ml->B_z_dz[j];
1163 a5err simerr = p_ml->err[j];
1170 if(!simerr && err) {err = err;}
1190 if(err) {simerr = 1;}
1191 p_gc->id[j] = p_fo->
id[j];
1192 p_gc->index[j] = p_fo->
index[j];
1194 real r, phi, z, ppar, mu, zeta, B_dB[15];
1196 real Rprt = p_fo->
r[j];
1198 real zprt = p_fo->
z[j];
1205 p_gc->mass[j] = p_fo->
mass[j];
1206 p_gc->charge[j] = p_fo->
charge[j];
1207 p_gc->weight[j] = p_fo->
weight[j];
1208 p_gc->time[j] = p_fo->
time[j];
1209 p_gc->mileage[j] = p_fo->
mileage[j];
1210 p_gc->endcond[j] = p_fo->
endcond[j];
1211 p_gc->running[j] = p_fo->
running[j];
1212 p_gc->walltile[j] = p_fo->
walltile[j];
1213 p_gc->cputime[j] = p_fo->
cputime[j];
1215 B_dB[0] = p_fo->
B_r[j];
1216 B_dB[1] = p_fo->
B_r_dr[j];
1218 B_dB[3] = p_fo->
B_r_dz[j];
1219 B_dB[4] = p_fo->
B_phi[j];
1223 B_dB[8] = p_fo->
B_z[j];
1224 B_dB[9] = p_fo->
B_z_dr[j];
1226 B_dB[11] = p_fo->
B_z_dz[j];
1231 Rprt, phiprt, zprt, pr , pphi, pz,
1232 &r, &phi, &z, &ppar, &mu, &zeta);
1237 real psi[1], rho[2];
1240 B_dB, r, phi, z, p_fo->
time[j], Bdata);
1244 psi, r, phi, z, p_fo->
time[j], Bdata);
1258 p_gc->zeta[j] = zeta;
1259 p_gc->ppar[j] = ppar;
1260 p_gc->rho[j] = rho[0];
1263 p_gc->theta[j] = p_fo->
theta[j];
1264 p_gc->theta[j] += atan2( (p_fo->
r[j]-axisrz[0]) * (p_gc->z[j]-axisrz[1])
1265 - (p_fo->
z[j]-axisrz[1]) * (p_gc->r[j]-axisrz[0]),
1266 (p_fo->
r[j]-axisrz[0]) * (p_gc->r[j]-axisrz[0])
1267 + (p_fo->
z[j]-axisrz[1]) * (p_gc->z[j]-axisrz[1]) );
1269 p_gc->B_r[j] = B_dB[0];
1270 p_gc->B_r_dr[j] = B_dB[1];
1271 p_gc->B_r_dphi[j] = B_dB[2];
1272 p_gc->B_r_dz[j] = B_dB[3];
1274 p_gc->B_phi[j] = B_dB[4];
1275 p_gc->B_phi_dr[j] = B_dB[5];
1276 p_gc->B_phi_dphi[j] = B_dB[6];
1277 p_gc->B_phi_dz[j] = B_dB[7];
1279 p_gc->B_z[j] = B_dB[8];
1280 p_gc->B_z_dr[j] = B_dB[9];
1281 p_gc->B_z_dphi[j] = B_dB[10];
1282 p_gc->B_z_dz[j] = B_dB[11];
1284 if(!simerr) {err = err;}
1287 p_gc->running[j] = 0;
1288 p_gc->endcond[j] = 0;
1303 p2->
r[j] = p1->
r[i];
1305 p2->
z[j] = p1->
z[i];
1324 p2->
id[j] = p1->
id[i];
1356 p2->r[j] = p1->r[i];
1357 p2->phi[j] = p1->phi[i];
1358 p2->z[j] = p1->z[i];
1359 p2->ppar[j] = p1->ppar[i];
1360 p2->mu[j] = p1->mu[i];
1361 p2->zeta[j] = p1->zeta[i];
1363 p2->time[j] = p1->time[i];
1364 p2->mileage[j] = p1->mileage[i];
1365 p2->weight[j] = p1->weight[i];
1366 p2->cputime[j] = p1->cputime[i];
1367 p2->rho[j] = p1->rho[i];
1368 p2->theta[j] = p1->theta[i];
1370 p2->mass[j] = p1->mass[i];
1371 p2->charge[j] = p1->charge[i];
1373 p2->id[j] = p1->id[i];
1374 p2->bounces[j] = p1->bounces[i];
1375 p2->running[j] = p1->running[i];
1376 p2->endcond[j] = p1->endcond[i];
1377 p2->walltile[j] = p1->walltile[i];
1379 p2->B_r[j] = p1->B_r[i];
1380 p2->B_phi[j] = p1->B_phi[i];
1381 p2->B_z[j] = p1->B_z[i];
1383 p2->B_r_dr[j] = p1->B_r_dr[i];
1384 p2->B_r_dphi[j] = p1->B_r_dphi[i];
1385 p2->B_r_dz[j] = p1->B_r_dz[i];
1387 p2->B_phi_dr[j] = p1->B_phi_dr[i];
1388 p2->B_phi_dphi[j] = p1->B_phi_dphi[i];
1389 p2->B_phi_dz[j] = p1->B_phi_dz[i];
1391 p2->B_z_dr[j] = p1->B_z_dr[i];
1392 p2->B_z_dphi[j] = p1->B_z_dphi[i];
1393 p2->B_z_dz[j] = p1->B_z_dz[i];
1406 p2->r[j] = p1->r[i];
1407 p2->phi[j] = p1->phi[i];
1408 p2->z[j] = p1->z[i];
1409 p2->pitch[j] = p1->pitch[i];
1411 p2->time[j] = p1->time[i];
1412 p2->mileage[j] = p1->mileage[i];
1413 p2->cputime[j] = p1->cputime[i];
1414 p2->rho[j] = p1->rho[i];
1415 p2->weight[j] = p1->weight[i];
1416 p2->theta[j] = p1->theta[i];
1418 p2->id[j] = p1->id[i];
1419 p2->running[j] = p1->running[i];
1420 p2->endcond[j] = p1->endcond[i];
1421 p2->walltile[j] = p1->walltile[i];
1423 p2->B_r[j] = p1->B_r[i];
1424 p2->B_phi[j] = p1->B_phi[i];
1425 p2->B_z[j] = p1->B_z[i];
1427 p2->B_r_dr[j] = p1->B_r_dr[i];
1428 p2->B_r_dphi[j] = p1->B_r_dphi[i];
1429 p2->B_r_dz[j] = p1->B_r_dz[i];
1431 p2->B_phi_dr[j] = p1->B_phi_dr[i];
1432 p2->B_phi_dphi[j] = p1->B_phi_dphi[i];
1433 p2->B_phi_dz[j] = p1->B_phi_dz[i];
1435 p2->B_z_dr[j] = p1->B_z_dr[i];
1436 p2->B_z_dphi[j] = p1->B_z_dphi[i];
1437 p2->B_z_dz[j] = p1->B_z_dz[i];
1476 real B_dB[15], r, phi, z, ppar, mu, zeta, psi[1], rho[2];
1484 &r, &phi, &z, &ppar, &mu, &zeta);
1486 if(!err && r <= 0) {
1489 if(!err && mu < 0) {
1514 ps->
B_phi = B_dB[4];
1544 real B_dB[15], psi[1], rho[2];
1558 ps->
B_phi = B_dB[4];
1573 real gamma, mu, ppar;
1586 if(!err && mu < 0) {
1606 ps->
theta = atan2(ps->
z-axisrz[1], ps->
r-axisrz[0]);
1615 real rprt, phiprt, zprt, pr, pphi, pz;
1617 real pparprt, muprt, zetaprt;
1621 &rprt, &phiprt, &zprt, &pparprt, &muprt, &zetaprt);
1627 phiprt, pparprt, muprt, zetaprt,
1630 if(!err && rprt <= 0) {
1660 real B_dB[15], psi[1], rho[2];
1689 ps->
theta = atan2(p->
z - axisrz[1], p->
r - axisrz[0]);
1704 ps->
B_phi = B_dB[4];
a5err B_field_eval_rho(real rho[2], real psi, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its psi derivative.
a5err B_field_eval_psi(real *psi, real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi.
a5err B_field_eval_B_dB(real B_dB[15], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field and its derivatives.
a5err B_field_get_axis_rz(real rz[2], B_field_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
Header file for B_field.c.
Header file for E_field.c.
Main header file for ASCOT5.
#define NSIMD
Number of particles simulated simultaneously in a particle group operations.
Header file containing physical and mathematical constants.
#define CONST_C
Speed of light [m/s]
#define CONST_C2
Speed of light squared [m^2/s^2]
unsigned long int a5err
Simulation error flag.
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
#define math_normc(a1, a2, a3)
Calculate norm of 3D vector from its components a1, a2, a3.
void particle_to_ml_dummy(particle_simd_ml *p_ml, int j)
Makes a dummy ML simulation marker.
void particle_gc_to_state(particle_simd_gc *p_gc, int j, particle_state *p, B_field_data *Bdata)
Convert GC to state.
a5err particle_input_gc_to_state(particle_gc *p, particle_state *ps, B_field_data *Bdata)
Convert an input guiding center marker to particle state.
void particle_copy_gc(particle_simd_gc *p1, int i, particle_simd_gc *p2, int j)
Copy GC struct.
a5err particle_state_to_gc(particle_state *p, int i, particle_simd_gc *p_gc, int j, B_field_data *Bdata)
Convert state into a GC SIMD marker.
a5err particle_state_to_fo(particle_state *p, int i, particle_simd_fo *p_fo, int j, B_field_data *Bdata)
Convert state into a FO SIMD marker.
void particle_fo_to_state(particle_simd_fo *p_fo, int j, particle_state *p, B_field_data *Bdata)
Convert FO to state.
void particle_to_fo_dummy(particle_simd_fo *p_fo, int j)
Makes a dummy FO simulation marker.
int particle_fo_to_gc(particle_simd_fo *p_fo, int j, particle_simd_gc *p_gc, B_field_data *Bdata)
Convert FO struct into a GC struct.
a5err particle_input_ml_to_state(particle_ml *p, particle_state *ps, B_field_data *Bdata)
Convert an input field line marker to particle state.
void particle_input_to_state(input_particle *p, particle_state *ps, B_field_data *Bdata)
Converts input marker to a marker state.
void particle_to_gc_dummy(particle_simd_gc *p_gc, int j)
Makes a dummy GC simulation marker.
void particle_copy_ml(particle_simd_ml *p1, int i, particle_simd_ml *p2, int j)
Copy ML struct.
void particle_allocate_fo(particle_simd_fo *p_fo, int nmrk)
Allocates struct representing particle markers.
a5err particle_state_to_ml(particle_state *p, int i, particle_simd_ml *p_ml, int j, B_field_data *Bdata)
Convert state to a ML SIMD marker.
a5err particle_input_p_to_state(particle *p, particle_state *ps, B_field_data *Bdata)
Convert an input particle marker to particle state.
void particle_offload_fo(particle_simd_fo *p)
Offload particle struct to GPU.
int particle_cycle_ml(particle_queue *q, particle_simd_ml *p, B_field_data *Bdata, int *cycle)
Replace finished ML markers with new ones or dummies.
void particle_ml_to_state(particle_simd_ml *p_ml, int j, particle_state *p, B_field_data *Bdata)
Convert ML to state.
int particle_cycle_gc(particle_queue *q, particle_simd_gc *p, B_field_data *Bdata, int *cycle)
Replace finished GC markers with new ones or dummies.
int particle_cycle_fo(particle_queue *q, particle_simd_fo *p, B_field_data *Bdata, int *cycle)
Replace finished FO markers with new ones or dummies.
void particle_copy_fo(particle_simd_fo *p1, int i, particle_simd_fo *p2, int j)
Copy FO struct.
Header file for particle.c.
Methods to evaluate elementary physical quantities.
#define physlib_gc_ppar(p, xi)
Evaluate guiding center parallel momentum [kg m/s] from momentum norm and pitch.
#define physlib_gc_mu(m, p, xi, B)
Evaluate guiding center magnetic moment [J/T] from momentum norm and pitch.
Magnetic field simulation data.
Wrapper for marker structs.
Struct representing NSIMD particle markers.
Struct representing NSIMD guiding center markers.
Struct representing NSIMD field line markers.
General representation of a marker.