38 for(
int i = 0; i <
NSIMD; i++) {
43 real Brpz[3] = {p->B_r[i], p->B_phi[i], p->B_z[i]};
51 real vin, pin, xiin, Xin_xyz[3];
52 pin =
physlib_gc_p( p->mass[i], p->mu[i], p->ppar[i], Bnorm);
53 xiin =
physlib_gc_xi(p->mass[i], p->mu[i], p->ppar[i], Bnorm);
55 Xin_xyz[0] = p->r[i] * cos(p->phi[i]);
56 Xin_xyz[1] = p->r[i] * sin(p->phi[i]);
63 p->r[i], p->phi[i], p->z[i],
70 n_species, mb, qb, nb, Tb);
76 real K = 0, Dpara = 0, nu = 0, DX = 0;
77 for(
int j = 0; j < n_species; j++) {
78 real vb = sqrt( 2 * Tb[j] / mb[j] );
84 qb[j], nb[j], vb, clogab[j],
87 qb[j], nb[j], vb, clogab[j],
90 qb[j], nb[j], vb, clogab[j],
93 qb[j], nb[j], vb, clogab[j],
103 real sdt = sqrt(h[i]);
105 dW[0]=sdt*rnd[0*
NSIMD + i];
106 dW[1]=sdt*rnd[1*
NSIMD + i];
107 dW[2]=sdt*rnd[2*
NSIMD + i];
108 dW[3]=sdt*rnd[3*
NSIMD + i];
109 dW[4]=sdt*rnd[4*
NSIMD + i];
114 real k1 = sqrt(2*DX);
117 real vout, xiout, Xout_xyz[3];
118 Xout_xyz[0] = Xin_xyz[0] + k1 * ( dW[0] - k2 * bhat[0] );
119 Xout_xyz[1] = Xin_xyz[1] + k1 * ( dW[1] - k2 * bhat[1] );
120 Xout_xyz[2] = Xin_xyz[2] + k1 * ( dW[2] - k2 * bhat[2] );
121 vout = vin + K*h[i] + sqrt( 2 * Dpara ) * dW[3];
122 xiout = xiin - xiin*nu*h[i] + sqrt(( 1 - xiin*xiin ) * nu) * dW[4];
127 vout = 2 * cutoff - vout;
131 xiout = ( (xiout > 0) - (xiout < 0) )
132 * ( 2 - fabs( xiout ) );
144 Xout_xyz[0] = Xin_xyz[0];
145 Xout_xyz[1] = Xin_xyz[1];
146 Xout_xyz[2] = Xin_xyz[2];
155 real B_dB[15], psi[1], rho[2];
158 Xout_rpz[2], p->time[i] + h[i],
163 Xout_rpz[2], p->time[i] + h[i],
173 p->B_r_dr[i] = B_dB[1];
174 p->B_r_dphi[i] = B_dB[2];
175 p->B_r_dz[i] = B_dB[3];
177 p->B_phi[i] = B_dB[4];
178 p->B_phi_dr[i] = B_dB[5];
179 p->B_phi_dphi[i] = B_dB[6];
180 p->B_phi_dz[i] = B_dB[7];
183 p->B_z_dr[i] = B_dB[9];
184 p->B_z_dphi[i] = B_dB[10];
185 p->B_z_dz[i] = B_dB[11];
189 Bnorm =
math_normc(B_dB[0], B_dB[4], B_dB[8]);
191 p->r[i] = Xout_rpz[0];
192 p->z[i] = Xout_rpz[2];
199 p->theta[i] += atan2( (R0-axisrz[0]) * (p->z[i]-axisrz[1])
200 - (z0-axisrz[1]) * (p->r[i]-axisrz[0]),
201 (R0-axisrz[0]) * (p->r[i]-axisrz[0])
202 + (z0-axisrz[1]) * (p->z[i]-axisrz[1]) );
203 p->phi[i] += atan2( Xin_xyz[0] * Xout_xyz[1]
204 - Xin_xyz[1] * Xout_xyz[0],
205 Xin_xyz[0] * Xout_xyz[0]
206 + Xin_xyz[1] * Xout_xyz[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.
Header file for B_field.c.
Main header file for ASCOT5.
#define NSIMD
Number of particles simulated simultaneously in a particle group operations.
#define MAX_SPECIES
Maximum number of plasma species.
Header file containing physical and mathematical constants.
unsigned long int a5err
Simulation error flag.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
#define math_unit(a, b)
Calculate unit vector b from a 3D vector a.
#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_normc(a1, a2, a3)
Calculate norm of 3D vector from its components a1, a2, a3.
#define math_norm(a)
Calculate norm of 3D vector a.
Header file for mccc package.
#define MCCC_CUTOFF
Defines minimum energy boundary condition.
Routines to evaluate coefficients needed to evaluate collisions.
#define mccc_coefs_Dpara(ma, qa, va, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic parallel diffusion coefficient [m^2/s^3].
#define mccc_coefs_dDpara(ma, qa, va, qb, nb, vb, clogab, mu0, dmu0)
Evaluate derivative of non-relativistic parallel diffusion coefficient [m/s^2].
#define mccc_coefs_K(va, Dpara, dDpara, Q)
Evaluate guiding center drag coefficient [m/s^2].
static void mccc_coefs_mufun(real mufun[3], real x, mccc_data *mdata)
Evaluate special functions needed by collision coefficients.
#define mccc_coefs_Dperp(ma, qa, va, qb, nb, vb, clogab, mu1)
Evaluate non-relativistic perpendicular diffusion coefficient [m^2/s^3].
#define mccc_coefs_nu(va, Dperp)
Evaluate pitch collision frequency [1/s].
#define mccc_coefs_DX(xi, Dpara, Dperp, gyrofreq)
Evaluate spatial diffusion coefficient [m^2/s].
static DECLARE_TARGET_END void mccc_coefs_clog(real *clogab, real ma, real qa, real va, int nspec, const real *mb, const real *qb, const real *nb, const real *Tb)
Evaluate Coulomb logarithm.
#define mccc_coefs_Q(ma, qa, mb, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic drag coefficient [m/s^2].
void mccc_gc_euler(particle_simd_gc *p, real *h, B_field_data *Bdata, plasma_data *pdata, mccc_data *mdata, real *rnd)
Integrate collisions for one time-step.
Header file for particle.c.
Methods to evaluate elementary physical quantities.
#define physlib_gc_xi(m, mu, ppar, B)
Evaluate guiding center pitch from parallel momentum and magnetic moment.
#define physlib_pnorm_vnorm(m, v)
Evaluate momentum norm [kg m/s] from velocity norm.
#define physlib_vnorm_pnorm(m, p)
Evaluate velocity norm [m/s] from momentum norm.
#define phys_gyrofreq_pnorm(m, q, p, B)
Evaluate gyrofrequency [rad/s] from momentum norm.
#define physlib_gc_ppar(p, xi)
Evaluate guiding center parallel momentum [kg m/s] from momentum norm and pitch.
#define physlib_gc_p(m, mu, ppar, B)
Evaluate guiding center momentum norm [kg m/s] from parallel momentum and magnetic moment.
#define physlib_gc_mu(m, p, xi, B)
Evaluate guiding center magnetic moment [J/T] from momentum norm and pitch.
const real * plasma_get_species_mass(plasma_data *pls_data)
Get mass of all plasma species.
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
const real * plasma_get_species_charge(plasma_data *pls_data)
Get charge of all plasma species.
a5err plasma_eval_densandtemp(real *dens, real *temp, real rho, real r, real phi, real z, real t, plasma_data *pls_data)
Evaluate plasma density and temperature for all species.
Header file for plasma.c.
Header file for random.c.
Magnetic field simulation data.
Parameters and data required to evaluate Coulomb collisions.
Struct representing NSIMD guiding center markers.