From 0ebf1aba736673c33ff84f87daa1ad7c2724fdea Mon Sep 17 00:00:00 2001 From: ruru25254649 Date: Thu, 22 Oct 2026 08:00:00 +0900 Subject: [PATCH] Reject chem_params%diffusion without chemistry The diffusion flux arrays (flux_src_n(E) and the species slots) are allocated only when chemistry is on, but the Riemann-state zeroing and the s_compute_additional_physics_rhs loops test chem_params%diffusion alone. A non-reacting case with chem_params%diffusion = T passed validation and then segfaulted on the first time step. Prohibit the combination in check_chemistry, and give the matching deallocation in s_finalize_rhs_module the chemistry guard its allocation has (#1908). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WPhkY8p1EHhGY7jScizJmC --- src/simulation/m_rhs.fpp | 2 +- toolchain/mfc/case_validator.py | 4 ++++ toolchain/mfc/test_case_validator.py | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/simulation/m_rhs.fpp b/src/simulation/m_rhs.fpp index a0a8046751..b854ec968f 100644 --- a/src/simulation/m_rhs.fpp +++ b/src/simulation/m_rhs.fpp @@ -2242,7 +2242,7 @@ contains end do end if - if (chem_params%diffusion .and. .not. (viscous .or. surface_tension .or. heat_conduction)) then + if (chemistry .and. chem_params%diffusion .and. .not. (viscous .or. surface_tension .or. heat_conduction)) then @:DEALLOCATE(flux_src_n(i)%vf(eqn_idx%E)%sf) end if diff --git a/toolchain/mfc/case_validator.py b/toolchain/mfc/case_validator.py index 476009fbd0..282dc85aea 100644 --- a/toolchain/mfc/case_validator.py +++ b/toolchain/mfc/case_validator.py @@ -2156,6 +2156,10 @@ def check_chemistry(self): # inconsistent and the simulation NaNs. See MFlowCode/MFC#1470. self.prohibit(chemistry and num_fluids is not None and num_fluids != 1, "chemistry is only supported for single-component flows (num_fluids = 1)") + # The diffusion flux arrays are allocated only under chemistry, but the Riemann-state and + # RHS loops test chem_params%diffusion alone, so without chemistry they write unallocated arrays. + self.prohibit(diffusion and not chemistry, "chem_params%diffusion requires chemistry = T") + # Chemistry with Euler bubbles is not currently supported: the IBM image-point # interpolation branch selects the bubbles/QBMM path before the chemistry path, so # the species state is not carried when both are enabled. Disallow the combination diff --git a/toolchain/mfc/test_case_validator.py b/toolchain/mfc/test_case_validator.py index c0170452d9..cd2d4be0c1 100644 --- a/toolchain/mfc/test_case_validator.py +++ b/toolchain/mfc/test_case_validator.py @@ -168,6 +168,14 @@ def test_accepts_2d(self): self.assertAccepts({**BASE_2D, "bf_spatial_support": "T"}) +class TestChemistryDiffusion(ConstraintTestCase): + def test_rejects_diffusion_without_chemistry(self): + self.assertRejects({**BASE, "chem_params%diffusion": "T"}, "chem_params%diffusion requires chemistry") + + def test_accepts_diffusion_with_chemistry(self): + self.assertAccepts({**CHEMISTRY, "chem_params%diffusion": "T"}) + + class TestChemistrySubstepping(ConstraintTestCase): def test_rejects_negative_substeps(self): self.assertRejects({**CHEMISTRY, "chem_params%reaction_substeps": -1}, "reaction_substeps must be >= 0")