Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry framework to burn #969

Merged
merged 38 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d12f9da
add retry framework to burn
zingale Aug 22, 2022
43034ab
Merge branch 'development' into retry_retry
zingale Aug 23, 2022
fef4e7e
more work on the retry mechanism
zingale Aug 23, 2022
763baad
fix compilation
zingale Aug 23, 2022
e4bba82
fix logic
zingale Aug 25, 2022
9443e2d
fix screening
zingale Sep 2, 2022
afb6c87
update benchmarks
zingale Sep 2, 2022
176c85d
Merge branch 'development' into fix_approx_screening
zingale Sep 5, 2022
92c8856
Merge branch 'development' into retry_retry
zingale Sep 7, 2022
cfa4619
Merge branch 'development' into retry_retry
zingale Sep 7, 2022
a8e00ba
Merge branch 'development' into fix_approx_screening
zingale Sep 7, 2022
58640e6
Merge branch 'fix_approx_screening' into retry_retry
zingale Sep 7, 2022
66d64da
Merge branch 'retry_retry' of github.com:zingale/Microphysics into re…
zingale Sep 7, 2022
cf7136b
Merge branch 'development' into retry_retry
zingale Sep 7, 2022
7eb5621
Merge branch 'retry_retry' of github.com:zingale/Microphysics into re…
zingale Sep 7, 2022
1d2447f
Merge branch 'development' into retry_retry
zingale Sep 27, 2022
5815195
Merge branch 'development' into retry_retry
zingale Oct 4, 2022
6590ff4
Merge branch 'development' into retry_retry
zingale Oct 20, 2022
0e176bf
Merge branch 'development' into retry_retry
zingale Oct 28, 2022
7403ee1
Merge branch 'development' into retry_retry
zingale Nov 1, 2022
bc6e870
Merge branch 'development' into retry_retry
zingale Nov 7, 2022
3f46561
Merge branch 'development' into retry_retry
zingale Nov 19, 2022
4ccaa00
add retry hooks
zingale Nov 19, 2022
af94192
Merge branch 'development' into retry_retry
zingale Nov 19, 2022
3b2172a
Merge branch 'development' into retry_retry
zingale Nov 30, 2022
d0d2f42
fix ifdef
zingale Nov 30, 2022
d19510f
Merge branch 'development' into retry_retry
zingale Dec 4, 2022
7c382aa
Merge branch 'development' into retry_retry
zingale Dec 16, 2022
296debe
fix compilation
zingale Dec 16, 2022
0aaf04d
Merge branch 'development' into retry_retry
zingale Jan 23, 2023
c155a94
Merge branch 'development' into retry_retry
zingale Jun 16, 2023
97cb2b2
Merge branch 'development' into retry_retry
zingale Dec 1, 2023
7d5f342
Merge branch 'development' into retry_retry
zingale Jan 11, 2024
36ff64c
Merge branch 'development' into retry_retry
zingale Feb 2, 2024
1acb93d
fix build
zingale Feb 2, 2024
461079b
update interface
zingale Feb 2, 2024
699d8be
template out the copy
zingale Feb 2, 2024
a16e59a
make if test easier to understand:w
zingale Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions integration/BackwardEuler/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,34 @@

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, const Real dt)
void actual_integrator (BurnT& state, const Real dt, bool is_retry=false)
{
constexpr int int_neqs = integrator_neqs<BurnT>();

be_t<int_neqs> be;

// Set the tolerances.

be.atol_spec = atol_spec; // mass fractions
be.atol_enuc = atol_enuc; // energy generated
if (!is_retry) {
be.atol_spec = atol_spec; // mass fractions
be.atol_enuc = atol_enuc; // energy generated

be.rtol_spec = rtol_spec; // mass fractions
be.rtol_enuc = rtol_enuc; // energy generated
be.rtol_spec = rtol_spec; // mass fractions
be.rtol_enuc = rtol_enuc; // energy generated
} else {
be.atol_spec = retry_atol_spec; // mass fractions
be.atol_enuc = retry_atol_enuc; // energy generated

be.rtol_spec = retry_rtol_spec; // mass fractions
be.rtol_enuc = retry_rtol_enuc; // energy generated
}

// set the Jacobian type
be.jacobian_type = jacobian;
if (is_retry && retry_swap_jacobian) {
be.jacobian_type = (jacobian == 1) ? 2 : 1;
} else {
be.jacobian_type = jacobian;
}

// Start off by assuming a successful burn.

Expand Down
46 changes: 33 additions & 13 deletions integration/BackwardEuler/actual_integrator_simplified_sdc.H
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, const Real dt)
void actual_integrator (BurnT& state, const Real dt, bool is_retry=false)
{
constexpr int int_neqs = integrator_neqs<BurnT>();

be_t<int_neqs> be;

// set the Jacobian type
be.jacobian_type = jacobian;

// Start off by assuming a successful burn.

state.success = true;
Expand All @@ -28,6 +25,13 @@ void actual_integrator (BurnT& state, const Real dt)
be.t = 0.0;
be.tout = dt;

// set the Jacobian type
if (is_retry && retry_swap_jacobian) {
be.jacobian_type = (jacobian == 1) ? 2 : 1;
} else {
be.jacobian_type = jacobian;
}

// Fill in the initial integration state.

burn_to_int(state, be);
Expand Down Expand Up @@ -60,22 +64,38 @@ void actual_integrator (BurnT& state, const Real dt)

Real sdc_min_density = amrex::min(state.rho, state.rho_orig + state.ydot_a[SRHO] * dt);

be.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac;
be.rtol_enuc = rtol_enuc * sdc_tol_fac;
if (!is_retry) {

be.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac;
be.rtol_enuc = rtol_enuc * sdc_tol_fac;

// Note: we define the input atol for species to refer only to the
// mass fraction part, and we multiply by a representative density
// so that atol becomes an absolutely tolerance on (rho X)

be.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac;
be.rtol_spec = rtol_spec * sdc_tol_fac;

} else {

be.atol_enuc = sdc_min_density * retry_atol_enuc * sdc_tol_fac;
be.rtol_enuc = retry_rtol_enuc * sdc_tol_fac;

// Note: we define the input atol for species to refer only to the
// mass fraction part, and we multiply by a representative density
// so that atol becomes an absolutely tolerance on (rho X)

be.atol_spec = sdc_min_density * retry_atol_spec * sdc_tol_fac;
be.rtol_spec = retry_rtol_spec * sdc_tol_fac;

}

if (scale_system) {
// the absolute tol for energy needs to reflect the scaled
// energy the integrator sees
be.atol_enuc /= state.e_scale;
}

// Note: we define the input atol for species to refer only to the
// mass fraction part, and we multiply by a representative density
// so that atol becomes an absolutely tolerance on (rho X)

be.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac;
be.rtol_spec = rtol_spec * sdc_tol_fac;

// Call the integration routine.

int istate = be_integrator(state, be);
Expand Down
2 changes: 1 addition & 1 deletion integration/ForwardEuler/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void initialize_int_state (IntT& int_state)

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, Real dt)
void actual_integrator (BurnT& state, Real dt, bool is_retry=false)
{
using namespace microphysics::forward_euler;

Expand Down
2 changes: 1 addition & 1 deletion integration/QSS/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool corrector (const BurnT& state_0, const Array1D<Real, 1, NumSpec>& f_minus_0

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, Real dt)
void actual_integrator (BurnT& state, Real dt, const bool is_retry=false)
{
initialize_state(state);

Expand Down
16 changes: 15 additions & 1 deletion integration/RKC/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, Real dt)
void actual_integrator (BurnT& state, Real dt, bool is_retry=false)
{
constexpr int int_neqs = integrator_neqs<BurnT>();

rkc_t<int_neqs> rkc_state{};

// Set the tolerances.

if (!is_retry) {
rkc_state.atol_spec = atol_spec; // mass fractions
rkc_state.atol_enuc = atol_enuc; // energy generated

rkc_state.rtol_spec = rtol_spec; // mass fractions
rkc_state.rtol_enuc = rtol_enuc; // energy generated
} else {
rkc_state.atol_spec = retry_atol_spec; // mass fractions
rkc_state.atol_enuc = retry_atol_enuc; // energy generated

rkc_state.rtol_spec = retry_rtol_spec; // mass fractions
rkc_state.rtol_enuc = retry_rtol_enuc; // energy generated
}

rkc_state.atol_spec = atol_spec; // mass fractions
rkc_state.atol_enuc = atol_enuc; // energy generated

Expand Down
24 changes: 18 additions & 6 deletions integration/VODE/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,34 @@ using namespace integrator_rp;

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, Real dt)
void actual_integrator (BurnT& state, Real dt, bool is_retry=false)
{
constexpr int int_neqs = integrator_neqs<BurnT>();

dvode_t<int_neqs> vode_state{};

// Set the tolerances.

vode_state.atol_spec = atol_spec; // mass fractions
vode_state.atol_enuc = atol_enuc; // energy generated
if (!is_retry) {
vode_state.atol_spec = atol_spec; // mass fractions
vode_state.atol_enuc = atol_enuc; // energy generated

vode_state.rtol_spec = rtol_spec; // mass fractions
vode_state.rtol_enuc = rtol_enuc; // energy generated
vode_state.rtol_spec = rtol_spec; // mass fractions
vode_state.rtol_enuc = rtol_enuc; // energy generated
} else {
vode_state.atol_spec = retry_atol_spec; // mass fractions
vode_state.atol_enuc = retry_atol_enuc; // energy generated

vode_state.rtol_spec = retry_rtol_spec; // mass fractions
vode_state.rtol_enuc = retry_rtol_enuc; // energy generated
}

// set the Jacobian type
vode_state.jacobian_type = static_cast<short>(jacobian);
if (is_retry && retry_swap_jacobian) {
vode_state.jacobian_type = (jacobian == 1) ? 2 : 1;
} else {
vode_state.jacobian_type = static_cast<short>(jacobian);
}

// Start off by assuming a successful burn.

Expand Down
46 changes: 33 additions & 13 deletions integration/VODE/actual_integrator_simplified_sdc.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ using namespace integrator_rp;

template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void actual_integrator (BurnT& state, Real dt)
void actual_integrator (BurnT& state, Real dt, bool is_retry=false)
{
constexpr int int_neqs = integrator_neqs<BurnT>();

dvode_t<int_neqs> vode_state{};

// set the Jacobian type
vode_state.jacobian_type = jacobian;

// Start off by assuming a successful burn.

state.success = true;
Expand All @@ -40,6 +37,13 @@ void actual_integrator (BurnT& state, Real dt)

vode_state.HMXI = 1.0_rt / ode_max_dt;

// set the Jacobian type
if (is_retry && retry_swap_jacobian) {
vode_state.jacobian_type = (jacobian == 1) ? 2 : 1;
} else {
vode_state.jacobian_type = jacobian;
}

// Fill in the initial integration state.

burn_to_int(state, vode_state);
Expand Down Expand Up @@ -72,22 +76,38 @@ void actual_integrator (BurnT& state, Real dt)

Real sdc_min_density = amrex::min(state.rho, state.rho_orig + state.ydot_a[SRHO] * dt);

vode_state.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac;
vode_state.rtol_enuc = rtol_enuc * sdc_tol_fac;
if (!is_retry) {

vode_state.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac;
vode_state.rtol_enuc = rtol_enuc * sdc_tol_fac;

// Note: we define the input atol for species to refer only to the
// mass fraction part, and we multiply by a representative density
// so that atol becomes an absolutely tolerance on (rho X)

vode_state.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac;
vode_state.rtol_spec = rtol_spec * sdc_tol_fac;

} else {

vode_state.atol_enuc = sdc_min_density * retry_atol_enuc * sdc_tol_fac;
vode_state.rtol_enuc = retry_rtol_enuc * sdc_tol_fac;

// Note: we define the input atol for species to refer only to the
// mass fraction part, and we multiply by a representative density
// so that atol becomes an absolutely tolerance on (rho X)

vode_state.atol_spec = sdc_min_density * retry_atol_spec * sdc_tol_fac;
vode_state.rtol_spec = retry_rtol_spec * sdc_tol_fac;

}

if (scale_system) {
// the absolute tol for energy needs to reflect the scaled
// energy the integrator sees
vode_state.atol_enuc /= state.e_scale;
}

// Note: we define the input atol for species to refer only to the
// mass fraction part, and we multiply by a representative density
// so that atol becomes an absolutely tolerance on (rho X)

vode_state.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac;
vode_state.rtol_spec = rtol_spec * sdc_tol_fac;

// Call the integration routine.

int istate = dvode(state, vode_state);
Expand Down
15 changes: 15 additions & 0 deletions integration/_parameters
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ nonaka_k integer 0
nonaka_level integer 0
nonaka_file character "nonaka_plot.dat"

# do we retry a failed burn with different parameters?
use_burn_retry integer 0

# do we swap the Jacobian (from analytic to numerical or vice versa) on
# a retry?
retry_swap_jacobian integer 1

# Tolerances for the solver (relative and absolute), for the
# species and energy equations.
retry_rtol_spec real 1.d-12
retry_rtol_enuc real 1.d-6

retry_atol_spec real 1.d-8
retry_atol_enuc real 1.d-6

# in the clean_state process, do we clip the species such that they
# are in [0, 1]?
do_species_clip integer 1
Expand Down
32 changes: 31 additions & 1 deletion integration/integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@
#include <actual_integrator.H>
#endif

template <typename BurnT, bool enable_retry>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void integrator_wrapper (BurnT& state, Real dt)
{

if constexpr (enable_retry) {
burn_t old_state{state};

actual_integrator(state, dt);

if (!state.success) {
state = old_state;
const bool is_retry = true;
actual_integrator(state, dt, is_retry);
}
} else {
actual_integrator(state, dt);
}

}


template <typename BurnT>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void integrator (BurnT& state, Real dt)
{
actual_integrator(state, dt);

if (integrator_rp::use_burn_retry) {
constexpr bool enable_retry{true};
integrator_wrapper<BurnT, enable_retry>(state, dt);
} else {
constexpr bool enable_retry{false};
integrator_wrapper<BurnT, enable_retry>(state, dt);

}
}

#endif