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
|
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) |
|
Note Has asynchronous variant '.asnc(...)' that returns Promise[...] |
|
Calculates the radial Fourier modes of this field (or the ratio to the given |
|
Computes the magnetic field on the specified grid. Doesn't download the field to the local machine. |
|
Attaches a cached computed version of this field. In future computations, this field will be interpolated |
|
Evaluates the magnetic field in the given coordinates. |
|
Evaluates the magnetic field in the given coordinates. Unlike interpolateXyz, this function |
|
Creates a field by loading a computed field. |
|
|
|
Creates a magnetic equilibrium field form an EFit file |
|
For a field of type "computed", returns the grid and the downloaded field tensor on the grid. |
|
Visualizes the contents in a graph structure. |
|
Evaluates the magnetic field at target positions by first computing the magnetic field |
|
Loads an instance of this class from a previously written archive file. |
|
Prints a tree version of this object. |
|
Resolves contained coils and magnetic configurations contained in this object (returned in a new instance) Note Has asynchronous variant '.asnc(...)' that returns Promise[...] |
|
Returns a new field rotated around the prescribed axis and center point |
|
Saves the object into an archive file (including all referenced data) |
|
Prints the contents as block-structured YAML |
|
Returns a new field shifted by the given vector |
|
Note Has asynchronous variant '.asnc(...)' that returns Promise[...] |
Attributes
|
Underlying Cap'n'proto struct (usually a builder 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', fourierConvention: Literal['regular', 'vmec'] = 'vmec', fourierNormalization: Literal['normalized', 'l2Preserving', 'unnormalized'] = 'normalized') 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))
fourierConvention: What type of Fourier modes to expand in. Also affects the DFT expansion Possible values are: - regular: Usual Fourier modes of type exp(2 *pi * i * (n * phi + m * theta)) - vmec: VMEC-style Fourier expansion of type exp(2 * pi * i * (m * theta - n * phi))
fourierNormalization: How to normalize the Fourier modes. Available normalizations are: - unnormalized: Performs no normalization of the Fourier transform. - l2Preserving: Divide by sqrt(nPhi * nTheta), which produces identical L2 norm of input values and Fourier coefficients - normalized: Divide by nPhi * nTheta, so that the modes are the actual mode expansion coefficients (so the inverse DFT requires
no normalization)
- 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[…]