Skip to content

Commit

Permalink
move tolerances to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
gardner48 committed Jun 19, 2024
1 parent 2db0d85 commit 43912e8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
35 changes: 35 additions & 0 deletions Src/Base/AMReX_IntegratorBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ protected:
*/
int max_steps = 500;

/**
* \brief Relative tolerance for adaptive time stepping (Real)
*/
amrex::Real rel_tol = 1.0e-4;

/**
* \brief Absolute tolerance for adaptive time stepping (Real)
*/
amrex::Real abs_tol = 1.0e-9;

/**
* \brief Relative tolerance for adaptive time stepping at the fast time
* scale (Real)
*/
amrex::Real fast_rel_tol = 1.0e-4;

/**
* \brief Absolute tolerance for adaptive time stepping at the fast time
* scale (Real)
*/
amrex::Real fast_abs_tol = 1.0e-9;


public:
IntegratorBase () = default;

Expand Down Expand Up @@ -340,6 +363,18 @@ public:
max_steps = steps;
}

void set_tolerances (amrex::Real rtol, amrex::Real atol)
{
rel_tol = rtol;
abs_tol = atol;
}

void set_fast_tolerances (amrex::Real rtol, amrex::Real atol)
{
fast_rel_tol = rtol;
fast_abs_tol = atol;
}

/**
* \brief Take a single time step from (time, S_old) to (time + dt, S_new)
* with the given step size.
Expand Down
15 changes: 15 additions & 0 deletions Src/Base/AMReX_TimeIntegrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ public:
integrator_ptr->set_adaptive_fast_step();
}

void set_max_steps (int steps)
{
integrator_ptr->set_max_steps(steps);
}

void set_tolerances (amrex::Real rtol, amrex::Real atol)
{
integrator_ptr->set_tolerances(rtol, atol);
}

void set_fast_tolerances (amrex::Real rtol, amrex::Real atol)
{
integrator_ptr->set_fast_tolerances(rtol, atol);
}

void advance (T& S_old, T& S_new, amrex::Real time, const amrex::Real dt)
{
integrator_ptr->advance(S_old, S_new, time, dt);
Expand Down
10 changes: 3 additions & 7 deletions Src/Extern/SUNDIALS/AMReX_SundialsIntegrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,11 @@ private:
// Single rate or slow time scale
void *arkode_mem = nullptr;
SUNLinearSolver LS = nullptr;
Real reltol = 1.0e-4;
Real abstol = 1.0e-9;

// Fast time scale
void *arkode_fast_mem = nullptr;
MRIStepInnerStepper fast_stepper = nullptr;
SUNLinearSolver fast_LS = nullptr;
Real fast_reltol = 1.0e-4;
Real fast_abstol = 1.0e-9;

void initialize_parameters ()
{
Expand Down Expand Up @@ -188,7 +184,7 @@ private:
ARKStepSetUserData(arkode_mem, &udata);

// Set integrator tolerances
ARKStepSStolerances(arkode_mem, reltol, abstol);
ARKStepSStolerances(arkode_mem, BaseT::rel_tol, BaseT::abs_tol);

// Create and attach linear solver for implicit methods
if (type == "DIRK" || type == "IMEX-RK") {
Expand Down Expand Up @@ -230,7 +226,7 @@ private:
ARKStepSetUserData(arkode_fast_mem, &udata);

// Set integrator tolerances
ARKStepSStolerances(arkode_fast_mem, fast_reltol, fast_abstol);
ARKStepSStolerances(arkode_fast_mem, BaseT::fast_rel_tol, BaseT::fast_abs_tol);

// Set post stage and step function
ARKStepSetPostprocessStageFn(arkode_fast_mem, SundialsUserFun::post_fast_stage);
Expand Down Expand Up @@ -267,7 +263,7 @@ private:
MRIStepSetUserData(arkode_mem, &udata);

// Set integrator tolerances
MRIStepSStolerances(arkode_mem, reltol, abstol);
MRIStepSStolerances(arkode_mem, BaseT::rel_tol, BaseT::abs_tol);

// Create and attach linear solver
if (type == "IM-MRI" || type == "IMEX-MRI") {
Expand Down

0 comments on commit 43912e8

Please sign in to comment.