7#include "../../offload_acc_omp.h"
37 GPU_DATA_IS_MAPPED(h[0:p->
n_mrk])
38 GPU_PARALLEL_LOOP_ALL_LEVELS
39 for(
int i = 0; i < p->
n_mrk; i++) {
53 real posrpz[3] = {p->
r[i], p->
phi[i], p->
z[i]};
54 real posxyz0[3],posxyz[3];
59 posxyz[0] = posxyz0[0] + pxyz[0] * h[i] / (2.0 * gamma * mass);
60 posxyz[1] = posxyz0[1] + pxyz[1] * h[i] / (2.0 * gamma * mass);
61 posxyz[2] = posxyz0[2] + pxyz[2] * h[i] / (2.0 * gamma * mass);
69 t0 + h[i]/2.0, Bdata);
73 t0 + h[i]/2.0, Edata, Bdata);
89 pminus[0] = pxyz[0] / (mass *
CONST_C) + sigma * Exyz[0];
90 pminus[1] = pxyz[1] / (mass *
CONST_C) + sigma * Exyz[1];
91 pminus[2] = pxyz[2] / (mass *
CONST_C) + sigma * Exyz[2];
98 real Bhat[9] = { 0, Bxyz[2], -Bxyz[1],
100 Bxyz[1], -Bxyz[0], 0};
104 real B2 = Bxyz[0]*Bxyz[0] + Bxyz[1]*Bxyz[1] + Bxyz[2]*Bxyz[2];
107 for(
int j=0; j<9; j++) {
108 A[j] = (Bhat[j] + d*Bhat2[j]) * (2.0*d/(1.0+d2*B2));
116 pfinal[0] = pminus[0] + pplus[0] + sigma*Exyz[0];
117 pfinal[1] = pminus[1] + pplus[1] + sigma*Exyz[1];
118 pfinal[2] = pminus[2] + pplus[2] + sigma*Exyz[2];
120 pxyz[0] = pfinal[0] * mass *
CONST_C;
121 pxyz[1] = pfinal[1] * mass *
CONST_C;
122 pxyz[2] = pfinal[2] * mass *
CONST_C;
126 fposxyz[0] = posxyz[0] + h[i] * pxyz[0] / (2.0 * gamma * mass);
127 fposxyz[1] = posxyz[1] + h[i] * pxyz[1] / (2.0 * gamma * mass);
128 fposxyz[2] = posxyz[2] + h[i] * pxyz[2] / (2.0 * gamma * mass);
132 p->
r[i] = sqrt(fposxyz[0]*fposxyz[0]+fposxyz[1]*fposxyz[1]);
136 posxyz0[0] * fposxyz[1] - posxyz0[1] * fposxyz[0],
137 posxyz0[0] * fposxyz[0] + posxyz0[1] * fposxyz[1] );
138 p->
z[i] = fposxyz[2];
142 p->
p_r[i] = pxyz[0] * cosp + pxyz[1] * sinp;
143 p->
p_phi[i] = -pxyz[0] * sinp + pxyz[1] * cosp;
164 p->
B_r[i] = BdBrpz[0];
169 p->
B_phi[i] = BdBrpz[4];
174 p->
B_z[i] = BdBrpz[8];
177 p->
B_z_dz[i] = BdBrpz[11];
184 p->
theta[i] += atan2( (R0-axisrz[0]) * (p->
z[i]-axisrz[1])
185 - (z0-axisrz[1]) * (p->
r[i]-axisrz[0]),
186 (R0-axisrz[0]) * (p->
r[i]-axisrz[0])
187 + (z0-axisrz[1]) * (p->
z[i]-axisrz[1]) );
217 #pragma omp simd aligned(h : 64)
218 for(i = 0; i <
NSIMD; i++) {
232 real posrpz[3] = {p->
r[i], p->
phi[i], p->
z[i]};
233 real posxyz0[3],posxyz[3];
238 posxyz[0] = posxyz0[0] + pxyz[0] * h[i] / (2 * gamma * mass);
239 posxyz[1] = posxyz0[1] + pxyz[1] * h[i] / (2 * gamma * mass);
240 posxyz[2] = posxyz0[2] + pxyz[2] * h[i] / (2 * gamma * mass);
252 t0 + h[i]/2, Edata, Bdata);
259 pert, posrpz[0], posrpz[1], posrpz[2], t0 + h[i]/2,
282 pminus[0] = pxyz[0] / (mass *
CONST_C) + sigma * Exyz[0];
283 pminus[1] = pxyz[1] / (mass *
CONST_C) + sigma * Exyz[1];
284 pminus[2] = pxyz[2] / (mass *
CONST_C) + sigma * Exyz[2];
288 sqrt( 1 +
math_dot(pminus,pminus) );
291 real Bhat[9] = { 0, Bxyz[2], -Bxyz[1],
292 -Bxyz[2], 0, Bxyz[0],
293 Bxyz[1], -Bxyz[0], 0};
297 real B2 = Bxyz[0]*Bxyz[0] + Bxyz[1]*Bxyz[1] + Bxyz[2]*Bxyz[2];
300 for(
int j=0; j<9; j++) {
301 A[j] = (Bhat[j] + d*Bhat2[j]) * (2.0*d/(1+d2*B2));
309 pfinal[0] = pminus[0] + pplus[0] + sigma*Exyz[0];
310 pfinal[1] = pminus[1] + pplus[1] + sigma*Exyz[1];
311 pfinal[2] = pminus[2] + pplus[2] + sigma*Exyz[2];
313 pxyz[0] = pfinal[0] * mass *
CONST_C;
314 pxyz[1] = pfinal[1] * mass *
CONST_C;
315 pxyz[2] = pfinal[2] * mass *
CONST_C;
319 fposxyz[0] = posxyz[0] + h[i] * pxyz[0] / (2 * gamma * mass);
320 fposxyz[1] = posxyz[1] + h[i] * pxyz[1] / (2 * gamma * mass);
321 fposxyz[2] = posxyz[2] + h[i] * pxyz[2] / (2 * gamma * mass);
325 p->
r[i] = sqrt(fposxyz[0]*fposxyz[0]+fposxyz[1]*fposxyz[1]);
329 posxyz0[0] * fposxyz[1] - posxyz0[1] * fposxyz[0],
330 posxyz0[0] * fposxyz[0] + posxyz0[1] * fposxyz[1] );
331 p->
z[i] = fposxyz[2];
335 p->
p_r[i] = pxyz[0] * cosp + pxyz[1] * sinp;
336 p->
p_phi[i] = -pxyz[0] * sinp + pxyz[1] * cosp;
357 p->
B_r[i] = BdBrpz[0];
362 p->
B_phi[i] = BdBrpz[4];
367 p->
B_z[i] = BdBrpz[8];
370 p->
B_z_dz[i] = BdBrpz[11];
377 p->
theta[i] += atan2( (R0-axisrz[0]) * (p->
z[i]-axisrz[1])
378 - (z0-axisrz[1]) * (p->
r[i]-axisrz[0]),
379 (R0-axisrz[0]) * (p->
r[i]-axisrz[0])
380 + (z0-axisrz[1]) * (p->
z[i]-axisrz[1]) );
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.
a5err B_field_eval_B(real B[3], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field.
Header file for B_field.c.
a5err E_field_eval_E(real E[3], real r, real phi, real z, real t, E_field_data *Edata, B_field_data *Bdata)
Evaluate electric field.
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 for boozer.c.
Header file containing physical and mathematical constants.
#define CONST_C
Speed of light [m/s]
unsigned long int a5err
Simulation error flag.
void math_matmul(real *matA, real *matB, int d1, int d2, int d3, real *matC)
Matrix multiplication.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
#define math_xyz2rpz(xyz, rpz)
Convert cartesian coordinates xyz to cylindrical coordinates rpz.
#define math_vec_rpz2xyz(vrpz, vxyz, phi)
Transform vector from cylindrical to cartesian basis: vrpz -> vxyz, phi is the toroidal angle in radi...
#define math_rpz2xyz(rpz, xyz)
Convert cylindrical coordinates rpz to cartesian coordinates xyz.
#define math_norm(a)
Calculate norm of 3D vector a.
a5err mhd_perturbations(real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.
#define MHD_INCLUDE_ALL
includemode parameter to include all modes (default)
Header file for particle.c.
Methods to evaluate elementary physical quantities.
#define physlib_gamma_pnorm(m, p)
Evaluate Lorentz factor from momentum norm.
void step_fo_vpa_mhd(particle_simd_fo *p, real *h, B_field_data *Bdata, E_field_data *Edata, boozer_data *boozer, mhd_data *mhd)
Integrate a full orbit step with VPA and MHd modes present.
void step_fo_vpa(particle_simd_fo *p, real *h, B_field_data *Bdata, E_field_data *Edata)
Integrate a full orbit step for a struct of particles with VPA.
Header file for step_fo_vpa.c.
Magnetic field simulation data.
Electric field simulation data.
Boozer parameters on the target.
Struct representing NSIMD particle markers.