Skip to content

Toroidal HDF5 grid/Bp stores B^zeta instead of physical B_phi #233

Description

@krystophny

Summary

For toroidal geometry (Igeometry=3), the HDF5 grid/Bp dataset is documented as the physical cylindrical toroidal component B^varphi, but write_grid stores the contravariant coordinate component B^zeta. The cylindrical scale factor R is missing.

Source-level cause

At current master (b23a2408fc3f1dfbc14896e16d73a57f7d1d9e88), src/sphdf5.f90 describes the grid outputs as cylindrical (B^R,B^varphi,B^Z) components. In the Igeometry=3 branch, however, the assignment is:

ijimag(jk) = ( one ) * gBzeta / sg(jk,0) ! Bp

Here gBzeta/sqrt(g) is B^zeta. Since zeta is the physical cylindrical angle in stzxyz, the physical unit-vector component is

B_phi = R * B^zeta.

The neighboring BR and BZ expressions already apply the coordinate-basis derivatives; only Bp omits its scale factor.

Reproduction

  1. Build current master and run the shipped toroidal case:
mkdir -p /tmp/spec-bp-repro
cp InputFiles/TestCases/G3V01L0Fi.001.sp /tmp/spec-bp-repro/
build/build/bin/xspec /tmp/spec-bp-repro/G3V01L0Fi.001.sp
  1. Inspect the first nonsingular radial grid point at theta=zeta=0 in the resulting HDF5 file. On current master the native values are:
R                 = 10.15625
grid/Bp           = 0.066064035949282...
R * grid/Bp       = 0.670962865109...

An independent reconstruction from the stored A_theta/A_zeta Fourier-Zernike coefficients gives the physical cylindrical component B_phi = 0.670962865109..., while it gives the contravariant component B^zeta = 0.066064035949282....

Across every nonsingular point in the shipped 32 x 32 x 8 grid:

max |grid/Bp - independently reconstructed B_phi|     = 6.7139900606e-1
max |R*grid/Bp - independently reconstructed B_phi|   = 1.67e-15
max |grid/BR - independently reconstructed B_R|       = 1.81e-16
max |grid/BZ - independently reconstructed B_Z|       = 1.53e-16

The independent reconstruction uses the native phase m*theta-in*zeta, the A_s=0 curl identities, the signed Jacobian, and the Cartesian map (R cos(zeta), R sin(zeta), Z); it does not call SPEC field helpers.

Expected behavior

For Igeometry=3, grid/Bp should store the physical cylindrical component consistently with its documentation and with grid/BR and grid/BZ:

ijimag(jk) = Rij(jk,0,0) * gBzeta / sg(jk,0) ! Bphi

Actual behavior

grid/Bp stores B^zeta, so consumers treating it as a cylindrical field component understate B_phi by a factor of R.

Suggested regression

For G3V01L0Fi.001.sp, independently reconstruct (B_R,B_phi,B_Z) from the vector-potential coefficients and geometry, then compare all three arrays pointwise. Keep a negative assertion that raw B^zeta differs from B_phi whenever R != 1.

This report concerns only the toroidal HDF5 grid component. It does not claim that the internal contravariant field, field-line equations, or BR/BZ outputs are wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions