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
00095 std::string DumpState(const std::string& rMessage,
00096 N_Vector Y = NULL);
00097
00102 void Init();
00103
00110 N_Vector CopyVector(N_Vector originalVec);
00111
00112 public:
00123 AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> pSolver,
00124 unsigned numberOfStateVariables,
00125 unsigned voltageIndex,
00126 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00127
00131 virtual ~AbstractCvodeCell();
00132
00137 double GetVoltage();
00138
00143 void SetVoltage(double voltage);
00144
00148 void ResetToInitialConditions();
00149
00156 N_Vector GetInitialConditions();
00157
00166 void SetStateVariables(N_Vector stateVars);
00167
00175 void SetStateVariablesUsingACopyOfThisVector(N_Vector stateVars);
00176
00183 N_Vector GetStateVariables();
00184
00192 virtual void EvaluateRhs(realtype t,
00193 N_Vector y,
00194 N_Vector ydot)=0;
00195
00196
00197
00198
00199
00212 OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0);
00213
00221 void ComputeExceptVoltage(double tStart, double tEnd);
00222
00227 void SetVoltageDerivativeToZero(bool clamp=true);
00228
00245 OdeSolution Solve(realtype tStart,
00246 realtype tEnd,
00247 realtype maxDt,
00248 realtype tSamp);
00249
00263 void Solve(realtype tStart,
00264 realtype tEnd,
00265 realtype maxDt);
00266
00273 void SetMaxSteps(long int numSteps);
00274
00279 long int GetMaxSteps();
00280
00288 void SetTolerances(double relTol=1e-4, double absTol=1e-6);
00289
00293 double GetRelativeTolerance();
00294
00298 double GetAbsoluteTolerance();
00299
00303 double GetLastStepSize();
00304
00305 private:
00306
00314 void SetupCvode(N_Vector initialConditions,
00315 realtype tStart,
00316 realtype maxDt);
00317
00319 void FreeCvodeMemory();
00320
00327 void CvodeError(int flag, const char * msg);
00328
00334 std::vector<double> MakeStdVec(N_Vector v);
00335 };
00336
00337
00338 #endif // _ABSTRACTCVODECELL_HPP_
00339 #endif // CHASTE_CVODE