AbstractCvodeCell.hpp
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 "OdeSolution.hpp"
00039 #include "AbstractOdeSystemInformation.hpp"
00040 #include "AbstractStimulusFunction.hpp"
00041 #include "AbstractIvpOdeSolver.hpp"
00042
00043
00044 #include <nvector/nvector_serial.h>
00045
00064 class AbstractCvodeCell
00065 {
00066 protected:
00068 unsigned mNumberOfStateVariables;
00070 unsigned mVoltageIndex;
00072 N_Vector mStateVariables;
00073
00080 boost::shared_ptr<AbstractOdeSystemInformation> mpSystemInfo;
00081
00083 boost::shared_ptr<AbstractStimulusFunction> mpIntracellularStimulus;
00084
00086 double mRelTol;
00088 double mAbsTol;
00089
00091 void* mpCvodeMem;
00096 long int mMaxSteps;
00097
00099 double mLastInternalStepSize;
00100
00104 bool mSetVoltageDerivativeToZero;
00105
00110 std::string DumpState(const std::string& message,
00111 N_Vector Y = NULL);
00112
00119 void Init();
00120
00124 N_Vector CopyVector(N_Vector originalVec);
00125
00126 public:
00134 AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> ,
00135 unsigned numberOfStateVariables,
00136 unsigned voltageIndex,
00137 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00138
00142 virtual ~AbstractCvodeCell();
00143
00145 unsigned GetVoltageIndex();
00146
00151 double GetVoltage();
00152
00157 void SetVoltage(double voltage);
00158
00164 void SetStimulusFunction(boost::shared_ptr<AbstractStimulusFunction> pStimulus);
00165
00171 double GetStimulus(double time);
00172
00174 unsigned GetNumberOfStateVariables();
00175
00177 const std::vector<std::string>& rGetVariableNames() const;
00178
00180 const std::vector<std::string>& rGetVariableUnits() const;
00181
00193 unsigned GetStateVariableNumberByName(const std::string name) const;
00194
00203 double GetStateVariableValueByNumber(unsigned varNumber) const;
00204
00212 std::string GetStateVariableUnitsByNumber(unsigned varNumber) const;
00213
00217 boost::shared_ptr<const AbstractOdeSystemInformation> GetSystemInformation() const;
00218
00225 N_Vector GetInitialConditions();
00226
00235 void SetStateVariables(N_Vector stateVars);
00236
00244 void SetStateVariablesUsingACopyOfThisVector(N_Vector stateVars);
00245
00252 N_Vector GetStateVariables();
00253
00260 N_Vector rGetStateVariables();
00261
00269 virtual void EvaluateRhs(realtype t,
00270 N_Vector y,
00271 N_Vector ydot)=0;
00272
00280 virtual void VerifyStateVariables()
00281 {
00282 }
00283
00284
00285
00286
00287
00292 void SetVoltageDerivativeToZero(bool clamp=true);
00293
00310 OdeSolution Solve(realtype tStart,
00311 realtype tEnd,
00312 realtype maxDt,
00313 realtype tSamp);
00314
00328 void Solve(realtype tStart,
00329 realtype tEnd,
00330 realtype maxDt);
00331
00336 void SetMaxSteps(long int numSteps);
00337
00342 long int GetMaxSteps();
00343
00351 void SetTolerances(double relTol=1e-4, double absTol=1e-6);
00352
00356 double GetRelativeTolerance();
00357
00361 double GetAbsoluteTolerance();
00362
00366 double GetLastStepSize();
00367
00368 private:
00369
00377 void SetupCvode(N_Vector initialConditions,
00378 realtype tStart,
00379 realtype maxDt);
00380
00382 void FreeCvodeMemory();
00383
00390 void CvodeError(int flag, const char * msg);
00391
00397 std::vector<double> MakeStdVec(N_Vector v);
00398
00399 };
00400
00401
00402 #endif // _ABSTRACTCVODECELL_HPP_
00403 #endif // CHASTE_CVODE