Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
TimeStepper Class Reference

#include <TimeStepper.hpp>

+ Collaboration diagram for TimeStepper:

Public Member Functions

 TimeStepper (double startTime, double endTime, double dt, bool enforceConstantTimeStep=false, std::vector< double > additionalTimes=std::vector< double >())
 
void AdvanceOneTimeStep ()
 
double GetTime () const
 
double GetNextTime () const
 
double GetNextTimeStep ()
 
double GetIdealTimeStep ()
 
bool IsTimeAtEnd () const
 
unsigned EstimateTimeSteps () const
 
unsigned GetTotalTimeStepsTaken () const
 
void ResetTimeStep (double dt)
 

Private Member Functions

double CalculateNextTime ()
 
template<class Archive >
void serialize (Archive &archive, const unsigned int version)
 

Private Attributes

double mStart
 
double mEnd
 
double mDt
 
unsigned mTotalTimeStepsTaken
 
unsigned mAdditionalTimesReachedDeprecated
 
double mTime
 
double mNextTime
 
double mEpsilon
 
std::vector< doublemAdditionalTimesDeprecated
 

Friends

class TestTimeStepper
 
class boost::serialization::access
 

Detailed Description

A helper class that provides a robust way to deal with time loops.

An incremented integer counter is used to calculate the current time and ensure that the correct end time.

Definition at line 52 of file TimeStepper.hpp.

Constructor & Destructor Documentation

◆ TimeStepper() [1/2]

TimeStepper::TimeStepper ( )
inlineprivate

Definition at line 59 of file TimeStepper.hpp.

◆ TimeStepper() [2/2]

TimeStepper::TimeStepper ( double  startTime,
double  endTime,
double  dt,
bool  enforceConstantTimeStep = false,
std::vector< double additionalTimes = std::vector<double> () 
)

Create a new time stepper over some simulation interval. Time units are not specified, but all parameters should have consistent units.

Parameters
startTimethe start of the interval
endTimethe end of the interval
dtthe time step to use.
enforceConstantTimeStepIf this is true the stepper estimates whether non-constant timesteps will be used and quits if so.
additionalTimesIf the timestepper needs to stop at certain additional times, they can be passed in in this std::vector. Defaults to empty. These times must be in ascending order. DEPRECATION: Note that these additional times are checked in order to ensure that the stepper will stop at these times anyway. (For example we want to check that new events such as electrodes switching on will be detected in a regular time loop.) New additional times are not added but instead throw an exception.

Definition at line 43 of file TimeStepper.cpp.

References CalculateNextTime(), EstimateTimeSteps(), EXCEPTION, mDt, mEnd, mEpsilon, mNextTime, and mStart.

Member Function Documentation

◆ AdvanceOneTimeStep()

◆ CalculateNextTime()

double TimeStepper::CalculateNextTime ( )
private
Returns
Compute what the time will be at the next time step.

Definition at line 106 of file TimeStepper.cpp.

References mAdditionalTimesDeprecated, mDt, mEnd, mEpsilon, mStart, and mTotalTimeStepsTaken.

Referenced by TimeStepper(), AdvanceOneTimeStep(), and ResetTimeStep().

◆ EstimateTimeSteps()

unsigned TimeStepper::EstimateTimeSteps ( ) const
Returns
Estimate number of time steps remaining, which may be an overestimate. Used to reserve memory for writing intermediate solutions.

Definition at line 170 of file TimeStepper.cpp.

References mDt, mEnd, and mStart.

Referenced by TimeStepper(), ExtendedBidomainProblem< DIM >::DefineWriterColumns(), AbstractOneStepIvpOdeSolver::Solve(), CvodeAdaptor::Solve(), and AbstractCvodeSystem::Solve().

◆ GetIdealTimeStep()

double TimeStepper::GetIdealTimeStep ( )
Returns
Get the size of the ideal time step (as set in the constructor. Note when a fixed time step is used GetNextTimeStep() == GetIdealTimeStep() until the end of the simulation when GetNextTimeStep() == 0.0

Definition at line 160 of file TimeStepper.cpp.

References mDt.

◆ GetNextTime()

◆ GetNextTimeStep()

double TimeStepper::GetNextTimeStep ( )
Returns
Get the size of the next time step which will be taken.

Note that this is often reported as the ideal timestep.

The actual time step is mNextTime - mTime which could be evaluated as GetNextTime() - GetTime() = mNextTime - mTime ~= mStart + (mTotalTimeStepsTaken + 1)*mDt - mTime ~= mStart + (mTotalTimeStepsTaken + 1)*mDt - (mStart + mTotalTimeStepsTaken*mDt) ~= mDt This wouldn't evaluate to mDt in general but to within 2*mEpsilon <= 2*DBL_EPSILON*mEnd*mDt When mEnd and/or mStart are a long way from zero then the value reported mNextTime - mTime will differ from mDt, even when the actual step is mDt

Definition at line 149 of file TimeStepper.cpp.

References mAdditionalTimesDeprecated, mDt, mEnd, mNextTime, and mTime.

Referenced by AbstractOneStepIvpOdeSolver::InternalSolve(), and AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve().

◆ GetTime()

◆ GetTotalTimeStepsTaken()

◆ IsTimeAtEnd()

◆ ResetTimeStep()

void TimeStepper::ResetTimeStep ( double  dt)

Set the time step to use for adaptive time integration. Note that this also resets mStart to be the current time and zeroes mTotalTimeStepsTaken.

Parameters
dtis the new time-step

Definition at line 180 of file TimeStepper.cpp.

References CalculateNextTime(), mDt, mNextTime, mStart, mTime, and mTotalTimeStepsTaken.

Referenced by AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve().

◆ serialize()

template<class Archive >
void TimeStepper::serialize ( Archive &  archive,
const unsigned int  version 
)
inlineprivate
Parameters
archivethe archive
versionthe current version of this class

Definition at line 193 of file TimeStepper.hpp.

References mAdditionalTimesDeprecated, mAdditionalTimesReachedDeprecated, mDt, mEnd, mEpsilon, mNextTime, mStart, mTime, and mTotalTimeStepsTaken.

Friends And Related Symbol Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Needed for serialization.

Definition at line 185 of file TimeStepper.hpp.

◆ TestTimeStepper

friend class TestTimeStepper
friend

Definition at line 54 of file TimeStepper.hpp.

Member Data Documentation

◆ mAdditionalTimesDeprecated

std::vector<double> TimeStepper::mAdditionalTimesDeprecated
private

DEPRECATED Vector to store the additional times the stepper must stop at.

Definition at line 182 of file TimeStepper.hpp.

Referenced by CalculateNextTime(), GetNextTimeStep(), and serialize().

◆ mAdditionalTimesReachedDeprecated

unsigned TimeStepper::mAdditionalTimesReachedDeprecated
private

DEPRECATED: The number of times one of the 'additional times' has been passed.

Definition at line 163 of file TimeStepper.hpp.

Referenced by serialize().

◆ mDt

double TimeStepper::mDt
private

◆ mEnd

double TimeStepper::mEnd
private

The end time.

Definition at line 154 of file TimeStepper.hpp.

Referenced by TimeStepper(), CalculateNextTime(), EstimateTimeSteps(), GetNextTimeStep(), IsTimeAtEnd(), and serialize().

◆ mEpsilon

double TimeStepper::mEpsilon
private

An architecture-dependent scaling factor. This is so that we can compare relative to the end time when mEnd is large. mEpsilon = DBL_EPSILON when mEnd is small = mEnd*DBL_EPSILON when mEnd is large

Definition at line 176 of file TimeStepper.hpp.

Referenced by TimeStepper(), CalculateNextTime(), and serialize().

◆ mNextTime

double TimeStepper::mNextTime
private

What the time will be after the next time step.

Definition at line 169 of file TimeStepper.hpp.

Referenced by TimeStepper(), AdvanceOneTimeStep(), GetNextTime(), GetNextTimeStep(), ResetTimeStep(), and serialize().

◆ mStart

double TimeStepper::mStart
private

The start time.

Definition at line 151 of file TimeStepper.hpp.

Referenced by TimeStepper(), CalculateNextTime(), EstimateTimeSteps(), ResetTimeStep(), and serialize().

◆ mTime

double TimeStepper::mTime
private

The current time.

Definition at line 166 of file TimeStepper.hpp.

Referenced by AdvanceOneTimeStep(), GetNextTimeStep(), GetTime(), IsTimeAtEnd(), ResetTimeStep(), and serialize().

◆ mTotalTimeStepsTaken

unsigned TimeStepper::mTotalTimeStepsTaken
private

The total number of time steps taken.

Definition at line 160 of file TimeStepper.hpp.

Referenced by AdvanceOneTimeStep(), CalculateNextTime(), GetTotalTimeStepsTaken(), ResetTimeStep(), and serialize().


The documentation for this class was generated from the following files: