Chaste Release::3.1
|
#include <TimeStepper.hpp>
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 | mAdditionalTimesReached |
double | mTime |
double | mNextTime |
double | mEpsilon |
std::vector< double > | mAdditionalTimes |
Friends | |
class | TestTimeStepper |
class | boost::serialization::access |
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.
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.
startTime | the start of the interval |
endTime | the end of the interval |
dt | the time step to use. |
enforceConstantTimeStep | If this is true the stepper estimates whether non-constant timesteps will be used and quits if so. |
additionalTimes | If 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. Note that if, for example, start=0, end=0.5, dt=0.1, and the additional stopping time is 0.33, the times used will be 0,0.1,0.2,0.3,0.33,0.4,0.5 NOT ..,0.33,0.43,0.5 |
Definition at line 43 of file TimeStepper.cpp.
References CalculateNextTime(), EstimateTimeSteps(), EXCEPTION, mAdditionalTimes, mDt, mEnd, mEpsilon, mNextTime, and mStart.
void TimeStepper::AdvanceOneTimeStep | ( | ) |
Step forward one step in time and update member variables.
Note that this should be used in conjuction with (not) IsTimeAtEnd because increment past the end of a simulation will throw an exception
Definition at line 134 of file TimeStepper.cpp.
References CalculateNextTime(), EXCEPTION, mNextTime, mTime, and mTotalTimeStepsTaken.
Referenced by AbstractRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractOneStepIvpOdeSolver::InternalSolve(), NhsModelWithBackwardSolver::RunDoNotUpdate(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), CvodeAdaptor::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AbstractCvodeSystem::Solve(), AdaptiveBidomainProblem::Solve(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractRushLarsenCardiacCell::SolveAndUpdateState(), AbstractBackwardEulerCardiacCell< SIZE >::SolveAndUpdateState(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
double TimeStepper::CalculateNextTime | ( | ) | [private] |
Compute what the time will be after the next time step.
Definition at line 105 of file TimeStepper.cpp.
References mAdditionalTimes, mAdditionalTimesReached, mDt, mEnd, mEpsilon, mStart, and mTotalTimeStepsTaken.
Referenced by AdvanceOneTimeStep(), ResetTimeStep(), and TimeStepper().
unsigned TimeStepper::EstimateTimeSteps | ( | ) | const |
Estimate number of time steps remaining, which may be an overestimate. Used to reserve memory for writing intermediate solutions.
Definition at line 191 of file TimeStepper.cpp.
References mAdditionalTimes, mDt, mEnd, and mStart.
Referenced by AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::DefineWriterColumns(), CvodeAdaptor::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AbstractCvodeSystem::Solve(), and TimeStepper().
double TimeStepper::GetIdealTimeStep | ( | ) |
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 181 of file TimeStepper.cpp.
References mDt.
double TimeStepper::GetNextTime | ( | ) | const |
Get the value time will take at the next step.
Definition at line 155 of file TimeStepper.cpp.
References mNextTime.
Referenced by CvodeAdaptor::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AbstractCvodeSystem::Solve(), AdaptiveBidomainProblem::Solve(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
double TimeStepper::GetNextTimeStep | ( | ) |
Get the size of the next time step which will be taken. GetNextTimeStep() == GetNextTime() - GetTime()
Definition at line 160 of file TimeStepper.cpp.
References mAdditionalTimes, mAdditionalTimesReached, mDt, mEnd, mNextTime, and mTime.
Referenced by AbstractOneStepIvpOdeSolver::InternalSolve(), and AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve().
double TimeStepper::GetTime | ( | ) | const |
Get the time.
Definition at line 150 of file TimeStepper.cpp.
References mTime.
Referenced by AbstractRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractOneStepIvpOdeSolver::InternalSolve(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AdaptiveBidomainProblem::Solve(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractRushLarsenCardiacCell::SolveAndUpdateState(), AbstractBackwardEulerCardiacCell< SIZE >::SolveAndUpdateState(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
unsigned TimeStepper::GetTotalTimeStepsTaken | ( | ) | const |
The number of times AdvanceOneTimeStep() has been called SINCE the last time ResetTimeStep() was called.
Definition at line 196 of file TimeStepper.cpp.
References mTotalTimeStepsTaken.
Referenced by AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), CvodeAdaptor::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AbstractCvodeSystem::Solve(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
bool TimeStepper::IsTimeAtEnd | ( | ) | const |
True when GetTime == endTime.
Definition at line 186 of file TimeStepper.cpp.
Referenced by AbstractRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractOneStepIvpOdeSolver::InternalSolve(), NhsModelWithBackwardSolver::RunDoNotUpdate(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), CvodeAdaptor::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AbstractCvodeSystem::Solve(), AdaptiveBidomainProblem::Solve(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractRushLarsenCardiacCell::SolveAndUpdateState(), AbstractBackwardEulerCardiacCell< SIZE >::SolveAndUpdateState(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
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.
dt | is the new time-step |
Definition at line 201 of file TimeStepper.cpp.
References CalculateNextTime(), mDt, mNextTime, mStart, mTime, and mTotalTimeStepsTaken.
Referenced by AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve().
void TimeStepper::serialize | ( | Archive & | archive, |
const unsigned int | version | ||
) | [inline, private] |
archive | the archive |
version | the current version of this class |
Definition at line 180 of file TimeStepper.hpp.
References mAdditionalTimes, mAdditionalTimesReached, mDt, mEnd, mEpsilon, mNextTime, mStart, mTime, and mTotalTimeStepsTaken.
friend class boost::serialization::access [friend] |
Needed for serialization.
Definition at line 172 of file TimeStepper.hpp.
std::vector<double> TimeStepper::mAdditionalTimes [private] |
Vector to store the additional times the stepper must stop at.
Definition at line 169 of file TimeStepper.hpp.
Referenced by CalculateNextTime(), EstimateTimeSteps(), GetNextTimeStep(), serialize(), and TimeStepper().
unsigned TimeStepper::mAdditionalTimesReached [private] |
The number of times one of the 'additional times' has been passed.
Definition at line 150 of file TimeStepper.hpp.
Referenced by CalculateNextTime(), GetNextTimeStep(), and serialize().
double TimeStepper::mDt [private] |
The size of time step.
Definition at line 144 of file TimeStepper.hpp.
Referenced by CalculateNextTime(), EstimateTimeSteps(), GetIdealTimeStep(), GetNextTimeStep(), ResetTimeStep(), serialize(), and TimeStepper().
double TimeStepper::mEnd [private] |
The end time.
Definition at line 141 of file TimeStepper.hpp.
Referenced by CalculateNextTime(), EstimateTimeSteps(), GetNextTimeStep(), IsTimeAtEnd(), serialize(), and TimeStepper().
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 163 of file TimeStepper.hpp.
Referenced by CalculateNextTime(), serialize(), and TimeStepper().
double TimeStepper::mNextTime [private] |
What the time will be after the next time step.
Definition at line 156 of file TimeStepper.hpp.
Referenced by AdvanceOneTimeStep(), GetNextTime(), GetNextTimeStep(), ResetTimeStep(), serialize(), and TimeStepper().
double TimeStepper::mStart [private] |
The start time.
Definition at line 138 of file TimeStepper.hpp.
Referenced by CalculateNextTime(), EstimateTimeSteps(), ResetTimeStep(), serialize(), and TimeStepper().
double TimeStepper::mTime [private] |
The current time.
Definition at line 153 of file TimeStepper.hpp.
Referenced by AdvanceOneTimeStep(), GetNextTimeStep(), GetTime(), IsTimeAtEnd(), ResetTimeStep(), and serialize().
unsigned TimeStepper::mTotalTimeStepsTaken [private] |
The total number of time steps taken, including those to get one of the 'additional times'.
Definition at line 147 of file TimeStepper.hpp.
Referenced by AdvanceOneTimeStep(), CalculateNextTime(), GetTotalTimeStepsTaken(), ResetTimeStep(), and serialize().