spectre.mesh_gen.map2disc
map2disc (BCM) conformal mapping of SPECTRE boundaries to nested interfaces.
The map2disc package provides a 2-D boundary-conformal map (BCM) that
maps the unit disc onto an arbitrary poloidal cross-section. By evaluating the
map at radii rho = sqrt(tflux) it produces geometrically smooth nested
interfaces inside a given plasma boundary.
This module holds the BCM-dependent pieces of mesh generation:
map_boundary_to_interfaces()— the single, source-agnostic mapping loop. It is also reused byspectre.converters.compute_guesses_map2disc.compute_interface_guesses_map2disc(), which maps a boundary given directly as Fourier-coefficient dicts.get_inface_func()/gen_mesh_calc_rz()— build the boundary curve from a liveSPECTREobject’s packed state and map it inward.
Both feed map_boundary_to_interfaces() a make_boundary callback — a
callable that, given a toroidal angle zeta, returns the boundary curve
theta -> (R, Z) at that cross-section.
Conventions are the caller’s responsibility: the negative-theta sign
convention and any rescaling of the returned radial gradients into SPECTRE’s
s in [-1, 1] coordinate are applied by the caller, not here. This routine
works purely in map2disc’s native rho in [0, 1] coordinate.
Module Contents
- spectre.mesh_gen.map2disc.map_boundary_to_interfaces(make_boundary, rho_arr, th_arr, zeta_arr, bcm_m, with_grad=False)
Conformally map a boundary inward to nested interfaces using map2disc BCM.
For each toroidal cross-section
zetainzeta_arrthe boundary curve is obtained frommake_boundary(zeta), a BCM solve is performed, and the map is evaluated on the(rho_arr, th_arr)grid. BCM is a purely 2-D map, so the full 3-D geometry is assembled onezetaslice at a time.- Args:
- make_boundary:
callable(zeta) -> callable(theta) -> (R, Z); given a toroidal angle it returns the boundary curve at that cross-section. Returning a per-
zetacurve lets the caller do any per-slice setup once instead of on every BCM evaluation.- rho_arr: 1-D array of radial positions in map2disc’s
[0, 1]coordinate (typically
sqrt(tflux)); one entry per interface.- th_arr: 1-D array of poloidal angles at which to evaluate the map. The
caller supplies the sign convention (SPECTRE uses negated angles).
zeta_arr: 1-D array of toroidal angles (one field period is sufficient). bcm_m: number of Fourier modes used by the BCM solver. with_grad: if
Truealso return the radial gradientsdR/drhoanddZ/drhoin map2disc’srhocoordinate.- make_boundary:
- Returns:
(R_arr, Z_arr)whenwith_gradisFalse, otherwise(R_arr, Z_arr, dRdrho_arr, dZdrho_arr). Every array has shape(len(rho_arr), len(zeta_arr), len(th_arr)).- Raises:
ImportError: if
map2discis not installed.
- spectre.mesh_gen.map2disc.get_inface_func(xin, test, zeta, inface)
Build the boundary curve of one SPECTRE interface at a fixed toroidal angle.
Unpacks the interface Fourier coefficients from the packed state vector
xinand returns a callabletheta -> (R, Z)evaluating interfaceinfaceof the SPECTRE objecttestat the toroidal anglezeta.- Args:
xin: packed interface state vector (see
spectre.utils.unpack_interfaces()). test: a liveSPECTREobject providing geometry and mode metadata. zeta: toroidal angle at which to evaluate the cross-section. inface: interface index (0 <= inface <= mvol - 1).- Returns:
callable(theta) -> (R, Z)evaluating the interface curve.- Raises:
RuntimeError: if
infaceis out of range.
- spectre.mesh_gen.map2disc.gen_mesh_calc_rz(xin, test, inface, bcm_m, rho_arr, th_arr, zeta_arr)
Conformally map a SPECTRE interface inward, returning R, Z and radial gradients.
Thin wrapper around
map_boundary_to_interfaces()that uses interfaceinfaceof the SPECTRE objecttestas the mapping boundary. The returned gradients are in map2disc’srho in [0, 1]coordinate; callers feeding SPECTRE’ss in [-1, 1]coordinate must rescale them (seespectre.mesh_gen.generators.gen_mesh_external()).- Args:
xin: packed interface state vector. test: a live
SPECTREobject. inface: interface index used as the mapping boundary. bcm_m: number of Fourier modes for the BCM solver. rho_arr: radial positions in map2disc’s[0, 1]coordinate. th_arr: poloidal angles (SPECTRE’s negated-theta convention). zeta_arr: toroidal angles.- Returns:
(R_arr, Z_arr, dRdrho_arr, dZdrho_arr), each of shape(len(rho_arr), len(zeta_arr), len(th_arr)).