AbstractCvodeCell.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 // Chaste headers
00038 #include "OdeSolution.hpp"
00039 #include "AbstractOdeSystemInformation.hpp"
00040 #include "AbstractStimulusFunction.hpp"
00041 #include "AbstractIvpOdeSolver.hpp"
00042 
00043 // CVODE headers
00044 #include <nvector/nvector_serial.h>
00045 
00064 class AbstractCvodeCell
00065 {
00066 protected:
00068     unsigned mNumberOfStateVariables;
00070     unsigned mVoltageIndex;
00072     N_Vector mStateVariables;
00073 
00080     boost::shared_ptr<AbstractOdeSystemInformation> mpSystemInfo;
00081 
00083     boost::shared_ptr<AbstractStimulusFunction> mpIntracellularStimulus;
00084 
00086     double mRelTol;
00088     double mAbsTol;
00089 
00091     void* mpCvodeMem;
00096     long int mMaxSteps;
00097 
00099     double mLastInternalStepSize;
00100 
00104     bool mSetVoltageDerivativeToZero;
00105 
00110     std::string DumpState(const std::string& message,
00111                           N_Vector Y = NULL);
00112 
00119     void Init();
00120 
00124     N_Vector CopyVector(N_Vector originalVec);
00125 
00126 public:
00134     AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> /* unused; should be empty */,
00135                       unsigned numberOfStateVariables,
00136                       unsigned voltageIndex,
00137                       boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00138 
00142     virtual ~AbstractCvodeCell();
00143 
00145     unsigned GetVoltageIndex();
00146 
00151     double GetVoltage();
00152 
00157     void SetVoltage(double voltage);
00158 
00164     void SetStimulusFunction(boost::shared_ptr<AbstractStimulusFunction> pStimulus);
00165 
00171     double GetStimulus(double time);
00172 
00174     unsigned GetNumberOfStateVariables();
00175 
00177     const std::vector<std::string>& rGetVariableNames() const;
00178 
00180     const std::vector<std::string>& rGetVariableUnits() const;
00181 
00193     unsigned GetStateVariableNumberByName(const std::string name) const;
00194 
00203     double GetStateVariableValueByNumber(unsigned varNumber) const;
00204 
00212     std::string GetStateVariableUnitsByNumber(unsigned varNumber) const;
00213 
00217     boost::shared_ptr<const AbstractOdeSystemInformation> GetSystemInformation() const;
00218 
00225     N_Vector GetInitialConditions();
00226 
00235     void SetStateVariables(N_Vector stateVars);
00236 
00244     void SetStateVariablesUsingACopyOfThisVector(N_Vector stateVars);
00245 
00252     N_Vector GetStateVariables();
00253 
00260     N_Vector rGetStateVariables();
00261 
00269     virtual void EvaluateRhs(realtype t,
00270                              N_Vector y,
00271                              N_Vector ydot)=0;
00272 
00280     virtual void VerifyStateVariables()
00281     {
00282     }
00283 
00284     //
00285     // Solver methods
00286     //
00287 
00292     void SetVoltageDerivativeToZero(bool clamp=true);
00293 
00310     OdeSolution Solve(realtype tStart,
00311                       realtype tEnd,
00312                       realtype maxDt,
00313                       realtype tSamp);
00314 
00328     void Solve(realtype tStart,
00329                realtype tEnd,
00330                realtype maxDt);
00331 
00336     void SetMaxSteps(long int numSteps);
00337 
00342     long int GetMaxSteps();
00343 
00351     void SetTolerances(double relTol=1e-4, double absTol=1e-6);
00352 
00356     double GetRelativeTolerance();
00357 
00361     double GetAbsoluteTolerance();
00362 
00366     double GetLastStepSize();
00367 
00368 private:
00369 
00377     void SetupCvode(N_Vector initialConditions,
00378                     realtype tStart,
00379                     realtype maxDt);
00380 
00382     void FreeCvodeMemory();
00383 
00390     void CvodeError(int flag, const char * msg);
00391 
00397     std::vector<double> MakeStdVec(N_Vector v);
00398 
00399 };
00400 
00401 
00402 #endif // _ABSTRACTCVODECELL_HPP_
00403 #endif // CHASTE_CVODE

Generated by  doxygen 1.6.2