freegsnke.jtor module

Classes representing different toroidal current density profiles in the plasma.

Copyright 2024 Nicola C. Amorisco, Adriano Agnello, George K. Holt, Ben Dudson.

Modified substantially from the original FreeGS code.

This file is part of FreeGSNKE.

FreeGSNKE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FreeGSNKE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>.

class freegsnke.jtor.ConstrainBetapIp(betap: float, Ip: float, fvac: float, alpha_m: float = 1.0, alpha_n: float = 2.0, Raxis: float = 1.0)[source]

Bases: Profile

Class describing the toroidal current density profile formulation defined in: Y. M. Jeon, 2015, “Development of a free-boundary tokamak equilibrium solver for advanced study of tokamak equilibria”. (https://link.springer.com/article/10.3938/jkps.67.843)

This formulation constrains profiles using the poloidal beta and plasma current.

Jtor_part2(R: ndarray, Z: ndarray, psi: ndarray, psi_axis: float, psi_bndry: float | None, mask: ndarray | None) → ndarray[source]

Second part of the calculation that will use the explicit parameterisation of the chosen profile function to calculate Jtor.

This is given by:

Jtor(ψ, R, Z) = L * [ (beta0 * R / Raxis) + ((1 - Beta0) * Raxis / R) ] * (1 - ψ^alpha_m)^alpha_n.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_axis (float) – Value of the poloidal field flux at the magnetic axis of the plasma.

  • psi_bndry (float or None) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface). If None, psi[0, 0] is used.

  • mask (np.ndarray or None) – Mask of points inside the last closed flux surface (no masking if None).

Returns:

Toroidal current density on the computational grid [A/m^2].

Return type:

np.ndarray

Raises:

ValueError – If the core mask is empty.

__init__(betap: float, Ip: float, fvac: float, alpha_m: float = 1.0, alpha_n: float = 2.0, Raxis: float = 1.0) → None[source]

Initialise the class.

Parameters:
  • betap (float) – Poloidal beta.

  • Ip (float) – Total plasma current [A].

  • fvac (float) – Vacuum toroidal field strength (f = R*B_tor) [T].

  • alpha_m (float, optional) – Shape/peakedness parameter (non-negative).

  • alpha_n (float, optional) – Shape/peakedness parameter (non-negative).

  • Raxis (float, optional) – Radial scaling parameter (non-negative).

Raises:

ValueError – If alpha_m, alpha_n or Raxis is negative.

ffprime(pn: ndarray) → ndarray[source]

Calculate the 1D ffprime (FdF/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed ffprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Jtor has not yet been calculated for this profile (so it cannot be normalised).

fvac() → float[source]

Return the vacuum field parameter fvac = R*Btor.

Returns:

The vacuum field parameter fvac = R*Btor [T m].

Return type:

float

pprime(pn: ndarray) → ndarray[source]

Calculate the 1D pprime (dp/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Jtor has not yet been calculated for this profile (so it cannot be normalised).

class freegsnke.jtor.ConstrainPaxisIp(paxis: float, Ip: float, fvac: float, alpha_m: float = 1.0, alpha_n: float = 2.0, Raxis: float = 1.0)[source]

Bases: Profile

Class describing the toroidal current density profile formulation defined in: Y. M. Jeon, 2015, “Development of a free-boundary tokamak equilibrium solver for advanced study of tokamak equilibria”. (https://link.springer.com/article/10.3938/jkps.67.843)

This formulation constrains profiles using the pressure on axis and plasma current.

Jtor_part2(R: ndarray, Z: ndarray, psi: ndarray, psi_axis: float, psi_bndry: float | None, mask: ndarray | None) → ndarray[source]

Second part of the calculation that will use the explicit parameterisation of the chosen profile function to calculate Jtor.

This is given by:

Jtor(ψ, R, Z) = L * [ (beta0 * R / Raxis) + ((1 - Beta0) * Raxis / R) ] * (1 - ψ^alpha_m)^alpha_n.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_axis (float) – Value of the poloidal field flux at the magnetic axis of the plasma.

  • psi_bndry (float or None) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface). If None, psi[0, 0] is used.

  • mask (np.ndarray or None) – Mask of points inside the last closed flux surface (no masking if None).

Returns:

Toroidal current density on the computational grid [A/m^2].

Return type:

np.ndarray

__init__(paxis: float, Ip: float, fvac: float, alpha_m: float = 1.0, alpha_n: float = 2.0, Raxis: float = 1.0) → None[source]

Initialise the class.

Parameters:
  • paxis (float) – Pressure on the magnetic axis [Pa].

  • Ip (float) – Total plasma current [A].

  • fvac (float) – Vacuum toroidal field strength (f = R*B_tor) [T].

  • alpha_m (float, optional) – Shape/peakedness parameter (non-negative).

  • alpha_n (float, optional) – Shape/peakedness parameter (non-negative).

  • Raxis (float, optional) – Radial scaling parameter (non-negative).

Raises:

ValueError – If alpha_m, alpha_n or Raxis is negative.

ffprime(pn: ndarray) → ndarray[source]

Calculate the 1D ffprime (FdF/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed ffprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Jtor has not yet been calculated for this profile (so it cannot be normalised).

fvac() → float[source]

Return the vacuum field parameter fvac = R*Btor.

Returns:

The vacuum field parameter fvac = R*Btor [T m].

Return type:

float

pprime(pn: ndarray) → ndarray[source]

Calculate the 1D pprime (dp/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Jtor has not yet been calculated for this profile (so it cannot be normalised).

class freegsnke.jtor.Fiesta_Topeol(Beta0: float, Ip: float, fvac: float, alpha_m: float = 1.0, alpha_n: float = 2.0, Raxis: float = 1.0)[source]

Bases: Profile

Class describing the toroidal current density profile formulation defined in: Y. M. Jeon, 2015, “Development of a free-boundary tokamak equilibrium solver for advanced study of tokamak equilibria”. (https://link.springer.com/article/10.3938/jkps.67.843)

In this class, Beta0 is specified directly.

Jtor_part2(R: ndarray, Z: ndarray, psi: ndarray, psi_axis: float, psi_bndry: float | None, mask: ndarray | None) → ndarray[source]

Second part of the calculation that will use the explicit parameterisation of the chosen profile function to calculate Jtor.

This is given by:

Jtor(ψ, R, Z) = L * [ (beta0 * R / Raxis) + ((1 - Beta0) * Raxis / R) ] * (1 - ψ^alpha_m)^alpha_n.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_axis (float) – Value of the poloidal field flux at the magnetic axis of the plasma.

  • psi_bndry (float or None) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface). If None, psi[0, 0] is used.

  • mask (np.ndarray or None) – Mask of points inside the last closed flux surface (no masking if None).

Returns:

Toroidal current density on the computational grid [A/m^2].

Return type:

np.ndarray

__init__(Beta0: float, Ip: float, fvac: float, alpha_m: float = 1.0, alpha_n: float = 2.0, Raxis: float = 1.0) → None[source]

Initialise the class.

Parameters:
  • Beta0 (float) – Scaling parameter.

  • Ip (float) – Total plasma current [A].

  • fvac (float) – Vacuum toroidal field strength (f = R*B_tor) [T].

  • alpha_m (float, optional) – Shape/peakedness parameter (non-negative).

  • alpha_n (float, optional) – Shape/peakedness parameter (non-negative).

  • Raxis (float, optional) – Radial scaling parameter (non-negative).

Raises:

ValueError – If alpha_m, alpha_n or Raxis is negative.

ffprime(pn: ndarray) → ndarray[source]

Calculate the 1D ffprime (FdF/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed ffprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Jtor has not yet been calculated for this profile (so it cannot be normalised).

fvac() → float[source]

Return the vacuum field parameter fvac = R*Btor.

Returns:

The vacuum field parameter fvac = R*Btor [T m].

Return type:

float

pprime(pn: ndarray) → ndarray[source]

Calculate the 1D pprime (dp/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Jtor has not yet been calculated for this profile (so it cannot be normalised).

class freegsnke.jtor.GeneralPprimeFFprime(Ip: float, fvac: float, psi_n: ndarray, pprime_data: ndarray | None = None, ffprime_data: ndarray | None = None, p_data: ndarray | None = None, f_data: ndarray | None = None, Raxis: float = 1, Ip_logic: bool = True, interpolator: str = 'univariate_spline')[source]

Bases: Profile

Class describing the general toroidal current density profile formulation:

Jtor(ψ, R, Z) = R * p’(ψ) + FF’(ψ) / (R * mu0).

Jtor_part2(R: ndarray, Z: ndarray, psi: ndarray, psi_axis: float, psi_bndry: float | None, mask: ndarray | None, torefine: bool = False, refineR: ndarray | None = None) → ndarray[source]

Second part of the calculation that will use the interpolated profile functions to calculate Jtor.

This is given by:

Jtor(ψ, R, Z) = L * [ (R / Raxis) * p’(ψ) + (Raxis / R) * FF’(ψ) / mu0 ],

where

p’(ψ) = pprime_func(ψ)

FF’(ψ) = ffprime_func(ψ)

and note ψ here is the normalised psi.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_axis (float) – Value of the poloidal field flux at the magnetic axis of the plasma.

  • psi_bndry (float or None) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface). If None, psi[0, 0] is used.

  • mask (np.ndarray or None) – Mask of points inside the last closed flux surface (no masking if None).

  • torefine (bool, optional) – If True, evaluate Jtor at refined sub-grid points only: psi and refineR hold the values at those points, and the unmasked, unnormalised current density is returned.

  • refineR (np.ndarray or None, optional) – R coordinates of the refined points (same shape as psi); used in place of R when torefine is True.

Returns:

Toroidal current density on the computational grid [A/m^2] (or at the refined points if torefine is True).

Return type:

np.ndarray

Raises:

ValueError – If the total plasma current of the (masked) profile is zero, so it cannot be renormalised.

__init__(Ip: float, fvac: float, psi_n: ndarray, pprime_data: ndarray | None = None, ffprime_data: ndarray | None = None, p_data: ndarray | None = None, f_data: ndarray | None = None, Raxis: float = 1, Ip_logic: bool = True, interpolator: str = 'univariate_spline') → None[source]

Initialise the class.

Parameters:
  • Ip (float) – Total plasma current [A].

  • fvac (float) – Vacuum toroidal field strength (f = R*B_tor) [T].

  • psi_n (np.ndarray) – A 1D array of normalised poloidal flux values, corresponding to the data in pprime_data, ffprime_data, p_data, and f_data.

  • pprime_data (np.ndarray or None, optional) – A 1D array of dp/dpsi_n (p is pressure) values at each value of normalised flux in psi_n.

  • ffprime_data (np.ndarray or None, optional) – A 1D array of fdf/dpsi_n (f is the toroidal magnetic field) values at each value of normalised flux in psi_n.

  • p_data (np.ndarray or None, optional) – A 1D array of p (p is pressure) values at each value of normalised flux in psi_n.

  • f_data (np.ndarray or None, optional) – A 1D array of f (f is the toroidal magnetic field) values at each value of normalised flux in psi_n.

  • Raxis (float, optional) – Radial scaling parameter (non-negative).

  • Ip_logic (bool, optional) – If True, entire profile is re-normalised to satisfy Ip identically.

  • interpolator (str, optional) – Defaults to using a “univariate_spline” or optionally a “cubic_spline”, data points in both are interpolated exactly.

ffprime(pn: ndarray) → ndarray[source]

Calculate the 1D ffprime (FdF/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed ffprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Ip_logic is True and Jtor has not yet been calculated for this profile (so it cannot be normalised).

fpol(pn: ndarray) → ndarray[source]

Calculate the 1D toroidal magnetic profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed toroidal magnetic field values at each normalised psi value.

Return type:

np.ndarray

fvac() → float[source]

Return the vacuum field parameter fvac = R*Btor.

Returns:

The vacuum field parameter fvac = R*Btor [T m].

Return type:

float

initialize_profile() → None[source]

Set up the attributes in the class ready for Jtor calculations.

Builds the interpolating functions pprime_func, p_func, ffprime_func and f_func from the supplied data.

Raises:

ValueError – If neither pprime_data nor p_data is provided, or neither ffprime_data nor f_data is provided.

pprime(pn: ndarray) → ndarray[source]

Calculate the 1D pprime (dp/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Ip_logic is True and Jtor has not yet been calculated for this profile (so it cannot be normalised).

pressure(pn: ndarray) → ndarray[source]

Calculate the 1D pressure profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pressure values at each normalised psi value.

Return type:

np.ndarray

class freegsnke.jtor.Lao85(Ip: float, fvac: float, alpha: list[float] | ndarray, beta: list[float] | ndarray, alpha_logic: bool = True, beta_logic: bool = True, Raxis: float = 1, Ip_logic: bool = True)[source]

Bases: Profile

Class describing the toroidal current density profile formulation defined in: Lao et al, 1985, “Reconstruction of current profile parameters and plasma shapes in tokamaks”. (https://dx.doi.org/10.1088/0029-5515/25/11/007)

See equations 2, 4, and 5.

Jtor_part2(R: ndarray, Z: ndarray, psi: ndarray, psi_axis: float, psi_bndry: float | None, mask: ndarray | None, torefine: bool = False, refineR: ndarray | None = None) → ndarray[source]

Second part of the calculation that will use the explicit parameterisation of the chosen profile function to calculate Jtor.

This is given by:

Jtor(ψ, R, Z) = L * [ (R / Raxis) * p’(ψ) + (Raxis / R) * FF’(ψ) / mu0 ],

where

p’(ψ) = sum(alpha_i ψ^i) - sum(alpha_i) ψ^(n_P+1),

FF’(ψ) = sum(beta_i ψ^i) - sum(beta_i) ψ^(n_F+1),

and note ψ here is the normalised psi.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_axis (float) – Value of the poloidal field flux at the magnetic axis of the plasma.

  • psi_bndry (float or None) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface). If None, psi[0, 0] is used.

  • mask (np.ndarray or None) – Mask of points inside the last closed flux surface (no masking if None).

  • torefine (bool, optional) – If True, evaluate Jtor at refined sub-grid points only: psi and refineR hold the values at those points, and the unmasked, unnormalised current density is returned.

  • refineR (np.ndarray or None, optional) – R coordinates of the refined points (same shape as psi); used in place of R when torefine is True.

Returns:

Toroidal current density on the computational grid [A/m^2] (or at the refined points if torefine is True).

Return type:

np.ndarray

Raises:

ValueError – If the total plasma current of the (masked) profile is zero, so it cannot be renormalised.

__init__(Ip: float, fvac: float, alpha: list[float] | ndarray, beta: list[float] | ndarray, alpha_logic: bool = True, beta_logic: bool = True, Raxis: float = 1, Ip_logic: bool = True) → None[source]

Initialise the class.

Parameters:
  • Ip (float) – Total plasma current [A].

  • fvac (float) – Vacuum toroidal field strength (f = R*B_tor) [T].

  • alpha (list or np.ndarray) – Polynomial coefficients for pprime.

  • beta (list or np.ndarray) – Polynomial coefficients for ffprime.

  • alpha_logic (bool, optional) – If True, include the n_{P+1} term to ensure pprime(1)=0 (see Jtor_part2).

  • beta_logic (bool, optional) – If True, include the n_{F+1} term to ensure ffprime(1)=0 (see Jtor_part2).

  • Raxis (float, optional) – Radial scaling parameter (non-negative).

  • Ip_logic (bool, optional) – If True, entire profile is re-normalised to satisfy Ip identically.

build_dJtorpsin1() → None[source]

Calculate dJtor/dpsi_n at psi_n=1 and store it in self.dJtorpsin1.

Notes

Requires the attribute self.eqR (the R grid), which is not set by this class itself.

ffprime(pn: ndarray) → ndarray[source]

Calculate the 1D ffprime (FdF/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed ffprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Ip_logic is True and Jtor has not yet been calculated for this profile (so it cannot be normalised).

fvac() → float[source]

Return the vacuum field parameter fvac = R*Btor.

Returns:

The vacuum field parameter fvac = R*Btor [T m].

Return type:

float

initialize_profile() → None[source]

Set up the attributes in the class ready for Jtor calculations.

Appends the extra polynomial terms (if alpha_logic/beta_logic) and sets the exponent arrays alpha_exp and beta_exp.

pprime(pn: ndarray) → ndarray[source]

Calculate the 1D pprime (dp/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pprime values at each normalised psi value.

Return type:

np.ndarray

Raises:

ValueError – If Ip_logic is True and Jtor has not yet been calculated for this profile (so it cannot be normalised).

pressure(pn: ndarray) → ndarray[source]

Calculate the 1D pressure profile in the plasma (vs. the normalised poloidal flux) without integrating the pprime profile (specifically for the Lao profile).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pressure values at each normalised psi value.

Return type:

np.ndarray

class freegsnke.jtor.Profile[source]

Bases: object

Base class from which profiles classes can inherit.

Jtor(R: ndarray, Z: ndarray, psi: ndarray, psi_bndry: float | None = None) → ndarray[source]

Calculate the toroidal current density on the computational grid.

This convenience wrapper combines the generic critical-point and core-mask identification in Jtor_part1() with the profile-specific current-density calculation implemented by each subclass in Jtor_part2().

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_bndry (float or None, optional) – Value of the poloidal field flux at the plasma boundary.

Returns:

Toroidal current density on the computational grid [A/m^2].

Return type:

np.ndarray

Jtor_part1(R: ndarray, Z: ndarray, psi: ndarray, psi_bndry: float | None = None, mask_outside_limiter: ndarray | None = None) → tuple[ndarray, ndarray, ndarray | None, float][source]

First part of the Jtor calculation that identifies critical points in the poloidal flux (generic to all profile functions). The second stage (in specific classes below) will be used for calculating Jtor using their explicit profile parameterisations.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_bndry (float or None, optional) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface).

  • mask_outside_limiter (np.ndarray or None, optional) – Mask of points outside the limiter, if any.

Returns:

  • opt (np.ndarray) – Each row represents an O-point of the form [R, Z, ψ(R,Z)] [m, m, Webers/2pi].

  • xpt (np.ndarray) – Each row represents an X-point of the form [R, Z, ψ(R,Z)] [m, m, Webers/2pi].

  • diverted_core_mask (np.ndarray of bool or None) – An array, the same shape as the computational grid, indicating the locations at which the core plasma resides (True) and where it does not (False). None if there are no X-points and no psi_bndry was given.

  • psi_bndry (float) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface).

Raises:

ValueError – If the ordering of the axis and boundary fluxes is inconsistent with the sign of the plasma current (unsuitable psi_plasma guess).

fpol(psinorm: ndarray | float) → ndarray | float[source]

Calculate the 1D toroidal magnetic profile in the plasma (vs. the normalised poloidal flux) by integrating the ffprime profile (ffprime = 0.5*d/dpsi(f^2)).

Parameters:

psinorm (float or np.array) – Normalised psi value(s) between 0 and 1.

Returns:

The computed F values at each normalised psi value.

Return type:

float or np.array

Raises:

ValueError – If the input and output arrays have different lengths.

pressure(psinorm)[source]

Calculate the 1D pressure profile in the plasma (vs. the normalised poloidal flux) by integrating the pprime profile.

Parameters:

psinorm (float or np.array) – Normalised psi value(s) between 0 and 1.

Returns:

The computed pressure values at each normalised psi value.

Return type:

float or np.array

class freegsnke.jtor.TensionSpline(Ip: float, fvac: float, pp_knots: list[float] | ndarray, pp_values: list[float] | ndarray, pp_values_2: list[float] | ndarray, pp_sigma: float, ffp_knots: list[float] | ndarray, ffp_values: list[float] | ndarray, ffp_values_2: list[float] | ndarray, ffp_sigma: float, Raxis: float = 1, Ip_logic: bool = True)[source]

Bases: Profile

Class describing the toroidal current density profile formulation that uses tension spline.

Jtor_part2(R: ndarray, Z: ndarray, psi: ndarray, psi_axis: float, psi_bndry: float | None, mask: ndarray | None) → ndarray[source]

Second part of the calculation that will use the explicit parameterisation of the chosen profile function to calculate Jtor. Typically used for more modelling more complex shaped profiles (from magnetics + MSE plasma reconstructions).

This is given by:

Jtor(ψ, R, Z) = L * [ (R / Raxis) * p’(ψ) + (Raxis / R) * FF’(ψ) / mu0 ],

where

p’(ψ) = sum(f_n),

FF’(ψ) = sum(f_n),

where f_n is the tension spline.

See https://catxmai.github.io/pdfs/Math212_ProjectReport.pdf for definition.

Parameters:
  • R (np.ndarray) – Radial coordinates of the grid points.

  • Z (np.ndarray) – Vertical coordinates of the grid points.

  • psi (np.ndarray) – Total poloidal field flux at each grid point [Webers/2pi].

  • psi_axis (float) – Value of the poloidal field flux at the magnetic axis of the plasma.

  • psi_bndry (float or None) – Value of the poloidal field flux at the boundary of the plasma (last closed flux surface). If None, psi[0, 0] is used.

  • mask (np.ndarray or None) – Mask of points inside the last closed flux surface (no masking if None).

Returns:

Toroidal current density on the computational grid [A/m^2].

Return type:

np.ndarray

Raises:

ValueError – If the total plasma current of the (masked) profile is zero, so it cannot be renormalised.

__init__(Ip: float, fvac: float, pp_knots: list[float] | ndarray, pp_values: list[float] | ndarray, pp_values_2: list[float] | ndarray, pp_sigma: float, ffp_knots: list[float] | ndarray, ffp_values: list[float] | ndarray, ffp_values_2: list[float] | ndarray, ffp_sigma: float, Raxis: float = 1, Ip_logic: bool = True) → None[source]

Initialise the class.

Parameters:
  • Ip (float) – Total plasma current [A].

  • fvac (float) – Vacuum toroidal field strength (f = R*B_tor) [T].

  • pp_knots (list or np.ndarray) – Knot points of pprime profile.

  • pp_values (list or np.ndarray) – Values of pprime at knot points.

  • pp_values_2 (list or np.ndarray) – Values of 2nd derivative of pprime at knot points.

  • pp_sigma (float) – Tension spline parameter for pprime (non-negative).

  • ffp_knots (list or np.ndarray) – Knot points of ffprime profile.

  • ffp_values (list or np.ndarray) – Values of ffprime at knot points.

  • ffp_values_2 (list or np.ndarray) – Values of 2nd derivative of ffprime at knot points.

  • ffp_sigma (float) – Tension spline parameter for ffprime (non-negative).

  • Raxis (float, optional) – Radial scaling parameter (non-negative).

  • Ip_logic (bool, optional) – If True, entire profile is re-normalised to satisfy Ip identically.

ffprime(pn: ndarray) → ndarray[source]

Calculate the 1D ffprime (FdF/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed ffprime values at each normalised psi value.

Return type:

np.ndarray

fvac() → float[source]

Return the vacuum field parameter fvac = R*Btor.

Returns:

The vacuum field parameter fvac = R*Btor [T m].

Return type:

float

pprime(pn: ndarray) → ndarray[source]

Calculate the 1D pprime (dp/dpsi) profile in the plasma (vs. the normalised poloidal flux).

Parameters:

pn (np.ndarray) – Array of normalised psi values between 0 and 1.

Returns:

The computed pprime values at each normalised psi value.

Return type:

np.ndarray

tension_spline(x: float | ndarray, xn: ndarray, yn: ndarray, zn: ndarray, sigma: float) → float | ndarray[source]

Evaluate the tension spline at locations in x using knot points xn, values at knot points yn, and second derivative values at knot points zn. Tension parameter is a non-negative float sigma.

Parameters:
  • x (float or np.array) – Normalised psi value(s) between 0 and 1 (a scalar or an array of any shape).

  • xn (np.array) – Array of knot points between 0 and 1.

  • yn (np.ndarray) – Values of the function at the knot points.

  • zn (np.ndarray) – Values of the 2nd derivative of the function at the knot points.

  • sigma (float) – Tension spline parameter (non-negative).

Returns:

The tension spline evaluated at the points in x (a float if x is a scalar, otherwise an array with the same shape as x).

Return type:

float or np.array