Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
|
#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 | mAdditionalTimesReachedDeprecated |
double | mTime |
double | mNextTime |
double | mEpsilon |
std::vector< double > | mAdditionalTimesDeprecated |
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.
|
inlineprivate |
Definition at line 59 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. 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.
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 123 of file TimeStepper.cpp.
References CalculateNextTime(), EXCEPTION, mNextTime, mTime, and mTotalTimeStepsTaken.
Referenced by AbstractGeneralizedRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractRushLarsenCardiacCell::ComputeExceptVoltage(), CardiacSimulation::CreateAndRun(), AbstractOneStepIvpOdeSolver::InternalSolve(), NhsModelWithBackwardSolver::RunDoNotUpdate(), CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractOneStepIvpOdeSolver::Solve(), CvodeAdaptor::Solve(), AbstractCvodeSystem::Solve(), AbstractBackwardEulerCardiacCell< SIZE >::SolveAndUpdateState(), AbstractBackwardEulerCardiacCell< 0u >::SolveAndUpdateState(), AbstractGeneralizedRushLarsenCardiacCell::SolveAndUpdateState(), AbstractRushLarsenCardiacCell::SolveAndUpdateState(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
|
private |
Definition at line 106 of file TimeStepper.cpp.
References mAdditionalTimesDeprecated, mDt, mEnd, mEpsilon, mStart, and mTotalTimeStepsTaken.
Referenced by TimeStepper(), AdvanceOneTimeStep(), and ResetTimeStep().
unsigned TimeStepper::EstimateTimeSteps | ( | ) | const |
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().
double TimeStepper::GetIdealTimeStep | ( | ) |
Definition at line 160 of file TimeStepper.cpp.
References mDt.
double TimeStepper::GetNextTime | ( | ) | const |
Definition at line 144 of file TimeStepper.cpp.
References mNextTime.
Referenced by CardiacSimulation::CreateAndRun(), CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractOneStepIvpOdeSolver::Solve(), CvodeAdaptor::Solve(), AbstractCvodeSystem::Solve(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
double TimeStepper::GetNextTimeStep | ( | ) |
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().
double TimeStepper::GetTime | ( | ) | const |
Definition at line 139 of file TimeStepper.cpp.
References mTime.
Referenced by AbstractGeneralizedRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractCardiacProblem< DIM, DIM, 2 >::CreateInitialCondition(), AbstractCardiacProblem< DIM, DIM, 2 >::CreateMeshFromHeartConfig(), AbstractOneStepIvpOdeSolver::InternalSolve(), AbstractCardiacProblem< DIM, DIM, 2 >::PreSolveChecks(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractOneStepIvpOdeSolver::Solve(), AbstractCvodeSystem::Solve(), AbstractBackwardEulerCardiacCell< SIZE >::SolveAndUpdateState(), AbstractBackwardEulerCardiacCell< 0u >::SolveAndUpdateState(), AbstractGeneralizedRushLarsenCardiacCell::SolveAndUpdateState(), AbstractRushLarsenCardiacCell::SolveAndUpdateState(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
unsigned TimeStepper::GetTotalTimeStepsTaken | ( | ) | const |
Definition at line 175 of file TimeStepper.cpp.
References mTotalTimeStepsTaken.
Referenced by AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractOneStepIvpOdeSolver::Solve(), CvodeAdaptor::Solve(), AbstractCvodeSystem::Solve(), and LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile().
bool TimeStepper::IsTimeAtEnd | ( | ) | const |
Definition at line 165 of file TimeStepper.cpp.
Referenced by AbstractGeneralizedRushLarsenCardiacCell::ComputeExceptVoltage(), AbstractRushLarsenCardiacCell::ComputeExceptVoltage(), CardiacSimulation::CreateAndRun(), AbstractOneStepIvpOdeSolver::InternalSolve(), NhsModelWithBackwardSolver::RunDoNotUpdate(), CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve(), AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve(), AbstractOneStepIvpOdeSolver::Solve(), CvodeAdaptor::Solve(), AbstractCvodeSystem::Solve(), AbstractBackwardEulerCardiacCell< SIZE >::SolveAndUpdateState(), AbstractBackwardEulerCardiacCell< 0u >::SolveAndUpdateState(), AbstractGeneralizedRushLarsenCardiacCell::SolveAndUpdateState(), AbstractRushLarsenCardiacCell::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 180 of file TimeStepper.cpp.
References CalculateNextTime(), mDt, mNextTime, mStart, mTime, and mTotalTimeStepsTaken.
Referenced by AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve().
|
inlineprivate |
archive | the archive |
version | the current version of this class |
Definition at line 193 of file TimeStepper.hpp.
References mAdditionalTimesDeprecated, mAdditionalTimesReachedDeprecated, mDt, mEnd, mEpsilon, mNextTime, mStart, mTime, and mTotalTimeStepsTaken.
|
friend |
Needed for serialization.
Definition at line 185 of file TimeStepper.hpp.
|
friend |
Definition at line 54 of file TimeStepper.hpp.
|
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().
|
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().
|
private |
The size of time step.
Definition at line 157 of file TimeStepper.hpp.
Referenced by TimeStepper(), CalculateNextTime(), EstimateTimeSteps(), GetIdealTimeStep(), GetNextTimeStep(), ResetTimeStep(), and serialize().
|
private |
The end time.
Definition at line 154 of file TimeStepper.hpp.
Referenced by TimeStepper(), CalculateNextTime(), EstimateTimeSteps(), GetNextTimeStep(), IsTimeAtEnd(), and serialize().
|
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().
|
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().
|
private |
The start time.
Definition at line 151 of file TimeStepper.hpp.
Referenced by TimeStepper(), CalculateNextTime(), EstimateTimeSteps(), ResetTimeStep(), and serialize().
|
private |
The current time.
Definition at line 166 of file TimeStepper.hpp.
Referenced by AdvanceOneTimeStep(), GetNextTimeStep(), GetTime(), IsTimeAtEnd(), ResetTimeStep(), and serialize().
|
private |
The total number of time steps taken.
Definition at line 160 of file TimeStepper.hpp.
Referenced by AdvanceOneTimeStep(), CalculateNextTime(), GetTotalTimeStepsTaken(), ResetTimeStep(), and serialize().