From c9fa72934b0d771a36472946b2a9cac1fac01886 Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Sun, 25 Oct 2026 21:32:10 +0100 Subject: [PATCH] Restore axisymmetric (Nz=1) completion of the virtual-casing normal field For Nz=1, bnorml evaluates only theta indices 0..(Nt+1)/2 and relies on the stellarator-symmetry mirror to fill the rest of the row. Fork PR #1 (d390088e) replaced the mirror by mirror_normal_field, whose toroidal loop is empty for Nz=1, so the upper half of the row kept stale values. This changed the free-boundary regression cases G3V08L3Fr and G3V08L3FrGrid (Ntor=0), e.g. Rij average difference 0.40 at tol 1e-10. mirror_normal_field now fills theta index jj > (Nt+1)/2 with -field(Nt-jj) for Nz=1. Unlike the upstream branch, it does not negate the computed theta=pi sample. The symmetry unit test now poisons exactly the samples bnorml does not evaluate, which fails without this change. Oracle independent of the references: a build that evaluates every grid point by brute force (Nzwithsym=Nz, no Nz=1 skip, no mirroring) reproduces the existing G3V08L3Fr and G3V08L3FrGrid references within 1e-10, as does this fix, so the references stay unchanged. All 8 CI reference cases pass with -std=legacy. --- src/bnorml.f90 | 8 ++++++++ tests/virtual_casing_symmetry.f90 | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bnorml.f90 b/src/bnorml.f90 index 3c2078b1..7c8a352c 100644 --- a/src/bnorml.f90 +++ b/src/bnorml.f90 @@ -344,12 +344,20 @@ end subroutine bnorml ! Complete an odd field under (theta,zeta) -> (-theta,-zeta). ! The theta=0 column maps to itself, without advancing the toroidal row. +! For Nz=1, bnorml evaluates only theta indices 0..(Nt+1)/2 of the single row. subroutine mirror_normal_field(Nt, Nz, Nzwithsym, field) implicit none integer, intent(in) :: Nt, Nz, Nzwithsym real, intent(inout) :: field(Nt*Nz) integer :: jj, kk, source, target + if (Nz.eq.1) then + do jj = (Nt+1)/2 + 1, Nt-1 + field(1+jj) = -field(1+Nt-jj) + enddo + return + endif + do kk = 1, Nz-Nzwithsym do jj = 0, Nt-1 source = 1 + jj + kk*Nt diff --git a/tests/virtual_casing_symmetry.f90 b/tests/virtual_casing_symmetry.f90 index 58d9c5f1..9b264e97 100644 --- a/tests/virtual_casing_symmetry.f90 +++ b/tests/virtual_casing_symmetry.f90 @@ -18,8 +18,13 @@ program test_virtual_casing_symmetry enddo enddo Nzwithsym = min(Nz, (Nz+3)/2) - field = 0.0 - field(1:Nt*Nzwithsym) = expected(1:Nt*Nzwithsym) + ! Poison every sample that bnorml does not evaluate. + field = huge(1.0) + if (Nz.eq.1) then + field(1:(Nt+1)/2+1) = expected(1:(Nt+1)/2+1) + else + field(1:Nt*Nzwithsym) = expected(1:Nt*Nzwithsym) + endif call mirror_normal_field(Nt, Nz, Nzwithsym, field) if (maxval(abs(field-expected)).gt.2.e-14) error stop 'periodic symmetry mismatch' deallocate(expected, field)