freegsnke.coil module

Poloidal field coil.

Used in machine to define coils. Can also be a base class for other coil types.

Copyright 2016-2019 Ben Dudson, University of York. Email: benjamin.dudson@york.ac.uk

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.coil.AreaCurrentLimit(current_density: float = 3500000000.0)[source]

Bases: object

Calculate the coil area based on a fixed current density limit.

__init__(current_density: float = 3500000000.0) → None[source]

Set the maximum current density.

Limits in general depend on the magnetic field. Typical values Nb3Sn ~ 3.5e9 A/m^2 https://doi.org/10.1016/0167-899X(86)90010-8

Parameters:

current_density (float, optional) – Maximum current density in A/m^2.

class freegsnke.coil.Coil(R: float, Z: float, current: float = 0.0, turns: int = 1, control: bool = True, area: float | ~freegsnke.coil.AreaCurrentLimit = <freegsnke.coil.AreaCurrentLimit object>)[source]

Bases: object

Represents a poloidal field coil.

The total toroidal current carried by the coil is current * turns.

Br(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate radial magnetic field Br at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

Bz(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate vertical magnetic field Bz at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

__init__(R: float, Z: float, current: float = 0.0, turns: int = 1, control: bool = True, area: float | ~freegsnke.coil.AreaCurrentLimit = <freegsnke.coil.AreaCurrentLimit object>) → None[source]

Set the coil location, current, turns, control flag and area.

The most important effect of the area is on the coil self-force: the smaller the area the larger the hoop force for a given current.

Parameters:
  • R (float) – Radial location of the coil in m.

  • Z (float) – Vertical location of the coil in m.

  • current (float, optional) – Current in each turn of the coil in A.

  • turns (int, optional) – Number of turns. Total coil current is current * turns.

  • control (bool, optional) – Enable or disable control system.

  • area (float or callable, optional) – Cross-section area in m^2. Either a fixed value (e.g. 0.025 for a 5x5 cm coil) or a callable taking the coil as its argument, e.g. AreaCurrentLimit(current_density) with the density in A/m^2, in which case the area is recalculated as the coil current is changed.

property area: float

The cross-section area of the coil in m^2.

If the stored area is a callable it is evaluated with the coil.

Returns:

Area in m^2.

Return type:

float

calcPsiFromGreens(pgreen: ndarray) → ndarray[source]

Calculate plasma psi from Greens functions and current.

Parameters:

pgreen (np.ndarray) – Poloidal flux Green’s function values (per unit current).

Returns:

Poloidal flux due to the coil, current * pgreen.

Return type:

np.ndarray

controlBr(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate radial magnetic field Br at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

controlBz(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate vertical magnetic field Bz at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

controlPsi(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate poloidal flux at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

controldBrdr(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate dBr/dr at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

controldBrdz(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate dBr/dz at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

controldBzdr(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate dBz/dr at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

controldBzdz(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate dBz/dz at (R, Z) due to a unit current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity per unit coil current (scaled by the number of turns).

Return type:

float or np.ndarray

copy() → Coil[source]

Create a new object that has identical attributes to self (a copy).

The copy method will need to be implemented for any subclasses of Coil to ensure the correct __init__ signature is called and to ensure lists/other object attributes are copied where appropriate (not passed by reference).

Returns:

The copied coil.

Return type:

Coil

createBrGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the Br Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createBzGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the Bz Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createPsiGreens(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the poloidal flux Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createPsiGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the poloidal flux Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createdBrdrGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the dBrdr Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createdBrdzGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the dBrdz Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createdBzdrGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the dBzdr Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

createdBzdzGreensVec(R: float | ndarray, Z: float | ndarray) → ndarray[source]

Calculate the dBzdz Green’s function at every point.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Green’s function values (per unit current) at the given points.

Return type:

np.ndarray

dBrdr(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate magnetic field gradient dBr/dr at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

dBrdz(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate magnetic field gradient dBr/dz at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

dBzdr(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate magnetic field gradient dBz/dr at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

dBzdz(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate magnetic field gradient dBz/dz at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

The quantity at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

dtype = dtype([('R', '<f8'), ('Z', '<f8'), ('current', '<f8'), ('turns', '<i8'), ('control', '?')])
classmethod from_numpy_array(value: ndarray) → Coil[source]

Restore a coil from a structured record with the coil serialization dtype.

Parameters:

value (np.ndarray) – Structured array with dtype Coil.dtype.

Returns:

The restored coil.

Return type:

Coil

Raises:

ValueError – If value.dtype does not match Coil.dtype.

getForces(equilibrium: object) → ndarray[source]

Calculate forces on the coil in Newtons.

Force on coil due to its own current:

Lorentz self-forces on curved current loops Physics of Plasmas 1, 3425 (1998); https://doi.org/10.1063/1.870491 David A. Garren and James Chen

The coil current is temporarily set to zero to evaluate the field due to all other coils and the plasma, then restored.

Parameters:

equilibrium (object) – Equilibrium providing Br(R, Z) and Bz(R, Z) methods.

Returns:

Array of two elements, [Fr, Fz], in N.

Return type:

np.ndarray

plot(axis: object | None = None, show: bool = False) → object[source]

Plot the coil location, using axis if given.

The area of the coil is used to set the radius, unless the coil has rectangular dimensions dR and dZ (see plot_nke).

Parameters:
  • axis (matplotlib.axes.Axes, optional) – Axis to plot on. A new figure is created if None.

  • show (bool, optional) – Passed to plot_nke; unused otherwise.

Returns:

The axis plotted on.

Return type:

matplotlib.axes.Axes

plot_nke(axis: object | None = None, show: bool = False) → object[source]

Plot the coil as a rectangle of size dR by dZ.

Requires the coil to have dR and dZ attributes.

Parameters:
  • axis (matplotlib.axes.Axes, optional) – Axis to plot on. A new figure is created if None.

  • show (bool, optional) – Unused.

Returns:

The axis plotted on.

Return type:

matplotlib.axes.Axes

psi(R: float | ndarray, Z: float | ndarray) → float | ndarray[source]

Calculate poloidal flux at (R, Z) due to the coil current.

Parameters:
  • R (float or np.ndarray) – Radial coordinate(s) in m.

  • Z (float or np.ndarray) – Vertical coordinate(s) in m.

Returns:

Poloidal flux at (R, Z); 0 if the coil current is negligible (|current| <= 1e-5 A).

Return type:

float or np.ndarray

to_numpy_array() → ndarray[source]

Convert the coil to a structured array, for writing output.

Returns:

Structured 0-d array with the coil serialization dtype.

Return type:

np.ndarray