CvodeAdaptor.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 _CVODEADAPTOR_HPP_
00031 #define _CVODEADAPTOR_HPP_
00032
00033 #include "ChasteSerialization.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
00061 int CvodeRhsAdaptor(realtype t, N_Vector y, N_Vector ydot, void* pData);
00062
00083 int CvodeRootAdaptor(realtype t, N_Vector y, realtype* pGOut, void* pData);
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00104 void CvodeErrorHandler(int errorCode, const char *module, const char *function,
00105 char *message, void* pData);
00106
00107
00108 typedef struct CvodeData_ {
00109 std::vector<realtype>* pY;
00110 AbstractOdeSystem* pSystem;
00111 } CvodeData;
00112
00127 class CvodeAdaptor : public AbstractIvpOdeSolver
00128 {
00129 private:
00131 friend class boost::serialization::access;
00138 template<class Archive>
00139 void serialize(Archive & archive, const unsigned int version)
00140 {
00141 archive & boost::serialization::base_object<AbstractIvpOdeSolver>(*this);
00142 archive & mRelTol;
00143 archive & mAbsTol;
00144
00145 }
00146
00148 void* mpCvodeMem;
00149
00151 N_Vector mInitialValues;
00152
00154 CvodeData mData;
00155
00157 double mRelTol;
00158
00160 double mAbsTol;
00161
00163 double mLastInternalStepSize;
00164
00169 long int mMaxSteps;
00170
00172 bool mCheckForRoots;
00173
00174 protected:
00175
00179 void SetupCvode(AbstractOdeSystem* pOdeSystem,
00180 std::vector<double>& rInitialY,
00181 double startTime, double maxStep);
00182
00186 void FreeCvodeMemory();
00187
00194 void CvodeError(int flag, const char * msg);
00195
00196 public:
00197
00205 CvodeAdaptor(double relTol=1e-4, double absTol=1e-6);
00206
00214 void SetTolerances(double relTol=1e-4, double absTol=1e-6);
00215
00219 double GetRelativeTolerance();
00220
00224 double GetAbsoluteTolerance();
00225
00229 double GetLastStepSize();
00230
00243 OdeSolution Solve(AbstractOdeSystem* pOdeSystem,
00244 std::vector<double>& rYValues,
00245 double startTime,
00246 double endTime,
00247 double maxStep,
00248 double timeSampling);
00249
00260 void Solve(AbstractOdeSystem* pOdeSystem,
00261 std::vector<double>& rYValues,
00262 double startTime,
00263 double endTime,
00264 double maxStep);
00265
00271 void CheckForStoppingEvents();
00272
00277 void SetMaxSteps(long int numSteps);
00278
00283 long int GetMaxSteps();
00284
00285 };
00286
00287 #include "SerializationExportWrapper.hpp"
00288 CHASTE_CLASS_EXPORT(CvodeAdaptor);
00289
00290 #endif // _CVODEADAPTOR_HPP_
00291 #endif // CHASTE_CVODE