Skip to content

Commit

Permalink
added: stopping criterion in time stepping
Browse files Browse the repository at this point in the history
this allows to stop the time stepping based on
some kind of application-defined norm. e.g.
when the norm of increments between timesteps falls
below some threshold
  • Loading branch information
akva2 committed May 19, 2022
1 parent ad42645 commit 5727aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/SIM/TimeStep.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ TimeStep::TimeStep () : step(0), iter(time.it), lstep(0)
f1 = 1.5;
f2 = 0.25;
maxStep = niter = 0;
stop_tol = 0.0;
incNorm = 1.0;
stepIt = mySteps.end();
}

Expand All @@ -51,6 +53,8 @@ TimeStep& TimeStep::operator= (const TimeStep& ts)
maxStep = ts.maxStep;
niter = ts.niter;
iter = ts.iter;
stop_tol = ts.stop_tol;
incNorm = ts.incNorm;

time = ts.time;
mySteps = ts.mySteps;
Expand Down Expand Up @@ -110,6 +114,7 @@ bool TimeStep::parse (const TiXmlElement* elem)
utl::getAttribute(elem,"dtMax",dtMax);
utl::getAttribute(elem,"maxCFL",maxCFL);
utl::getAttribute(elem,"nInitStep",nInitStep);
utl::getAttribute(elem,"stop_tolerance",stop_tol);
utl::getAttribute(elem,"maxStep",maxStep);
utl::getAttribute(elem,"f1",f1);
utl::getAttribute(elem,"f2",f2);
Expand Down Expand Up @@ -266,6 +271,12 @@ bool TimeStep::increment ()
<< std::endl;
return false;
}
else if (incNorm < stop_tol)
{
IFEM::cout <<"\n ** Terminating, solution increment norm "
<< incNorm << " less than tolerance " << stop_tol << std::endl;
return false;
}

niter = iter;
time.t += time.dt;
Expand Down
3 changes: 3 additions & 0 deletions src/SIM/TimeStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TimeStep
double starTime; //!< Start time of simulation
double stopTime; //!< Stop time of simulation
double maxCFL; //!< CFL restriction on time step size (0.0: no restriction)
double incNorm; //!< Norm of change between timesteps

private:
int niter; //!< Number of iterations in previous time step
Expand All @@ -87,6 +88,8 @@ class TimeStep
double f1; //!< Scale factor for increased time step size
double f2; //!< Scale factor for reduced time step size

double stop_tol; //!< Stop time step loop if incNorm < stop_tol

typedef std::pair<std::vector<double>,double> Step; //!< Time step definition
typedef std::vector<Step> TimeSteps; //!< Time step container

Expand Down

0 comments on commit 5727aa9

Please sign in to comment.