fusionsc.magnetics.MagneticConfig

class fusionsc.magnetics.MagneticConfig(val=None, msgSize=1024, byReference=False)

Magnetic configuration class. Wraps an instance of fusionsc.service.MagneticField.Builder and provides access to +, -, *, and / operators.

Methods

__init__([val, msgSize, byReference])

Creates a new instance by either: - Allocating a new message of size msgSize (if val is None) - Storing a reference to the target (if byReference is set) - Copying the message from the given target (accepts Cap'n'proto messages, YAML strings, lists, dicts, and NumPy arrays)

cache(filename)

Note Has asynchronous variant '.asnc(...)' that returns Promise[...]

calculateRadialModes(surfaces[, ...])

Calculates the radial Fourier modes of this field (or the ratio to the given

compute(grid)

Computes the magnetic field on the specified grid. Doesn't download the field to the local machine.

computeCached(grid)

Attaches a cached computed version of this field. In future computations, this field will be interpolated

evaluatePhizr(points)

Evaluates the magnetic field in the given coordinates.

evaluateXyz(points)

Evaluates the magnetic field in the given coordinates. Unlike interpolateXyz, this function

fromComputed(grid, field)

Creates a field by loading a computed field.

fromDipoles(positions, moments, radii)

fromEFit([contents, filename])

Creates a magnetic equilibrium field form an EFit file

getComputed([grid])

For a field of type "computed", returns the grid and the downloaded field tensor on the grid.

graph(**kwargs)

Visualizes the contents in a graph structure.

interpolateXyz(points[, grid])

Evaluates the magnetic field at target positions by first computing the magnetic field

load()

Loads an instance of this class from a previously written archive file.

ptree()

Prints a tree version of this object.

resolve()

Resolves contained coils and magnetic configurations contained in this object (returned in a new instance) Note Has asynchronous variant '.asnc(...)' that returns Promise[...]

rotate(angle, axis[, center])

Returns a new field rotated around the prescribed axis and center point

save(filename)

Saves the object into an archive file (including all referenced data)

toYaml([flow])

Prints the contents as block-structured YAML

translate(dx)

Returns a new field shifted by the given vector

upload()

Note Has asynchronous variant '.asnc(...)' that returns Promise[...]

Attributes

data

Underlying Cap'n'proto struct (usually a builder type).

type

Methods

MagneticConfig.__init__(val=None, msgSize=1024, byReference=False)

Creates a new instance by either: - Allocating a new message of size msgSize (if val is None) - Storing a reference to the target (if byReference is set) - Copying the message from the given target (accepts Cap’n’proto messages,

YAML strings, lists, dicts, and NumPy arrays)

MagneticConfig.cache(filename) Any

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.calculateRadialModes(surfaces: SurfaceArray, normalizeAgainst: MagneticConfig | None = None, nMax=5, mMax=5, nPhi=0, nTheta=0, nSym=1, useFFT=True, quantity: Literal['field', 'flux'] = 'field') Any

Calculates the radial Fourier modes of this field (or the ratio to the given background field) on the given surfaces

Parameters:
  • surfaces: Description of the magnetic surfaces to evaluate on.

  • normalizeAgainst: Optional field to normalize again

  • nMax: Maximum absolute toroidal mode number to calculate

  • mMax: Maximum poloidal mode number to calcualte

  • nPhi: Number of toroidal points on grid

  • nTheta: Number of poloidal points on grid

  • nSym: Toroidal symmetry

  • useFFT: Whether to use the fast FFT-based Fourier path (as opposed to a slower cosine fit)

  • quantity: Whether to calculate the radial field or the radial flux (field * (dx/dPhi x dx/dTheta))

Returns:

A dict with the following entries: - cosCoeffs: […, 2 * nMax + 1, mMax + 1] array of cosine coefficients of Fourier mode expansion - sinCoeffs: […, 2 * nMax + 1, mMax + 1] array of sine coefficients of Fourier mode expansion - nTor: [2 * nMax + 1, 1] array of toroidal mode numbers - mPol: [1, mMax + 1] array of poloidal mode numbers

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.compute(grid) Any

Computes the magnetic field on the specified grid. Doesn’t download the field to the local machine.

Returns:

A magnetic field of type ‘computedField’ that holds a reference to the (eventually computed, possible remotely held) computed field.

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.computeCached(grid) Any

Attaches a cached computed version of this field. In future computations, this field will be interpolated as long as all points of the compute request lie inside its grid definition.

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.evaluatePhizr(points) Any

Evaluates the magnetic field in the given coordinates.

Parameters:
  • points: A numpy-array of shape [3, …] (at least 1D) with the points in r, z, phi coordinates.

Returns:

A numpy array of shape points.shape with the field as x, y, z field (cartesian).

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.evaluateXyz(points) Any

Evaluates the magnetic field in the given coordinates. Unlike interpolateXyz, this function does NOT compute the field on a grid and then interpolate, but instead evaluates the field directly at the given point.

Parameters:
  • points: A numpy-array of shape [3, …] (at least 1D) with the points in x, y, z coordinates.

Returns:

A numpy array of shape points.shape with the field as x, y, z field (cartesian).

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

static MagneticConfig.fromComputed(grid, field)

Creates a field by loading a computed field.

Parameters:
  • grid: An object that can be assigned to a service.MagneticField (e.g. YAML string, service.MagneticField.Reader or .Builder, apprioriate python dict)

  • field: A tensor of shape [nPhi, nZ, nR, 3] holding the magnetic field. The last axis describes the magnetic field component. The components are (indices 0 to 2) bPhi, bZ, bR.

Returns:

A magnetic field object matching the given grid and the field values at the interpolation points

static MagneticConfig.fromDipoles(positions, moments, radii)
static MagneticConfig.fromEFit(contents: str | None = None, filename: str | None = None)

Creates a magnetic equilibrium field form an EFit file

MagneticConfig.getComputed(grid=None) Any

For a field of type “computed”, returns the grid and the downloaded field tensor on the grid.

Returns:
  • A service.ToroidalGrid.Builder describing the grid.

  • A tensor of shape [nPhi, nZ, nR, 3] holding the magnetic field. The last axis describes the magnetic field component. The components are (indices 0 to 2) bPhi, bZ, bR.

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.graph(**kwargs)

Visualizes the contents in a graph structure. Requires graphviz

MagneticConfig.interpolateXyz(points, grid=None) Any

Evaluates the magnetic field at target positions by first computing the magnetic field at the target points (if not yet done), and then

Parameters:
  • points: A numpy-array of shape [3, …] (at least 1D) with the points in x, y, z coordinates.

  • grid: An optional grid parameter required if the field is not yet computed. The grid

Returns:

A numpy array of shape points.shape with the field as x, y, z field (cartesian).

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.load() Any

Loads an instance of this class from a previously written archive file.

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.ptree()

Prints a tree version of this object. Requires the printree library.

MagneticConfig.resolve() Any

Resolves contained coils and magnetic configurations contained in this object (returned in a new instance) Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.rotate(angle, axis, center=[0, 0, 0])

Returns a new field rotated around the prescribed axis and center point

MagneticConfig.save(filename) Any

Saves the object into an archive file (including all referenced data)

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

MagneticConfig.toYaml(flow=False)

Prints the contents as block-structured YAML

MagneticConfig.translate(dx)

Returns a new field shifted by the given vector

MagneticConfig.upload() Any

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]