spectre.converters.simsvmec2spectre
VMEC-to-SPECTRE converter using the simsopt Vmec interface.
Module Contents
- spectre.converters.simsvmec2spectre.simsvmec2spectre(vmec_obj, tfluxes=None, nvol=None, mpol=None, ntor=None, inface_current=False, profile_type=None, filename=None, plot=False, angle_fix=True, interface_guess=None, map2disc_kwargs=None)
Generate a SPECTRE input from a simsopt VMEC equilibrium.
Reads pressure, rotational-transform or current profiles and the plasma boundary from a simsopt
Vmecobject, discretises them onto a set of SPECTRE interfaces, and optionally writes the result to a TOML file.Supports both VMEC
input.*files (vmec_obj.indata) andwout_*.ncoutput files (vmec_obj.wout). Onlypower_seriescurrent profiles are supported.- Args:
vmec_obj: simsopt
Vmecinstance. tfluxes: 1-D array-like of interface toroidal-flux values in (0, 1].Mutually exclusive with
nvol. Iftfluxes[-1] < 1, the outermost SPECTRE interface is interior to the VMEC plasma boundary; the boundary coefficients (rbc/zbs) are then replaced with the interpolated geometry attfluxes[-1]. This requiresinterface_guessto be'wout'or'map2disc'.- nvol: number of SPECTRE volumes; interfaces are placed uniformly.
Mutually exclusive with
tfluxes.
mpol: poloidal Fourier resolution. Defaults to
vmec_obj.boundary.mpol. ntor: toroidal Fourier resolution. Defaults tovmec_obj.boundary.ntor. inface_current: ifFalse(default), the toroidal current is placedas distributed volume current (
ivolume); ifTrue, it is placed entirely on the interfaces as sheet current (isurf). Only relevant when the VMEC equilibrium uses a current profile. The continuous-to-discrete current mapping is provisional — seedistribute_current_to_interfaces().- profile_type:
'iota'or'current', overriding auto-detection. When
None(default), the type is inferred from the source:ncurrforindata, or whetheraiis nonzero forwout.- filename: path for the output TOML file. If
None, no file is written and the result is returned only.
- plot: if
True, show a figure comparing VMEC continuous profiles with the SPECTRE-discretised values.
- angle_fix: if
True(default), apply the θ→-θ handedness correction to boundary and interface coefficients (n→-n for m>0, ZBS negated). This replaces the need for
lchangeangle=Truein the TOML. Because θ→-θ reverses the poloidal direction, the poloidal-sense scalars are negated to match: the rotational transform (iota/oita) and the toroidal current (curtor, and hence the derivedisurf/ivolume). Set toFalseonly for equilibria that run correctly withoutlchangeangle.- interface_guess: strategy for generating initial interface geometry.
None(default) — no guesses; SPECTRE linearly interpolates (linitialize=1).'wout'— cubic interpolation of VMEC flux surfaces from a wout file (requires theVmecobject to have been loaded from awout_*.ncfile).'map2disc'— conformal mapping via themap2disclibrary; works from bothinput.*andwout_*.ncsources. When guesses are provided,linitialize=0.- map2disc_kwargs: optional dict of keyword arguments forwarded to
compute_interface_guesses_map2disc()(e.g.{"ntheta": 32, "nzeta": 15, "bcm_m": 4}). Only used wheninterface_guess='map2disc'.
- Returns:
Validated
InputParameterspydantic object.- Raises:
RuntimeError: if neither
tfluxesnornvolis provided. RuntimeError: ifvmec_objhas neitherindatanorwout. RuntimeError: if the current-profile type is not'power_series'. RuntimeError: ifinterface_guess='wout'but the Vmec object has no wout. ValueError: ifinterface_guessis notNone,'wout', or'map2disc'. ValueError: iftfluxes[-1] < 1butinterface_guessisNone.