Galerkin Solver

The Galerkin solver is the third [ForceFreeStates] integrator: the singular Galerkin method of the Fortran RDCON for the outer-region Δ′ of resistive stability (Glasser, Wang and Park (2016)).

What it computes

Instead of integrating the Euler–Lagrange system radially, it discretizes the displacement on a packed radial grid of Hermite-cubic finite elements and solves one global banded system. The cells adjacent to each rational surface carry the large and small power-law asymptotic solutions analytically, so the singular behavior is built into the basis rather than resolved numerically, and the solve yields the Δ′ matrix and the PEST-3 matching blocks of every surface at once.

Governing equations

The ideal coefficient is reconstructed as $F = (QL)(QL)^\dagger$ from the interpolated Cholesky factor $L$ with the resonance factor $Q = \operatorname{diag}(m - nq)$, the same representation the Euler–Lagrange integration and the singular-surface expansions use, so $F$ stays Hermitian positive semidefinite between spline knots. The weak form of the same system as on the Stability page is assembled on the Hermite basis, with the resonant and extension cells next to each rational surface carrying the asymptotic solutions $|\psi - \psi_s|^{-1/2 \pm \sqrt{-D_I}}$.

Running it

Select it in [ForceFreeStates] and set its options in [Galerkin], as in examples/DIIID-like_gal_resistive_example (abridged):

[ForceFreeStates]
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]

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).

Outputs

DatasetMeaning
SingularSurfaces/Delta_prime_matrixthe Δ′ 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_coilthe side-major matching matrix and the coil-response columns (rpec_flag = true)
SingularSurfaces/pest3_A, pest3_B, pest3_Gammathe 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/.

Numerical notes

  • The radial grid is packed toward the rational surfaces and the edge, and the banded system is factorized by a Hermitian Cholesky decomposition, falling back to a Jacobi-scaled LU when the band is not Hermitian positive definite; the factorization used is recorded as solver.
  • The singular cells make the solution insensitive to the resolution at the rational surfaces, so convergence is set by the smooth part of the grid (nx).

API reference

GeneralizedPerturbedEquilibrium.ForceFreeStates.GalCell — Type
GalCell

One grid cell of the Galerkin discretization. Port of Fortran cell_type (gal.f).

Fields

  • etype::GalCellType — none / resonant / extension(1,2)
  • extra::GalSide — none / left / right (side of the neighbouring singular surface)
  • emap::Int — global index of the extra (small resonant) DOF; 0 if none
  • map::Matrix{Int} — (mpert, np+1) local→global DOF map (Fortran cell%map(mpert, 0:np))
  • x::NTuple{2,Float64} — [x_left, x_right] of the cell
  • x_lsode::Float64 — resonant-integration truncation point (res cells only)
  • erhs::ComplexF64, ediag::ComplexF64 — resonant RHS and diagonal contributions
  • rhs::Matrix{ComplexF64} — (mpert, np+1) cell RHS (driving term from the big solution)
  • emat::Matrix{ComplexF64} — (mpert, np+1) coupling of the extra DOF to the Hermite DOFs
  • mat::Array{ComplexF64,4} — (mpert, mpert, np+1, np+1) cell stiffness block
source
GeneralizedPerturbedEquilibrium.ForceFreeStates.GalSingAsymp — Type
GalSingAsymp

Two-sided singular asymptotics for the Galerkin solver: separate right (sig=+1) and left (sig=−1) power series, mirroring Fortran sing.f vmatr/vmatl. Each is evaluated at a positive distance |ψ−ψ_s| (real √, real pfac, no z<0 renormalization), so the directly-extracted Δ′ matches gal.f.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.GalWorkspace — Type
GalWorkspace

Global workspace for the Galerkin solve. Port of Fortran gal_type (gal.f).

intvl has length msing+1 (Fortran intvl(0:msing), accessed as intvl[ising+1]). kl = ku = mpert*(np+1). mat is stored full band, ldab = 2*kl + ku + 1 (LAPACK gbtrf! layout); solver records the factorization gal_banded_solve! used ("cholesky" or "LU").

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.GalerkinResult — Type
GalerkinResult

Solver internals and FEM diagnostics of the outer-region Galerkin solve. The Δ′ payload is not here; galerkin_solve returns it separately as a DeltaPrimeData (ForceFreeStatesResult.delta_prime).

Fields

  • msing::Int — number of resonant surfaces solved; may be fewer than result.surfaces, since only surfaces inside the domain and the resolved m-band are kept (gal_resonant_surfaces).
  • sing_psi, sing_q::Vector{Float64}, sing_m, sing_n::Vector{Int} — per-surface identifiers, core→edge, in the order the Δ′ matrices are indexed.
  • di::Vector{Float64}, alpha::Vector{ComplexF64} — Mercier index and exponent per surface.
  • solver::String — factorization actually used: "cholesky", "LU", or "none" when no resonant surfaces were present.
source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_make_grid! — Method
gal_make_grid!(intvl::GalInterval, ising::Int, msing::Int, sings::Vector{SingType},
               nn::Int, psilow::Float64, psihigh::Float64, ctrl::ForceFreeStatesControl)

Set the cell types (res/ext/ext1/ext2/none), sides, resonant integration limits, and packed node positions for interval ising (0-based, 0:msing). Port of Fortran gal_make_grid (gal.f), dx1dx2_flag=true path. intvl.x/intvl.dx have length nx+1, intvl.cells length nx (preallocated by the caller). sings is the filtered list of resonant surfaces (1-based, sings[ising] = Fortran sing(ising)).

Note (faithful to Fortran): the lower-surface width scale uses |nn·q1| (gal.f) but the upper-surface scale uses |q1| without nn (gal.f). Identical for nn = 1.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_make_map! — Method
gal_make_map!(ws::GalWorkspace, mpert::Int)

Build the local→global DOF numbering with the 2*mpert C¹ overlap between adjacent Hermite cells and the interleaved extra (small resonant) DOFs (emap). Port of Fortran gal_make_map (gal.f). Sets ws.ndim. The skip/emap bookkeeping reserves a global slot for each resonant coefficient and shares it between the res cell and its neighbouring ext cell.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_resonant_surfaces — Method
gal_resonant_surfaces(intr, equil) -> (sings, psilow, psihigh)

Resonant surfaces inside the integration domain, in increasing ψ (Fortran sing(1:msing)), with the domain bounds. psilow is raised above the axis by sing_min! when q < qlow somewhere on the grid (excludes that region); it falls back to the equilibrium axis bound if sing_min! was not run (intr.psilow still 0).

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_extension! — Method
gal_extension!(cell, ising, mats, profiles, intr, asymps, sings, nn, nodes, weights)

Build cell.emat, cell.ediag, cell.rhs, cell.erhs for an extension cell (ext/ext1/ext2). Port of gal_extension (gal.f). The big solution (column 1 of the gal asymptotic) drives the RHS; for ext cells the small solution (column 2) also forms the resonant coupling emat/ediag.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_gauss_quad! — Method
gal_gauss_quad!(cell, mats, profiles, intr, nodes, weights, swap_edge)

Accumulate the nonresonant Hermite stiffness block cell.mat by Gauss-Lobatto quadrature. Port of gal_gauss_quad (gal.f). When swap_edge (the final cell of the last interval), the right-node value/slope DOFs (Fortran pb(2)↔pb(3)) are swapped so the edge-value DOF lands at index 3, matching the free-boundary BC (gal.f).

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_get_fkg — Method
gal_get_fkg(mats, intr, x, q; Fbuf=nothing, Kbuf=nothing, Gbuf=nothing) -> (F, K, G)

Evaluate the ideal-MHD Euler–Lagrange coefficients of the outer-region weak form (Glasser 2016, PoP 23, 112506), F = Q F̄ Qᴴ, K = Q K̄, G = Ḡ, at flux x with safety factor q, where Q = diag(m - n q). F̄ is rebuilt from its Cholesky factor mats.ideal.F_spline_lower, matching the Euler–Lagrange kernel. Optional *buf matrices are filled and returned instead of allocating. Port of gal_get_fkg (gal.f).

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_resonant! — Method
gal_resonant!(cell, ising, mats, profiles, intr, asymps, sings, nn, gal_tol, gal_gnstep, verbose)

Compute the resonant-cell contributions cell.erhs, cell.ediag, cell.rhs, cell.emat by adaptive quadrature (QuadGK) of the residual-operator integrand. Port of gal_lsode_int/gal_lsode_der (gal.f): the Fortran LSODE accumulation is replaced by quadgk over [x_bdy, x_lsode].

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_set_boundary! — Method
gal_set_boundary!(ws, mpert, wv_edge)

Apply the axis (u(0)=0 identity) and edge boundary conditions to the boundary cells' mat, plus the rpec coil-source RHS injection, before global assembly. Port of gal_set_boundary (gal.f). The edge branch is one of:

  • rpec (ncoil = ws.nsol - 2*msing > 0): identity edge and a unit source at the edge value DOF of coil column 2*msing+ipert for each poloidal mode ipert. gal_assemble_rhs! only fills columns 1:2*msing, so the injection is not clobbered.
  • free boundary (wv_edge !== nothing): add the vacuum block wvac·psio² at the edge value DOF.
  • fixed boundary (else): identity edge.
source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_get_solution — Method
gal_get_solution(ws, asymps, sings, intr, x, iintvl, icell, isol; want_d=true, cut_delta=nothing)
    -> (sol, dsol, iintvl, icell)

Reconstruct the displacement sol (length mpert) — and, when want_d, its analytic radial derivative dsol = d(sol)/dψ — at flux x for solution column isol, from the solved Galerkin coefficients ws.sol. Port of gal_get_solution (gal.f). iintvl/icell are a monotone cell cursor advanced and returned for the next call. dsol is nothing if !want_d.

Passing cut_delta (the (nsol, 2·msing) small-solution coefficient matrix, i.e. GalerkinResult.delta) selects the cut solution: the leading-order resonant content is subtracted from the reconstruction, leaving the smooth background that the resistive inner-layer solution is added to when forming the composite solution at a rational surface. want_d is forced off in that case.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_output_solution — Method
gal_output_solution(ws, asymps, sings, intr, profiles, psihigh; delta=nothing) -> OuterSolutionBasis

Build the gal-native packed radial grid (inner→edge; GAL_INTERP_NP_RES points per resonant/extension cell, GAL_INTERP_NP elsewhere, plus the edge point ψ=psihigh) and evaluate ξ AND the analytic ξ′ over it for every solution column. Port of gal_output_solution (gal.f), returning ξ rather than b^ψ.

When delta (the (nsol, 2·msing) small-solution coefficient matrix) is supplied, the cut solution xi_cut is evaluated on the same grid, as the background of MatchProblem's composite inner solution.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_banded_solve! — Method
gal_banded_solve!(mat, sol, kl, ku, solver) -> String

Solve the full-band system mat (LAPACK gbtrf storage) in place of sol and return the solver used. "auto" tries gal_cholesky_solve! and reports a fallback to gal_scaled_lu_solve! for unequal bandwidths, asymmetric off-diagonal entries, or a non-positive-definite real-diagonal system. "cholesky" errors instead of falling back.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_cholesky_solve! — Method
gal_cholesky_solve!(mat, sol, kl, ku) -> Bool

Banded Cholesky solve of the full-band system mat, leaving mat untouched. Rows that are identity rows (Dirichlet DOFs: axis, fixed or coil edge) have their columns moved to the right-hand side. The free block's off-diagonal entries must agree with their conjugate partners within 1e-10 * sqrt(abs(A_ii)) * sqrt(abs(A_jj)). Cholesky uses the lower band and deliberately projects the diagonal onto its real part. Returns false, with sol unchanged, for unequal bandwidths, nonfinite entries, off-diagonal asymmetry, or a non-positive-definite projected matrix.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_make_arrays! — Method
gal_make_arrays!(ws, ctrl, equil, mats, intr, asymps, sings, nn, wv_edge)

Assemble the global banded matrix and RHS. For each cell: Gauss-Lobatto Hermite stiffness (gal_gauss_quad!), then the resonant (gal_resonant!) or extension (gal_extension!) contributions; then the boundary conditions and the scatter into ws.mat/ws.rhs. Port of gal_make_arrays.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.gal_scaled_lu_solve! — Method
gal_scaled_lu_solve!(mat, sol, kl, ku) -> sol

Banded LU solve in place: mat (LAPACK gbtrf! band storage, ldab = 2kl + ku + 1) is overwritten by its factor and sol (the right-hand sides on entry) by the solution. The system is first symmetrically Jacobi-scaled, D·A·D with d_j = |A_jj|^(-1/2) (1 for a zero diagonal): the assembled diagonal spans ~25 decades, and unscaled banded LU loses the small resonant coefficients that carry Δ′.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.galerkin_solve — Method
galerkin_solve(ctrl::ForceFreeStatesControl, equil, mats::MatrixSplines,
               intr::ForceFreeStatesInternal; wv=nothing, cut_solution=false)
    -> (GalerkinResult, Union{Nothing,DeltaPrimeData}, Union{Nothing,OuterSolutionBasis})

Compute the outer-region Δ′ matching matrix by the singular Galerkin method. Port of gal_solve (gal.f). Single toroidal mode only (intr.npert == 1). Returns the solver internals as a GalerkinResult, the Δ′ payload as the shared DeltaPrimeData and the solutions on the Galerkin grid as an OuterSolutionBasis; if there are no resonant surfaces in the domain it returns an empty result and two nothings.

wv is the vacuum energy matrix from free_run, which supplies the free-boundary edge term wv_edge = wv · psio²; pass nothing for a fixed-boundary edge. cut_solution also keeps the cut solution, for a later MatchProblem's composite inner profiles.

source
GeneralizedPerturbedEquilibrium.ForceFreeStates.write_galerkin! — Method
write_galerkin!(out_h5, result::GalerkinResult, basis; basis_output=false)

Write the Galerkin surface list (a subset of SingularSurfaces/ when the domain or the m-band excludes rationals) under ForceFreeStates/Solutions/GalerkinIntegration/. The Δ′/PEST-3 matrices and closed ξ profiles are written by the driver writer, not here. With basis_output, the solve's basis (an OuterSolutionBasis or nothing) is written under Basis/.

source

See Stability for the module this solver belongs to and Tearing for the inner-layer models matched to its Δ′.