Skip to content

Commit 3aa62dd

Browse files
committed
added: stopping criterion in time stepping
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
1 parent ad42645 commit 3aa62dd

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/ASM/TimeDomain.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ struct TimeDomain
2525
double dt; //!< Current timestep (or load parameter) increment
2626
double dtn; //!< Previous timestep (or load parameter) increment
2727
double CFL; //!< Current CFL number (used by CFD simulators)
28+
double incNorm; //!< Norm of change between timesteps
2829
int it; //!< Current iteration within current time/load step
2930
char first; //!< If \e true, this is the first load/time step
3031

3132
//! \brief Default constructor.
3233
explicit TimeDomain(int i = 0, bool f = true) : it(i), first(f)
33-
{ t = dt = dtn = CFL = 0.0; }
34+
{ t = dt = dtn = CFL = incNorm = 0.0; }
3435
//! \brief Constructor for linear problems with fixed (non-zero) time.
3536
explicit TimeDomain(double t0) : t(t0), it(0), first(true)
36-
{ dt = dtn = CFL = 0.0; }
37+
{ dt = dtn = CFL = incNorm = 0.0; }
3738
};
3839

3940
#endif

src/SIM/TimeStep.C

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ TimeStep::TimeStep () : step(0), iter(time.it), lstep(0)
3232
f1 = 1.5;
3333
f2 = 0.25;
3434
maxStep = niter = 0;
35+
stop_tol = 0.0;
3536
stepIt = mySteps.end();
3637
}
3738

@@ -51,6 +52,7 @@ TimeStep& TimeStep::operator= (const TimeStep& ts)
5152
maxStep = ts.maxStep;
5253
niter = ts.niter;
5354
iter = ts.iter;
55+
stop_tol = ts.stop_tol;
5456

5557
time = ts.time;
5658
mySteps = ts.mySteps;
@@ -110,6 +112,7 @@ bool TimeStep::parse (const TiXmlElement* elem)
110112
utl::getAttribute(elem,"dtMax",dtMax);
111113
utl::getAttribute(elem,"maxCFL",maxCFL);
112114
utl::getAttribute(elem,"nInitStep",nInitStep);
115+
utl::getAttribute(elem,"stop_tolerance",stop_tol);
113116
utl::getAttribute(elem,"maxStep",maxStep);
114117
utl::getAttribute(elem,"f1",f1);
115118
utl::getAttribute(elem,"f2",f2);
@@ -266,6 +269,12 @@ bool TimeStep::increment ()
266269
<< std::endl;
267270
return false;
268271
}
272+
else if (time.incNorm > 0.0 && time.incNorm < stop_tol)
273+
{
274+
IFEM::cout <<"\n ** Terminating, solution increment norm "
275+
<< time.incNorm << " less than tolerance " << stop_tol << std::endl;
276+
return false;
277+
}
269278

270279
niter = iter;
271280
time.t += time.dt;

src/SIM/TimeStep.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class TimeStep
6262
//! \brief Returns \e true if the end of the simulation has been reached.
6363
bool finished() const;
6464

65+
//! \brief Returns configured stopping tolerance.
66+
double stopTolerance() const { return stop_tol; }
67+
6568
//! \brief Serialize internal state for restarting purposes.
6669
//! \param data Container for serialized data
6770
bool serialize(std::map<std::string,std::string>& data) const;
@@ -87,6 +90,8 @@ class TimeStep
8790
double f1; //!< Scale factor for increased time step size
8891
double f2; //!< Scale factor for reduced time step size
8992

93+
double stop_tol; //!< Stop time step loop if incNorm < stop_tol
94+
9095
typedef std::pair<std::vector<double>,double> Step; //!< Time step definition
9196
typedef std::vector<Step> TimeSteps; //!< Time step container
9297

0 commit comments

Comments
 (0)