71 #pragma omp parallel for
72 for(
int k = 0; k < Neval; k++) {
113 #pragma omp parallel for
114 for(
int k = 0; k < Neval; k++) {
115 real rhoval[2], psival[4];
121 dpsidr[k] = psival[1];
122 dpsidphi[k] = psival[2];
123 dpsidz[k] = psival[3];
128 drhodpsi[k] = rhoval[1];
144 #pragma omp parallel for
145 for(
int k = 0; k < Neval; k++) {
150 Raxis[k] = axisrz[0];
151 zaxis[k] = axisrz[1];
178 #pragma omp parallel for
179 for(
int j=0; j<Neval; j++) {
189 if( rhodrho[0] > rho[j] ) {
199 real costh = cos(theta[j]);
200 real sinth = sin(theta[j]);
201 for(
int i=0; i<maxiter; i++) {
202 rj = axisrz[0] + x * costh;
203 zj = axisrz[1] + x * sinth;
207 if( fabs(rho[j] - rhodrho[0]) < tol ) {
213 real drhodx = costh * rhodrho[1] + sinth * rhodrho[3];
214 x = x - (rhodrho[0] - rho[j]) / drhodx;
217 x = (x + (rhodrho[0] - rho[j]) / drhodx) / 2;
239 real rz[2],
real step,
real tol,
int maxiter,
int ascent) {
245 real phi = 0.0, time = 0.0;
246 real psidpsi[4], nextrz[2];
255 nextrz[0] = rz[0] - step * psidpsi[1];
256 nextrz[1] = rz[1] - step * psidpsi[3];
259 if(sqrt( (nextrz[0] - rz[0]) * (nextrz[0] - rz[0])
260 + (nextrz[1] - rz[1]) * (nextrz[1] - rz[1]) ) < tol) {
267 psidpsi, rz[0], phi, rz[1], time, &sim->
B_data);
268 psi[0] = psi[0] + (tol * psidpsi[1] + tol * psidpsi[3]);
276 if(iter == maxiter) {
308 real psidpsi[4], nextrzphi[3];
318 nextrzphi[0] = rzphi[0] - step * psidpsi[1];
319 nextrzphi[1] = rzphi[1] - step * psidpsi[3];
320 nextrzphi[2] = rzphi[2] - step/rzphi[0] * psidpsi[2];
329 if (nextrzphi[2] > phimax) {nextrzphi[2] = phimax;}
330 if (nextrzphi[2] < phimin) {nextrzphi[2]=phimin;}
334 if(sqrt( (nextrzphi[0] - rzphi[0]) * (nextrzphi[0] - rzphi[0])
335 + (nextrzphi[1] - rzphi[1]) * (nextrzphi[1] - rzphi[1])
336 + rzphi[0]*(nextrzphi[2] - rzphi[2]) *
337 rzphi[0]*(nextrzphi[2] - rzphi[2])) < tol){
339 rzphi[0] = nextrzphi[0];
340 rzphi[1] = nextrzphi[1];
341 rzphi[2] = nextrzphi[2];
345 psidpsi, rzphi[0], rzphi[2], rzphi[1], time, &sim->
B_data);
347 + (tol * ( psidpsi[1] + psidpsi[2]/rzphi[0] + psidpsi[3] ));
351 rzphi[0] = nextrzphi[0];
352 rzphi[1] = nextrzphi[1];
353 rzphi[2] = nextrzphi[2];
356 if(iter == maxiter) {
379 #pragma omp parallel for
380 for(
int k = 0; k < Neval; k++) {
424 for(
int i=1; i<n_species; i++) {
450 #pragma omp parallel for
451 for(
int k = 0; k < Neval; k++) {
463 for(
int i=0; i<n_species; i++) {
464 dens[k + i*Neval] = n[i];
465 temp[k + i*Neval] = T[i]/
CONST_E;
484 #pragma omp parallel for
485 for(
int k = 0; k < Neval; k++) {
486 real psi[1], rho[2], n0[1];
531 #pragma omp parallel for
532 for(
int k = 0; k < Neval; k++) {
534 real psithetazeta[12], rhoval[2];
545 psi[k] = psithetazeta[0];
546 theta[k] = psithetazeta[4];
547 zeta[k] = psithetazeta[8];
548 dpsidr[k] = psithetazeta[1];
549 dpsidphi[k] = psithetazeta[2];
550 dpsidz[k] = psithetazeta[3];
551 dthetadr[k] = psithetazeta[5];
552 dthetadphi[k] = psithetazeta[6];
553 dthetadz[k] = psithetazeta[7];
554 dzetadr[k] = psithetazeta[9];
555 dzetadphi[k] = psithetazeta[10];
556 dzetadz[k] = psithetazeta[11];
578 #pragma omp parallel for
579 for(
int k = 0; k < Neval; k++) {
581 real psithetazeta[12], B[15];
593 real bvec[] = {B[0], B[4], B[8]};
594 real gradpsi[] = {psithetazeta[1],
595 psithetazeta[2]/R[k],
597 real gradtheta[] = {psithetazeta[5],
598 psithetazeta[6]/R[k],
600 real gradzeta[] = {psithetazeta[9],
601 psithetazeta[10]/R[k],
604 real veca[3], vecb[3];
608 qprof[k] = (veca[1] - bvec[1]) / vecb[1];
611 jac[k] = -1.0 /
math_dot(veca, gradpsi);
648 for(
int i=0; i<n_modes; i++) {
684 #pragma omp parallel for
685 for(
int k = 0; k < Neval; k++) {
687 if(
mhd_eval(mhd_dmhd, R[k], phi[k], z[k], t[k], includemode,
691 alpha[k] = mhd_dmhd[0];
692 dadr[k] = mhd_dmhd[2];
693 dadphi[k] = mhd_dmhd[3];
694 dadz[k] = mhd_dmhd[4];
695 dadt[k] = mhd_dmhd[1];
696 Phi[k] = mhd_dmhd[5];
697 dPhidr[k] = mhd_dmhd[7];
698 dPhidphi[k] = mhd_dmhd[8];
699 dPhidz[k] = mhd_dmhd[9];
700 dPhidt[k] = mhd_dmhd[6];
729 #pragma omp parallel for
730 for(
int k = 0; k < Neval; k++) {
737 mhd_br[k] = pert_field[0];
738 mhd_bphi[k] = pert_field[1];
739 mhd_bz[k] = pert_field[2];
740 mhd_er[k] = pert_field[3];
741 mhd_ephi[k] = pert_field[4];
742 mhd_ez[k] = pert_field[5];
743 mhd_phi[k] = pert_field[6];
784 #pragma omp parallel for
785 for(
int k=0; k<Neval; k++) {
786 real mufun[3] = {0., 0., 0.};
804 for(
int iv=0; iv<Nv; iv++) {
807 for(
int ib=0; ib<n_species; ib++) {
815 real vb = sqrt( 2 * Tb[ib] / mb[ib] );
816 real x = va[iv] / vb;
821 clogab[ib], mufun[0]);
823 clogab[ib], mufun[0]);
825 clogab[ib], mufun[2]);
827 vb, clogab[ib], mufun[0]);
829 vb, clogab[ib], mufun[1]);
831 vb, clogab[ib], mufun[0],
837 int idx = ib*Nv*Neval + Nv * k + iv;
838 if(mu0 != NULL) { mu0[idx] = mufun[0]; }
839 if(mu1 != NULL) { mu1[idx] = mufun[1]; }
840 if(dmu0 != NULL) { dmu0[idx] = mufun[2]; }
841 if(clog != NULL) { clog[idx] = clogab[ib]; }
842 if(F != NULL) { F[idx] = Fb; }
843 if(Dpara != NULL) { Dpara[idx] = Dparab; }
844 if(Dperp != NULL) { Dperp[idx] = Dperpb; }
845 if(K != NULL) { K[idx] = Kb; }
846 if(nu != NULL) { nu[idx] = nub; }
847 if(Q != NULL) { Q[idx] = Qb; }
848 if(dQ != NULL) { dQ[idx] = dQb; }
849 if(dDpara != NULL) { dDpara[idx] = dDparab; }
875 int Aa,
int Za,
real ma,
int reac_type,
real* ratecoeff) {
882 #pragma omp parallel for
883 for (
int k=0; k < Neval; k++) {
904 for (
int j=0; j < Nv; j++) {
910 &val, Za, Aa, E, ma, nspec, Zb, Ab, T0[0], n0,
914 ratecoeff[Nv*k + j] = val;
918 &val, Za, Aa, E, ma, nion, Zb, Ab, T[0], n,
922 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.
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.
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.
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.
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_neutral_eval_density(sim_data *sim, int Neval, real *R, real *phi, real *z, real *t, real *dens)
Evaluate neutral density at given coordinates.
void libascot_E_field_eval_E(sim_data *sim, 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_eval_collcoefs(sim_data *sim, 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_boozer_eval_fun(sim_data *sim, int Neval, real *R, real *phi, real *z, real *t, real *qprof, real *jac, real *jacB2)
Evaluate boozer coordinates related quantities.
void libascot_B_field_gradient_descent_3d(sim_data *sim, real psi[1], real rzphi[3], real phimin, real phimax, real step, real tol, int maxiter, int ascent)
Find one psi minimum using the gradient descent method for 3D field inside a sector (phimin < phi < p...
void libascot_eval_ratecoeff(sim_data *sim, 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_mhd_eval_perturbation(sim_data *sim, 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.
int libascot_plasma_get_n_species(sim_data *sim)
Get number of plasma species.
void libascot_mhd_get_mode_specs(sim_data *sim, int *nmode, int *mmode, real *amplitude, real *omega, real *phase)
Get MHD mode amplitude, frequency, phase, and mode numbers.
void libascot_plasma_eval_background(sim_data *sim, int Neval, real *R, real *phi, real *z, real *t, real *dens, real *temp)
Evaluate plasma density and temperature at given coordinates.
void libascot_boozer_eval_psithetazeta(sim_data *sim, 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.
int libascot_mhd_get_n_modes(sim_data *sim)
Get number of MHD modes.
void libascot_B_field_rhotheta2rz(sim_data *sim, 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.
void libascot_B_field_eval_B_dB(sim_data *sim, 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_B_field_get_axis(sim_data *sim, int Neval, real *phi, real *Raxis, real *zaxis)
Get magnetic axis at given coordinates.
void libascot_plasma_get_species_mass_and_charge(sim_data *sim, real *mass, real *charge, int *anum, int *znum)
Get mass and charge of all plasma species.
void libascot_mhd_eval(sim_data *sim, 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_B_field_gradient_descent(sim_data *sim, 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_B_field_eval_rho(sim_data *sim, 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.
#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.
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.
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.
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