freegsnke.fieldtracer module
Tracing of magnetic field lines in an equilibrium.
Copyright 2024 Nicola C. Amorisco, Adriano Agnello, George K. Holt, Ben Dudson.
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.fieldtracer.FieldTracer(eq: object)[source]
Bases:
objectFollow magnetic field lines in an equilibrium.
- __init__(eq: object) None[source]
Initialise a FieldTracer for an equilibrium.
The domain-checking method is the wall-based one if the equilibrium’s tokamak has a wall, otherwise the computational domain is used.
- Parameters:
eq (object) – Equilibrium object.
- eqDomain(R: ndarray, Z: ndarray, evolving: ndarray) ndarray[source]
Zero the entries of evolving for points outside the computational domain.
- Parameters:
R (np.ndarray) – Major radius of the points [m].
Z (np.ndarray) – Height of the points [m].
evolving (np.ndarray) – Array of the same shape as R and Z, modified in place.
- Returns:
The updated evolving array.
- Return type:
np.ndarray
- fieldDirection(pos: ndarray, toroidal_angle: float, evolving: ndarray, backward: bool) ndarray[source]
Calculate the rate of change of position with toroidal angle.
Used as the right-hand side of the ODE integrated by
follow.- Parameters:
pos (np.ndarray) – Flattened (R, Z, length) positions of the field lines.
toroidal_angle (float) – Toroidal angle (unused; the field is axisymmetric).
evolving (np.ndarray) – Per-line flags, 1 for lines still inside the domain and 0 once they have left it; updated in place.
backward (bool) – If True, follow the field lines in the -B direction.
- Returns:
Flattened (dR/dphi, dZ/dphi, dl/dphi) for each line.
- Return type:
np.ndarray
- follow(Rstart: ndarray, Zstart: ndarray, angles: ndarray, rtol: float | None = None, backward: bool = False) ndarray[source]
Follow magnetic field lines from (Rstart, Zstart) to given toroidal angles.
- Parameters:
Rstart (np.ndarray) – Starting major radii [m].
Zstart (np.ndarray) – Starting heights [m], same shape as Rstart.
angles (np.ndarray) – Toroidal angles at which to output the positions [rad].
rtol (float, optional) – Relative tolerance passed to
scipy.integrate.odeint.backward (bool, optional) – If True, the field lines are followed in the -B direction.
- Returns:
(R, Z, length) along each line, shape
angles.shape + Rstart.shape + (3,).- Return type:
np.ndarray
- wallDomain(R: ndarray, Z: ndarray, evolving: ndarray) None[source]
Zero the entries of evolving for points outside the wall.
This is done by counting intersections of the line from the domain centre to each point with the wall.
- Parameters:
R (np.ndarray) – Major radius of the points [m].
Z (np.ndarray) – Height of the points [m].
evolving (np.ndarray) – Array of the same shape as R and Z, modified in place.
- class freegsnke.fieldtracer.LineCoordinates(R: ndarray, Z: ndarray, length: ndarray)[source]
Bases:
objectCoordinates of a field line.
- R
Major radius [m].
- Type:
np.ndarray
- Z
Height [m].
- Type:
np.ndarray
- length
Field line length [m].
- Type:
np.ndarray
- All of R, Z and length are NumPy arrays of the same shape.
- freegsnke.fieldtracer.traceFieldLines(eq: object, solwidth: float = 0.03, nlines: int = 10, nturns: int = 50, npoints: int = 200, axis: object | None = None) tuple[LineCoordinates, LineCoordinates][source]
Trace field lines from the outboard midplane.
- Parameters:
eq (object) – Equilibrium object.
solwidth (float, optional) – The width of the SOL [m].
nlines (int, optional) – Number of field lines to follow.
nturns (int, optional) – Number of times around the tokamak to follow.
npoints (int, optional) – Maximum number of points per line. Lines may hit a wall.
axis (object, optional) – Matplotlib Axes. If given, field lines are plotted on it.
- Returns:
forward (LineCoordinates) – Coordinates of the field lines followed in the +B direction.
backward (LineCoordinates) – Coordinates of the field lines followed in the -B direction. Both have
R,Zandlengthas 2D arrays of shape (npoints, nlines).
Examples
>>> forward, backward = traceFieldLines(eq)