AbstractCvodeCell.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 _ABSTRACTCVODECELL_HPP_
00031 #define _ABSTRACTCVODECELL_HPP_
00032 
00033 #include <vector>
00034 #include <string>
00035 #include <boost/shared_ptr.hpp>
00036 
00037 // This is only needed to prevent compilation errors on PETSc 2.2/Boost 1.33.1 combo
00038 #include "UblasVectorInclude.hpp"
00039 
00040 // Chaste headers
00041 #include "OdeSolution.hpp"
00042 #include "AbstractOdeSystemInformation.hpp"
00043 #include "AbstractStimulusFunction.hpp"
00044 #include "AbstractIvpOdeSolver.hpp"
00045 #include "AbstractParameterisedSystem.hpp"
00046 #include "AbstractCardiacCellInterface.hpp"
00047 
00048 // CVODE headers
00049 #include <nvector/nvector_serial.h>
00050 
00069 class AbstractCvodeCell : public AbstractCardiacCellInterface, public AbstractParameterisedSystem<N_Vector>
00070 {
00071 protected:
00073     double mRelTol;
00075     double mAbsTol;
00076 
00078     void* mpCvodeMem;
00083     long int mMaxSteps;
00084 
00086     double mLastInternalStepSize;
00087 
00089     double mMaxDt;
00090 
00098     std::string DumpState(const std::string& rMessage,
00099                           N_Vector Y = NULL);
00100 
00105     void Init();
00106 
00107 public:
00118     AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> pSolver,
00119                       unsigned numberOfStateVariables,
00120                       unsigned voltageIndex,
00121                       boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00122 
00126     virtual ~AbstractCvodeCell();
00127 
00132     double GetVoltage();
00133 
00138     void SetVoltage(double voltage);
00139 
00147     virtual void EvaluateRhs(realtype t,
00148                              N_Vector y,
00149                              N_Vector ydot)=0;
00150 
00151     //
00152     // Solver methods
00153     //
00154 
00160     void SetTimestep(double maxDt);
00161 
00172     virtual void SolveAndUpdateState(double tStart, double tEnd);
00173 
00186     OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0);
00187 
00195     void ComputeExceptVoltage(double tStart, double tEnd);
00196 
00201     void SetVoltageDerivativeToZero(bool clamp=true);
00202 
00219     OdeSolution Solve(realtype tStart,
00220                       realtype tEnd,
00221                       realtype maxDt,
00222                       realtype tSamp);
00223 
00237     void Solve(realtype tStart,
00238                realtype tEnd,
00239                realtype maxDt);
00240 
00247     void SetMaxSteps(long int numSteps);
00248 
00253     long int GetMaxSteps();
00254 
00262     void SetTolerances(double relTol=1e-5, double absTol=1e-7);
00263 
00267     double GetRelativeTolerance();
00268 
00272     double GetAbsoluteTolerance();
00273 
00277     double GetLastStepSize();
00278 
00279 private:
00280 
00288     void SetupCvode(N_Vector initialConditions,
00289                     realtype tStart,
00290                     realtype maxDt);
00291 
00293     void FreeCvodeMemory();
00294 
00301     void CvodeError(int flag, const char * msg);
00302 
00308     std::vector<double> MakeStdVec(N_Vector v);
00309 };
00310 
00311 
00312 #endif // _ABSTRACTCVODECELL_HPP_
00313 #endif // CHASTE_CVODE

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5