AMReX-Astro / AMReX-Astro/Castro

SCF relaxation hardcodes A/B points for z-axis rotation but does not validate `rot_axis`

Open Beginner friendly
#3,234 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit bug :bug: self-consistent field init
Dominant language
C++
Stars
340
Forks
105
Avg merge
3d 8h
Merged PRs (30d)
8

Description

Summary

do_hscf_solve() sets SCF anchor points as equatorial on x and polar on z (scf_r_A[0], scf_r_B[2]) and comments that this assumes z-axis rotation. There is no guard enforcing castro::rot_axis == 3, so users can run SCF with another axis and get inconsistent physics.

Location

  • Source/scf/scf_relax.cpp:76
  • Source/scf/scf_relax.cpp:77
  • Source/scf/scf_relax.cpp:248
  • Source/scf/scf_relax.cpp:382

Problem Details

Current setup:

scf_r_A[0] += castro::scf_equatorial_radius;
scf_r_B[2] += castro::scf_polar_radius;

Multiple later comments state the algorithm assumes rotation on the z-axis, but no runtime check enforces that assumption.

Impact

  • SCF solution can be physically incorrect when rot_axis != 3.
  • Silent misconfiguration risk: run completes with wrong equilibrium target.

Suggested Patch

Fail fast unless z-axis rotation is used for SCF:

diff --git a/Source/scf/scf_relax.cpp b/Source/scf/scf_relax.cpp
--- a/Source/scf/scf_relax.cpp
+++ b/Source/scf/scf_relax.cpp
@@   
     if (scf_polar_radius > scf_equatorial_radius) {
         amrex::Error("Polar radius must not be larger than equatorial radius for SCF relaxation.");
     }
+
+    if (castro::rot_axis != 3) {
+        amrex::Error("SCF relaxation currently assumes rot_axis = 3 (z-axis).");
+    }

Prepared by Codex

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Source/scf/scf_relax.cpp at lines 76-77, then inspect the related assumptions around lines 248 and 382. Add validation for the rotation axis before SCF relaxation proceeds, and run an SCF configuration with a non-z rotation axis to confirm it fails clearly while the z-axis case remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.