Skip to content

PERTURBED EQUILIBRIUM - Coupling matrices and resonant vectors for singular coupling#201

Merged
logan-nc merged 3 commits into
feature/coil-forcing-termsfrom
feature/coupling-matrices
Mar 24, 2026
Merged

PERTURBED EQUILIBRIUM - Coupling matrices and resonant vectors for singular coupling#201
logan-nc merged 3 commits into
feature/coil-forcing-termsfrom
feature/coupling-matrices

Conversation

@logan-nc
Copy link
Copy Markdown
Collaborator

Summary

  • PerturbedEquilibriumState: Replaces zero-padded [npert, msing] arrays and legacy coupling_coefficient/resonant_amplitude fields with dense [n_rational × numpert_total] coupling matrices (C_resonant_flux, C_resonant_current, C_island_width_sq, C_penetrated_field, C_delta_prime) and applied resonant vectors [n_rational] = C · amp_vec. Adds surface metadata arrays (rational_psi, rational_q, rational_m_res, rational_n, rational_surface_idx). Matches Fortran GPEC's C_f_x_out / Phi_res output structure.
  • SingularCoupling: Rewrites compute_singular_coupling_metrics! to collect all resonant (surface, n) pairs, compute full coupling rows using the off-diagonal ca_l/ca_r column (jump_vec = ca_r[:,resnum,2,s] - ca_l[:,resnum,2,s]), precompute L_surf once per pair, and apply forcing via R = C * amp_vec. Updates compute_island_diagnostics! for the new [n_rational] vector structure.
  • Utils: Rewrites write_outputs_to_HDF5 to write ComplexF64 directly (no _real/_imag splits), write all C_ matrices, applied vectors, and metadata. Removes unused ctrl parameter.
  • benchmarks/benchmark_fortran.jl: New script comparing Julia vs Fortran GPEC outputs using Fortran NetCDF files; reads rational_psi/rational_q for surface matching, resonant_flux as [n_rational] vector.
  • benchmarks/Project.toml: Separate benchmarks project for NCDatasets (benchmark-only dependency, not in main Project.toml).

Test plan

  • Run benchmark_fortran.jl against DIIID_ideal_example to confirm 4 resonant surfaces are found with matching ψ locations (--skip-run after first run)
  • Verify gpec.h5 structure: perturbed_equilibrium/singular_coupling/ should contain C_resonant_flux (4,34), resonant_flux (4,), rational_psi (4,), etc.
  • Merge normalizations fix branch and re-run benchmark to confirm magnitudes converge toward Fortran reference

🤖 Generated with Claude Code

logan-nc and others added 3 commits March 24, 2026 09:41
… review' comments

claude.yml was matching any '@claude' mention, including '@claude review', causing
both workflows to fire simultaneously. Added !contains('@claude review') exclusion
so review requests are handled exclusively by claude-code-review.yml.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…claude-reviews

GITHUB ACTIONS - BUG FIX - Prevent duplicate Claude reviews on @claude review comments
…vectors for singular coupling

Replaces the zero-padded [npert, msing] singular coupling arrays with a dense
[n_rational × numpert_total] coupling matrix structure matching Fortran GPEC's
C_f_x_out / Phi_res output format.

Key changes:
- PerturbedEquilibriumState: add C_ coupling matrices [n_rational × numpert_total],
  applied resonant vectors [n_rational], and surface metadata (rational_psi, rational_q,
  rational_m_res, rational_n, rational_surface_idx); remove legacy coupling_coefficient
  and resonant_amplitude fields
- SingularCoupling: rewrite compute_singular_coupling_metrics! to collect all resonant
  (surface, n) pairs, compute full coupling rows from off-diagonal ca_l/ca_r columns
  (jump_vec = ca_r[:,resnum,2,s] - ca_l[:,resnum,2,s]), precompute L_surf once per pair,
  apply forcing via R = C * amp_vec; update compute_island_diagnostics! for new [n_rational]
  vector structure
- Utils: rewrite write_outputs_to_HDF5 to write ComplexF64 directly (no _real/_imag split),
  write all C_ matrices, applied vectors, and metadata; remove ctrl parameter (unused)
- benchmarks/benchmark_fortran.jl: new script comparing Julia vs Fortran GPEC outputs
  using Fortran NC files; updated to read new h5 paths (rational_psi/rational_q for
  surface matching, resonant_flux as [n_rational] vector)
- benchmarks/Project.toml: separate project for NCDatasets (benchmark-only dep)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@logan-nc
Copy link
Copy Markdown
Collaborator Author

Current status (bad disagreement to be fixed in the other branch)


GPEC Fortran vs Julia Comparison — DIIID_ideal_example

Scalar Parameters — excellent match:

  ┌────────┬──────────┬──────────┬──────┐                                                                               
  │        │ Fortran  │  Julia   │ Rel% │                                                                                 
  ├────────┼──────────┼──────────┼──────┤                                                                               
  │ psilim │ 0.991539 │ 0.991538 │ 0.0% │
  ├────────┼──────────┼──────────┼──────┤
  │ qlim   │ 5.200000 │ 5.200000 │ 0.0% │                                                                                 
  └────────┴──────────┴──────────┴──────┘                                                                                 
                                                                                                                          

W_t Eigenvalue (least stable) — 0.7% difference (very good)

q Profile RMS — 0.00% (essentially identical)

Mercier Criterion — ~1.4% RMS mismatch (small)

Resonant Surface Comparison — the coupling structure is now working (4 surfaces found, matching Fortran's 4 rational
surfaces), but magnitudes differ substantially:

  | q | psi   | Φ_res Fort | Φ_res Julia | w_isl Fort | w_isl Julia |                                               
  | 2 | 0.594 | 6.06e-4    | 5.68e-3     | 0.102      | 0.069 |                                                                       
  | 3 | 0.819 | 4.25e-4    | 1.68        | 0.066      | 0.697 |                                                                          
  | 4 | 0.928 | 8.75e-5    | 5.35        | 0.024      | 0.873 |                                                                          
  | 5 | 0.988 | 9.42e-4    | 0.348       | 0.037      | 0.099 |            

@logan-nc logan-nc merged commit c73ce58 into feature/coil-forcing-terms Mar 24, 2026
1 check failed
@logan-nc logan-nc deleted the feature/coupling-matrices branch March 24, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants