AbstractCvodeCell.cpp

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 
00031 #include <sstream>
00032 #include <iostream>
00033 #include <cmath>
00034 
00035 #include "AbstractCvodeCell.hpp"
00036 #include "Exception.hpp"
00037 #include "HeartConfig.hpp"
00038 #include "VectorHelperFunctions.hpp"
00039 
00040 
00041 AbstractCvodeCell::AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> /* unused */,
00042                                      unsigned numberOfStateVariables,
00043                                      unsigned voltageIndex,
00044                                      boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
00045     : AbstractCardiacCellInterface(boost::shared_ptr<AbstractIvpOdeSolver>(), voltageIndex, pIntracellularStimulus),
00046       AbstractCvodeSystem(numberOfStateVariables),
00047       mMaxDt(DOUBLE_UNSET)
00048 {
00049 }
00050 
00051 
00052 AbstractCvodeCell::~AbstractCvodeCell()
00053 {
00054 }
00055 
00056 double AbstractCvodeCell::GetVoltage()
00057 {
00058     assert(mStateVariables);
00059     return GetAnyVariable(mVoltageIndex);
00060 }
00061 
00062 void AbstractCvodeCell::SetVoltage(double voltage)
00063 {
00064     assert(mStateVariables);
00065     SetAnyVariable(mVoltageIndex, voltage);
00066 }
00067 
00068 
00069 void AbstractCvodeCell::SetTimestep(double maxDt)
00070 {
00071     mMaxDt = maxDt;
00072 }
00073 
00074 
00075 void AbstractCvodeCell::SolveAndUpdateState(double tStart, double tEnd)
00076 {
00077     if (mMaxDt == DOUBLE_UNSET)
00078     {
00079         SetTimestep(HeartConfig::Instance()->GetPrintingTimeStep());
00080     }
00081     Solve(tStart, tEnd, mMaxDt);
00082 }
00083 
00084 OdeSolution AbstractCvodeCell::Compute(double tStart, double tEnd, double tSamp)
00085 {
00086     if (tSamp == 0.0)
00087     {
00088         tSamp = HeartConfig::Instance()->GetPrintingTimeStep();
00089     }
00090     if (mMaxDt == DOUBLE_UNSET)
00091     {
00092         SetTimestep(tSamp);
00093     }
00094     return Solve(tStart, tEnd, mMaxDt, tSamp);
00095 }
00096 
00097 
00098 void AbstractCvodeCell::ComputeExceptVoltage(double tStart, double tEnd)
00099 {
00100     EXCEPTION("This method is not yet implemented for CVODE cells.");
00101 }
00102 
00103 
00104 void AbstractCvodeCell::SetVoltageDerivativeToZero(bool clamp)
00105 {
00106     if (clamp != mSetVoltageDerivativeToZero)
00107     {
00108         ResetSolver();
00109         mSetVoltageDerivativeToZero = clamp;
00110     }
00111 }
00112 
00113 
00114 #endif // CHASTE_CVODE
Generated on Thu Dec 22 13:00:06 2011 for Chaste by  doxygen 1.6.3