Describe the bug
Case-optimized 1D and 2D MHD simulations using the HLL Riemann solver compile out required magnetic-pressure and total-energy-flux calculations. Several blocks in m_riemann_solver_hll.fpp are guarded by:
#:if not MFC_CASE_OPTIMIZATION or num_dims > 2
For a case-optimized 2D simulation, this condition is false. However, MFC uses three velocity and magnetic-field components for MHD even when num_dims is 1 or 2 (num_vels=3). Therefore, magnetic pressure remains zero and the MHD energy flux is not assigned, eventually producing NaNs.
To Reproduce
- Check out the current master branch.
- Run the standard 2D MHD rotor example with case optimization:
./mfc.sh run examples/2D_mhd_rotor/case.py \
-t pre_process simulation \
-n 1 -j 1 \
--no-debug --no-gpu \
--case-optimization
- The simulation produces NaNs around time step 10:
NaN(s) in timestep output. 195 129 0 1 0 10 399 399 0
- Run the same example without case optimization:
./mfc.sh run examples/2D_mhd_rotor/case.py \
-t pre_process simulation \
-n 1 -j 1 \
--no-debug --no-gpu
- The non-case-optimized simulation completes all 376 steps successfully.
Expected behavior
The case-optimized rotor simulation should complete successfully and produce the same numerical solution as the non-case-optimized build, within expected floating-point differences. Case optimization should change compilation and performance, not remove required MHD physics.
Screenshots
Not applicable.
Environment
- OS: Ubuntu 24.04.4 LTS, Linux 6.17.0-40-generic, x86-64
- Compiler: GNU Fortran 13.3.0
- MPI: Open MPI 4.1.6
- CPU build with --no-debug --no-gpu
Additional context
The affected HLL code in m_riemann_solver_hll.fpp includes:
- Relativistic MHD state calculations near lines 261 and 277.
- Non-relativistic magnetic pressure near line 285.
- Non-relativistic MHD energy flux near line 493.
Similar issues occur in m_riemann_solver_lf.fpp:
- Near line 254, case optimization removes the required relativistic-MHD state calculations in optimized 1D and 2D cases.
- Near line 395, case optimization removes the ideal-MHD energy-flux assignment in optimized 1D cases.
However, the LF Riemann solver is currently prohibited for MHD in case_validator.py, so these LF issues are not exposed through officially supported case configurations.
Describe the bug
Case-optimized 1D and 2D MHD simulations using the HLL Riemann solver compile out required magnetic-pressure and total-energy-flux calculations. Several blocks in m_riemann_solver_hll.fpp are guarded by:
For a case-optimized 2D simulation, this condition is false. However, MFC uses three velocity and magnetic-field components for MHD even when
num_dimsis 1 or 2 (num_vels=3). Therefore, magnetic pressure remains zero and the MHD energy flux is not assigned, eventually producing NaNs.To Reproduce
Expected behavior
The case-optimized rotor simulation should complete successfully and produce the same numerical solution as the non-case-optimized build, within expected floating-point differences. Case optimization should change compilation and performance, not remove required MHD physics.
Screenshots
Not applicable.
Environment
Additional context
The affected HLL code in
m_riemann_solver_hll.fppincludes:Similar issues occur in
m_riemann_solver_lf.fpp:However, the LF Riemann solver is currently prohibited for MHD in
case_validator.py, so these LF issues are not exposed through officially supported case configurations.