vmec_jax.field

Magnetic field representation utilities.

This module implements the contravariant magnetic-field components used by VMEC:

  • bsupu : B^u (poloidal-angle contravariant component)

  • bsupv : B^v (toroidal-angle contravariant component)

in terms of:
  • the Jacobian sqrtg (signed),

  • flux functions phipf(s) = dPhi/ds and chipf(s) = dChi/ds,

  • and the VMEC lambda field (stored in a scaled form; see lamscale).

Important convention

VMEC’s public wout files store the lambda coefficients in a scaled form, and VMEC multiplies lambda-derivatives by a scalar lamscale before using them in B. We follow that convention here so we can validate against the bundled wout reference.

The formulas implemented here match VMEC’s bcovar + add_fluxes logic:

bsupv = overg * (phipf + lamscale * lam_u) bsupu = overg * (chipf + lamscale * lam_v)

where overg = 1 / (signgs * sqrtg) following VMEC’s bcovar convention.

Functions

b2_from_bsup(geom, bsupu, bsupv)

Compute B^2 from contravariant components and the covariant metric.

b_cartesian_from_bsup(geom, bsupu, bsupv, *, ...)

Compute Cartesian B=(Bx,By,Bz) from contravariant components.

b_cartesian_from_state(state, static[, ...])

Compute Cartesian magnetic field from a solved VMEC state.

bsub_from_bsup(geom, bsupu, bsupv)

Compute covariant components (B_u, B_v) from contravariant (B^u, B^v).

bsup_from_geom(geom, *, phipf, chipf, nfp, ...)

Compute (bsupu, bsupv) from a Geom.

bsup_from_sqrtg_lambda(*, sqrtg, lam_u, ...)

Compute (bsupu, bsupv) from a Jacobian and lambda derivatives.

chips_from_chipf(chipf)

Reconstruct VMEC's chips(js) (full-mesh poloidal flux function) from chipf(js).

chips_from_wout_chipf(*, chipf, phipf[, ...])

Resolve full-mesh chips from a wout-style chipf array.

full_mesh_from_half_mesh_avg(half)

Invert VMEC's 1D half-mesh averaging map.

half_mesh_avg_from_full_mesh(full)

VMEC half-mesh averaging map used for several radial 1D arrays.

lamscale_from_phips(phips, s)

Compute VMEC's lamscale from phips and the radial grid s.

signgs_from_sqrtg(sqrtg, *[, axis_index])

Infer VMEC's signgs (+1 or -1) from a signed Jacobian array.