CvodeAdaptor.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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 // CVODE headers
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 // Note: declared here since it's also used by AbstractCvodeCell.
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         // All other member variables given values on each call.
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
Generated on Thu Dec 22 13:00:17 2011 for Chaste by  doxygen 1.6.3