freegsnke.multi_coil module
Classes and routines to represent coils and circuits.
Copyright 2019 Chris Marsden, Tokamak Energy. Email: Chris.Marsden@tokamakenergy.co.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.multi_coil.MultiCoil(R: float | list[float] | ~numpy.ndarray, Z: float | list[float] | ~numpy.ndarray, current: float = 0.0, turns: int = 1, control: bool = True, mirror: bool = False, polarity: list[float] | ~numpy.ndarray | None = None, area: float | ~freegsnke.coil.AreaCurrentLimit = <freegsnke.coil.AreaCurrentLimit object>)[source]
Bases:
CoilA coil represented by one or more filaments, optionally mirrored in Z=0.
This class is multifunctional and can model several coil arrangements: 1. A single PF coil 2. A block of several PF coil filaments, modelled as
a single point in (R,Z)
a list of (R,Z) points for each filament in the block
In both cases, the specified coil(s) can also be mirrored in Z=0 and connected in a circuit sharing the same power supply. In such a case, there is also the option to specify the polarity of the currents in the upper and lower coil blocks, enabling the wiring of these blocks in opposite directions.
For multiple point coils, the total toroidal current carried by the point coil block is
current * turns.- property R: float
Major radius of the coil centre in m.
- Returns:
Mean radial position of the filaments.
- Return type:
float
- property Z: float
Height of the coil centre in m.
- Returns:
Mean vertical position of the filaments.
- Return type:
float
- __init__(R: float | list[float] | ~numpy.ndarray, Z: float | list[float] | ~numpy.ndarray, current: float = 0.0, turns: int = 1, control: bool = True, mirror: bool = False, polarity: list[float] | ~numpy.ndarray | None = None, area: float | ~freegsnke.coil.AreaCurrentLimit = <freegsnke.coil.AreaCurrentLimit object>) None[source]
Set the filament locations, current, turns, mirroring and polarity.
- Parameters:
R (float or array-like) – Radial location(s) in m. A single value is the coil centre (moving it moves all filaments); a sequence gives the filament locations.
Z (float or array-like) – Vertical location(s) in m, with the same length as
R.current (float, optional) – Current in each turn of the coil in A.
turns (int, optional) – Number of turns in the point coil block; total block current is
current * turns. Only used ifRandZare single points, otherwise it is set to the number of filaments.control (bool, optional) – Enable or disable control system.
mirror (bool, optional) – Mirror the point/detailed coil block in Z=0, creating a circuit.
polarity (array-like of float, optional) – Wiring of the circuit, same or opposite direction, as
[block 1, block 2]. Defaults to[1.0, 1.0].area (float or callable, optional) – Cross-section area of the block 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.
- controlBr(R: float | ndarray, Z: float | ndarray) float | ndarray[source]
Calculate radial magnetic field Br at (R, Z) due to a unit current.
Sums the contributions of all filaments (and their Z=0 mirror images if
mirroris set), weighted bypolarity.- 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) per unit coil current.
- 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.
Sums the contributions of all filaments (and their Z=0 mirror images if
mirroris set), weighted bypolarity.- 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) per unit coil current.
- 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.
Sums the contributions of all filaments (and their Z=0 mirror images if
mirroris set), weighted bypolarity.- 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) per unit coil current.
- Return type:
float or np.ndarray
- copy() MultiCoil[source]
Create a copy of this object.
The extra attributes
rectangle,resistivity,dRanddZare copied (by reference) if present.- Returns:
A new instance of the same class with copied attributes.
- Return type:
- dtype = dtype([('RZlen', '<i8'), ('R', '<f8', (500,)), ('Z', '<f8', (500,)), ('current', '<f8'), ('turns', '<i8'), ('control', '?'), ('mirror', '?'), ('polarity', '<f8', (2,))])
- classmethod from_numpy_array(value: ndarray) MultiCoil[source]
Restore a filament group from a structured serialization record.
- Parameters:
value (np.ndarray) – Structured array with dtype
MultiCoil.dtype.- Returns:
The restored coil.
- Return type:
- Raises:
ValueError – If
value.dtypedoes not matchMultiCoil.dtype.
- plot(axis: object | None = None, show: bool = False) object[source]
Plot the coil geometry including the turn (filament) locations.
This method attempts to plot the coil using the class’s plot_nke method. If that fails (e.g., due to a missing method or plotting error), it falls back to plotting the coil turn positions directly using matplotlib.
- Parameters:
axis (matplotlib.axes.Axes, optional) – The Matplotlib axis to plot on. If None, a new figure and axis are created.
show (bool, optional) – Passed to
plot_nke;plt.show()is not called.
- Returns:
The axis object containing the plot.
- Return type:
matplotlib.axes.Axes
- plot_nke(axis: object | None = None, show: bool = False) object[source]
Plot each filament as a rectangle of size
dRbydZ.Requires the coil to have
dRanddZattributes.- 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