Analysis

Analysis holds the plotting and post-processing functions for GPEC results, grouped by the stage they read. Each registered plot takes the in-memory result or the path of the gpec.h5 it was saved to; available_plots lists them with what each source can draw (see Plotting a result).

Submodules

  • ForceFreeStates: the eigenmode energies, the crit scan and the displacement profiles of a stability solve
  • Equilibrium: flux surfaces, profiles and the radial grid of an equilibrium
  • CoilForcing: coil geometry and the normal-field spectra it drives
  • PerturbedEquilibrium: the plasma response, the resonant fields, island widths and Chirikov parameter against ψ_N or q
  • PerturbedEquilibriumModes: helpers that convert the modal output to (ψ, θ) and (ψ, θ, φ) grids for real-space plots
  • ErrorFields: coil sensitivities, tolerance distributions, locking risk and correction limits (see Error Fields)

examples/DIIID-like_ideal_example/analyze_example.jl, examples/Solovev_ideal_example/analyze_example.jl and examples/DIIID-like_error_field_example/analyze_example.jl are worked examples of each; the s–α maps of local stability use salpha_reference, compute_ballooning_stability! and scan_delta_prime_map. write_imas on the Utilities page exports results to an IMAS data dictionary.

Drawing

The plots are drawn with Makie, which GPEC loads only when a session loads a Makie backend. Load one alongside GPEC, from your own or the global environment:

using GeneralizedPerturbedEquilibrium, CairoMakie   # files: PNG, PDF, SVG
using GeneralizedPerturbedEquilibrium, GLMakie      # interactive windows that zoom, pan and rotate

Every plot returns a Makie Figure, and save_path saves it with the loaded backend (GLMakie writes PNG only). Without a backend a plot throws an ArgumentError saying which to load.

The summary figures of a DIII-D-like run (examples/DIIID-like_ideal_example):

Equilibrium summary: flux surfaces and the q, μ₀p and 2πF profiles, with the n = 1 rational surfaces

Stability summary: critical determinant, free-boundary energies and the least stable eigenmodes

Perturbed-equilibrium summary: resonant field, edge spectrum, plasma displacement and b_n on the poloidal plane

The C-coil set around the plasma boundary

GeneralizedPerturbedEquilibrium.Analysis — Module
Analysis

Post-processing and visualization utilities for GPEC simulation outputs.

Every registered plot takes a result in memory or the path of the gpec.h5 it was saved to, and throws an ArgumentError naming what to change in the run when that source lacks the data it draws. available_plots(src) lists the plots for a result, a path, or the named tuple main returns. Every plot is exported here and from the package, so plot_qprofile(eq) needs no module prefix.

Submodules

  • ForceFreeStates: Plotting functions for ForceFreeStates (DCON-style ideal MHD stability) results
  • Equilibrium: Plotting functions for equilibrium profiles and flux surfaces
  • CoilForcing: Plotting functions for coil forcing spectra
  • PerturbedEquilibrium: Plotting functions for perturbed equilibrium and singular coupling results
  • PerturbedEquilibriumModes: Data helpers to convert modal GPEC output to (ψ, θ) and (ψ, θ, φ) grids
  • ErrorFields: Plotting functions for the error-field assessment (coil sensitivities, tolerance Monte Carlo, locking risk, phasing maps)
source

Plot registry

GeneralizedPerturbedEquilibrium.Analysis.PlotEntry — Type
PlotEntry

A registered plot.

Fields

  • fn::Function - The plotting function.
  • sources::Tuple - The types it accepts as its first argument; AbstractString means a gpec.h5 path.
  • needs::Tuple{Vararg{Symbol}} - The capabilities (see capabilities) a source must have for it to draw.
  • description::String - One line on what it draws.
  • any_of::Tuple - For a summary, the capabilities of each of its panels: it draws when a source has every capability of at least one panel, and is empty for a single plot.
source
GeneralizedPerturbedEquilibrium.Analysis.available_plots — Method
available_plots(src) -> PlotCatalog

The registered plots for src with whether each can draw from it, and the reason when it cannot. src is a result in memory, a gpec.h5 path, or the named tuple main returns (one section per stage result). Every listed function takes src as its first argument.

source

ForceFreeStates

GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates — Module
ForceFreeStates

Post-processing and visualization functions for ForceFreeStates (DCON-style ideal MHD stability) results. Each plot takes the ForceFreeStatesResult in memory or the path of a gpec.h5 it was saved to, and throws an ArgumentError naming what to change in the run when the source lacks the data it draws (see Analysis.available_plots).

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_ballooning_alpha_boundaries — Method
plot_ballooning_alpha_boundaries(bnd; psi_min=0.0, save_path=nothing)
plot_ballooning_alpha_boundaries(bnd, dpmap; psi_min=0.0, save_path=nothing)

Plot the infinite-n ballooning diagram with the first and second stability boundaries; with dpmap, over a map of Δ′ signed so that positive is stable on every surface, with its zero contour.

Arguments

  • bnd: The named tuple LocalStability.ballooning_alpha_boundaries returns
  • dpmap: The named tuple LocalStability.ballooning_delta_prime_map returns

Keyword arguments

  • psi_min: Lower ψ_N limit (default: 0.0)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_ballooning_alpha_boundary — Method
plot_ballooning_alpha_boundary(src; psi_min=0.0, save_path=nothing)

Plot the infinite-n ballooning diagram: the equilibrium pressure gradient α and its first stability boundary against ψ_N, with the unstable surfaces shaded.

Arguments

  • src: A LocalStabilityResult, or the path of a gpec.h5 written with a [LocalStability] section

Keyword arguments

  • psi_min: Lower ψ_N limit, e.g. 0.9 for the pedestal (default: 0.0)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_cond_fbar — Method
plot_cond_fbar(src; save_path=nothing)

Plot cond(F̄) against ψ_N from the kinetic singular-surface scan, with the threshold, the rational surfaces and any accepted kinetic singular surfaces marked.

Arguments

  • src: A kinetic ForceFreeStatesResult, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_critical_determinant — Method
plot_critical_determinant(src; save_path=nothing)

Plot the critical determinant against ψ_N on a signed pseudo-log axis, titled with its zero crossings (none means fixed-boundary stable).

Arguments

  • src: A Forward or Riccati ForceFreeStatesResult, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_delta_coil — Method
plot_delta_coil(src; part=:real, save_path=nothing)

Plot Δ_coil, the response at each side of each rational surface to a unit source on each edge poloidal harmonic, as a heatmap.

Arguments

  • src: A Riccati ForceFreeStatesResult or a Galerkin one solved with rpec_flag = true, or the path of a gpec.h5 it was saved to

Keyword arguments

  • part: :real (default, diverging symmetric-log colours), :imag, or :abs (log colours)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_delta_prime — Method
plot_delta_prime(src; part=:real, save_path=nothing)

Plot the inter-surface Δ′ matrix (PEST-3 convention, ψ_N-referenced) as a heatmap with each entry written in, rows and columns labelled by rational surface.

Arguments

  • src: A Riccati or Galerkin ForceFreeStatesResult, or the path of a gpec.h5 it was saved to

Keyword arguments

  • part: :real (default, diverging symmetric-log colours), :imag, or :abs (log colours)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_delta_prime_raw — Method
plot_delta_prime_raw(src; part=:real, save_path=nothing)

Plot the raw outer-region matching matrix D′ as a heatmap, with the left and right sides of each rational surface grouped under it on both axes.

Arguments

  • src: A Riccati or Galerkin ForceFreeStatesResult, or the path of a gpec.h5 it was saved to

Keyword arguments

  • part: :real (default, diverging symmetric-log colours), :imag, or :abs (log colours)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_edge_stability_scan — Method
plot_edge_stability_scan(src; save_path=nothing)

Plot the total, plasma and vacuum free-boundary energies against the edge truncation q, with the chosen truncation marked.

Arguments

  • src: A ForceFreeStatesResult produced with dW_edge_scan_start < psilim, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_eigenvalues — Method
plot_eigenvalues(src; matrix_type=:all, save_path=nothing)

Plot the free-boundary energy eigenvalues (the power-normalized pencil W·v = λN·v), most unstable first: the total δW and its plasma and vacuum parts, on a signed pseudo-log axis with the unstable sign shaded.

Arguments

  • src: A ForceFreeStatesResult with free-boundary energies (vac_flag = true), or the path of a gpec.h5 it was saved to

Keyword arguments

  • matrix_type: :all (default), or one of :total, :plasma, :vacuum
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_energy_eigenvectors — Method
plot_energy_eigenvectors(src; nmodes=nothing, save_path=nothing)

Plot |v_m| of the free-boundary energy eigenvectors (unit power norm) against poloidal harmonic m, least stable at the top.

Arguments

  • src: A ForceFreeStatesResult with free-boundary energies (vac_flag = true), or the path of a gpec.h5 it was saved to

Keyword arguments

  • nmodes: Number of least stable eigenmodes drawn (default: all)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_ffs_summary — Method
plot_ffs_summary(src; save_path=nothing)

Plot the stability panels the source supplies, two per row: the critical determinant, the free-boundary energies, the least stable mode's displacement, Δ′_ii at each rational surface, and the energy eigenvectors.

Arguments

  • src: A ForceFreeStatesResult, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure. Throws an ArgumentError naming every missing capability when no panel can be drawn.

source
GeneralizedPerturbedEquilibrium.Analysis.ForceFreeStates.plot_mode_displacement — Method
plot_mode_displacement(src; modes=nothing, save_path=nothing)

Plot |ξ^ψm| against ψN for the least stable free-boundary eigenmode, one curve per harmonic, with the rational surfaces labelled along the top.

Arguments

  • src: A ForceFreeStatesResult with stored ξ profiles, or the path of a gpec.h5 it was saved to

Keyword arguments

  • modes: The m values to draw (default: nothing, the six largest)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source

Equilibrium

GeneralizedPerturbedEquilibrium.Analysis.Equilibrium.plot_equilibrium_summary — Method
plot_equilibrium_summary(src; n=1, save_path=nothing)

Plot the equilibrium's headline scalars, its flux surfaces in (R, Z), and q, μ₀p and 2πF against a shared ψ_N axis.

Arguments

  • src: A PlasmaEquilibrium, a ForceFreeStatesResult, or the path of a gpec.h5

Keyword arguments

  • n: Toroidal mode number whose rational surfaces q = m/n are marked on a bare equilibrium (default: 1); a stability result or gpec.h5 marks the surfaces it solved for
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.Equilibrium.plot_f_profile — Method
plot_f_profile(src; n=1, save_path=nothing)

Plot 2πF = RBφ against ψN, with the rational surfaces labelled along the top.

Arguments

  • src: A PlasmaEquilibrium, a ForceFreeStatesResult, or the path of a gpec.h5

Keyword arguments

  • n: Toroidal mode number whose rational surfaces q = m/n are marked on a bare equilibrium (default: 1); a stability result or gpec.h5 marks the surfaces it solved for
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.Equilibrium.plot_flux_surfaces — Method
plot_flux_surfaces(src; n_psi=11, n_theta=18, n=1, save_path=nothing)

Plot flux surfaces and constant-θ spokes in (R, Z) at equal aspect, with the rational surfaces in colour.

Arguments

  • src: A PlasmaEquilibrium, a ForceFreeStatesResult, or the path of a gpec.h5

Keyword arguments

  • n_psi: Number of flux surfaces drawn (default: 11)
  • n_theta: Number of constant-θ spokes drawn (default: 18)
  • n: Toroidal mode number whose rational surfaces q = m/n are marked on a bare equilibrium (default: 1); a stability result or gpec.h5 marks the surfaces it solved for
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.Equilibrium.plot_gse — Method
plot_gse(gse; n_theta_lines=8, save_path=nothing)

Plot the Grad-Shafranov residual against ψ_N on several θ slices, with the θ-integrated residual as a thick line. Not registered: the equilibrium does not store its residual yet.

Arguments

  • gse: The named tuple Equilibrium.equilibrium_gse! returns

Keyword arguments

  • n_theta_lines: Number of θ slices drawn (default: 8)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.Equilibrium.plot_pressure_profile — Method
plot_pressure_profile(src; n=1, save_path=nothing)

Plot μ₀p against ψ_N, with the rational surfaces labelled along the top.

Arguments

  • src: A PlasmaEquilibrium, a ForceFreeStatesResult, or the path of a gpec.h5

Keyword arguments

  • n: Toroidal mode number whose rational surfaces q = m/n are marked on a bare equilibrium (default: 1); a stability result or gpec.h5 marks the surfaces it solved for
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.Equilibrium.plot_qprofile — Method
plot_qprofile(src; show_singular=true, n=1, save_path=nothing)

Plot the safety factor q against ψ_N, with q₀ and q₉₅ marked and the rational surfaces labelled along the top.

Arguments

  • src: A PlasmaEquilibrium, a ForceFreeStatesResult, or the path of a gpec.h5

Keyword arguments

  • show_singular: Mark the rational surfaces (default: true)
  • n: Toroidal mode number whose rational surfaces q = m/n are marked on a bare equilibrium (default: 1); a stability result or gpec.h5 marks the surfaces it solved for
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source

CoilForcing

GeneralizedPerturbedEquilibrium.Analysis.CoilForcing — Module
CoilForcing

Coil geometry and fields on the plasma control surface: the coils in 3D and in (R, Z), the forcing spectrum, normal field maps in (φ, θ), and the 3D boundary coloured by any control-surface field. Coils are coloured on the same diverging map as the normal field they drive, so a positive current reads as positive b_n beneath the coil.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.control_surface_scalar — Method
control_surface_scalar(equil, modes, n; mtheta=180, nphi=180, psi=nothing,
                       helicity=nothing) -> Matrix{Float64}

Inverse-Fourier-transform a spectral control-surface quantity into a real-space [mtheta, nphi] field on the plasma boundary, ready to colour plot_surface_3d.

modes are complex Fourier amplitudes indexed by poloidal mode m for a single toroidal mode n — a Vector{ForcingMode} (filtered to n) or a (m_vals, amplitudes) tuple. The quantity is arbitrary (e.g. applied normal field b_n_x, total b_n, displacement xi_n); the caller supplies whichever modes they want to view.

The transform inverts the SFL Fourier decomposition used by ForcingTerms.fourier_decompose_bn: f(θ) = Σ_m amp_m e^{i m θ}, the per-θ correction e^{i n ν(ψ,θ)} from equil.rzphi_nu, then the toroidal extension in the machine angle c(θ,φ) = -Re[f(θ) e^{i n·hel·φ}]. The e^{i n·hel·φ} follows from the SFL→machine map φ = -hel(2π ζ + ν) (ζ the SFL toroidal angle the modes were decomposed against); substituting 2π ζ = -hel·φ - ν is what turns the decomposition's ζ exponential into the ν correction times e^{i n·hel·φ}.

Sign / helicity convention

The reconstruction tracks the source coil toroidally (the field lobe sits at the coil's φ), carried by helicity = sign(Bt)·sign(Ip) in e^{i n·hel·φ} (equil.rzphi_nu/equil.params). The leading - is a display orientation so that a positive coil current reads as a positive b_n_x lobe beneath it — GPEC's outward-normal flux is intrinsically negative there, so the overall sign is the coil↔surface colour convention while the spatial structure and magnitude are physical. Pass helicity to override sign(Bt)·sign(Ip) if the toroidal tracking is wrong for your machine.

Band-limited reconstruction

The field is reconstructed only from the supplied m modes, so it is band-limited to that poloidal range. A source placed within ~one grid cell of the surface makes the field near-singular and the truncated series rings (Gibbs oscillation — e.g. a spurious dip where a single lobe is expected). Keep coils at a realistic standoff from the boundary, or widen the m range, for a clean reconstruction.

Keyword arguments

  • mtheta, nphi: poloidal/toroidal grid resolution
  • psi: flux surface (default equil.rzphi_xs[end], the boundary)
  • helicity: override sign(Bt)·sign(Ip)
source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_bn_contour — Method
plot_bn_contour(pe; coils=false, save_path=nothing)
plot_bn_contour(bn, mtheta, nzeta; n=nothing, save_path=nothing)

Plot the applied normal field b_n on the control surface, toroidal angle φ against poloidal angle θ (0 at the outboard midplane), optionally with the coil conductors projected onto it; or a raw Biot–Savart B·n̂ grid in tesla.

Arguments

  • pe: A PerturbedEquilibriumState with a forcing
  • bn: Normal field [mtheta, nzeta] on the boundary grid

Keyword arguments

  • coils: Draw the coil conductors projected onto the map (default: false)
  • n: Toroidal mode number named in the title (default: nothing)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_coil_geometry_3d — Method
plot_coil_geometry_3d(coil_sets; equil=nothing, save_path=nothing)
plot_coil_geometry_3d(pe; save_path=nothing)

Plot the coil conductors in 3D at equal data aspect, coloured by current, with the plasma boundary as an opaque surface when an equilibrium is given. Use GLMakie to rotate it.

Arguments

  • coil_sets: Vector{CoilSet} from ForcingTerms.load_coil_sets
  • pe: A PerturbedEquilibriumState forced by coils, drawn with its boundary

Keyword arguments

  • equil: A PlasmaEquilibrium whose boundary is drawn (default: nothing)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_coil_geometry_rz — Method
plot_coil_geometry_rz(coil_sets; equil=nothing, psi=nothing, save_path=nothing)
plot_coil_geometry_rz(pe; save_path=nothing)

Plot the coils in the (R, Z) plane, each set labelled beside itself, over the plasma boundary when an equilibrium is given. A single toroidal loop is a point in (R, Z) and is drawn as a marker.

Arguments

  • coil_sets: Vector{CoilSet} from ForcingTerms.load_coil_sets
  • pe: A PerturbedEquilibriumState forced by coils, drawn with its boundary

Keyword arguments

  • equil: A PlasmaEquilibrium whose boundary is drawn (default: nothing)
  • psi: The flux surface drawn as the boundary (default: the outermost grid surface)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_control_surface — Method
plot_control_surface(src, v; weighting=:root_area, n=nothing, label="the given spectrum", arb=false, coils=false,
                     save_path=nothing)

Plot any control-surface spectrum, such as a forcing, a response or an eigenvector, as the bare normal field b_n on the control surface: toroidal angle φ against poloidal angle θ (0 at the outboard midplane).

Arguments

  • src: A PlasmaResponse supplying the control-surface operators and geometry, or a PerturbedEquilibriumState, whose coils can also be drawn
  • v: The spectrum, one entry per control-surface harmonic

Keyword arguments

  • weighting: How v is stored: :root_area (b̃, default), :area (b̄) or :bare (b)
  • n: Toroidal mode number drawn (default: the first)
  • label: The source named in the title, e.g. "the applied forcing"
  • arb: Label the colour scale in arbitrary units, for a normalized vector (default: false, tesla)
  • coils: Draw the coil conductors projected onto the map (default: false)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_mode_spectrum — Method
plot_mode_spectrum(forcing_modes; mlow=nothing, mhigh=nothing, rational_m=Int[], save_path=nothing)
plot_mode_spectrum(pe; save_path=nothing)

Plot the forcing spectrum |Φ_x(m, n)| against poloidal harmonic m as step lines, one per toroidal mode number.

Arguments

  • forcing_modes: Vector{ForcingMode} from compute_coil_forcing_modes!
  • pe: A PerturbedEquilibriumState, drawn across its poloidal range with its resonant harmonics marked

Keyword arguments

  • mlow, mhigh: Poloidal range of the x axis (default: the modes' own range)
  • rational_m: Resonant harmonics to mark (default: none)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_sources — Method
plot_sources(rmp; n=1, color=:current, save_path=nothing)

Plot the coils of an RMPField in 3D at equal data aspect, with no plasma: every coil term of a sum together, each term's currents scaled by its weight. Mode-table and spectrum terms have no geometry and are counted in the title. Use GLMakie to rotate it.

Arguments

  • rmp: An RMPField with at least one coil term

Keyword arguments

  • n: Toroidal mode number that sets the n-modulated tilts (default: 1)
  • color: :current colours each conductor by its current in kA, :set gives each coil set its own colour (default: :current)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.CoilForcing.plot_surface_3d — Method
plot_surface_3d(equil; color_by=nothing, coil_sets=nothing, mtheta=180, nphi=180, psi=nothing, clim=nothing,
                label="", title="Plasma boundary", save_path=nothing)
plot_surface_3d(equil, modes, n; coil_sets=nothing, mtheta=180, nphi=180, psi=nothing, helicity=nothing,
                label="", save_path=nothing)

Plot the 3D plasma boundary at equal data aspect, unlit and coloured by a control-surface field on a diverging map, with coils coloured by current on the same map. Use GLMakie to rotate it. The second form colours the surface by control_surface_scalar.

Keyword arguments

  • color_by: A real [mtheta, nphi] field on the surface (default: nothing, an uncoloured surface)
  • coil_sets: Coils drawn with the surface (default: nothing)
  • mtheta, nphi, psi: Surface grid and flux surface; must match color_by
  • clim: Symmetric colour limit (default: the field's largest magnitude)
  • label: Colour-bar label of the field
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source

PerturbedEquilibrium

GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium — Module
PerturbedEquilibrium

Post-processing and visualization functions for GPEC perturbed equilibrium results. Each plot takes the PerturbedEquilibriumState in memory or the path of a gpec.h5 it was saved to, and throws an ArgumentError naming what to change in the run when the source lacks the data it draws (see Analysis.available_plots).

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_coupling_matrix — Method
plot_coupling_matrix(src; n=nothing, save_path=nothing)

Plot the resonant coupling matrix C, the resonant area-weighted field b̄res at each rational surface per unit applied harmonic b̃m, with its singular value decomposition C = U Σ Vᴴ: |C| against surface and m, the left singular vectors |U| on the same surface axis, the right singular vectors |V| on the same m axis (V₁ is the dominant mode), and the singular values σ. Surfaces outside the decomposition's core window are shaded.

Arguments

  • src: A PlasmaResponse, or a PerturbedEquilibriumState (its response's matrix)

Keyword arguments

  • n: Toroidal mode number drawn (default: the first)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_dominant_mode_surface — Method
plot_dominant_mode_surface(src; mode=1, n=nothing, save_path=nothing)

Plot dominant resonant-coupling mode mode, the right singular vector of the resonant coupling matrix, as the normal field it represents on the control surface: toroidal angle φ against poloidal angle θ, in arbitrary units (the vector has unit norm).

Arguments

  • src: A PlasmaResponse, or a PerturbedEquilibriumState (its response's modes)

Keyword arguments

  • mode: Which dominant mode, 1 the strongest (default: 1)
  • n: Toroidal mode number drawn (default: the first)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_driven_delta_prime — Method
plot_driven_delta_prime(src; save_path=nothing)

Plot the forcing-driven Re Δ′ at each rational surface, the response to the applied forcing; for the equilibrium's own Δ′ of a Riccati or Galerkin solve, see ForceFreeStates.plot_delta_prime.

Arguments

  • src: A PerturbedEquilibriumState, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_effective_islands — Method
plot_effective_islands(pe; phi=0.0, save_path=nothing)

Plot the island chains the effective resonant flux would open, in (θ, ψN) and on the poloidal plane at toroidal angle φ, with each chain's half-width w/2 (in ψN) listed.

Arguments

  • pe: A PerturbedEquilibriumState with the singular coupling

Keyword arguments

  • phi: Toroidal angle in radians (default: 0.0)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_islands — Method
plot_islands(pe; phi=0.0, save_path=nothing)

Plot the island chains of the penetrated field in (θ, ψN) and on the poloidal plane at toroidal angle φ. The half-width scales from the effective one as w² ∝ |b̄|: wpen = weff √(|b̄pen| / |b̄_res|).

Arguments

  • pe: A PerturbedEquilibriumState from a matched run, which carries a penetrated field

Keyword arguments

  • phi: Toroidal angle in radians (default: 0.0)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_mode_spectrogram — Method
plot_mode_spectrogram(src; component=:xi_psi, style=:log_heatmap, save_path=nothing)

Plot a response component's poloidal harmonics against ψ_N, with the rational surfaces and the resonance m = n q(ψ) marked.

Arguments

  • src: A PerturbedEquilibriumState with the reconstructed response, or the path of a gpec.h5 it was saved to

Keyword arguments

  • component: :xi_psi (ξ^ψ, default), :b_psi (the area-weighted b̄^ψ, in T), :Jb_theta or :Jb_zeta (J·b^θ and J·b^ζ, in T m²)
  • style: :log_heatmap (default), :linear_heatmap, or :lines (the eight largest harmonics)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_perturbed_equilibrium_summary — Method
plot_perturbed_equilibrium_summary(src; save_path=nothing)

Plot the panels the source supplies: the resonant field at each rational surface, the edge b̄^ψ spectrum, the ξ^ψ spectrogram and, from a state in memory, b_n on the poloidal plane at φ = 0.

Arguments

  • src: A PerturbedEquilibriumState, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure. Throws an ArgumentError when no panel can be drawn.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_perturbed_field_rz — Method
plot_perturbed_field_rz(pe; component=:b_n, phi=0.0, deform=false, clip=0.9, save_path=nothing)

Plot the perturbed normal field bn or normal displacement ξn on the poloidal plane at toroidal angle φ, drawn on the flux-surface grid with the rational surfaces outlined; with deform, also the boundary displaced along its normal by a scaled ξ_n over the equilibrium outline.

Arguments

  • pe: A PerturbedEquilibriumState with the stored normal field and displacement

Keyword arguments

  • component: :b_n (T, default) or :xi_n (m)
  • phi: Toroidal angle in radians (default: 0.0)
  • deform: Draw the displaced boundary, scaled so its largest displacement is 5 % of the minor radius (default: false)
  • clip: Quantile of |value| that sets the symmetric colour range; larger values saturate. 1 shows the full range (default: 0.9)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_resonant_area_weighted_field — Method
plot_resonant_area_weighted_field(src; save_path=nothing)

Plot the resonant coupling at each rational surface in rows sharing a q = m/n axis: the resonant area-weighted field |b̄res|, the resonant current |Ires|, the island half-width w/2, the effective island-overlap Chirikov parameter and the forcing-driven Re Δ′. Toroidal mode numbers are distinguished by colour; the title counts the surfaces with overlapping islands.

Arguments

  • src: A PerturbedEquilibriumState, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_resonant_area_weighted_field_amplitude — Method
plot_resonant_area_weighted_field_amplitude(src; save_path=nothing)

Plot the resonant area-weighted field |b̄res| = |Φres|/A at each rational surface [Pharr 2026], in tesla, beside the penetrated field |b̄_pen| when the run carries one.

Arguments

  • src: A PerturbedEquilibriumState, or the path of a gpec.h5 it was saved to

Keyword arguments

  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibrium.plot_singular_mode_rz — Method
plot_singular_mode_rz(src; modes=nothing, phi=0.0, save_path=nothing)

Plot dominant resonant-coupling modes on the control-surface cross-section: the boundary in (R, Z) as a band coloured by each mode's normal field bn at toroidal angle φ, normalized to its peak, one panel per mode. The modes are the stored decomposition's, over the rational surfaces with ψN ≤ 0.9.

Arguments

  • src: A PlasmaResponse, or a PerturbedEquilibriumState (its response's modes)

Keyword arguments

  • modes: Which dominant modes, 1 the strongest (default: the first three that exist)
  • phi: Toroidal angle in radians (default: 0.0)
  • save_path: If given, save the figure to this path (default: nothing)

Returns

A Makie Figure.

source

PerturbedEquilibriumModes

GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibriumModes.modes_to_theta — Method
modes_to_theta(h5_file, variable; mtheta=nothing, keep_sfl_phi=true)

Convert modal output (npsi, numpert_total) from a gpec.h5 file to theta-space (npsi, mtheta, npert).

Reads all required metadata (mlow, nlow, mpert, npert) and spline data (ν) from the HDF5 file.

Arguments

  • h5_file::String: Path to gpec.h5 output file
  • variable::String: HDF5 dataset path, e.g. "PerturbedEquilibrium/Response/xi_R"

Keyword arguments

  • mtheta::Int: theta grid resolution (default: max(2*(|mlow|+mpert), 512))
  • keep_sfl_phi::Bool: if true (default), output in SFL toroidal angle; if false, apply exp(i*n*ν(ψ,θ)) to convert to machine toroidal angle and conjugate if helicity > 0 (matches Fortran gpout_xbrzphifun)

Returns

  • theta_data::Array{ComplexF64,3}: [npsi × mtheta × npert]
  • theta_grid::Vector{Float64}: [mtheta] SFL theta ∈ [0, 1)
  • n_vals::Vector{Int}: [npert] toroidal mode numbers
Note

When used on the cylindrical components xi_R, xi_Z, xi_phi, b_R, b_Z, b_phi these are currently in beta and show up to ~20% discrepancies vs Fortran.

source
GeneralizedPerturbedEquilibrium.Analysis.PerturbedEquilibriumModes.theta_to_thetaphi — Method
theta_to_thetaphi(theta_data, n_vals; nphi=nothing)

Extend theta-space data to a (θ, φ) grid via toroidal inverse DFT.

f(θ, φ) = Σₙ fₙ(θ) exp(i·n·φ)

Arguments

  • theta_data::Array{ComplexF64,3}: [npsi × mtheta × npert] from modes_to_theta
  • n_vals::Vector{Int}: toroidal mode numbers

Keyword arguments

  • nphi::Int: toroidal grid points (default: max(4*maximum(abs.(n_vals)), 64))

Returns

  • full_data::Array{ComplexF64,3}: [npsi × mtheta × nphi]
  • phi_grid::Vector{Float64}: [nphi] in radians ∈ [0, 2π)
source

ErrorFields

GeneralizedPerturbedEquilibrium.Analysis.ErrorFields — Module
ErrorFields

Plots for the error-field assessment stored under ErrorFields/ of a GPEC HDF5 output: per-coil sensitivities, the tolerance Monte Carlo distributions, the locking risk and its dependence on tolerance, the threshold scaling, the dominant coupling mode, and coil-array phasing maps. Every plot takes a list of label => h5path pairs so design revisions can be overplotted, with a single-path convenience method for the common case.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.Sources — Type

A label paired with something to plot: a gpec.h5 path, or a result already in memory (ErrorFields.ErrorFieldsResult, SensitivityTable, CoilSensitivities, MonteCarloResult, RiskResult, or a vector of CoilOverlap). Analysing coil geometry that was never part of a run produces the latter, so the plots accept both.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields._load — Method

The overlap distribution lives on the Monte Carlo result and the penetration threshold on the risk result, so a plot that draws both against each other needs the pair. Pass them together as a tuple rather than separately, which would leave each half unable to find the other.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_applied_spectra — Method
plot_applied_spectra(ctx, overlaps; normalize=true, save_path=nothing)
plot_applied_spectra(h5path, coil_sets; normalize=true, save_path=nothing, kwargs...)

Plot each coil set's applied spectrum against the dominant resonant mode. normalize = true scales every curve to its own peak, which says whether a coil drives a different part of the spectrum; false keeps the amplitudes, which says whether it simply drives less.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_coil_sensitivities — Method
plot_coil_sensitivities(sources; quantity=:shift, coils=nothing, yscale=:identity, save_path=nothing)
plot_coil_sensitivities(source; kwargs...)

Plot each coil set's dominant-mode sensitivity as a stem and dot per row, across runs matched by coil set name. quantity is :shift (per millimetre of rigid in-plane shift), :tilt (per degree), :rim (the same tilt as rim displacement, the unit mechanical tolerances arrive in), :as_designed (|δ| as built), or :fraction (the resonant share of the coil's own applied spectrum, 100·|δ|·B_T0/‖b̃‖ in percent). coils restricts and orders the coil sets shown; a name a source does not carry is an error. yscale = :log10 puts the values on a log axis. Coil sets whose value is roundoff (an axisymmetric coil has no n ≠ 0 field) are left out and counted in the title.

Each source is a gpec.h5 path, an ErrorFieldsResult, a SensitivityTable, or a vector of CoilOverlap (:as_designed and :fraction only). :fraction needs the applied field as well as the overlap, so it is not available from a SensitivityTable.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_correction_requirement — Method
plot_correction_requirement(req::EF.CorrectionRequirement; save_path=nothing)
plot_correction_requirement(h5path, source_name, array_names; save_path=nothing, kwargs...)

Plot an ErrorFields.correction_requirement: the resonant field on each rational surface before correction, after each array's dominant-mode correction alone and after the joint least-squares correction, as stems on a log axis; then one polar panel per array with the complex current it needs as a phasor (kilo-ampere-turns, or a factor on the array's current as given when any array's ampere-turns are unknown): the solo dominant-mode factor, the minimum-current member of the set's dominant-mode family, and the joint least-squares factor.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_efc_ntv_limits — Method
plot_efc_ntv_limits(h5path; torque_budget, delta_threshold=nothing, safety_factor=1.0, delta_max=15, profiles=false, save_path=nothing)
plot_efc_ntv_limits(couplings::Vector{EF.EFCCoupling}; delta_threshold, torque_budget, kwargs...)

Plot the correction current against intrinsic overlap for each correction array (ErrorFields/NTV/): the single-mode current and the NTV-limited current whose residual torque lowers the threshold, with the largest correctable overlap marked and the zero-rotation limits as points (residual torque: circle, whole field: star). When the run tabulated the torques against rotation, a second panel shows those tables with the reference rotation; with profiles, a third the torque integrated from the axis at zero rotation shift. Nonzero torque_rtol or budget_rtol shade the band between the pessimistic and optimistic curves. delta_threshold defaults to the run's fitted penetration threshold; torque_budget is the torque, N·m, that would bring the reference rotation to rest.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_error_field_summary — Method
plot_error_field_summary(src; save_path=nothing)

Plot the panels of a run's error-field assessment it supplies: the overlap distribution against the threshold's CDF, titled with the locking probability; the locking risk against tolerance scale, titled with the allowable scale for 1 % risk; and the coil sets' shift sensitivity. src is an ErrorFields.ErrorFieldsResult or the path of a gpec.h5 it was saved to.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_linearity_check — Method
plot_linearity_check(check::EF.LinearityCheck; save_path=nothing)
plot_linearity_check(h5path; scales=(1.0, 2.0), save_path=nothing, kwargs...)

Plot the relative error of the linear sensitivity model at finite displacements, from ErrorFields.linearity_check: one stem per row on a log axis, grouped by coil set or coherent group, shift and tilt told apart by colour and the scale by marker, with the 1 % level marked. A row whose linear change vanishes has no relative error and is not drawn.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_linearity_residuals — Method
plot_linearity_residuals(sources; at=:tolerance, coils=nothing, tolerances=nothing, fd_step_shift_m=nothing, fd_step_tilt_deg=nothing, yscale=:log10, save_path=nothing)
plot_linearity_residuals(source; kwargs...)

Plot how linear each coil set's field is in its rigid motions: for the six taps (shift and tilt about x, y, z) the ratio of the central second difference to the largest first difference among the set's taps, as stored in ErrorFields/CoilSensitivities/*_linearity_residual. at = :step shows it at the finite-difference steps; at = :tolerance rescales each tap by tolerance / step to the coil's own tolerance range. Tolerances come from the file's snapshot or tolerances; steps from the recorded deck or fd_step_shift_m and fd_step_tilt_deg. The 1 % level at which the sensitivity calculation warns is marked. One panel per source, on a log axis unless yscale = :identity.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_locking_risk — Method
plot_locking_risk(sources; corrected=true, target_percent=nothing, save_path=nothing)
plot_locking_risk(source; kwargs...)

Plot the locking probability against tolerance scale from each run's ErrorFields/Risk/ToleranceScan/, intrinsic and (when corrected) with error-field correction, with the batch spread as error bars, on log-log axes when any probability is positive; a scale where no sample locked is then left off. With target_percent the target is marked and the title gives the allowable scale where the scan reaches it.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_needed_current — Method
plot_needed_current(mc, array::EF.CoilOverlap; coupling=nothing, delta_threshold=nothing, torque_budget=nothing, save_path=nothing)

Plot the distribution of the current array needs to cancel each sampled machine's dominant-mode overlap (ErrorFields.needed_current_distribution), in kilo-ampere-turns when the array's ampere-turns are known, with the as-designed value marked; with the array's EFCCoupling, the threshold and the torque budget, also the NTV-limited correctable current and the fraction of samples beyond it (ErrorFields.uncorrectable_probability).

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_overlap_contributions — Method
plot_overlap_contributions(ctx, overlaps; save_path=nothing)
plot_overlap_contributions(h5path, coil_sets; save_path=nothing, kwargs...)

Plot which poloidal harmonics produce each coil set's overlap, conj(V[m])·b̃[m] rotated so the coil's own total is real; each coil's steps sum to its resonant fraction, given in the legend. It separates a coil that drives the resonant harmonics weakly from one that drives them strongly and cancels against itself.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_overlap_phasors — Method
plot_overlap_phasors(sources; coils=nothing, save_path=nothing)
plot_overlap_phasors(source; kwargs...)

Plot each error-field coil set's as-built dominant-mode overlap δ as an arrow in the complex plane, laid head to tail so the walk ends at the run's total, rotated so the total is real: an arrow along it adds to the error field, one against it cancels part of another coil's. One panel per source, since the mode phase is arbitrary between runs. The NTV correction arrays and coil sets with no as-designed n ≠ 0 field are left out; throws when no coil set has one. On a file the walk's end is checked against the stored Monte Carlo delta_as_designed.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_phasing_map — Method
plot_phasing_map(h5path, coil_names; psi_low=0.0, psi_high=CORE_PSI_HIGH, mode=1, nphase=180, quantity=:delta_per_kat, save_path=nothing)
plot_phasing_map(map::EF.PhasingMap; quantity=:delta_per_kat, save_path=nothing)

Plot the dominant-mode overlap per kilo-ampere-turn (:delta_per_kat) or the resonant fraction of the applied field (:resonant_fraction_percent) against the relative toroidal phases of two or three coil arrays (EF.phasing_map): a line for two arrays, a filled contour with the extreme marked for three.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_surface_overlay — Method
plot_surface_overlay(ctx, overlaps; ntheta=256, nzeta=180, top=4, save_path=nothing)
plot_surface_overlay(h5path, coil_sets; save_path=nothing, kwargs...)

Plot the applied normal field on the control surface of the top coil sets with the largest overlap, each scaled to its own peak, with contours of the dominant resonant mode over it: a coil driving a different poloidal region from the one the dominant mode occupies couples poorly however strong it is. Toroidal angle φ against poloidal angle θ, with the outboard midplane at θ = 0.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_threshold_scaling — Method
plot_threshold_scaling(sources; save_path=nothing)
plot_threshold_scaling(source; kwargs...)

Plot each run's overlap distributions against the penetration threshold on a log |δ| axis: the threshold as its cumulative distribution P(lock | δ) on a 0–1 right axis, with the nominal threshold (the fit at the central exponents, the CDF's median) marked. The CDF is rebuilt from the recorded scaling and scenario when the source records them, and otherwise drawn from the stored values on the Monte Carlo bins. A source needs the overlap distribution and the threshold together; pass a (MonteCarloResult, RiskResult) tuple for results in memory.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_tolerance_budget — Method
plot_tolerance_budget(h5path; psi_low=0.0, psi_high=CORE_PSI_HIGH, mode=1, tolerance_scale=1.0, sort=:total, top=nothing, save_path=nothing)
plot_tolerance_budget(table, tolerances, coil_sets; monte_carlo=nothing, kwargs...)
plot_tolerance_budget(terms::NamedTuple; monte_carlo=nothing, sort=:total, top=nothing, save_path=nothing)

Plot the worst-case tolerance budget as stacked horizontal bars, one per coil set, coherent group and the unattributed budget: the as-designed |δ|, the shift term and the tilt term of ErrorFields.worst_case_terms, which sum to the abs_delta_worst_case the Monte Carlo sizes its histogram by. sort orders the bars by :total (largest at the top), :name, or :none; top keeps only that many largest. With a Monte Carlo result the sample mean of |δ| and the as-designed total are marked.

source
GeneralizedPerturbedEquilibrium.Analysis.ErrorFields.plot_tolerance_pdf — Method
plot_tolerance_pdf(sources; corrected=true, normalize=false, xscale=:identity, show_batches=false, save_path=nothing)
plot_tolerance_pdf(source; kwargs...)

Plot the Monte Carlo distributions of the dominant-mode overlap |δ| of each run, intrinsic and (when corrected) with error-field correction, with the as-designed overlap marked unless it is roundoff. show_batches draws each batch's intrinsic histogram faintly under the mean, the sampling noise a risk figure inherits.

source