From 2cd61d2fba556e2b947b1dd7751d085e776bd536 Mon Sep 17 00:00:00 2001 From: Zhi Date: Mon, 1 May 2023 22:52:26 -0400 Subject: [PATCH 1/9] nse bailout initial commit --- Source/driver/Castro_advance_ctu.cpp | 10 ++++++++++ Source/driver/_cpp_parameters | 3 +++ 2 files changed, 13 insertions(+) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index aa33d46d64..7154a0dae1 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -613,6 +613,16 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, int num_subcycles_remaining = int(round(((time + dt) - subcycle_time) / dt_subcycle)); if (num_subcycles_remaining > max_subcycles) { +#ifdef NSE_NET + if (do_nse_bailout) { + + // find the smallest allowed dt_subcycle and then enable nse_net bailout + + dt_subcycle = ((time + dt) - subcycle_time) / max_subcycles; + nse_molar_independent = true; + nse_skip_molar = true; + } +#else amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl << " If you would like to override this, increase the parameter castro.max_subcycles." << std::endl; diff --git a/Source/driver/_cpp_parameters b/Source/driver/_cpp_parameters index 2e08eb46b2..53707e1456 100644 --- a/Source/driver/_cpp_parameters +++ b/Source/driver/_cpp_parameters @@ -402,6 +402,9 @@ stopping_criterion_field string "" # Threshold value for determining whether to stop. stopping_criterion_value Real 1.e200 +# whether to do nse_net bailout when max_subcycles is reached +nse_bailout int 0 + #----------------------------------------------------------------------------- # category: reactions #----------------------------------------------------------------------------- From e15c368d7021a9dcb9d219e2c4d0e3357d324652 Mon Sep 17 00:00:00 2001 From: Zhi Date: Tue, 2 May 2023 12:15:52 -0400 Subject: [PATCH 2/9] allow nse parameters to restore after subcycle --- Source/driver/Castro_advance_ctu.cpp | 25 ++++++++++++++++++++++++- Source/driver/_cpp_parameters | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index 7154a0dae1..9fe038b09d 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -573,6 +573,13 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, Real last_dt_subcycle = 1.e200; +#ifdef NSE_NET + bool do_bailout = true; + bool old_nse_dx_independent = nse_dx_independent; + bool old_nse_molar_independent = nse_molar_independent; + bool old_nse_skip_molar = nse_skip_molar; +#endif + while (subcycle_time < (1.0 - eps) * (time + dt)) { // Save the dt_subcycle before modifying it, we will use it later. @@ -614,19 +621,27 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, if (num_subcycles_remaining > max_subcycles) { #ifdef NSE_NET - if (do_nse_bailout) { + if (do_nse_bailout && do_bailout) { // find the smallest allowed dt_subcycle and then enable nse_net bailout dt_subcycle = ((time + dt) - subcycle_time) / max_subcycles; + nse_dx_independent = true; nse_molar_independent = true; nse_skip_molar = true; + + do_bailout = false; + + amrex::Print() << std::endl + << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl + << " Reperforming subcycle with smallest possible dt_subcycle and nse_bailout." << std::endl; } #else amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl << " If you would like to override this, increase the parameter castro.max_subcycles." << std::endl; amrex::Abort("Error: too many subcycles."); +#endif } // If we get to this point, we survived the sanity checks. Print out the current subcycle iteration. @@ -813,6 +828,14 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, } + // Restore the original nse configuration + +#ifdef NSE_NET + nse_dx_independent = old_nse_dx_independent; + nse_molar_independent = old_nse_molar_independent; + nse_skip_molar = old_nse_skip_molar; +#endif + // We want to return the subcycled timestep as a suggestion. // Let's be sure to return the subcycled timestep that was // unmodified by anything we had to do in the last subcycle diff --git a/Source/driver/_cpp_parameters b/Source/driver/_cpp_parameters index 53707e1456..b50368cffd 100644 --- a/Source/driver/_cpp_parameters +++ b/Source/driver/_cpp_parameters @@ -403,7 +403,7 @@ stopping_criterion_field string "" stopping_criterion_value Real 1.e200 # whether to do nse_net bailout when max_subcycles is reached -nse_bailout int 0 +do_nse_bailout int 0 #----------------------------------------------------------------------------- # category: reactions From 4d7915bd93acafab50e4d7a44c793355e88fe6c9 Mon Sep 17 00:00:00 2001 From: Zhi Date: Tue, 2 May 2023 15:42:10 -0400 Subject: [PATCH 3/9] fix: include abort --- Source/driver/Castro_advance_ctu.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index 9fe038b09d..90e0d9fc4f 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -636,12 +636,11 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl << " Reperforming subcycle with smallest possible dt_subcycle and nse_bailout." << std::endl; } -#else +#endif amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl << " If you would like to override this, increase the parameter castro.max_subcycles." << std::endl; amrex::Abort("Error: too many subcycles."); -#endif } // If we get to this point, we survived the sanity checks. Print out the current subcycle iteration. From fad43e06fd550e05d4515ee61c21484c1faa7453 Mon Sep 17 00:00:00 2001 From: Zhi Date: Tue, 2 May 2023 15:57:28 -0400 Subject: [PATCH 4/9] add else to the abort part --- Source/driver/Castro_advance_ctu.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index 90e0d9fc4f..370090c39d 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -635,12 +635,15 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl << " Reperforming subcycle with smallest possible dt_subcycle and nse_bailout." << std::endl; - } + } else { #endif amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl << " If you would like to override this, increase the parameter castro.max_subcycles." << std::endl; amrex::Abort("Error: too many subcycles."); +#ifdef NSE_NET + } +#endif } // If we get to this point, we survived the sanity checks. Print out the current subcycle iteration. From 9398c5f6f3e19428776860b014505a0eeafbb8bf Mon Sep 17 00:00:00 2001 From: Zhi Date: Wed, 3 May 2023 15:00:05 -0400 Subject: [PATCH 5/9] fix number_subcycles_remaining after enter bailout --- Source/driver/Castro_advance_ctu.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index 370090c39d..a6d83166d5 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -625,11 +625,12 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, // find the smallest allowed dt_subcycle and then enable nse_net bailout - dt_subcycle = ((time + dt) - subcycle_time) / max_subcycles; + dt_subcycle = ((time + dt) - subcycle_time) / (max_subcycles); + number_subcycles_remaining = max_subcycles; + nse_dx_independent = true; nse_molar_independent = true; nse_skip_molar = true; - do_bailout = false; amrex::Print() << std::endl From 4b9dbc12263c834789c0072cb8c30a07d5e61b67 Mon Sep 17 00:00:00 2001 From: Zhi Date: Wed, 3 May 2023 15:03:44 -0400 Subject: [PATCH 6/9] fix typo --- Source/driver/Castro_advance_ctu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index a6d83166d5..573aac61be 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -626,7 +626,7 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, // find the smallest allowed dt_subcycle and then enable nse_net bailout dt_subcycle = ((time + dt) - subcycle_time) / (max_subcycles); - number_subcycles_remaining = max_subcycles; + num_subcycles_remaining = max_subcycles; nse_dx_independent = true; nse_molar_independent = true; From a7399207bc98cf9c27fb3befe8336b04939d5172 Mon Sep 17 00:00:00 2001 From: Zhi Date: Mon, 5 Jun 2023 12:39:21 -0400 Subject: [PATCH 7/9] update --- Source/driver/Castro_advance_ctu.cpp | 28 ++++++++++++++++------------ Source/driver/_cpp_parameters | 4 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index e6d8b2130a..2c17dfbe6b 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -492,10 +492,12 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, Real last_dt_subcycle = 1.e200; #ifdef NSE_NET - bool do_bailout = true; - bool old_nse_dx_independent = nse_dx_independent; - bool old_nse_molar_independent = nse_molar_independent; - bool old_nse_skip_molar = nse_skip_molar; + if (loosen_nse_bailout) { + bool do_loosen = true; + bool old_nse_dx_independent = nse_dx_independent; + bool old_nse_molar_independent = nse_molar_independent; + bool old_nse_skip_molar = nse_skip_molar; + } #endif while (subcycle_time < (1.0 - eps) * (time + dt)) { @@ -539,9 +541,9 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, if (num_subcycles_remaining > max_subcycles) { #ifdef NSE_NET - if (do_nse_bailout && do_bailout) { + if (loosen_nse_bailout && do_loosen) { - // find the smallest allowed dt_subcycle and then enable nse_net bailout + // find the smallest allowed dt_subcycle and then loosen nse_net bailout condition dt_subcycle = ((time + dt) - subcycle_time) / (max_subcycles); num_subcycles_remaining = max_subcycles; @@ -549,7 +551,7 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, nse_dx_independent = true; nse_molar_independent = true; nse_skip_molar = true; - do_bailout = false; + do_loosen = false; amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl @@ -749,12 +751,14 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, } +#ifdef NSE_NET // Restore the original nse configuration - -#ifdef NSE_NET - nse_dx_independent = old_nse_dx_independent; - nse_molar_independent = old_nse_molar_independent; - nse_skip_molar = old_nse_skip_molar; + + if (loosen_nse_bailout) { + nse_dx_independent = old_nse_dx_independent; + nse_molar_independent = old_nse_molar_independent; + nse_skip_molar = old_nse_skip_molar; + } #endif // We want to return the subcycled timestep as a suggestion. diff --git a/Source/driver/_cpp_parameters b/Source/driver/_cpp_parameters index aaaf6502e0..e806d8d9e1 100644 --- a/Source/driver/_cpp_parameters +++ b/Source/driver/_cpp_parameters @@ -402,8 +402,8 @@ stopping_criterion_field string "" # Threshold value for determining whether to stop. stopping_criterion_value Real 1.e200 -# whether to do nse_net bailout when max_subcycles is reached -do_nse_bailout int 0 +# whether to loosen nse bailout condition when max_subcycles is reached +loosen_nse_bailout int 0 #----------------------------------------------------------------------------- # category: reactions From 398ce9a12a804d33ef8a82ecb451b27a78e39d18 Mon Sep 17 00:00:00 2001 From: Zhi Date: Mon, 5 Jun 2023 12:40:46 -0400 Subject: [PATCH 8/9] update message --- Source/driver/Castro_advance_ctu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index 2c17dfbe6b..901a784442 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -555,7 +555,7 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, amrex::Print() << std::endl << " The subcycle mechanism requested " << num_subcycles_remaining << " subcycled timesteps, which is larger than the maximum of " << max_subcycles << "." << std::endl - << " Reperforming subcycle with smallest possible dt_subcycle and nse_bailout." << std::endl; + << " Reperforming subcycle with smallest possible dt_subcycle and loosen nse bailout conditions." << std::endl; } else { #endif amrex::Print() << std::endl From 1ed9e6dc29ce8a353e72c406428cacee232b996e Mon Sep 17 00:00:00 2001 From: Zhi Date: Mon, 5 Jun 2023 12:51:05 -0400 Subject: [PATCH 9/9] revert --- Source/driver/Castro_advance_ctu.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Source/driver/Castro_advance_ctu.cpp b/Source/driver/Castro_advance_ctu.cpp index 901a784442..18839d752b 100644 --- a/Source/driver/Castro_advance_ctu.cpp +++ b/Source/driver/Castro_advance_ctu.cpp @@ -492,12 +492,10 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, Real last_dt_subcycle = 1.e200; #ifdef NSE_NET - if (loosen_nse_bailout) { - bool do_loosen = true; - bool old_nse_dx_independent = nse_dx_independent; - bool old_nse_molar_independent = nse_molar_independent; - bool old_nse_skip_molar = nse_skip_molar; - } + bool do_loosen = true; + bool old_nse_dx_independent = nse_dx_independent; + bool old_nse_molar_independent = nse_molar_independent; + bool old_nse_skip_molar = nse_skip_molar; #endif while (subcycle_time < (1.0 - eps) * (time + dt)) { @@ -753,12 +751,10 @@ Castro::subcycle_advance_ctu(const Real time, const Real dt, int amr_iteration, #ifdef NSE_NET // Restore the original nse configuration - - if (loosen_nse_bailout) { - nse_dx_independent = old_nse_dx_independent; - nse_molar_independent = old_nse_molar_independent; - nse_skip_molar = old_nse_skip_molar; - } + + nse_dx_independent = old_nse_dx_independent; + nse_molar_independent = old_nse_molar_independent; + nse_skip_molar = old_nse_skip_molar; #endif // We want to return the subcycled timestep as a suggestion.