From 3c454758c7c0af5c978e30684c9fce8f11024e26 Mon Sep 17 00:00:00 2001 From: zhi Date: Thu, 9 Oct 2025 17:02:27 -0400 Subject: [PATCH 1/5] add check interval for checking nse inside integrator --- integration/RKC/rkc.H | 14 ++++++++------ integration/VODE/vode_dvode.H | 9 ++++++++- nse_solver/_parameters | 3 +++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/integration/RKC/rkc.H b/integration/RKC/rkc.H index 25393632b3..5a71fb8f41 100644 --- a/integration/RKC/rkc.H +++ b/integration/RKC/rkc.H @@ -246,15 +246,17 @@ int rkclow (BurnT& state, RkcT& rstate) // wild exploration. Also ensure we are not working > tmax, // so we don't need to worry about extrapolating back in time. - if (rstate.nsteps > MIN_NSE_BAILOUT_STEPS && rstate.t <= rstate.tout) { - // first we need to make the burn_t in sync + // For NSE_NET, we only check for some interval to prevent + // expensive check overhead -#ifdef STRANG - update_thermodynamics(state, rstate); + if (rstate.nsteps > MIN_NSE_BAILOUT_STEPS && rstate.t <= rstate.tout +#ifdef NSE_NET + && vstate.n_step % nse_check_interval == 0 #endif -#ifdef SDC + ) { + // first we need to make the burn_t in sync + int_to_burn(rstate.t, rstate, state); -#endif if (in_nse(state)) { return IERR_ENTERED_NSE; diff --git a/integration/VODE/vode_dvode.H b/integration/VODE/vode_dvode.H index bbbf414398..132ce26488 100644 --- a/integration/VODE/vode_dvode.H +++ b/integration/VODE/vode_dvode.H @@ -233,7 +233,14 @@ int dvode (BurnT& state, DvodeT& vstate) // wild exploration. Also ensure we are not working > tmax, // so we don't need to worry about extrapolating back in time. - if (vstate.n_step > MIN_NSE_BAILOUT_STEPS && vstate.tn <= vstate.tout) { + // For NSE_NET, we only check for some interval to prevent + // expensive check overhead + + if (vstate.n_step > MIN_NSE_BAILOUT_STEPS && vstate.tn <= vstate.tout +#ifdef NSE_NET + && vstate.n_step % nse_check_interval == 0 +#endif + ) { // first we need to make the burn_t in sync int_to_burn(vstate.tn, vstate, state); diff --git a/nse_solver/_parameters b/nse_solver/_parameters index e77ef19002..49d6d40974 100644 --- a/nse_solver/_parameters +++ b/nse_solver/_parameters @@ -43,3 +43,6 @@ T_nse_net real -1.0 # Minimum Temperature required for NSE T_min_nse real 4.0e9 + +# NSE check interval in integrator +nse_check_interval int 5 \ No newline at end of file From b90a6882d24376dda106d093a0610d38d4453a6a Mon Sep 17 00:00:00 2001 From: zhi Date: Thu, 9 Oct 2025 17:21:04 -0400 Subject: [PATCH 2/5] fix comiplation --- nse_solver/_parameters | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nse_solver/_parameters b/nse_solver/_parameters index 49d6d40974..80d1cfe475 100644 --- a/nse_solver/_parameters +++ b/nse_solver/_parameters @@ -45,4 +45,4 @@ T_nse_net real -1.0 T_min_nse real 4.0e9 # NSE check interval in integrator -nse_check_interval int 5 \ No newline at end of file +nse_check_interval int 5 From 64a2c056d4266c5376da50ccd23d3096517d16a4 Mon Sep 17 00:00:00 2001 From: zhi Date: Thu, 9 Oct 2025 17:31:38 -0400 Subject: [PATCH 3/5] update doc --- Docs/source/nse_net.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Docs/source/nse_net.rst b/Docs/source/nse_net.rst index 0278b2cc1d..d4b637f99f 100644 --- a/Docs/source/nse_net.rst +++ b/Docs/source/nse_net.rst @@ -354,3 +354,7 @@ to the self-consistent nse check: the subsequent NSE checks. This is mainly to avoid unnecessary computations of computing the NSE mass fractions when the current temperature is too low. This is set to 4.0e9 by default. + +* ``nse.nse_check_interval`` is the interval at which we perform the + nse check in the integrator. This is used to minimize the + expensive check overhead. This is set to 5 by default. From 8a5e7d450d22633390e747d6f0080be8e2f5eb5c Mon Sep 17 00:00:00 2001 From: zhi Date: Mon, 20 Oct 2025 12:42:09 -0400 Subject: [PATCH 4/5] try to add a temperature check too --- integration/RKC/rkc.H | 2 +- integration/VODE/vode_dvode.H | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/RKC/rkc.H b/integration/RKC/rkc.H index 5a71fb8f41..f134ec2d6f 100644 --- a/integration/RKC/rkc.H +++ b/integration/RKC/rkc.H @@ -251,7 +251,7 @@ int rkclow (BurnT& state, RkcT& rstate) if (rstate.nsteps > MIN_NSE_BAILOUT_STEPS && rstate.t <= rstate.tout #ifdef NSE_NET - && vstate.n_step % nse_check_interval == 0 + && (vstate.n_step % nse_check_interval == 0 || state.T > 6.e9_rt) #endif ) { // first we need to make the burn_t in sync diff --git a/integration/VODE/vode_dvode.H b/integration/VODE/vode_dvode.H index 132ce26488..474d02276b 100644 --- a/integration/VODE/vode_dvode.H +++ b/integration/VODE/vode_dvode.H @@ -238,7 +238,7 @@ int dvode (BurnT& state, DvodeT& vstate) if (vstate.n_step > MIN_NSE_BAILOUT_STEPS && vstate.tn <= vstate.tout #ifdef NSE_NET - && vstate.n_step % nse_check_interval == 0 + && (vstate.n_step % nse_check_interval == 0 || state.T > 6.e9_rt) #endif ) { // first we need to make the burn_t in sync From 90c51c89e5c7b53ab85c3be01dee4d066b82132c Mon Sep 17 00:00:00 2001 From: zhi Date: Fri, 7 Nov 2025 15:59:17 -0500 Subject: [PATCH 5/5] allow negative rhoX in in_nse, and allow nse_burn if nse is detected in integrator instead of redoing nse check --- interfaces/burner.H | 20 ++++++++++++-------- nse_solver/nse_check.H | 9 --------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/interfaces/burner.H b/interfaces/burner.H index 7ac706e42e..f885f2dac1 100644 --- a/interfaces/burner.H +++ b/interfaces/burner.H @@ -50,23 +50,27 @@ void burner (BurnT& state, amrex::Real dt) // left after the failure amrex::Real dt_remaining = amrex::max(dt - state.time, 0.0_rt); - // we use a relaxed NSE criteria now to catch states that are - // right on the edge of being in NSE + if (!state.success && dt_remaining > 0.0_rt) { + + // Proceed with NSE burn if NSE is detected within integrator + // If we allow a relaxed NSE criteria to catch states that are + // right on the edge of being in NSE, then evaluate that here. #ifdef NSE_TABLE - if (in_nse(state, true) && !state.success && dt_remaining > 0.0) { + if (state.error_code == IERR_ENTERED_NSE || in_nse(state, true)) { #else - if (in_nse(state, nse_skip_molar) && !state.success && dt_remaining > 0.0) { + if (state.error_code == IERR_ENTERED_NSE || (nse_skip_molar && in_nse(state, nse_skip_molar))) { #endif #ifndef AMREX_USE_GPU - std::cout << "recovering burn failure in NSE, zone = (" << state.i << ", " << state.j << ", " << state.k << ")" << std::endl; + std::cout << "recovering burn failure in NSE, zone = (" << state.i << ", " << state.j << ", " << state.k << ")" << std::endl; #endif - // This will append to state.e the amount additional - // energy released from adjusting to the new NSE state + // This will append to state.e the amount additional + // energy released from adjusting to the new NSE state #ifdef SDC - sdc_nse_burn(state, dt_remaining); + sdc_nse_burn(state, dt_remaining); #endif + } } } #else diff --git a/nse_solver/nse_check.H b/nse_solver/nse_check.H index 10956b8b4e..72c6f66790 100644 --- a/nse_solver/nse_check.H +++ b/nse_solver/nse_check.H @@ -544,15 +544,6 @@ bool in_nse(burn_t& current_state, bool skip_molar_check=false) { return current_state.nse; } - // Check if any of the input rhoX is negative - // This indicates a burn failure, so we should return false - - for (int n = 0; n < NumSpec; ++n) { - if (current_state.y[SFS+n] < 0.0_rt) { - return current_state.nse; - } - } - // Get the NSE state using (rho, T, Ye) as input // Then compare input molar fractions to the NSE molar fractions.