AMReX-Astro / AMReX-Astro/Castro

MHD plot variable eint_E includes magnetic energy in the reported internal energy

Open
#3,380 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit mhd
Dominant language
C++
Stars
340
Forks
105
Avg merge
3d 8h
Merged PRs (30d)
8

Description

Summary

The eint_E derived field subtracts kinetic energy from total specific energy but does not subtract magnetic energy in MHD builds. Consequently it reports e + B_cc^2/(2*rho) instead of the specific internal energy e.

Affected code

  • Source/driver/Derive.cpp:53–75: ca_dereint1().
  • Source/driver/Castro_setup.cpp:837–838: unconditional registration of eint_E, with only fluid state inputs.
  • Source/driver/Castro.cpp:3865–3893: add_magnetic_e() explicitly adds cell-centered magnetic energy to UEDEN.

Reviewed at commit 7abbd3ef7.

Trigger and impact

Build with USE_MHD=TRUE, initialize a nonzero magnetic field, and request eint_E in a plotfile. The result overestimates thermal energy, potentially by a large factor in magnetically dominated states. Comparing eint_E and eint_e then suggests a dual-energy inconsistency even for a consistent initial state.

Minimal reproduction

For a uniform stationary cell with rho = 1, rho*e = 2, and cell-centered magnetic field (2, 0, 0):

  • Castro stores rho*E = 2 + 0.5*4 = 4.
  • ca_dereint1() returns 4/1 - 0 = 4.
  • Expected eint_E, and the value of eint_e, is 2.

For an integration check, use Exec/mhd_tests/Alfven, request both derived fields in the initial plotfile, and compare their difference with B_cc^2/(2*rho).

Suggested fix

Provide the MHD derivation with the face-centered magnetic fields and subtract magnetic energy using the same face-to-cell averaging as the evolution. The current registration supplies only State_Type, so changing just the arithmetic in the callback is insufficient. Preserve the meaning of internal energy derived from total energy rather than replacing it with the separately evolved UEINT.

Validation

Source tracing and an isolated Python calculation reproduced 4 versus the expected 2. No MHD executable was built or run. A regression should check initial data with nonzero magnetic field and also a zero-field case.

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 with ca_dereint1() in Source/driver/Derive.cpp and trace the eint_E registration in Source/driver/Castro_setup.cpp, then review magnetic-energy handling in Source/driver/Castro.cpp. Run Exec/mhd_tests/Alfven with both derived fields in the initial plotfile. Done means eint_E matches eint_e for nonzero magnetic fields, differs by the expected magnetic energy where appropriate, and remains correct for zero field.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.