torax.physics package

Submodules

torax.physics.charge_states module

Routines for calculating impurity charge states.

torax.physics.charge_states.calculate_average_charge_state_single_species(Te, ion_symbol)[source]

Calculates the average charge state of an impurity based on the Marvin 2018 polynomial fit.

The polynomial fit range is 0.1-100 keV, which is well within the typical bounds of core tokamak modelling. For safety, inputs are clipped to avoid extrapolation outside this range.

Parameters:
  • Te (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Electron temperature [keV].

  • ion_symbol (str) – Species to calculate average charge state for.

Returns:

Average charge state [amu].

Return type:

Z

torax.physics.charge_states.get_average_charge_state(ion_symbols, ion_mixture, Te)[source]

Calculates or prescribes average impurity charge state profile (JAX-compatible).

Parameters:
  • ion_symbols (Sequence[str]) – Species to calculate average charge state for.

  • ion_mixture (DynamicIonMixture) – DynamicIonMixture object containing impurity information. The index of the ion_mixture.fractions array corresponds to the index of the ion_symbols array.

  • Te (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Electron temperature [keV]. Can be any sized array, e.g. on cell grid, face grid, or a single scalar.

Returns:

Average charge state profile [amu].

The shape of avg_Z is the same as Te.

Return type:

avg_Z

torax.physics.collisions module

Physics calculations related to collisional quantities.

Functions:
  • coll_exchange: Computes the collisional ion-electron heat exchange coefficient (equipartion).

  • calc_nu_star: Calculates the nu_star parameter: the electron-ion collision frequency normalized by bounce frequency.

  • fast_ion_fractional_heating_formula: Returns the fraction of heating that goes to the ions according to Stix 1975 analyticlal formulas.

  • _calculate_lambda_ei: Calculates the Coulomb logarithm for electron-ion collisions.

  • _calculate_weighted_Zeff: Calculates ion mass weighted Zeff used in the equipartion calculation.

  • _calculate_log_tau_e_Z1: Calculates log of electron-ion collision time for Z=1 plasma.

torax.physics.collisions.calc_nu_star(geo, core_profiles, nref, Zeff_face, coll_mult)[source]

Calculates nustar.

Electron-ion collision frequency normalized by bounce frequency.

Parameters:
  • geo (Geometry) – Torus geometry.

  • core_profiles (CoreProfiles) – Core plasma profiles.

  • nref (float) – Reference value for normalization

  • Zeff_face (Array) – Effective ion charge on face grid.

  • coll_mult (float) – Collisionality multiplier in QLKNN for sensitivity testing.

Returns:

on face grid.

Return type:

nu_star

torax.physics.collisions.coll_exchange(core_profiles, nref, Qei_mult)[source]

Computes collisional ion-electron heat exchange coefficient (equipartion).

Parameters:
  • core_profiles (CoreProfiles) – Core plasma profiles.

  • nref (float) – Reference value for normalization

  • Qei_mult (float) – multiplier for ion-electron heat exchange term

Returns:

ion-electron collisional heat exchange coefficient.

Return type:

Qei_coeff

torax.physics.collisions.fast_ion_fractional_heating_formula(birth_energy, temp_el, fast_ion_mass)[source]

Returns the fraction of heating that goes to the ions.

From eq. 5 and eq. 26 in Mikkelsen Nucl. Tech. Fusion 237 4 1983. Note there is a typo in eq. 26 where a 2x term is missing in the numerator of the log.

Parameters:
  • birth_energy (Union[float, Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Birth energy of the fast ions in keV.

  • temp_el (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Electron temperature.

  • fast_ion_mass (float) – Mass of the fast ions in amu.

Return type:

Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]

Returns:

The fraction of heating that goes to the ions.

torax.physics.formulas module

Physics formulas mostly related to CoreProfiles calculations.

Functions:
  • calculate_main_ion_dilution_factor: Calculates the main ion dilution factor based on average impurity charge and Zeff.

  • calculate_pressure: Calculates pressure from density and temperatures.

  • calc_pprime: Calculates total pressure gradient with respect to poloidal flux.

  • calc_FFprime: Calculates FF’, an output quantity used for equilibrium coupling.

  • calculate_stored_thermal_energy: Calculates stored thermal energy from pressures.

  • calculate_greenwald_fraction: Calculates the Greenwald fraction from the averaged electron density (can be line-averaged or volume-averaged).

torax.physics.formulas.calc_FFprime(core_profiles, geo)[source]

Calculates FF’, an output quantity used for equilibrium coupling.

Calculation is based on the following formulation of the magnetic equilibrium equation: \(-j_{tor} = 2\pi (Rp' + \frac{1}{\mu_0 R}FF')\)

And following division by R and flux surface averaging:

\(-\langle \frac{j_{tor}}{R} \rangle = 2\pi (p' + \langle\frac{1}{R^2}\rangle\frac{FF'}{\mu_0})\)

Parameters:
  • core_profiles (CoreProfiles) – CoreProfiles object containing information on temperatures and densities.

  • geo (Geometry) – Magnetic equilibrium.

Returns:

F is the toroidal flux function, and F’ is its derivative with

respect to the poloidal flux.

Return type:

FFprime

torax.physics.formulas.calc_pprime(core_profiles)[source]

Calculates total pressure gradient with respect to poloidal flux.

Parameters:

core_profiles (CoreProfiles) – CoreProfiles object containing information on temperatures and densities.

Returns:

Total pressure gradient \(\partial p / \partial \psi\)

with respect to the normalized toroidal flux coordinate, on the face grid.

Return type:

pprime

torax.physics.formulas.calculate_greenwald_fraction(ne_avg, core_profiles, geo)[source]

Calculates the Greenwald fraction from the averaged electron density.

Different averaging can be used, e.g. volume-averaged or line-averaged.

Parameters:
  • ne_avg (Union[Float[Array, ''], Float[ndarray, ''], number, float]) – Averaged electron density [nref m^-3]

  • core_profiles (CoreProfiles) – CoreProfiles object containing information on currents and densities.

  • geo (Geometry) – Geometry object

Returns:

Greenwald density fraction

Return type:

fgw

torax.physics.formulas.calculate_main_ion_dilution_factor(Zi, Zimp, Zeff)[source]

Calculates the main ion dilution factor based on a single assumed impurity and general main ion charge.

Parameters:
  • Zi (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • Zimp (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • Zeff (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

Return type:

Array

torax.physics.formulas.calculate_pressure(core_profiles)[source]

Calculates pressure from density and temperatures on the face grid.

Parameters:

core_profiles (CoreProfiles) – CoreProfiles object containing information on temperatures and densities.

Returns:

Electron thermal pressure [Pa] pressure_thermal_ion_face: Ion thermal pressure [Pa] pressure_thermal_tot_face: Total thermal pressure [Pa]

Return type:

pressure_thermal_el_face

torax.physics.formulas.calculate_stored_thermal_energy(p_el, p_ion, p_tot, geo)[source]

Calculates stored thermal energy from pressures.

Parameters:
  • p_el (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Electron pressure [Pa]

  • p_ion (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Ion pressure [Pa]

  • p_tot (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – Total pressure [Pa]

  • geo (Geometry) – Geometry object

Returns:

Electron thermal stored energy [J] wth_ion: Ion thermal stored energy [J] wth_tot: Total thermal stored energy [J]

Return type:

wth_el

torax.physics.psi_calculations module

Calculations related to derived quantities from poloidal flux (psi).

Functions:
  • calc_q: Calculates the q-profile (q).

  • calc_jtot: Calculate flux-surface-averaged toroidal current density.

  • calc_s: Calculates magnetic shear (s).

  • calc_s_rmid: Calculates magnetic shear (s), using midplane r as radial coordinate.

  • calc_Wpol: Calculates total magnetic energy (Wpol).

  • calc_li3: Calculates normalized internal inductance li3 (ITER convention).

  • calc_q95: Calculates the q-profile at 95% of the normalized poloidal flux.

  • calculate_psi_grad_constraint_from_Ip_tot: Calculates the gradient constraint on the poloidal flux (psi) from Ip.

  • _calc_bpol2: Calculates square of poloidal field (Bp).

torax.physics.psi_calculations.calc_Wpol(geo, psi)[source]

Calculates total magnetic energy (Wpol) from poloidal flux (psi).

Parameters:
Return type:

Array

torax.physics.psi_calculations.calc_jtot(geo, psi)[source]

Calculate flux-surface-averaged toroidal current density from poloidal flux.

Calculation based on jtot = dI/dS

Parameters:
Returns:

total current density [A/m2] on cell grid jtot_face: total current density [A/m2] on face grid Ip_profile_face: cumulative total plasma current profile [A] on face grid

Return type:

jtot

torax.physics.psi_calculations.calc_li3(Rmaj, Wpol, Ip_total)[source]

Calculates li3 based on a formulation using Wpol.

Normalized internal inductance is defined as: li = <Bpol^2>_V / <Bpol^2>_LCFS where <>_V is a volume average and <>_LCFS is the average at the last closed flux surface.

We use the ITER convention for normalized internal inductance defined as: li3 = 2*V*<Bpol^2>_V / (mu0^2 Ip^2*Rmaj) = 4 * Wpol / (mu0 Ip^2*Rmaj)

Ip (total plasma current) enters through the integral form of Ampere’s law. Since Wpol also corresponds to a volume integral of the poloidal field, we can define li3 with respect to Wpol.

Parameters:
  • Rmaj (Array) – Major radius.

  • Wpol (Array) – Total magnetic energy.

  • Ip_total (Array) – Total plasma current.

Returns:

Normalized internal inductance, ITER convention.

Return type:

li3

torax.physics.psi_calculations.calc_q95(psi_norm_face, q_face)[source]

Calculates q95 from the q profile and the normalized poloidal flux.

Parameters:
  • psi_norm_face (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – normalized poloidal flux

  • q_face (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']]) – safety factor on the face grid

Returns:

q at 95% of the normalized poloidal flux

Return type:

q95

torax.physics.psi_calculations.calc_q_face(geo, psi)[source]

Calculates the q-profile on the face grid given poloidal flux (psi).

Parameters:
Return type:

Union[Array, ndarray, bool, number]

torax.physics.psi_calculations.calc_s_face(geo, psi)[source]

Calculates magnetic shear on the face grid from poloidal flux (psi).

Parameters:
Return type:

Array

torax.physics.psi_calculations.calc_s_rmid(geo, psi)[source]

Calculates magnetic shear (s) from poloidal flux (psi).

Version taking the derivative of iota with respect to the midplane r, in line with expectations from circular-derived models like QuaLiKiz.

Parameters:
Returns:

Magnetic shear, on the face grid.

Return type:

s_face

torax.physics.psi_calculations.calculate_psi_grad_constraint_from_Ip_tot(Ip_tot, geo)[source]

Calculates the gradient constraint on the poloidal flux (psi) from Ip.

Parameters:
Return type:

Array

torax.physics.psi_calculations.calculate_psidot_from_psi_sources(*, psi_sources, sigma, sigma_face, resistivity_multiplier, psi, geo)[source]

Calculates psidot (loop voltage) from the sum of the psi sources.

Parameters:
  • psi_sources (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • sigma (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • sigma_face (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • resistivity_multiplier (float)

  • psi (CellVariable)

  • geo (Geometry)

Return type:

Array

torax.physics.scaling_laws module

Calculations related to empirical scaling laws.

Functions:
  • calculate_plh_scaling_factor: Calculates the H-mode transition power according to Martin 2008, and the density corresponding to the P_LH_min according to Ryter 2014.

  • calculate_scaling_law_confinement_time: Calculates the predicted thermal energy confinement time from a given empirical scaling law.

torax.physics.scaling_laws.calculate_plh_scaling_factor(geo, core_profiles)[source]

Calculates the H-mode transition power scalings.

See Y.R. Martin and Tomonori Takizuka. “Power requirement for accessing the H-mode in ITER.” Journal of Physics: Conference Series. Vol. 123. No. 1. IOP Publishing, 2008.

Only valid for hydrogenic isotopes and mixtures (H, D, T). Includes a simple inverse scaling of the factor to average isotope mass.

For an overview see U Plank, U., et al. “Overview of L-to H-mode transition experiments at ASDEX Upgrade.” Plasma Physics and Controlled Fusion 65.1 (2022): 014001.

Parameters:
Returns:

P_LH scaling factor for high density branch, minimum P_LH,

P_LH = max(P_LH_min, P_LH_hi_dens) for practical use, and the density corresponding to the P_LH_min.

Return type:

Tuple of

torax.physics.scaling_laws.calculate_scaling_law_confinement_time(geo, core_profiles, Ploss, scaling_law)[source]

Calculates the thermal energy confinement time for a given empirical scaling law.

Parameters:
  • geo (Geometry) – Torus geometry.

  • core_profiles (CoreProfiles) – Core plasma profiles.

  • Ploss (Array) – Plasma power loss in W.

  • scaling_law (str) – Scaling law to use.

Return type:

Array

Returns:

Thermal energy confinement time in s.

Module contents

This package contains functionality related to calculating physics quantities.