Skip to content

pmodb NetCDF field-function reshape corrupts theta=0 complex value and omits endpoint #277

Description

@krystophny

Summary

The four complex scalar field-function variables written by gpout_pmodb have a one-point-short RESHAPE extent. Their NetCDF poloidal dimension contains mthsurf+1 points (theta=0...1), but lines 2991--3002 reshape the source arrays to (/mstep,mthsurf,2/). The result corrupts the complex value at theta=0 and leaves the periodic endpoint as fill.

Affected variables:

  • b_eul_fun
  • b_lag_fun
  • Bdivxi_perp_fun
  • Bkappaxi_perp_fun

The adjacent normal-field writer correctly uses (/mstep,mthsurf+1,2/) at lines 3635--3638.

Reproduction

Revision: 19b43523684d3336856462608d1ac56f6ed5f308.

I built GPEC with GNU Fortran, OpenBLAS, and system netCDF, ran the repository's regression_solovev_kinetic_example, and replaced its coil drive by one explicitly complex boundary harmonic:

coil_flag = .false.
harmonic_flag = .true.
cosmn(2) = 1e-4
sinmn(2) = 2e-4

I ran the same DCON solution twice with (ip_direction,bt_direction)=(positive,positive) and (positive,negative), giving NetCDF helicity=+1 and -1. The internal b_lag spectra are bitwise identical. For theta_dcon indices 1--63, every field-function value obeys the source's expected -helicity imaginary-part map exactly. At index 0, however, both runs contain the same complex value rather than conjugates; its imaginary part is identically copied from its real part. At index 64 (theta_dcon=1) both components are fill.

Representative b_lag_fun(theta=0,psi index 100) values:

helicity=+1:  1.6715577267257276e-4 + 1.6715577267257276e-4 i
helicity=-1:  1.6715577267257276e-4 + 1.6715577267257276e-4 i

At an interior point the expected map works:

helicity=+1:  1.5994490543356555e-4 + 1.4473644169856975e-4 i
helicity=-1:  1.5994490543356555e-4 - 1.4473644169856975e-4 i

Cause

The arrays eulbparfout, lagbparfout, divxprpfout, and curvfout have the periodic 0:mthsurf poloidal extent. The NetCDF theta coordinate also has mthsurf+1 entries. The four writes nevertheless use:

(/mstep,mthsurf,2/)

so the concatenated real/imaginary source is split at the wrong offset and supplied with one missing poloidal plane.

Expected

Use (/mstep,mthsurf+1,2/), add a complex nonzero-sine regression, and assert:

  • both components at theta=0 are correct;
  • the periodic endpoint equals theta=0;
  • reversing helicity reverses only the packed imaginary component for the same native solution.

Scope

This is an output serialization defect in the four pmodb field-function variables. The Fourier-space b_eul, b_lag, Bdivxi_perp, and Bkappaxi_perp variables are not affected. No production source was changed during this audit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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