75 #pragma omp parallel for
76 for(
int k = 0; k < Neval; k++) {
122 #pragma omp parallel for
123 for(
int k = 0; k < Neval; k++) {
124 real rhoval[2], psival[4];
130 dpsidr[k] = psival[1];
131 dpsidphi[k] = psival[2];
132 dpsidz[k] = psival[3];
137 drhodpsi[k] = rhoval[1];
158 #pragma omp parallel for
159 for(
int k = 0; k < Neval; k++) {
164 Raxis[k] = axisrz[0];
165 zaxis[k] = axisrz[1];
197 #pragma omp parallel for
198 for(
int j=0; j<Neval; j++) {
208 if( rhodrho[0] > rho[j] ) {
218 real costh = cos(theta[j]);
219 real sinth = sin(theta[j]);
220 for(
int i=0; i<maxiter; i++) {
221 rj = axisrz[0] + x * costh;
222 zj = axisrz[1] + x * sinth;
226 if( fabs(rho[j] - rhodrho[0]) < tol ) {
232 real drhodx = costh * rhodrho[1] + sinth * rhodrho[3];
233 x = x - (rhodrho[0] - rho[j]) / drhodx;
236 x = (x + (rhodrho[0] - rho[j]) / drhodx) / 2;
259 real rz[2],
real step,
real tol,
int maxiter,
int ascent) {
268 real phi = 0.0, time = 0.0;
269 real psidpsi[4], nextrz[2];
278 nextrz[0] = rz[0] - step * psidpsi[1];
279 nextrz[1] = rz[1] - step * psidpsi[3];
282 if(sqrt( (nextrz[0] - rz[0]) * (nextrz[0] - rz[0])
283 + (nextrz[1] - rz[1]) * (nextrz[1] - rz[1]) ) < tol) {
290 psidpsi, rz[0], phi, rz[1], time, &sim.
B_data);
291 psi[0] = psi[0] + (tol * psidpsi[1] + tol * psidpsi[3]);
299 if(iter == maxiter) {
331 #pragma omp parallel for
332 for(
int k = 0; k < Neval; k++) {
357 plasma_offload_array);
373 real* charge,
int* anum,
int* znum) {
377 plasma_offload_array);
387 for(
int i=1; i<n_species; i++) {
418 plasma_offload_array);
421 #pragma omp parallel for
422 for(
int k = 0; k < Neval; k++) {
434 for(
int i=0; i<n_species; i++) {
435 dens[k + i*Neval] = n[i];
436 temp[k + i*Neval] = T[i]/
CONST_E;
456 real* neutral_offload_array,
int Neval,
463 neutral_offload_array);
465 #pragma omp parallel for
466 for(
int k = 0; k < Neval; k++) {
467 real psi[1], rho[2], n0[1];
509 real* boozer_offload_array,
int Neval,
519 boozer_offload_array);
521 #pragma omp parallel for
522 for(
int k = 0; k < Neval; k++) {
524 real psithetazeta[12], rhoval[2];
535 psi[k] = psithetazeta[0];
536 theta[k] = psithetazeta[4];
537 zeta[k] = psithetazeta[8];
538 dpsidr[k] = psithetazeta[1];
539 dpsidphi[k] = psithetazeta[2];
540 dpsidz[k] = psithetazeta[3];
541 dthetadr[k] = psithetazeta[5];
542 dthetadphi[k] = psithetazeta[6];
543 dthetadz[k] = psithetazeta[7];
544 dzetadr[k] = psithetazeta[9];
545 dzetadphi[k] = psithetazeta[10];
546 dzetadz[k] = psithetazeta[11];
575 boozer_offload_array);
577 #pragma omp parallel for
578 for(
int k = 0; k < Neval; k++) {
580 real psithetazeta[12], B[15];
592 real bvec[] = {B[0], B[4], B[8]};
593 real gradpsi[] = {psithetazeta[1],
594 psithetazeta[2]/R[k],
596 real gradtheta[] = {psithetazeta[5],
597 psithetazeta[6]/R[k],
599 real gradzeta[] = {psithetazeta[9],
600 psithetazeta[10]/R[k],
603 real veca[3], vecb[3];
607 qprof[k] = (veca[1] - bvec[1]) / vecb[1];
610 jac[k] = -1.0 /
math_dot(veca, gradpsi);
645 int* mmode,
real* amplitude,
real* omega,
real* phase) {
656 for(
int i=0; i<n_modes; i++) {
691 real* boozer_offload_array,
real* mhd_offload_array,
int Neval,
700 boozer_offload_array);
704 #pragma omp parallel for
705 for(
int k = 0; k < Neval; k++) {
707 if(
mhd_eval(mhd_dmhd, R[k], phi[k], z[k], t[k], includemode,
711 alpha[k] = mhd_dmhd[0];
712 dadr[k] = mhd_dmhd[2];
713 dadphi[k] = mhd_dmhd[3];
714 dadz[k] = mhd_dmhd[4];
715 dadt[k] = mhd_dmhd[1];
716 Phi[k] = mhd_dmhd[5];
717 dPhidr[k] = mhd_dmhd[7];
718 dPhidphi[k] = mhd_dmhd[8];
719 dPhidz[k] = mhd_dmhd[9];
720 dPhidt[k] = mhd_dmhd[6];
747 real* boozer_offload_array,
real* mhd_offload_array,
int Neval,
756 boozer_offload_array);
760 #pragma omp parallel for
761 for(
int k = 0; k < Neval; k++) {
768 mhd_br[k] = pert_field[0];
769 mhd_bphi[k] = pert_field[1];
770 mhd_bz[k] = pert_field[2];
771 mhd_er[k] = pert_field[3];
772 mhd_ephi[k] = pert_field[4];
773 mhd_ez[k] = pert_field[5];
774 mhd_phi[k] = pert_field[6];
818 plasma_offload_array);
825 #pragma omp parallel for
826 for(
int k=0; k<Neval; k++) {
827 real mufun[3] = {0., 0., 0.};
845 for(
int iv=0; iv<Nv; iv++) {
848 for(
int ib=0; ib<n_species; ib++) {
856 real vb = sqrt( 2 * Tb[ib] / mb[ib] );
857 real x = va[iv] / vb;
862 clogab[ib], mufun[0]);
864 clogab[ib], mufun[0]);
866 clogab[ib], mufun[2]);
868 vb, clogab[ib], mufun[0]);
870 vb, clogab[ib], mufun[1]);
872 vb, clogab[ib], mufun[0],
878 int idx = ib*Nv*Neval + Nv * k + iv;
879 if(mu0 != NULL) { mu0[idx] = mufun[0]; }
880 if(mu1 != NULL) { mu1[idx] = mufun[1]; }
881 if(dmu0 != NULL) { dmu0[idx] = mufun[2]; }
882 if(clog != NULL) { clog[idx] = clogab[ib]; }
883 if(F != NULL) { F[idx] = Fb; }
884 if(Dpara != NULL) { Dpara[idx] = Dparab; }
885 if(Dperp != NULL) { Dperp[idx] = Dperpb; }
886 if(K != NULL) { K[idx] = Kb; }
887 if(nu != NULL) { nu[idx] = nub; }
888 if(Q != NULL) { Q[idx] = Qb; }
889 if(dQ != NULL) { dQ[idx] = dQb; }
890 if(dDpara != NULL) { dDpara[idx] = dDparab; }
919 real* plasma_offload_array,
real* neutral_offload_array,
920 real* asigma_offload_array,
922 int Aa,
int Za,
real ma,
int reac_type,
real* ratecoeff) {
928 plasma_offload_array);
930 neutral_offload_array);
932 asigma_offload_array);
939 #pragma omp parallel for
940 for (
int k=0; k < Neval; k++) {
961 for (
int j=0; j < Nv; j++) {
967 &val, Za, Aa, E, ma, nspec, Zb, Ab, T0[0], n0,
971 ratecoeff[Nv*k + j] = val;
975 &val, Za, Aa, E, ma, nion, Zb, Ab, T[0], n,
979 ratecoeff[Nv*k + j] = val * n[0];
a5err B_field_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
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_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
int B_field_init(B_field_data *Bdata, B_field_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
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.
int E_field_init(E_field_data *Edata, E_field_offload_data *offload_data, real *offload_array)
Initialize electric field data struct on target.
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 MAX_SPECIES
Maximum number of plasma species.
a5err asigma_eval_cx(real *ratecoeff, int z_1, int a_1, real E, real mass, int nspec, const int *znum, const int *anum, real T_0, real *n_0, asigma_data *asigma_data)
Evaluate charge exchange rate coefficient.
int asigma_init(asigma_data *asigma_data, asigma_offload_data *offload_data, real *offload_array)
Initializes atomic reaction data struct on target.
a5err asigma_eval_bms(real *ratecoeff, int z_1, int a_1, real E, real mass, int nion, const int *znum, const int *anum, real T_e, real *n_i, asigma_data *asigma_data)
Evaluate beam stopping rate coefficient.
Header file for asigma.c.
void boozer_init(boozer_data *boozerdata, boozer_offload_data *offload_data, real *offload_array)
Initialize boozer data struct on target.
a5err boozer_eval_psithetazeta(real psithetazeta[12], int *isinside, real r, real phi, real z, B_field_data *Bdata, boozer_data *boozerdata)
Evaluate Boozer coordinates and partial derivatives.
Header file for boozer.c.
Header file containing physical and mathematical constants.
#define CONST_M_E
Electron mass [kg]
#define CONST_C
Speed of light [m/s]
#define CONST_E
Elementary charge [C]
Header file for hdf5_bfield.c.
Header file for hdf5_boozer.c.
Header file for hdf5_efielc.c.
Header file for hdf5_helpers.h.
Header file for hdf5_interface.c.
Header file for hdf5_mhd.c.
Header file for hdf5_neutral.c.
Header file for hdf5_plasma.c.
Header file for hdf5_wall.c.
void libascot_mhd_eval(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, real *mhd_offload_array, int Neval, real *R, real *phi, real *z, real *t, int includemode, real *alpha, real *dadr, real *dadphi, real *dadz, real *dadt, real *Phi, real *dPhidr, real *dPhidphi, real *dPhidz, real *dPhidt)
Evaluate MHD perturbation potentials.
void libascot_eval_ratecoeff(sim_offload_data *sim_offload_data, real *B_offload_array, real *plasma_offload_array, real *neutral_offload_array, real *asigma_offload_array, int Neval, real *R, real *phi, real *z, real *t, int Nv, real *va, int Aa, int Za, real ma, int reac_type, real *ratecoeff)
Evaluate atomic reaction rate coefficient.
void libascot_plasma_eval_background(sim_offload_data *sim_offload_data, real *B_offload_array, real *plasma_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *dens, real *temp)
Evaluate plasma density and temperature at given coordinates.
void libascot_B_field_eval_B_dB(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *BR, real *Bphi, real *Bz, real *BR_dR, real *BR_dphi, real *BR_dz, real *Bphi_dR, real *Bphi_dphi, real *Bphi_dz, real *Bz_dR, real *Bz_dphi, real *Bz_dz)
Evaluate magnetic field vector and derivatives at given coordinates.
void libascot_eval_collcoefs(sim_offload_data *sim_offload_data, real *B_offload_array, real *plasma_offload_array, int Neval, real *R, real *phi, real *z, real *t, int Nv, real *va, real ma, real qa, real *F, real *Dpara, real *Dperp, real *K, real *nu, real *Q, real *dQ, real *dDpara, real *clog, real *mu0, real *mu1, real *dmu0)
Evaluate collision coefficients.
void libascot_B_field_gradient_descent(sim_offload_data *sim_offload_data, real *B_offload_array, real psi[1], real rz[2], real step, real tol, int maxiter, int ascent)
Find psi on axis using the gradient descent method.
void libascot_E_field_eval_E(sim_offload_data *sim_offload_data, real *B_offload_array, real *E_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *ER, real *Ephi, real *Ez)
Evaluate electric field vector at given coordinates.
void libascot_B_field_eval_rho(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *rho, real *drhodpsi, real *psi, real *dpsidr, real *dpsidphi, real *dpsidz)
Evaluate normalized poloidal flux at given coordinates.
int libascot_mhd_get_n_modes(sim_offload_data *sim_offload_data, real *mhd_offload_array)
Get number of MHD modes.
void libascot_boozer_eval_fun(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *qprof, real *jac, real *jacB2)
Evaluate boozer coordinates related quantities.
void libascot_mhd_get_mode_specs(sim_offload_data *sim_offload_data, real *mhd_offload_array, int *nmode, int *mmode, real *amplitude, real *omega, real *phase)
Get MHD mode amplitude, frequency, phase, and mode numbers.
void libascot_B_field_get_axis(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *phi, real *Raxis, real *zaxis)
Get magnetic axis at given coordinates.
void libascot_neutral_eval_density(sim_offload_data *sim_offload_data, real *B_offload_array, real *neutral_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *dens)
Evaluate neutral density at given coordinates.
void libascot_boozer_eval_psithetazeta(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *psi, real *theta, real *zeta, real *dpsidr, real *dpsidphi, real *dpsidz, real *dthetadr, real *dthetadphi, real *dthetadz, real *dzetadr, real *dzetadphi, real *dzetadz, real *rho)
Evaluate boozer coordinates and derivatives.
void libascot_plasma_get_species_mass_and_charge(sim_offload_data *sim_offload_data, real *plasma_offload_array, real *mass, real *charge, int *anum, int *znum)
Get mass and charge of all plasma species.
void libascot_mhd_eval_perturbation(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, real *mhd_offload_array, int Neval, real *R, real *phi, real *z, real *t, int includemode, real *mhd_br, real *mhd_bphi, real *mhd_bz, real *mhd_er, real *mhd_ephi, real *mhd_ez, real *mhd_phi)
Evaluate MHD perturbation EM-field components.
void libascot_B_field_rhotheta2rz(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *rho, real *theta, real *phi, real t, int maxiter, real tol, real *r, real *z)
Map (rho, theta, phi) to (R,z) coordinates.
int libascot_plasma_get_n_species(sim_offload_data *sim_offload_data, real *plasma_offload_array)
Get number of plasma species.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
#define math_cross(a, b, c)
Calculate cross product for 3D vectors c = a x b.
#define math_norm(a)
Calculate norm of 3D vector a.
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_dQ(ma, qa, mb, qb, nb, vb, clogab, dmu0)
Evaluate derivative of non-relativistic drag 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_F(ma, qa, mb, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic friction coefficient [m/s^2].
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].
int mhd_get_n_modes(mhd_data *mhddata)
Return number of modes.
const real * mhd_get_amplitude(mhd_data *mhddata)
Return mode amplitudes.
const int * mhd_get_nmode(mhd_data *mhddata)
Return mode toroidal numbers.
int mhd_init(mhd_data *mhddata, mhd_offload_data *offload_data, real *offload_array)
Initialize MHD data struct on target.
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.
const int * mhd_get_mmode(mhd_data *mhddata)
Return mode poloidal numbers.
const real * mhd_get_frequency(mhd_data *mhddata)
Return mode frequencies.
a5err mhd_eval(real mhd_dmhd[10], real r, real phi, real z, real t, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate the needed quantities from MHD mode for orbit following.
const real * mhd_get_phase(mhd_data *mhddata)
Return mode phases.
int neutral_get_n_species(neutral_data *ndata)
Get the number of neutral species.
int neutral_init(neutral_data *ndata, neutral_offload_data *offload_data, real *offload_array)
Initialize neutral data struct on target.
a5err neutral_eval_n0(real *n0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral density.
a5err neutral_eval_t0(real *t0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral temperature.
Header file for neutral.c.
Methods to evaluate elementary physical quantities.
#define physlib_gamma_vnorm(v)
Evaluate Lorentz factor from velocity norm.
const real * plasma_get_species_mass(plasma_data *pls_data)
Get mass of all plasma species.
const int * plasma_get_species_znum(plasma_data *pls_data)
Get charge number of ion 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.
int plasma_init(plasma_data *pls_data, plasma_offload_data *offload_data, real *offload_array)
Initialize plasma data struct on target.
const int * plasma_get_species_anum(plasma_data *pls_data)
Get atomic mass number of ion species.
Header file for plasma.c.
Header file for simulate.c.
neutral_data neutral_data
Simulation offload struct.
B_field_offload_data B_offload_data
plasma_offload_data plasma_offload_data
neutral_offload_data neutral_offload_data
mhd_offload_data mhd_offload_data
asigma_offload_data asigma_offload_data
boozer_offload_data boozer_offload_data
E_field_offload_data E_offload_data