ASCOT5
Loading...
Searching...
No Matches
Functions
libascot.c File Reference

Library of Ascot5 functions for external use. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <hdf5.h>
#include <math.h>
#include "ascot5.h"
#include "gitver.h"
#include "simulate.h"
#include "B_field.h"
#include "E_field.h"
#include "plasma.h"
#include "wall.h"
#include "neutral.h"
#include "boozer.h"
#include "mhd.h"
#include "asigma.h"
#include "consts.h"
#include "physlib.h"
#include "simulate/mccc/mccc_coefs.h"
#include "hdf5_interface.h"
#include "hdf5io/hdf5_helpers.h"
#include "hdf5io/hdf5_bfield.h"
#include "hdf5io/hdf5_efield.h"
#include "hdf5io/hdf5_plasma.h"
#include "hdf5io/hdf5_wall.h"
#include "hdf5io/hdf5_neutral.h"
#include "hdf5io/hdf5_boozer.h"
#include "hdf5io/hdf5_mhd.h"

Go to the source code of this file.

Functions

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_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.
 
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_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.
 
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.
 
int libascot_plasma_get_n_species (sim_offload_data *sim_offload_data, real *plasma_offload_array)
 Get number of plasma species.
 
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_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_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_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.
 
int libascot_mhd_get_n_modes (sim_offload_data *sim_offload_data, real *mhd_offload_array)
 Get number of MHD modes.
 
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_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_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_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_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.
 

Detailed Description

Library of Ascot5 functions for external use.

Functions in this file allows to evaluate input data and quantities using the same methods as is used in actual simulation.

Definition in file libascot.c.

Function Documentation

◆ libascot_B_field_eval_B_dB()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
BRoutput array [T].
Bphioutput array [T].
Bzoutput array [T].
BR_dRoutput array [T].
BR_dphioutput array [T].
BR_dzoutput array [T].
Bphi_dRoutput array [T].
Bphi_dphioutput array [T].
Bphi_dzoutput array [T].
Bz_dRoutput array [T].
Bz_dphioutput array [T].
Bz_dzoutput array [T].

Definition at line 65 of file libascot.c.

◆ libascot_B_field_eval_rho()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
rhooutput array for the normalized poloidal flux.
drhodpsioutput array for normalized poloidal flux psi derivative.
psioutput array for the poloidal flux [Wb].
dpsidroutput array for the poloidal flux R derivative [Wb/m].
dpsidphioutput array for the poloidal flux phi derivative [Wb/rad].
dpsidzoutput array for the poloidal flux z derivative [Wb/m].

Definition at line 113 of file libascot.c.

◆ libascot_B_field_get_axis()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
Nevalnumber of evaluation points.
phiphi coordinates of the evaluation points [rad].
Raxisoutput array for axis R coordinates.
zaxisoutput array for axis z coordinates.

Definition at line 151 of file libascot.c.

◆ libascot_B_field_rhotheta2rz()

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.

This function implements the Newton method. If the function fails on a given position, the corresponding (R,z) values in the output arrays are not altered.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
Nevalnumber of query points.
rhothe square root of the normalized poloidal flux values.
thetapoloidal angles [rad].
phitoroidal angles [rad].
ttime coordinate (same for all) [s].
maxitermaximum number of iterations in Newton algorithm.
tolalgorithm is stopped when |rho - rho(r,z)| < tol
routput array for R coordinates [m].
zoutput array for z coordinates [m].

Definition at line 188 of file libascot.c.

◆ libascot_B_field_gradient_descent()

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.

Note that the psi value is not returned in case this algorithm fails.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
psivalue of psi on axis if this function did not fail
rzinitial (R,z) position where also the result is stored
stepthe step size
tolthe current position is accepted if the distance (in meters) between this and the previous point is below this value
maxitermaximum number of iterations before failure
ascentif true the algorithm instead ascends to find psi0 (> psi1)

Definition at line 257 of file libascot.c.

◆ libascot_E_field_eval_E()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
E_offload_arrayinitialized electric field offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
ERoutput array [V/m].
Ephioutput array [V/m].
Ezoutput array [V/m].

Definition at line 320 of file libascot.c.

◆ libascot_plasma_get_n_species()

int libascot_plasma_get_n_species ( sim_offload_data * sim_offload_data,
real * plasma_offload_array )

Get number of plasma species.

Parameters
sim_offload_datainitialized simulation offload data struct
plasma_offload_arrayinitialized plasma offload data
Returns
number of plasma species.

Definition at line 352 of file libascot.c.

◆ libascot_plasma_get_species_mass_and_charge()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
plasma_offload_arrayinitialized plasma offload data
massmass output array [kg].
chargecharge output array [C].
anumatomic mass number output array [1].
znumcharge number output array [1].

Definition at line 371 of file libascot.c.

◆ libascot_plasma_eval_background()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized mangetic field offload data
plasma_offload_arrayinitialized plasma offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
densoutput array [m^-3].
tempoutput array [eV].

Definition at line 409 of file libascot.c.

◆ libascot_neutral_eval_density()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized mangetic field offload data
neutral_offload_arrayinitialized neutral offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
densoutput array [m^-3].

Definition at line 454 of file libascot.c.

◆ libascot_boozer_eval_psithetazeta()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
boozer_offload_arrayinitialized boozer offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
psioutput array
thetaoutput array
zetaoutput array
dpsidroutput array
dpsidphioutput array
dpsidzoutput array
dthetadroutput array
dthetadphioutput array
dthetadzoutput array
dzetadroutput array
dzetadphioutput array
dzetadzoutput array
rhooutput array

Definition at line 507 of file libascot.c.

◆ libascot_boozer_eval_fun()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
boozer_offload_arrayinitialized boozer offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
qprofarray for storing the (flux averaged) safety factor.
jacarray for storing the coordinate Jacobian.
jacB2array for storing the coordinate Jacobian multiplied with B^2.

Definition at line 566 of file libascot.c.

◆ libascot_mhd_get_n_modes()

int libascot_mhd_get_n_modes ( sim_offload_data * sim_offload_data,
real * mhd_offload_array )

Get number of MHD modes.

Parameters
sim_offload_datainitialized simulation offload data struct
mhd_offload_arrayinitialized mhd offload data
Returns
number of MHD modes

Definition at line 623 of file libascot.c.

◆ libascot_mhd_get_mode_specs()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
mhd_offload_arrayinitialized mhd offload data
nmodeoutput array for toroidal mode number
mmodeoutput array for poloidal mode number
amplitudeoutput array for mode amplitude
omegaoutput array for mode frequency
phaseoutput array for mode phase

Definition at line 643 of file libascot.c.

◆ libascot_mhd_eval()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
boozer_offload_arrayinitialized boozer offload data
mhd_offload_arrayinitialized MHD offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
includemodemode index to include or MHD_INCLUDE_ALL
alphaoutput array
dadroutput array
dadphioutput array
dadzoutput array
dadtoutput array
Phioutput array
dPhidroutput array
dPhidphioutput array
dPhidzoutput array
dPhidtoutput array

Definition at line 689 of file libascot.c.

◆ libascot_mhd_eval_perturbation()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
boozer_offload_arrayinitialized boozer offload data
mhd_offload_arrayinitialized MHD offload data
Nevalnumber of evaluation points.
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
includemodemode index to include or MHD_INCLUDE_ALL
mhd_broutput array
mhd_bphioutput array
mhd_bzoutput array
mhd_eroutput array
mhd_ephioutput array
mhd_ezoutput array
mhd_phioutput array

Definition at line 745 of file libascot.c.

◆ libascot_eval_collcoefs()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
plasma_offload_arrayinitialized plasma offload data
Nevalnumber of evaluation points
RR coordinates of the evaluation points [m]
phiphi coordinates of the evaluation points [rad]
zz coordinates of the evaluation points [m]
ttime coordinates of the evaluation points [s]
Nvnumber of velocity grid points
vatest particle velocities at the evaluation point [m/s]
matest particle mass [kg]
qatest particle charge [C]
Foutput array
Dparaoutput array
Dperpoutput array
Koutput array
nuoutput array
Qoutput array
dQoutput array
dDparaoutput array
clogoutput array
mu0output array
mu1output array
dmu0output array

Definition at line 806 of file libascot.c.

◆ libascot_eval_ratecoeff()

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.

Parameters
sim_offload_datainitialized simulation offload data struct
B_offload_arrayinitialized magnetic field offload data
plasma_offload_arrayinitialized magnetic field offload data
neutral_offload_arrayinitialized magnetic field offload data
asigma_offload_arrayinitialized magnetic field offload data
Nevalnumber of evaluation points in (R, phi, z, t).
RR coordinates of the evaluation points [m].
phiphi coordinates of the evaluation points [rad].
zz coordinates of the evaluation points [m].
ttime coordinates of the evaluation points [s].
Nvnumber of evaluation points in velocity space.
vatest particle velocities [m/s].
Aatest particle atomic mass number.
Zatest particle charge number.
matest particle mass.
reac_typereaction type
ratecoeffoutput array where evaluated values are stored [1/m^2].

Definition at line 917 of file libascot.c.