pyrokinetics.diagnostics.field_line.FieldLine#

class pyrokinetics.diagnostics.field_line.FieldLine(pyro)[source]#

Bases: object

Parameters:

pyro (Pyro)

__init__(pyro)[source]#
Parameters:

pyro (Pyro)

Methods

__init__(pyro)

compute_half_displacement(xarray, yarray, ...)

Integrates delta B along the field line from a set of starting points.

compute_length_per_turn([ntheta])

Computes the distance along the field line per poloidal turn.

compute_linear_tearing_parameter()

Computes the distance along the field line per poloidal turn.

follow_field_line(xarray, yarray, nturns, ...)

Integrates delta B along the field line from a set of starting points.

parallel_correlation_length(time)

Compute the radial correlation length λ_x at each y using the Wiener–Khinchin theorem.

poincare(xarray, yarray, nturns, time, rhostar)

Integrates delta B along the field line from a set of starting points.

radial_diffusion_coefficient(xarray, yarray, ...)

Calculates the radial diffusion coefficient using the definition

compute_half_displacement(xarray, yarray, time, rhostar, use_invfft=False, smoothing=0.0, unwrap=False, max_fraction=0.25, pad_factor=1, integration_order=4)[source]#

Integrates delta B along the field line from a set of starting points. It returns the final (x, y) coordinates of the points. You can specify how many turns along the field line you wish to integrate

This routine may take a while depending on nturns and on the number of magnetic field lines. The parameter rhostar is required by the flux-tube boundary condition. Available for nonlinear simulations If unwrap is False (default) the returned coordinates are wrapped into the periodic domain. If unwrap is True, the routine does not apply modulo operations so that the cumulative displacement is retained.

You need to load the simulation output files before calling this function.

Parameters:
  • xarray (ArrayLike, units [rhoref]) – Array containing x coordinate of initial field line positions

  • yarray (ArrayLike, units [rhoref]) – Array containing y coordinate of initial field line positions

  • time (float, time reference)

  • rhostar (float, units [rhoref / lref]) – rhostar is needed to set the boundary conditionon the magnetic field line

  • use_invfft (bool) – If True, the inverse Fourier transform is computed every (x, y) points along the magnetic field line. It is much more accurate but very slow.

  • smoothing (float) – Sets level of smoothing done in RectBivariateSpline

  • unwrap (Optional[bool]) – If True, the x- coordinates are not wrapped into the periodic domain so that cumulative displacements are available.

  • theta_min (float) – Sets lower limit of field line integral (default -pi). Can’t be set if nturns>1

  • theta_max (float) – Sets upper limit of field line integral (default pi). Can’t be set if nturns>1

  • max_fraction (float, optional) – Maximum allowed x‐step size as a fraction of the full radial domain Lx. Steps with |Δx| > max_fraction * Lx issue a warning but are retained. Default is 0.25.

  • pad_factor (int, optional) – Factor by which to pad the kx spectrum before transforming. A value of 2 doubles the kx resolution (nx → 2·nx). Larger values increase real-space grid resolution but cost more CPU. Default is 1.

  • integration_order (int)

Returns:

points – 4D array of shape (2, nturns, len(yarray), len(xarray)) containing the x and y coordinates shaped according to the initial field line position. See example_poincare.py for a simple example.

Return type:

ArrayLike, units [rhoref]

Raises:

RuntimeError: – In case of linear simulation or GKOutput not loaded

compute_length_per_turn(ntheta=256)[source]#

Computes the distance along the field line per poloidal turn.

Use metric_terms to determine the field aligned covariant metric g_theta_theta from which we can get dLdtheta by

dLdtheta = 1 / sqrt(g_theta_theta)

This is then integrated over the poloidal turn to determine the distance travelled along the field line

Parameters:

ntheta (int) – Number of theta points to be used for MetricTerms

Returns:

length_per_turn – The field line length per turn.

Return type:

float, units [lref]

compute_linear_tearing_parameter()[source]#

Computes the distance along the field line per poloidal turn.

Use metric_terms to determine the field aligned covariant metric g_theta_theta from which we can get dLdtheta by

dLdtheta = 1 / sqrt(g_theta_theta)

This is then integrated over the poloidal turn to determine the distance travelled along the field line

Parameters:

ntheta (int) – Number of theta points to be used for MetricTerms

Returns:

length_per_turn – The field line length per turn.

Return type:

float, units [lref]

follow_field_line(xarray, yarray, nturns, time, rhostar, use_invfft=False, smoothing=0.0, unwrap=False, theta_min=None, theta_max=None, max_fraction=0.25, pad_factor=1, integration_order=4, return_delta_x=False)[source]#

Integrates delta B along the field line from a set of starting points. It returns the final (x, y) coordinates of the points. You can specify how many turns along the field line you wish to integrate

This routine may take a while depending on nturns and on the number of magnetic field lines. The parameter rhostar is required by the flux-tube boundary condition. Available for nonlinear simulations If unwrap is False (default) the returned coordinates are wrapped into the periodic domain. If unwrap is True, the routine does not apply modulo operations so that the cumulative displacement is retained.

You need to load the simulation output files before calling this function.

Parameters:
  • xarray (ArrayLike, units [rhoref]) – Array containing x coordinate of initial field line positions

  • yarray (ArrayLike, units [rhoref]) – Array containing y coordinate of initial field line positions

  • nturns (int, number of intersection points)

  • time (float, time reference)

  • rhostar (float, units [rhoref / lref]) – rhostar is needed to set the boundary conditionon the magnetic field line

  • use_invfft (bool) – If True, the inverse Fourier transform is computed every (x, y) points along the magnetic field line. It is much more accurate but very slow.

  • smoothing (float) – Sets level of smoothing done in RectBivariateSpline

  • unwrap (Optional[bool]) – If True, the x- coordinates are not wrapped into the periodic domain so that cumulative displacements are available.

  • theta_min (float) – Sets lower limit of field line integral (default -pi). Can’t be set if nturns>1

  • theta_max (float) – Sets upper limit of field line integral (default pi). Can’t be set if nturns>1

  • max_fraction (float, optional) – Maximum allowed x‐step size as a fraction of the full radial domain Lx. Steps with |Δx| > max_fraction * Lx issue a warning but are retained. Default is 0.25.

  • pad_factor (int, optional) – Factor by which to pad the kx spectrum before transforming. A value of 2 doubles the kx resolution (nx → 2·nx). Larger values increase real-space grid resolution but cost more CPU. Default is 1.

  • return_delta_x (bool)

Returns:

points – 4D array of shape (2, nturns, len(yarray), len(xarray)) containing the x and y coordinates shaped according to the initial field line position. See example_poincare.py for a simple example.

Return type:

ArrayLike, units [rhoref]

Raises:

RuntimeError: – In case of linear simulation or GKOutput not loaded

parallel_correlation_length(time)[source]#

Compute the radial correlation length λ_x at each y using the Wiener–Khinchin theorem.

  1. Reconstructs b(x) = ∂y A_par via direct Fourier‐mode summation using self._invfft.

  2. Computes the power spectrum P(k) = |FFT[b(x)]|².

  3. Obtains the autocorrelation C(Δ) = IFFT[P(k)], normalized so C(0)=1.

4. Identifies λ_x(θ,y) as the smallest Δ where C(Δ) = 1/e. Finally, λ_x(y) is taken as the mean over θ.

You need to load the simulation output files before calling this function.

Parameters:

time (float, time reference)

Returns:

points – 4D array of shape (2, nturns, len(yarray), len(xarray)) containing the x and y coordinates shaped according to the initial field line position. See example_poincare.py for a simple example.

Return type:

ArrayLike, units [rhoref]

Raises:

RuntimeError: – In case of linear simulation or GKOutput not loaded

poincare(xarray, yarray, nturns, time, rhostar, use_invfft=False, smoothing=0.0, unwrap=False, max_fraction=0.25, pad_factor=1, integration_order=4)[source]#

Integrates delta B along the field line from a set of starting points. It returns the final (x, y) coordinates of the points. You can specify how many turns along the field line you wish to integrate

This routine may take a while depending on nturns and on the number of magnetic field lines. The parameter rhostar is required by the flux-tube boundary condition. Available for nonlinear simulations If unwrap is False (default) the returned coordinates are wrapped into the periodic domain. If unwrap is True, the routine does not apply modulo operations so that the cumulative displacement is retained.

You need to load the simulation output files before calling this function.

Parameters:
  • xarray (ArrayLike, units [rhoref]) – Array containing x coordinate of initial field line positions

  • yarray (ArrayLike, units [rhoref]) – Array containing y coordinate of initial field line positions

  • nturns (int, number of intersection points)

  • time (float, time reference)

  • rhostar (float, units [rhoref / lref]) – rhostar is needed to set the boundary conditionon the magnetic field line

  • use_invfft (bool) – If True, the inverse Fourier transform is computed every (x, y) points along the magnetic field line. It is much more accurate but very slow.

  • smoothing (float) – Sets level of smoothing done in RectBivariateSpline

  • unwrap (Optional[bool]) – If True, the x- coordinates are not wrapped into the periodic domain so that cumulative displacements are available.

  • max_fraction (float, optional) – Maximum allowed x‐step size as a fraction of the full radial domain Lx. Steps with |Δx| > max_fraction * Lx issue a warning but are retained. Default is 0.25.

  • pad_factor (int, optional) – Factor by which to pad the kx spectrum before transforming. A value of 2 doubles the kx resolution (nx → 2·nx). Larger values increase real-space grid resolution but cost more CPU. Default is 1.

  • integration_order (int, optional) – Order of Runge Kutta scheme to be used when integrating along field line

Returns:

points – 4D array of shape (2, nturns, len(yarray), len(xarray)) containing the x and y coordinates shaped according to the initial field line position. See example_poincare.py for a simple example.

Return type:

ArrayLike, units [rhoref]

Raises:

RuntimeError: – In case of linear simulation or GKOutput not loaded

radial_diffusion_coefficient(xarray, yarray, nturns, time, rhostar, length_per_turn=None, use_invfft=False, smoothing=0.0, unwrap=True)[source]#

Calculates the radial diffusion coefficient using the definition

D_r = <(r(l) - r(0))^2> / (2 * l_total)

where r(l) is the radial (x) coordinate at turn l, and the average is taken over all field lines. Here, l_total = nturns * length_per_turn.

Parameters:
  • xarray (ArrayLike) – Array containing initial radial (x) positions.

  • yarray (ArrayLike) – Array containing initial y positions.

  • nturns (int) – Number of turns over which to integrate.

  • time (float) – Time reference.

  • rhostar (float) – Parameter for the flux-tube boundary condition.

  • length_per_turn (float, optional) – Distance along the field line per turn. If not provided, it is computed using the local geometry.

  • use_invfft (bool, optional) – Whether to use the inverse FFT method.

  • smoothing (float, optional) – Smoothing parameter for interpolation.

  • unwrap (bool, optional) – If True, positions are not wrapped so that the cumulative displacement is retained.

Returns:

D_r – The estimated radial diffusion coefficient.

Return type:

float