AbstractGeneralizedRushLarsenCardiacCell.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "AbstractGeneralizedRushLarsenCardiacCell.hpp"
00047 #include <cassert>
00048 #include <cmath>
00049 #include "Exception.hpp"
00050 #include "OdeSolution.hpp"
00051 #include "TimeStepper.hpp"
00052
00053 AbstractGeneralizedRushLarsenCardiacCell::AbstractGeneralizedRushLarsenCardiacCell(unsigned numberOfStateVariables,
00054 unsigned voltageIndex,
00055 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
00056 : AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver>(),
00057 numberOfStateVariables,
00058 voltageIndex,
00059 pIntracellularStimulus)
00060 {
00061 mPartialF.resize(numberOfStateVariables);
00062 mEvalF.resize(numberOfStateVariables);
00063 mYInit.resize(numberOfStateVariables);
00064 }
00065
00066 AbstractGeneralizedRushLarsenCardiacCell::~AbstractGeneralizedRushLarsenCardiacCell()
00067 {}
00068
00069 OdeSolution AbstractGeneralizedRushLarsenCardiacCell::Compute(double tStart, double tEnd, double tSamp)
00070 {
00071
00072 if (tSamp < mDt)
00073 {
00074 tSamp = mDt;
00075 }
00076 const unsigned n_steps = (unsigned) floor((tEnd - tStart)/tSamp + 0.5);
00077 assert(fabs(tStart+n_steps*tSamp - tEnd) < 1e-12);
00078 const unsigned n_small_steps = (unsigned) floor(tSamp/mDt+0.5);
00079 assert(fabs(mDt*n_small_steps - tSamp) < 1e-12);
00080
00081
00082 OdeSolution solutions;
00083 solutions.SetNumberOfTimeSteps(n_steps);
00084 solutions.rGetSolutions().push_back(rGetStateVariables());
00085 solutions.rGetTimes().push_back(tStart);
00086 solutions.SetOdeSystemInformation(this->mpSystemInfo);
00087
00088
00089 for (unsigned i=0; i<n_steps; i++)
00090 {
00091 double curr_time = tStart;
00092 for (unsigned j=0; j<n_small_steps; j++)
00093 {
00094 curr_time = tStart + i*tSamp + j*mDt;
00095
00096 UpdateTransmembranePotential(curr_time);
00097 ComputeOneStepExceptVoltage(curr_time);
00098 VerifyStateVariables();
00099 }
00100
00101
00102 solutions.rGetSolutions().push_back(rGetStateVariables());
00103 solutions.rGetTimes().push_back(curr_time+mDt);
00104 }
00105
00106 return solutions;
00107 }
00108
00109 void AbstractGeneralizedRushLarsenCardiacCell::ComputeExceptVoltage(double tStart, double tEnd)
00110 {
00111 SetVoltageDerivativeToZero(true);
00112 TimeStepper stepper(tStart, tEnd, mDt);
00113
00114 while (!stepper.IsTimeAtEnd())
00115 {
00116 ComputeOneStepExceptVoltage(stepper.GetTime());
00117
00118 #ifndef NDEBUG
00119
00120 VerifyStateVariables();
00121 #endif // NDEBUG
00122
00123 stepper.AdvanceOneTimeStep();
00124 }
00125 SetVoltageDerivativeToZero(false);
00126 }
00127
00128 void AbstractGeneralizedRushLarsenCardiacCell::SolveAndUpdateState(double tStart, double tEnd)
00129 {
00130 TimeStepper stepper(tStart, tEnd, mDt);
00131
00132 while (!stepper.IsTimeAtEnd())
00133 {
00134 UpdateTransmembranePotential(stepper.GetTime());
00135 ComputeOneStepExceptVoltage(stepper.GetTime());
00136 VerifyStateVariables();
00137
00138 stepper.AdvanceOneTimeStep();
00139 }
00140 }
00141