Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
78020ca
ForceFreeStates.Galerkin - FEATURE! - Prepare Galerkin results for in…
matt-pharr Nov 4, 2026
f2f0bef
ForceFreeStates.Matching - FEATURE! - Publish the matched plasma ener…
matt-pharr Nov 6, 2026
4d82426
Merge branch 'feature/analysis-plots-overhaul' into feature/galerkin-…
matt-pharr Nov 7, 2026
0e941cd
Analysis - FEATURE - Frame matched free-boundary energies and show th…
matt-pharr Nov 10, 2026
ad757dc
Merge branch 'feature/analysis-plots-overhaul' into feature/galerkin-…
matt-pharr Nov 10, 2026
4a935cc
Merge branch refactor/riccati-single-pass into feature/galerkin-plasm…
matt-pharr Nov 16, 2026
b76c6c8
Merge branch refactor/riccati-single-pass into feature/galerkin-plasm…
matt-pharr Nov 16, 2026
9125645
Merge branch refactor/riccati-single-pass into feature/galerkin-plasm…
matt-pharr Nov 17, 2026
b6bfdf9
PerturbedEquilibrium - FEATURE! - Accept Riccati results in plasma_re…
matt-pharr Nov 18, 2026
02e8804
PerturbedEquilibrium - REFACTOR! - Rename the forcing-driven Δ′ to Δ_mn
matt-pharr Nov 18, 2026
adc5e59
PerturbedEquilibrium - FEATURE! - Add the asymptotic Δ_mn metrics bes…
matt-pharr Nov 18, 2026
a997da7
Merge branch refactor/riccati-single-pass into feature/galerkin-plasm…
matt-pharr Nov 18, 2026
6a6da27
Merge branch refactor/riccati-single-pass into feature/galerkin-plasm…
matt-pharr Nov 19, 2026
bbd1215
PerturbedEquilibrium - FEATURE! - Accept matched results with only th…
matt-pharr Nov 23, 2026
139b4bc
Merge branch refactor/riccati-single-pass into feature/galerkin-plasm…
matt-pharr Nov 23, 2026
19662a4
Repo - BUGFIX - Pass error_field_response, not the removed rpec_flag,…
matt-pharr Nov 23, 2026
7f6cc84
Examples - FEATURE - Drive the Riccati and matched Galerkin DIII-D ex…
matt-pharr Nov 25, 2026
0c02af7
Analysis - FEATURE - Let the coupling plots choose their matrix and c…
matt-pharr Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ The complete GPEC analysis pipeline:
### Stability
- `SingType` - Singular surface data including:
- Rational surface location (ψ, ρ, q = m/n, dq/dψ)
- Δ' (tearing stability parameter) — **stub**; the valid Δ' is `ForceFreeStatesResult.delta_prime.matrix`
- Δ' (tearing stability parameter) — **stub**; the valid Δ' is `ForceFreeStatesResult.delta_prime` (`DeltaPrimeData`)
- Asymptotic solution bases at the inner-layer boundaries
- `ForceFreeStatesResult` - Published product of a solve: mode space, metric/matrix fits, singular
surfaces, and the per-integrator products (ξ solution and its basis, free-boundary energies,
Expand Down
4 changes: 2 additions & 2 deletions docs/development/hdf5-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Conventions for the structure and naming of the `gpec.h5` output file. Every wri

**The schema must be intuitive to a plasma physicist who is not a developer of this code.** The top level largely mirrors the TOML sections / major `src/` modules — which are themselves organized along physics lines — but **physics intuition wins whenever the two diverge**. Worked examples of that rule:

- All per-rational-surface stability results consolidate under `SingularSurfaces/`, regardless of which algorithm produced them: the GGJ coefficients sit beside the Δ′/PEST-3 matching results, and the Riccati BVP and the Galerkin outer-region solve write the *same* `Delta_prime_matrix`/`Delta_prime_raw`/`Delta_coil`/`pest3_*` paths rather than each owning a producer-named subgroup.
- All per-rational-surface stability results consolidate under `SingularSurfaces/`, regardless of which algorithm produced them: the GGJ coefficients sit beside the Δ′/PEST-3 matching results, and the Riccati BVP and the Galerkin outer-region solve write the *same* `Delta_prime_*`/`Delta_EF`/`pest3_*` paths rather than each owning a producer-named subgroup.
- `EulerLagrangeMatrices` over a bare `Matrices` — group names must say what the data *is*, not which array it came from. Same reasoning renamed `matrices_<method>/` → `KineticMatrices/`.

Physics-topic groups elevated to top level (rather than nested under their producer): `Info/`, `Input/`, `SingularSurfaces/`, `LocalStability/`, `SurfaceGeometries/`.
Expand Down Expand Up @@ -42,7 +42,7 @@ Top level (11 groups):
| `Equilibrium/` | Scalars (`beta_N`, `q_axis`, `q_95`, `I_p`, …) plus `Profiles/` (1-D on `psi`: 2piF, mu0p, dVdpsi, q) and `Geometry/` (2-D on `psi`×`theta`: rcoords, offset, nu, jac) |
| `ForceFreeStates/` | `Solutions/ForwardIntegration/` (u-solutions), `Solutions/GalerkinIntegration/` (the gal surface list, `gal_basis_output`-gated `Basis/`), `Solutions/Match/` (closed ξ profiles of a `[Match]` in the shared layout, on the grid of the Galerkin or Riccati outer solutions), `write_el_matrices`-gated `EulerLagrangeMatrices/{Ideal,Kinetic}`, `FreeBoundaryStability/`, `EdgeScan/` |
| `LocalStability/` | Mercier `D_I`, resistive interchange `D_R`, `ballooning_Delta_prime` on `psi`; the ballooning α boundary on `ballooning_psi` |
| `SingularSurfaces/` | Per-rational-surface data: `rational_psi`/`rational_q`/`rational_m`/`rational_n`, GGJ coefficients, `Delta_prime_matrix`/`Delta_prime_raw`/`Delta_coil`/`pest3_A`/`pest3_B`/`pest3_Gamma` (Riccati or Galerkin alike), the inner-layer `Match/` results, `Kinetic/` |
| `SingularSurfaces/` | Per-rational-surface data: `rational_psi`/`rational_q`/`rational_m`/`rational_n`, GGJ coefficients, `Delta_prime_raw_freeboundary`/`Delta_prime_raw_fixedboundary`/`Delta_EF`/`edge_response`, the free-boundary `Delta_prime_matrix`/`pest3_A`/`pest3_B`/`pest3_Gamma` and their `_fixedboundary` counterparts (Riccati or Galerkin alike), the inner-layer `Match/` results, `Kinetic/` |
| `PerturbedEquilibrium/` | `ForcingModes/`, `Response/`, `ResponseMatrices/`, `SingularCoupling/`, `Energies/`, `TorqueResponse/` (kinetic forward solves: ψ-resolved `T_xe`, `T_source`), control-surface spectra |
| `KineticForces/` | `<method>/` (torque/energy profiles, `dTdpsi_ell` resolved by bounce harmonic on the `ell` scale, `KineticMatrices/`); multi-ion runs add `PerSpecies/<species>/<method>/` with the same per-method layout, summing to the top-level total |
| `ErrorFields/` | `CoilSensitivities/` (per-coil-set control-surface spectra and their rigid shift/tilt derivatives, `DominantMode/` full-window projection); `MonteCarlo/` (intrinsic and corrected `\|δ\|` histograms over the sampled tolerances, per batch and averaged); `Risk/` (threshold density, `P(lock\|δ)`, locking probabilities, `ToleranceScan/`); `NTV/` (correction-coil overlap and NTV torque couplings per kAt) |
Expand Down
12 changes: 6 additions & 6 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,26 @@ The weights are linear-combination coefficients, not physical amplitudes: a coil
The second argument of `solve` picks the formalism and its fields are that formalism's numerical settings; physical inputs belong on `ForceBalanceProblem`:

```julia
ffs = solve(eq, Forward(; eulerlagrange_tolerance=1e-8); nn=1, vac_flag=true) # dense ξ profiles: the only input plasma_response accepts; kinetic solves
ffs = solve(eq, Riccati(; nchunks=40); nn=1, vac_flag=true) # chunked propagators, Δ′ matrix (default)
ffs = solve(eq, Forward(; eulerlagrange_tolerance=1e-8); nn=1, vac_flag=true) # dense ξ profiles; kinetic solves
ffs = solve(eq, Riccati(; nchunks=40); nn=1, vac_flag=true) # chunked propagators, Δ′ matrix, ξ profiles (default)
ffs = solve(eq, Galerkin(; nx=512); nn=1) # finite-element outer-region Δ′
```

A result carries `nothing` in the fields its integrator does not produce, and consumers warn and skip rather than erroring; `plasma_response` in particular needs a `Forward()` solve with `wall=nothing` (it errors on a wall or a Galerkin result and skips with a warning on a Riccati one), see [Stability](stability.md).
A result carries `nothing` in the fields its integrator does not produce, and consumers warn and skip rather than erroring; `plasma_response` in particular needs a `Riccati()` or `Forward()` solve, or a `Galerkin(; error_field_response=true)` solve, with `vac_flag=true` and `wall=nothing` (it errors on a wall, any other Galerkin result or a matched one), see [Stability](stability.md).
A kinetic solve takes `Forward()` with the problem's `kinetic` keyword: `kinetic=KineticForcesControl(; ...)` evaluates the drift-kinetic matrices on the equilibrium's kinetic profiles, `kinetic=TestKineticMatrices(; scale)` uses synthetic matrices, `kinetic_factor` scales either, and `km = kinetic_matrices(prob)` evaluates the source once for reuse in later solves ([`KineticMatrices`](@ref GeneralizedPerturbedEquilibrium.ForceFreeStates.KineticMatrices)).

## Inner-layer matching

A `MatchProblem` holds the outer Δ′ a solve published plus per-surface layer parameters, and the inner-layer model passed to `solve` computes the layer response at the prescribed rotation; the result is a new `ForceFreeStatesResult` with the closure changed from `:ideal` to `:matched` and the eigenfunctions replaced, so layer-parameter scans cost one cheap match per point:

```julia
ffs = solve(eq, Galerkin(; rpec_flag=true, cut_solution=true); nn=1)
ffs = solve(eq, Galerkin(; error_field_response=true, cut_solution=true); nn=1)
matched = solve(MatchProblem(ffs; eta=1e-6, rho=1e-7, rotation=0.0), GGJModel())
bpens = [solve(MatchProblem(ffs; eta=1e-6, rho=1e-7, rotation=f), GGJModel()).bpen for f in 0.0:50.0:500.0]
penetrated_fields = [solve(MatchProblem(ffs; eta=1e-6, rho=1e-7, rotation=f), GGJModel()).penetrated_area_weighted_field for f in 0.0:50.0:500.0]
```

A scalar applies to every surface and a vector gives one value per entry of `ffs.surfaces`, core to edge.
The problem needs a Δ′ payload with coil-response columns, so it accepts Galerkin (`rpec_flag=true`) and Riccati (`vac_flag=true`) results. Both publish the outer solutions the match combines in `ffs.basis`; the composite inner-region profiles need Galerkin's `cut_solution=true`, and a Riccati basis always carries its cut solution.
The problem needs a Δ′ payload with error-field (EF) columns, so it accepts Galerkin and Riccati results with `error_field_response=true` (the default; Riccati also needs `vac_flag=true`). Both publish the outer solutions the match combines in `ffs.basis`, so either gives the matched `solution` and `wp`; the composite inner-region profiles need Galerkin's `cut_solution=true`, and a Riccati basis always carries its cut solution.
`GGJModel()` is the closure-capable model; `SLAYERModel()` is slab-only and drives the tearing solve instead.

## Tearing stability
Expand Down
20 changes: 10 additions & 10 deletions docs/src/galerkin.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ integrator = "Galerkin"
[Galerkin]
nx = 256 # Hermite-cubic elements per interval between singular surfaces
pfac = 0.03 # grid packing ratio toward the singular surfaces
rpec_flag = true # edge coil-response columns (Delta_coil), needed by [Match] and [Tearing]
error_field_response = true # error-field (EF) columns (Delta_EF): the ideal ξ solution and W_plasma, needed by [Match]
```

`cut_solution = true` (default `false`) adds the cut solution that composite inner-region profiles need.

It replaces the radial integration rather than supplementing it: the run computes its own vacuum response at the control surface (with `vac_flag`) but produces no free-boundary energies, no ODE trace and no `crit` scan, it does not support the kinetic solve, and its result cannot drive `[PerturbedEquilibrium]`, which needs the free-boundary δW of a `"Forward"` solve.
A `[Match]` section matches the inner layer to its Δ′ and gives a driven ``\xi`` solution; the composite inner-region profiles need `cut_solution = true` (`Galerkin(; cut_solution=true)` followed by `solve(MatchProblem(ffs))` in a script).
It replaces the radial integration rather than supplementing it: the run computes its own vacuum response at the control surface (with `vac_flag`), produces no ODE trace and no `crit` scan, and does not support the kinetic solve. With `error_field_response = true` and `vac_flag = true` it also produces the free-boundary energies of its ideal solution, so it can drive `[PerturbedEquilibrium]` like a `"Forward"` solve; a `[Match]`ed result cannot yet.
With `error_field_response = true` the error-field (EF) columns, one per edge mode with unit edge displacement and no inner-layer drive, are solved with the edge held fixed; their small-solution coefficients are `Delta_EF`, they are the ideal (perfectly shielded) ``\xi`` solution, and the force they exert on the edge is the fixed-boundary plasma energy matrix ``W_P`` of Eq. 66 of [Glasser (2016)](citations.md#ForceFreeStates).
A `[Match]` section matches the inner layer to its Δ′ and replaces them with the driven ``\xi`` solution, whose edge response ``W_P`` is complex: its anti-Hermitian part is the torque absorbed in the layers. The composite inner-region profiles need `cut_solution = true` (`Galerkin(; cut_solution=true)` followed by `solve(MatchProblem(ffs))` in a script).

## Outputs

| Dataset | Meaning |
|---|---|
| `SingularSurfaces/Delta_prime_matrix` | the Δ′ matrix in the PEST-3 convention, on the same path as the Riccati result, so downstream stages never branch on which formalism ran |
| `SingularSurfaces/Delta_prime_raw`, `Delta_coil` | the side-major matching matrix and the coil-response columns (`rpec_flag = true`) |
| `SingularSurfaces/pest3_A`, `pest3_B`, `pest3_Gamma` | the PEST-3 interchange and mixed blocks ``A'``, ``B'``, ``\Gamma'`` |
| `ForceFreeStates/Solutions/GalerkinIntegration/` | the surface list, the factorization used (`solver`) and, with `basis_output = true`, the `Basis/` group |
| `ForceFreeStates/Solutions/Match/` | with a `[Match]` section, the closed ``\xi`` profiles on the Galerkin grid |

Nothing is written under `ForceFreeStates/FreeBoundaryStability/`.
| `SingularSurfaces/Delta_prime_matrix` | the Δ′ matrix in the PEST-3 convention, on the same path as the Riccati result, so downstream stages never branch on which formalism ran; free-boundary with `vac_flag = true` (with `error_field_response = true` a second factorization re-solves the big-solution columns with the vacuum edge, so the EF columns never enter it; `free_boundary_delta_prime = false` skips it for matching-only scans, leaving no tearing Δ′) and fixed-boundary otherwise |
| `SingularSurfaces/Delta_prime_raw_freeboundary`, `Delta_prime_raw_fixedboundary`, `Delta_EF`, `edge_response` | the side-major matching matrices with the vacuum and the fixed edge, the error-field (EF) response (`error_field_response = true`), and the edge momentum of each fixed-edge big-solution column |
| `SingularSurfaces/pest3_A`, `pest3_B`, `pest3_Gamma` (and `_fixedboundary`) | the PEST-3 interchange and mixed blocks ``A'``, ``B'``, ``\Gamma'`` |
| `ForceFreeStates/Solutions/GalerkinIntegration/` | the ideal closed ``\xi`` profiles on the Galerkin grid (`error_field_response = true`), the surface list, the factorization used (`solver`) and, with `basis_output = true`, the `Basis/` group |
| `ForceFreeStates/Solutions/Match/` | with a `[Match]` section, the matched ``\xi`` profiles on the Galerkin grid, in place of the ideal ones |
| `ForceFreeStates/FreeBoundaryStability/` | `W_plasma`, the plasma energy matrix ``W_P`` of the closed solution (`error_field_response = true`), and with `vac_flag = true` the vacuum and free-boundary energies and eigenmodes as for a `"Forward"` solve |

## Numerical notes

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The [Workflow](workflow.md) page maps every stage to its physics, deck sections
| `ForceFreeStates` — ideal (or drift-kinetic) MHD stability by the Newcomb criterion, with the `Vacuum` response of the `[Wall]` (a wall case is a separate deck from a response case) | `[ForceFreeStates]` | `ForceFreeStates/FreeBoundaryStability/`, `SingularSurfaces/Delta_prime_matrix` |
| `LocalStability` — Mercier, resistive-interchange and ballooning criteria | `[LocalStability]` | `LocalStability/` |
| `Match` — the resistive inner layer matched to the outer-region Δ′ | `[Match]` | `SingularSurfaces/Match/` |
| `PerturbedEquilibrium` — the plasma response to the field of `[ForcingTerms]`: resonant fields, islands, overlap; needs a `"Forward"` solve without a wall | `[PerturbedEquilibrium]` | `PerturbedEquilibrium/SingularCoupling/` |
| `PerturbedEquilibrium` — the plasma response to the field of `[ForcingTerms]`: resonant fields, islands, overlap; needs a `"Riccati"` or `"Forward"` (or `error_field_response` `"Galerkin"`) solve with `vac_flag = true` and without a wall | `[PerturbedEquilibrium]` | `PerturbedEquilibrium/SingularCoupling/` |
| `KineticForces` — the neoclassical toroidal viscosity torque of that response | `[KineticForces]` | `KineticForces/` |
| `ErrorFields` — coil tolerances, locking risk and correction limits | `[ErrorFields]` | `ErrorFields/Risk/` |
| `Tearing` — tearing growth rates and critical resonant fields from an inner-layer model | `[Tearing]` | `Tearing/Roots/` |
Expand Down
2 changes: 1 addition & 1 deletion docs/src/inner_layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Penetration is the first resolved saddle-node bifurcation on the path from ``Q_0

## Running it

From `examples/DIIID-like_SLAYER_example/gpec.toml`, after a `[ForceFreeStates]` solve with `integrator = "Riccati"` and `vac_flag = true` (or `"Galerkin"` with `rpec_flag = true`), which provides the Δ′ matrix, and with a kinetic file on the equilibrium:
From `examples/DIIID-like_SLAYER_example/gpec.toml`, after a `[ForceFreeStates]` solve with `integrator = "Riccati"` or `"Galerkin"` and `vac_flag = true`, which provides the Δ′ matrix, and with a kinetic file on the equilibrium:

```toml
[Tearing]
Expand Down
13 changes: 8 additions & 5 deletions docs/src/perturbed_equilibrium.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ The run writes up to five coupling matrices under `PerturbedEquilibrium/Singular
| `C_resonant_current` | the pitch-resonant current | A/T |
| `C_island_width_sq` | the squared island half-width | 1/T |
| `C_penetrated_area_weighted_field` | the penetrated field, when the run computes it | dimensionless |
| `C_Delta_prime` | the forcing-driven Δ′ | 1/T |
| `C_Delta_mn` | the forcing-driven ``\Delta_{mn}`` | 1/T |

All but the penetrated field are built from the jump of ``\partial b^\psi/\partial\psi`` across ``|m - nq| = 5\times10^{-4}``. That jump depends on the width it is taken across wherever the Mercier index ``D_I \ne -1/4``, so a single-n run on a `"Riccati"` or `error_field_response` `"Galerkin"` solve also writes each of them with the suffix `_asymptotic`, built from the jump of the asymptotic small solution, which no width enters; the applied quantities carry the same suffix, and `ResonantCoupling(src; matrix=:resonant_area_weighted_field_asymptotic)` wraps that resonant-field matrix.

`ResonantCoupling` wraps the first; any of the others decomposes over any window of surfaces through the bare-matrix form of `dominant_coupling`, with the ``\tilde b`` conform taken from a `ResonantCoupling` of the same file, since the bare matrix carries no (m, n) labels for `check_mode_basis` to guard the projection:

Expand Down Expand Up @@ -91,15 +93,15 @@ The coupling matrices `C_*` map the applied ``\tilde b`` to each of these quanti

## Running it

The response needs a force-free-states solve with `integrator = "Forward"` and no `[Wall]`.
`"Forward"` is the only integrator that retains the dense ``\xi`` solution the operators are built from: a `"Riccati"` solve (the deck default) makes `plasma_response` warn that the response is skipped and return empty operators, so the failure surfaces only when a field is applied, and a `"Galerkin"` or `[Match]`ed solve, which publishes no free-boundary δW, is an error.
The response needs a force-free-states solve with `vac_flag = true` and no `[Wall]`.
The operators are built from a dense ``\xi`` solution with its free-boundary δW, which a `"Riccati"` solve (the deck default), a `"Forward"` solve and a `"Galerkin"` solve with `error_field_response = true` all provide when `vac_flag = true`: a `"Galerkin"` solve without those flags or a `[Match]`ed solve, whose singular coupling is not defined yet, is an error. The ψ-resolved torque response (`compute_torque_response`) needs a `"Forward"` kinetic solve.
A solve with a wall is an error too, because the surface inductance is the free-space one and ``\Lambda`` from a wall run would mix two vacuum models; the wall case of a stability study is therefore a separate deck.

From `examples/DIIID-like_ideal_example/gpec.toml`, after the `[ForceFreeStates]` solve and a `[ForcingTerms]` drive:

```toml
[ForceFreeStates]
integrator = "Forward" # the dense ξ solution the response needs ("Riccati" is the default); no [Wall]
integrator = "Forward" # the dense ξ solution the response needs ("Riccati", the default, supplies one too); no [Wall]

[PerturbedEquilibrium]
compute_singular_coupling = true # resonant fields, islands and Chirikov parameter
Expand Down Expand Up @@ -141,8 +143,9 @@ with the `RMPField` built from coils or a file as on the [Scripting API](api.md)
| `PerturbedEquilibrium/SingularCoupling/resonant_current` | the pitch-resonant current | A |
| `PerturbedEquilibrium/SingularCoupling/island_width_sq`, `island_half_width` | ``w_s^2`` and ``w_s`` in ψ_N | |
| `PerturbedEquilibrium/SingularCoupling/chirikov_parameter` | ``\sigma_s`` | |
| `PerturbedEquilibrium/SingularCoupling/Delta_prime` | the forcing-driven tearing Δ′ per surface | |
| `PerturbedEquilibrium/SingularCoupling/Delta_mn` | the forcing-driven ``\Delta_{mn}`` per surface | |
| `PerturbedEquilibrium/SingularCoupling/C_*` | the coupling matrices from the applied ``\tilde b`` to each quantity above | |
| `PerturbedEquilibrium/SingularCoupling/*_asymptotic` | the resonant field, current, island widths, Chirikov parameter, ``\Delta_{mn}`` and their `C_*` matrices from the jump of the asymptotic small solution | as above |
| `PerturbedEquilibrium/SingularCoupling/DominantMode/singular_values`, `right_singular_vectors`, `left_singular_vectors`, `rational_index`, `forcing_overlap` | the core-window SVD of the resonant-field coupling | |
| `PerturbedEquilibrium/Energies/plasma_energy`, `vacuum_energy`, `surface_energy` | the perturbed energies | J |
| `PerturbedEquilibrium/Energies/toroidal_torque` | the boundary-response torque ``T_\phi`` | N·m |
Expand Down
Loading
Loading