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 #ifdef CHASTE_CVODE
00030 #ifndef _ABSTRACTCVODECELL_HPP_
00031 #define _ABSTRACTCVODECELL_HPP_
00032
00033 #include <vector>
00034 #include <string>
00035 #include <boost/shared_ptr.hpp>
00036
00037
00038 #include "UblasVectorInclude.hpp"
00039
00040
00041 #include "OdeSolution.hpp"
00042 #include "AbstractOdeSystemInformation.hpp"
00043 #include "AbstractStimulusFunction.hpp"
00044 #include "AbstractIvpOdeSolver.hpp"
00045 #include "AbstractParameterisedSystem.hpp"
00046 #include "AbstractCardiacCellInterface.hpp"
00047
00048
00049 #include <nvector/nvector_serial.h>
00050
00069 class AbstractCvodeCell : public AbstractCardiacCellInterface, public AbstractParameterisedSystem<N_Vector>
00070 {
00071 protected:
00073 double mRelTol;
00075 double mAbsTol;
00076
00078 void* mpCvodeMem;
00083 long int mMaxSteps;
00084
00086 double mLastInternalStepSize;
00087
00089 double mMaxDt;
00090
00098 std::string DumpState(const std::string& rMessage,
00099 N_Vector Y = NULL);
00100
00105 void Init();
00106
00113 N_Vector CopyVector(N_Vector originalVec);
00114
00115 public:
00126 AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> pSolver,
00127 unsigned numberOfStateVariables,
00128 unsigned voltageIndex,
00129 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00130
00134 virtual ~AbstractCvodeCell();
00135
00140 double GetVoltage();
00141
00146 void SetVoltage(double voltage);
00147
00151 void ResetToInitialConditions();
00152
00159 N_Vector GetInitialConditions();
00160
00169 void SetStateVariables(N_Vector stateVars);
00170
00178 void SetStateVariablesUsingACopyOfThisVector(N_Vector stateVars);
00179
00187 virtual void EvaluateRhs(realtype t,
00188 N_Vector y,
00189 N_Vector ydot)=0;
00190
00191
00192
00193
00194
00200 void SetTimestep(double maxDt);
00201
00212 virtual void SolveAndUpdateState(double tStart, double tEnd);
00213
00226 OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0);
00227
00235 void ComputeExceptVoltage(double tStart, double tEnd);
00236
00241 void SetVoltageDerivativeToZero(bool clamp=true);
00242
00259 OdeSolution Solve(realtype tStart,
00260 realtype tEnd,
00261 realtype maxDt,
00262 realtype tSamp);
00263
00277 void Solve(realtype tStart,
00278 realtype tEnd,
00279 realtype maxDt);
00280
00287 void SetMaxSteps(long int numSteps);
00288
00293 long int GetMaxSteps();
00294
00302 void SetTolerances(double relTol=1e-5, double absTol=1e-7);
00303
00307 double GetRelativeTolerance();
00308
00312 double GetAbsoluteTolerance();
00313
00317 double GetLastStepSize();
00318
00319 private:
00320
00328 void SetupCvode(N_Vector initialConditions,
00329 realtype tStart,
00330 realtype maxDt);
00331
00333 void FreeCvodeMemory();
00334
00341 void CvodeError(int flag, const char * msg);
00342
00348 std::vector<double> MakeStdVec(N_Vector v);
00349 };
00350
00351
00352 #endif // _ABSTRACTCVODECELL_HPP_
00353 #endif // CHASTE_CVODE