Skip to content

Commit

Permalink
standardize integrator error codes (#1234)
Browse files Browse the repository at this point in the history
this will allow us to more easily template the actual_integrator routines
  • Loading branch information
zingale authored Jun 24, 2023
1 parent a39c4ed commit 25258a9
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 61 deletions.
2 changes: 1 addition & 1 deletion integration/BackwardEuler/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void actual_integrator (BurnT& state, const Real dt)
state.n_jac = be.n_jac;
state.n_step = be.n_step;

if (istate < 0) {
if (istate != IERR_SUCCESS) {
state.success = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void actual_integrator (BurnT& state, const Real dt)

normalize_abundances_sdc_burn(state);

if (istate < 0) {
if (istate != IERR_SUCCESS) {
state.success = false;
}

Expand Down
14 changes: 7 additions & 7 deletions integration/BackwardEuler/be_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int single_step (BurnT& state, BeT& be, const Real dt)
{
constexpr int int_neqs = integrator_neqs<BurnT>();

int ierr = BE_SUCCESS;
int ierr = IERR_SUCCESS;
bool converged = false;

// create our current guess for the solution -- just as a first
Expand Down Expand Up @@ -97,7 +97,7 @@ int single_step (BurnT& state, BeT& be, const Real dt)
dgefa<int_neqs>(be.jac, pivot, ierr_linpack);

if (ierr_linpack != 0) {
ierr = BE_LU_DECOMPOSITION_ERROR;
ierr = IERR_LU_DECOMPOSITION_ERROR;
break;
}

Expand Down Expand Up @@ -132,12 +132,12 @@ int single_step (BurnT& state, BeT& be, const Real dt)

if (! converged) {

if (ierr == BE_SUCCESS) {
if (ierr == IERR_SUCCESS) {

// if we didn't set another error, then we probably ran
// out of iterations, so set nonconvergence

ierr = BE_NONCONVERGENCE;
ierr = IERR_CORRECTOR_CONVERGENCE;

// reset the solution to the original
for (int n = 1; n <= int_neqs; n++) {
Expand Down Expand Up @@ -201,7 +201,7 @@ int be_integrator (BurnT& state, BeT& be)
Array1D<Real, 1, int_neqs> y_fine;

ierr = single_step(state, be, dt_sub/2);
if (ierr == BE_SUCCESS) {
if (ierr == IERR_SUCCESS) {
ierr = single_step(state, be, dt_sub/2);

// store the fine dt solution
Expand Down Expand Up @@ -239,7 +239,7 @@ int be_integrator (BurnT& state, BeT& be)
step_success = true;
}

if (ierr == BE_SUCCESS && step_success) {
if (ierr == IERR_SUCCESS && step_success) {

// there were no problems with the mechanics of the step
// (linear algebra, etc.) and we met our error
Expand Down Expand Up @@ -277,7 +277,7 @@ int be_integrator (BurnT& state, BeT& be)
}

if (be.n_step >= ode_max_steps) {
ierr = BE_TOO_MANY_STEPS;
ierr = IERR_TOO_MANY_STEPS;
}

return ierr;
Expand Down
4 changes: 2 additions & 2 deletions integration/RKC/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ void actual_integrator (BurnT& state, Real dt)
// integration was successful.

for (int n = 1; n <= NumSpec; ++n) {
if (rkc_state.y(n) < -rkc_failure_tolerance) {
if (rkc_state.y(n) < -species_failure_tolerance) {
state.success = false;
}

// Don't enforce the condition below
// for primordial chem
if (!use_number_densities) {
if (rkc_state.y(n) > 1.0_rt + rkc_failure_tolerance) {
if (rkc_state.y(n) > 1.0_rt + species_failure_tolerance) {
state.success = false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration/RKC/actual_integrator_simplified_sdc.H
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ void actual_integrator (BurnT& state, Real dt)
}

for (int n = 1; n <= NumSpec; ++n) {
if (rkc_state.y(SFS+n) / state.y[SRHO] < -rkc_failure_tolerance) {
if (rkc_state.y(SFS+n) / state.y[SRHO] < -species_failure_tolerance) {
state.success = false;
}

if (rkc_state.y(SFS+n) / state.y[SRHO] > 1.0_rt + rkc_failure_tolerance) {
if (rkc_state.y(SFS+n) / state.y[SRHO] > 1.0_rt + species_failure_tolerance) {
state.success = false;
}
}
Expand Down
12 changes: 0 additions & 12 deletions integration/RKC/rkc_type.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@

const amrex::Real UROUND = std::numeric_limits<amrex::Real>::epsilon();

// We will use this parameter to determine if a given species abundance
// is unreasonably small or large (each X must satisfy
// -failure_tolerance <= X <= 1.0 + failure_tolerance).
const Real rkc_failure_tolerance = 1.e-2_rt;

enum rkc_errors {
IERR_SUCCESS = 1,
IERR_BAD_INPUTS = -1,
IERR_DT_UNDERFLOW = -2,
IERR_SPRAD_CONVERGENCE = -3,
IERR_TOO_MANY_STEPS = -4};

template <int int_neqs>
struct rkc_t {

Expand Down
8 changes: 4 additions & 4 deletions integration/VODE/actual_integrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ void actual_integrator (BurnT& state, Real dt)
// Add some checks that indicate a burn fail even if VODE thinks the
// integration was successful.

if (istate < 0) {
if (istate != IERR_SUCCESS) {
state.success = false;
}

for (int n = 1; n <= NumSpec; ++n) {
if (vode_state.y(n) < -vode_failure_tolerance) {
if (vode_state.y(n) < -species_failure_tolerance) {
state.success = false;
}

// Don't enforce the condition below
// for primordial chem
if (!use_number_densities) {
if (vode_state.y(n) > 1.0_rt + vode_failure_tolerance) {
if (vode_state.y(n) > 1.0_rt + species_failure_tolerance) {
state.success = false;
}
}
Expand All @@ -153,7 +153,7 @@ void actual_integrator (BurnT& state, Real dt)
// If we failed, print out the current state of the integration.

if (!state.success) {
if (istate != -100) {
if (istate != IERR_ENTERED_NSE) {
#ifndef AMREX_USE_GPU
std::cout << Font::Bold << FGColor::Red << "[ERROR] integration failed in net" << ResetDisplay << std::endl;
std::cout << "istate = " << istate << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions integration/VODE/actual_integrator_simplified_sdc.H
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void actual_integrator (BurnT& state, Real dt)
// Add some checks that indicate a burn fail even if VODE thinks the
// integration was successful.

if (istate < 0) {
if (istate != IERR_SUCCESS) {
state.success = false;
}

Expand All @@ -132,11 +132,11 @@ void actual_integrator (BurnT& state, Real dt)
}

for (int n = 1; n <= NumSpec; ++n) {
if (vode_state.y(SFS+n) / state.y[SRHO] < -vode_failure_tolerance) {
if (vode_state.y(SFS+n) / state.y[SRHO] < -species_failure_tolerance) {
state.success = false;
}

if (vode_state.y(SFS+n) / state.y[SRHO] > 1.0_rt + vode_failure_tolerance) {
if (vode_state.y(SFS+n) / state.y[SRHO] > 1.0_rt + species_failure_tolerance) {
state.success = false;
}
}
Expand All @@ -156,7 +156,7 @@ void actual_integrator (BurnT& state, Real dt)
// If we failed, print out the current state of the integration.

if (!state.success) {
if (istate != -100) {
if (istate != IERR_ENTERED_NSE) {
#ifndef AMREX_USE_GPU
std::cout << Font::Bold << FGColor::Red << "[ERROR] integration failed in net" << ResetDisplay << std::endl;
std::cout << "istate = " << istate << std::endl;
Expand Down
25 changes: 8 additions & 17 deletions integration/VODE/vode_dvode.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int dvode (BurnT& state, DvodeT& vstate)

// Flag determining if we were successful.

int istate = 1;
int istate = IERR_SUCCESS;

// Return if the final time matches the starting time.

Expand Down Expand Up @@ -153,8 +153,7 @@ int dvode (BurnT& state, DvodeT& vstate)

vstate.t = vstate.tn;

istate = -1;
return istate;
return IERR_TOO_MANY_STEPS;

}

Expand Down Expand Up @@ -194,8 +193,7 @@ int dvode (BurnT& state, DvodeT& vstate)
#ifndef AMREX_USE_GPU
std::cout << Font::Bold << FGColor::Red << "DVODE: too much accuracy requested at start of integration" << ResetDisplay << std::endl;
#endif
istate = -3;
return istate;
return IERR_TOO_MUCH_ACCURACY_REQUESTED;
}

// Too much accuracy requested for machine precision.
Expand All @@ -208,8 +206,7 @@ int dvode (BurnT& state, DvodeT& vstate)

vstate.t = vstate.tn;

istate = -2;
return istate;
return IERR_TOO_MUCH_ACCURACY_REQUESTED;

}

Expand All @@ -229,9 +226,7 @@ int dvode (BurnT& state, DvodeT& vstate)
}

vstate.t = vstate.tn;

istate = -4;
return istate;
return IERR_DT_UNDERFLOW;

}
else if (kflag == -2) {
Expand All @@ -245,9 +240,7 @@ int dvode (BurnT& state, DvodeT& vstate)
}

vstate.t = vstate.tn;

istate = -5;
return istate;
return IERR_CORRECTOR_CONVERGENCE;

}

Expand All @@ -272,9 +265,8 @@ int dvode (BurnT& state, DvodeT& vstate)
#endif

if (in_nse(state)) {
istate = -100;
vstate.t = vstate.tn;
return istate;
return IERR_ENTERED_NSE;
}
}
#endif
Expand Down Expand Up @@ -302,8 +294,7 @@ int dvode (BurnT& state, DvodeT& vstate)

vstate.t = vstate.tout;

istate = 2;
return istate;
return IERR_SUCCESS;

}
}
Expand Down
12 changes: 6 additions & 6 deletions integration/VODE/vode_dvstep.H
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ int dvstep (BurnT& state, DvodeT& vstate)

// Constrain abundances such that they are not negative (within a tolerance)
// or greater than one (within a tolerance).
if (vstate.y(i) < -vode_failure_tolerance) {
if (vstate.y(i) < -species_failure_tolerance) {
valid_update = false;
}

// Don't enforce the condition below if
// vstate.y contains number densities
if (!use_number_densities) {
if (vstate.y(i) > 1.0_rt + vode_failure_tolerance) {
if (vstate.y(i) > 1.0_rt + species_failure_tolerance) {
valid_update = false;
}
}
Expand Down Expand Up @@ -293,11 +293,11 @@ int dvstep (BurnT& state, DvodeT& vstate)
break;
}

if (vstate.y(SFS+i) < -vode_failure_tolerance * rho_current) {
if (vstate.y(SFS+i) < -species_failure_tolerance * rho_current) {
valid_update = false;
}

if (vstate.y(SFS+i) > (1.0_rt + vode_failure_tolerance) * rho_current) {
if (vstate.y(SFS+i) > (1.0_rt + species_failure_tolerance) * rho_current) {
valid_update = false;
}

Expand All @@ -311,11 +311,11 @@ int dvstep (BurnT& state, DvodeT& vstate)
// y(2:2+NumSpec-1) = rho X
// y(NumSpec+2) = rho e

if (vstate.y(1+i) < -vode_failure_tolerance * vstate.y(1)) {
if (vstate.y(1+i) < -species_failure_tolerance * vstate.y(1)) {
valid_update = false;
}

if (vstate.y(1+i) > (1.0_rt + vode_failure_tolerance) * vstate.y(1)) {
if (vstate.y(1+i) > (1.0_rt + species_failure_tolerance) * vstate.y(1)) {
valid_update = false;
}
#endif
Expand Down
5 changes: 0 additions & 5 deletions integration/VODE/vode_type.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ const amrex::Real CCMXJ = 0.2e0_rt;

const amrex::Real HMIN = 0.0_rt;

// We will use this parameter to determine if a given species abundance
// is unreasonably small or large (each X must satisfy
// -failure_tolerance <= X <= 1.0 + failure_tolerance).
const Real vode_failure_tolerance = 1.e-2_rt;

// For each species whose abundance is above a certain threshold, we do
// not allow its mass fraction to change by more than a certain amount
// in any integration step.
Expand Down
19 changes: 19 additions & 0 deletions integration/integrator_data.H
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ const int INT_NEQS = SVAR_EVOLVE;
const int INT_NEQS = NumSpec + 2;
#endif


// We will use this parameter to determine if a given species
// abundance is unreasonably small or large (each X must satisfy
// -failure_tolerance <= X <= 1.0 + failure_tolerance).
const Real species_failure_tolerance = 1.e-2_rt;

enum integrator_errors {
IERR_SUCCESS = 1,
IERR_BAD_INPUTS = -1,
IERR_DT_UNDERFLOW = -2,
IERR_SPRAD_CONVERGENCE = -3,
IERR_TOO_MANY_STEPS = -4,
IERR_TOO_MUCH_ACCURACY_REQUESTED = -5,
IERR_CORRECTOR_CONVERGENCE = -6,
IERR_LU_DECOMPOSITION_ERROR = -7,
IERR_ENTERED_NSE = -100
};


template<typename BurnT>
constexpr int integrator_neqs ()
{
Expand Down

0 comments on commit 25258a9

Please sign in to comment.