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 <boost/serialization/access.hpp>
00034 #include <boost/serialization/base_object.hpp>
00035
00036 #include "AbstractIvpOdeSolver.hpp"
00037 #include "OdeSolution.hpp"
00038
00039
00040 #include <cvode/cvode.h>
00041 #include <nvector/nvector_serial.h>
00042 #include <sundials/sundials_nvector.h>
00043 #include <cvode/cvode_dense.h>
00044
00045
00046 #include <boost/serialization/export.hpp>
00047
00064 int CvodeRhsAdaptor(realtype t, N_Vector y, N_Vector ydot, void *pData);
00065
00086 int CvodeRootAdaptor(realtype t, N_Vector y, realtype *pGOut, void *pData);
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00107 void CvodeErrorHandler(int errorCode, const char *module, const char *function,
00108 char *message, void *pData);
00109
00110
00111 typedef struct CvodeData_ {
00112 std::vector<realtype>* pY;
00113 AbstractOdeSystem* pSystem;
00114 } CvodeData;
00115
00130 class CvodeAdaptor : public AbstractIvpOdeSolver
00131 {
00132 private:
00134 friend class boost::serialization::access;
00141 template<class Archive>
00142 void serialize(Archive & archive, const unsigned int version)
00143 {
00144
00145 archive & boost::serialization::base_object<AbstractIvpOdeSolver>(*this);
00146 archive & mRelTol;
00147 archive & mAbsTol;
00148
00149 }
00150
00152 void *mpCvodeMem;
00153
00155 N_Vector mInitialValues;
00156
00158 CvodeData mData;
00159
00161 double mRelTol;
00162
00164 double mAbsTol;
00165
00167 double mLastInternalStepSize;
00168
00173 long int mMaxSteps;
00174
00176 bool mCheckForRoots;
00177
00178 protected:
00179
00183 void SetupCvode(AbstractOdeSystem* pOdeSystem,
00184 std::vector<double>& rInitialY,
00185 double startTime, double maxStep);
00186
00190 void FreeCvodeMemory();
00191
00198 void CvodeError(int flag, const char * msg);
00199
00200 public:
00201
00209 CvodeAdaptor(double relTol=1e-4, double absTol=1e-6);
00210
00218 void SetTolerances(double relTol=1e-4, double absTol=1e-6);
00219
00223 double GetRelativeTolerance();
00224
00228 double GetAbsoluteTolerance();
00229
00233 double GetLastStepSize();
00234
00247 OdeSolution Solve(AbstractOdeSystem* pOdeSystem,
00248 std::vector<double>& rYValues,
00249 double startTime,
00250 double endTime,
00251 double maxStep,
00252 double timeSampling);
00253
00264 void Solve(AbstractOdeSystem* pOdeSystem,
00265 std::vector<double>& rYValues,
00266 double startTime,
00267 double endTime,
00268 double maxStep);
00269
00275 void CheckForStoppingEvents();
00276
00281 void SetMaxSteps(long int numSteps);
00282
00287 long int GetMaxSteps();
00288
00289 };
00290
00291 BOOST_CLASS_EXPORT(CvodeAdaptor);
00292
00293 #endif // _CVODEADAPTOR_HPP_
00294 #endif // CHASTE_CVODE