freegsnke.geqdsk module

Handles reading and writing of Equilibrium objects

Writing is relatively straightforward, but reading requires inferring the currents in the PF coils

Copyright 2016 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/>.

freegsnke.geqdsk.ceilPow2(val: float) → int[source]

Find a power of two greater than or equal to val.

Parameters:

val (float) – Positive value.

Returns:

Smallest power of two that is >= val.

Return type:

int

freegsnke.geqdsk.isPow2(val: int) → bool[source]

Check whether an integer is a power of 2.

Parameters:

val (int) – Integer to test.

Returns:

True if val is a power of 2.

Return type:

bool

freegsnke.geqdsk.read(fh: TextIO, machine: object, rtol: float = 0.001, ntheta: int = 8, show: bool = False, axis: object | None = None, pause: float = 0.0001, cocos: int = 1, domain: tuple[float, float, float, float] | None = None, blend: float = 0.0, fit_sol: bool = False, maxits: int | None = 50) → Equilibrium[source]

Read a G-EQDSK format file and build an Equilibrium from it.

A nonlinear solve is performed, using Picard iteration.

Parameters:
  • fh (TextIO) – Open, readable text file handle.

  • machine (object) – Machine object defining coil locations.

  • rtol (float, optional) – Relative error in the nonlinear solve.

  • ntheta (int, optional) – Number of points in poloidal angle on the separatrix, used to constrain the plasma shape.

  • show (bool, optional) – Set to True to show the solution in a new figure.

  • axis (object, optional) – Matplotlib Axes for plotting. Implies show=True.

  • pause (float, optional) – Delay between output plots. If negative, waits for the window to be closed.

  • cocos (int, optional) – COordinate COnventions. Not fully handled yet, only whether psi is divided by 2pi or not: if > 10 then psi is divided by 2pi.

  • domain (tuple[float, float, float, float], optional) – The (R, Z) domain to solve for, (Rmin, Rmax, Zmin, Zmax).

  • blend (float, optional) – Weighting (between 0 and 1) of the previous poloidal flux at each step of the Picard iteration. The default (0.0) uses no blending. Blending slows convergence, but can stabilise some oscillating unstable solutions.

  • fit_sol (bool, optional) – If False (default) then only the poloidal flux inside the separatrix is used to constrain the coil currents. This is particularly for reading SCENE input, which is not valid outside the separatrix. If True, the whole domain is used in the fitting, which is useful if the locations of strike points need to be constrained.

  • maxits (int or None, optional) – Maximum number of Picard iterations. None means no limit; if the limit is exceeded then a RuntimeError is raised.

Returns:

The equilibrium. In addition, eq.control is the control system (set only if an X-point is found) and eq._profiles the profiles object.

Return type:

Equilibrium

Raises:

ValueError – If both fit_sol and domain are given.

freegsnke.geqdsk.write(eq: ~freegsnke.equilibrium.Equilibrium, fh: ~typing.TextIO, label: str | None = None, oxpoints: tuple | None = None, fileformat: ~typing.Callable[[...], None] = <function write>) → None[source]

Write a GEQDSK equilibrium file, given an Equilibrium object.

Parameters:
  • eq (Equilibrium) – Equilibrium object.

  • fh (TextIO) – Open, writable text file handle.

  • label (str, optional) – Text label to put in the file.

  • oxpoints (tuple, optional) – O- and X-points (opoint, xpoint) as returned by critical.find_critical. If not given, they are calculated using critical.find_critical.

  • fileformat (Callable[..., None], optional) – Low-level writer, called as fileformat(data, fh, label=label). Defaults to the GEQDSK writer.