AbstractCvodeSystem.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 _ABSTRACTCVODESYSTEM_HPP_
00031 #define _ABSTRACTCVODESYSTEM_HPP_
00032 
00033 #include <vector>
00034 #include <string>
00035 #include <algorithm>
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 includes
00041 #include "OdeSolution.hpp"
00042 #include "AbstractParameterisedSystem.hpp"
00043 #include "Exception.hpp"
00044 
00045 // Serialiazation
00046 //#include "ChasteSerialization.hpp"
00047 //#include <boost/serialization/split_member.hpp>
00048 //#include <boost/serialization/vector.hpp>
00049 //#include <boost/serialization/version.hpp>
00050 //#include "ClassIsAbstract.hpp"
00051 
00052 // CVODE headers
00053 #include <nvector/nvector_serial.h>
00054 
00082 class AbstractCvodeSystem : public AbstractParameterisedSystem<N_Vector>
00083 {
00084 private:
00092     void SetupCvode(N_Vector initialConditions,
00093                     realtype tStart,
00094                     realtype maxDt);
00095 
00100     void RecordStoppingPoint(double stopTime);
00101 
00103     void FreeCvodeMemory();
00104 
00111     void CvodeError(int flag, const char * msg);
00112 
00114     N_Vector mLastSolutionState;
00115 
00117     double mLastSolutionTime;
00118 
00120     bool mAutoReset;
00121 
00122 protected:
00123 
00125     bool mUseAnalyticJacobian;
00126 
00128     double mRelTol;
00129 
00131     double mAbsTol;
00132 
00134     void* mpCvodeMem;
00135 
00140     long int mMaxSteps;
00141 
00143     double mLastInternalStepSize;
00144 
00149     void Init();
00150 
00151 public:
00152 
00158     AbstractCvodeSystem(unsigned numberOfStateVariables);
00159 
00163     virtual ~AbstractCvodeSystem();
00164 
00172     virtual void EvaluateYDerivatives(realtype time,
00173                                       N_Vector y,
00174                                       N_Vector ydot)=0;
00175 
00183     void SetAutoReset(bool autoReset);
00184 
00195     void ResetSolver();
00196 
00215     OdeSolution Solve(realtype tStart,
00216                       realtype tEnd,
00217                       realtype maxDt,
00218                       realtype tSamp);
00219 
00235     void Solve(realtype tStart,
00236                realtype tEnd,
00237                realtype maxDt);
00238 
00245     void SetMaxSteps(long int numSteps);
00246 
00251     long int GetMaxSteps();
00252 
00260     void SetTolerances(double relTol=1e-5, double absTol=1e-7);
00261 
00265     double GetRelativeTolerance();
00266 
00270     double GetAbsoluteTolerance();
00271 
00275     double GetLastStepSize();
00276 
00277 
00278 //    /**
00279 //     * An alternative approach to stopping events; currently only useful with CVODE.
00280 //     * CVODE can search for roots (zeros) of this function while solving the ODE system,
00281 //     * and home in on them to find sign transitions to high precision.
00282 //     *
00283 //     * The default implementation here fakes a root function using CalculateStoppingEvent.
00284 //     *
00285 //     * @param time  the current time
00286 //     * @param rY  the current values of the state variables
00287 //     */
00288 //    virtual double CalculateRootFunction(double time, const std::vector<double>& rY);
00289 //
00290 //    /**
00291 //     * Get whether an analytic Jacobian is used.
00292 //     *
00293 //     * @return mUseAnalyticJacobian
00294 //     */
00295 //    bool GetUseAnalyticJacobian();
00296 
00297 //    /**
00298 //     * \todo move to AbstractParameterisedSystem? (1540)
00299 //     *
00300 //     * @return const reference to the state variables in the ODE system (used in archiving).
00301 //     */
00302 //    const std::vector<double>& rGetConstStateVariables() const;
00303 
00304 };
00305 
00306 //CLASS_IS_ABSTRACT(AbstractCvodeSystem)
00307 
00308 #endif //_ABSTRACTCVODESYSTEM_HPP_
00309 #endif // CHASTE_CVODE
00310 
00311 
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3