essos.mgrid

VMEC mgrid read/write helpers for ESSOS coil fields.

The writer mirrors the SIMSOPT MagneticField.to_mgrid convention: fields are evaluated on a cylindrical tensor grid with layout (nphi, nz, nr) and written to VMEC/MAKEGRID-compatible NetCDF files.

Attributes

_BIOT_SAVART_PAIR_BUDGET

Classes

MGrid

VMEC mgrid data and a JAX-compatible interpolated magnetic field.

Functions

_pad_string(→ str)

_unpack(→ str)

_interpolate_component(fields, weights, r, phi, z, *, ...)

Trilinearly interpolate coil-group tables, periodically in phi.

coils_to_mgrid(→ MGrid)

Sample a periodic coil field and write a VMEC-compatible mgrid file.

Module Contents

essos.mgrid._BIOT_SAVART_PAIR_BUDGET = 4000000
essos.mgrid._pad_string(string: str) → str
essos.mgrid._unpack(binary_array: Any) → str
essos.mgrid._interpolate_component(fields, weights, r, phi, z, *, rmin, rmax, zmin, zmax, nfp)

Trilinearly interpolate coil-group tables, periodically in phi.

class essos.mgrid.MGrid

Bases: essos.fields.MagneticField

VMEC mgrid data and a JAX-compatible interpolated magnetic field.

B(points) returns Cartesian field vectors. R and Z are clamped to the tabulated bounds; phi is periodic with period 2*pi/nfp. The field is trilinearly interpolated between grid nodes.

nr: int = 51
nz: int = 51
nphi: int = 24
nfp: int = 2
rmin: float = 0.2
rmax: float = 0.4
zmin: float = -0.1
zmax: float = 0.1
br_arr: Any
bp_arr: Any
bz_arr: Any
coil_names: list[str] = []
mode: str = 'N'
raw_coil_current: Any
__post_init__()
property n_ext_cur: int
add_field_cylindrical(br: Any, bp: Any, bz: Any, name: str | None = None) → None

Append one external-current group in cylindrical components.

property _field_weights
property br
property bp
property bz
property bvec
b_cyl(r, phi, z)

Return (B_R, B_phi, B_Z) at broadcastable cylindrical points.

B(points)

Return the interpolated field in Cartesian coordinates.

AbsB(points)

Return the field magnitude for each Cartesian point.

sqrtg(points)
to_xyz(points)
_tree_flatten()
classmethod _tree_unflatten(aux, children)
write(filename: str | pathlib.Path) → None

Write the mgrid to a VMEC-compatible NetCDF file.

classmethod from_file(filename: str | pathlib.Path) → MGrid

Read an mgrid NetCDF file.

essos.mgrid.coils_to_mgrid(coils: Any, filename: str | pathlib.Path, *, nr: int = 10, nphi: int = 4, nz: int = 12, rmin: float = 1.0, rmax: float = 2.0, zmin: float = -0.5, zmax: float = 0.5, nfp: int | None = None, name: str = 'essos_coils') → MGrid

Sample a periodic coil field and write a VMEC-compatible mgrid file.