Skip to content

Fix bug in zero_fields_near_cylorigin for |m| >= 2#3164

Open
oskooi wants to merge 3 commits intoNanoComp:masterfrom
oskooi:bug_fix_cyl_r0
Open

Fix bug in zero_fields_near_cylorigin for |m| >= 2#3164
oskooi wants to merge 3 commits intoNanoComp:masterfrom
oskooi:bug_fix_cyl_r0

Conversation

@oskooi
Copy link
Collaborator

@oskooi oskooi commented Mar 6, 2026

Fixes #2644.

Root cause: The zero_fields_near_cylorigin stability mechanism in step_db.cpp (lines 397-456) is incomplete for |m| >= 2. It only zeros field components on integer-r grid points (Dp, Dz for D_stuff; Br for B_stuff) but not the half-integer-r components (Dr for D_stuff; Bp, Bz for B_stuff).

When an Er source extends to r=0, it injects current into Dr at the half-integer-r grid points near the origin (r = 0.02, 0.06 for resolution 25). Because Dr was not being zeroed, the nonzero Dr/Er at small r feeds into the Bz curl update via the im/r × Er term, which amplifies by ~100× at r=0.02 for m=2. This Bz then drives Hz, which feeds back into Dr via the im/r × Hz term — creating an exponentially growing feedback loop.

When offset = 0.15 (in the test script), the source region starts at r=0.075, placing no source current at the first two Er grid points (r=0.02, 0.06) that fall within the zeroing range, so the instability doesn't trigger.

Fix (src/step_db.cpp): Extended the field-zeroing to include all six D/B components near the cylindrical origin for |m| >= 2:

  • D_stuff: Added zeroing of Dr alongside existing Dp, Dz
  • B_stuff: Added zeroing of Bp, Bz alongside existing Br

This breaks the feedback loop by ensuring Bz is zeroed near r=0, so Hz remains zero and the im/r amplification never feeds back into Dr.

@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.90%. Comparing base (f29a8c7) to head (b39cee2).
⚠️ Report is 111 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3164      +/-   ##
==========================================
+ Coverage   73.81%   73.90%   +0.09%     
==========================================
  Files          18       18              
  Lines        5423     5454      +31     
==========================================
+ Hits         4003     4031      +28     
- Misses       1420     1423       +3     

see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

numerical stability in cylindrical coordinate

2 participants