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 _CVODEADAPTOR_HPP_
00031 #define _CVODEADAPTOR_HPP_
00032
00033 #include <vector>
00034
00035 #include "ChasteSerialization.hpp"
00036 #include <boost/serialization/base_object.hpp>
00037
00038 #include "AbstractIvpOdeSolver.hpp"
00039 #include "OdeSolution.hpp"
00040
00041
00042 #include <cvode/cvode.h>
00043 #include <nvector/nvector_serial.h>
00044
00045
00052 void CvodeErrorHandler(int errorCode, const char *module, const char *function,
00053 char *message, void* pData);
00054
00055
00056
00061 typedef struct CvodeData_ {
00063 std::vector<realtype>* pY;
00065 AbstractOdeSystem* pSystem;
00066 } CvodeData;
00067
00082 class CvodeAdaptor : public AbstractIvpOdeSolver
00083 {
00084 private:
00086 friend class boost::serialization::access;
00093 template<class Archive>
00094 void serialize(Archive & archive, const unsigned int version)
00095 {
00096 archive & boost::serialization::base_object<AbstractIvpOdeSolver>(*this);
00097 archive & mRelTol;
00098 archive & mAbsTol;
00099 archive & mLastInternalStepSize;
00100 archive & mMaxSteps;
00101 archive & mCheckForRoots;
00102
00103 }
00104
00106 void* mpCvodeMem;
00107
00109 N_Vector mInitialValues;
00110
00112 CvodeData mData;
00113
00115 double mRelTol;
00116
00118 double mAbsTol;
00119
00121 double mLastInternalStepSize;
00122
00127 long int mMaxSteps;
00128
00130 bool mCheckForRoots;
00131
00132 protected:
00133
00142 void SetupCvode(AbstractOdeSystem* pOdeSystem,
00143 std::vector<double>& rInitialY,
00144 double startTime, double maxStep);
00145
00149 void FreeCvodeMemory();
00150
00160 void CvodeError(int flag, const char * msg);
00161
00162 public:
00163
00171 CvodeAdaptor(double relTol=1e-4, double absTol=1e-6);
00172
00180 void SetTolerances(double relTol=1e-4, double absTol=1e-6);
00181
00185 double GetRelativeTolerance();
00186
00190 double GetAbsoluteTolerance();
00191
00195 double GetLastStepSize();
00196
00209 OdeSolution Solve(AbstractOdeSystem* pOdeSystem,
00210 std::vector<double>& rYValues,
00211 double startTime,
00212 double endTime,
00213 double maxStep,
00214 double timeSampling);
00215
00226 void Solve(AbstractOdeSystem* pOdeSystem,
00227 std::vector<double>& rYValues,
00228 double startTime,
00229 double endTime,
00230 double maxStep);
00231
00237 void CheckForStoppingEvents();
00238
00245 void SetMaxSteps(long int numSteps);
00246
00251 long int GetMaxSteps();
00252
00253 };
00254
00255 #include "SerializationExportWrapper.hpp"
00256 CHASTE_CLASS_EXPORT(CvodeAdaptor)
00257
00258 #endif // _CVODEADAPTOR_HPP_
00259 #endif // CHASTE_CVODE