AbstractCardiacCell.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 #include "AbstractCardiacCell.hpp"
00029 
00030 #include <cassert>
00031 #include <iostream>
00032 
00033 #include "HeartConfig.hpp"
00034 #include "Exception.hpp"
00035 
00036 AbstractCardiacCell::AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver> pOdeSolver,
00037                                          unsigned numberOfStateVariables,
00038                                          unsigned voltageIndex,
00039                                          boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
00040     : AbstractCardiacCellInterface(pOdeSolver, voltageIndex, pIntracellularStimulus),
00041       AbstractOdeSystem(numberOfStateVariables),
00042       mDt(HeartConfig::Instance()->GetOdeTimeStep())
00043 {
00044     // The second clause is to allow for FakeBathCell.
00045     assert(voltageIndex < mNumberOfStateVariables || mNumberOfStateVariables == 0);
00046 }
00047 
00048 AbstractCardiacCell::~AbstractCardiacCell()
00049 {
00050 }
00051 
00052 void AbstractCardiacCell::Init()
00053 {
00054     SetStateVariables(GetInitialConditions());
00055     mParameters.resize(rGetParameterNames().size());
00056 }
00057 
00058 void AbstractCardiacCell::ResetToInitialConditions()
00059 {
00060     SetStateVariables(GetInitialConditions());
00061 }
00062 
00063 void AbstractCardiacCell::SetTimestep(double dt)
00064 {
00065     mDt = dt;
00066 }
00067 
00068 void AbstractCardiacCell::SolveAndUpdateState(double tStart, double tEnd)
00069 {
00070     mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
00071 }
00072 
00073 OdeSolution AbstractCardiacCell::Compute(double tStart, double tEnd, double tSamp)
00074 {
00075     if (tSamp < mDt)
00076     {
00077         tSamp = mDt;
00078     }
00079     return mpOdeSolver->Solve(this, rGetStateVariables(), tStart, tEnd, mDt, tSamp);
00080 }
00081 
00082 void AbstractCardiacCell::ComputeExceptVoltage(double tStart, double tEnd)
00083 {
00084     double saved_voltage = GetVoltage();
00085 
00086     mSetVoltageDerivativeToZero = true;
00087     mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
00088     mSetVoltageDerivativeToZero = false;
00089 
00090     SetVoltage(saved_voltage); // In case of naughty models
00091 
00092 #ifndef NDEBUG
00093     //Note that tests which rely on this throwing  (e.g. such-and-such a variable is out of range)
00094     //ought to be anotated with the NDEBUG macro
00095     VerifyStateVariables();
00096 #endif // NDEBUG
00097 }
00098 
00099 void AbstractCardiacCell::SetVoltage(double voltage)
00100 {
00101     SetAnyVariable(mVoltageIndex, voltage);
00102 }
00103 
00104 double AbstractCardiacCell::GetVoltage()
00105 {
00106     return GetAnyVariable(mVoltageIndex);
00107 }
00108 
00109 double AbstractCardiacCell::GetIntracellularCalciumConcentration()
00110 {
00111     EXCEPTION("AbstractCardiacCell::GetIntracellularCalciumConcentration() called. Either model has no [Ca_i] or method has not been implemented yet");
00112 }
00113 
00114 
00115 
00116 #include "LuoRudy1991.hpp"
00117 #include "LuoRudy1991BackwardEuler.hpp"
00118 void AbstractCardiacCell::CheckForArchiveFix()
00119 {
00120     if (dynamic_cast<CellLuoRudy1991FromCellML*>(this) || dynamic_cast<CellLuoRudy1991FromCellMLBackwardEuler*>(this))
00121     {
00122         // The LR91 model saved in previous Chaste versions had a different ordering of state variables...
00123         // Old is h, j, m, CaI, V, d, f, x
00124         // New is V, m, h, j, d, f, X, [Ca]
00125         assert(GetNumberOfStateVariables() == 8);
00126         unsigned var_index_map[8] = {2, 3, 1, 7, 0, 4, 5, 6};
00127         std::vector<double> old_state(this->mStateVariables);
00128         for (unsigned i=0; i<8; i++)
00129         {
00130             this->mStateVariables[var_index_map[i]] = old_state[i];
00131         }
00132         // It also didn't use to have parameters...
00133         this->mParameters.resize(this->rGetParameterNames().size());
00134         assert(this->mParameters.size() == 1u);
00135         this->mParameters[0] = 23.0;
00136     }
00137 }
00138 
00139 
00140 /*
00141  *  METHODS NEEDED BY FAST CARDIAC CELLS
00142  */
00143 void AbstractCardiacCell::SetState(CellModelState state)
00144 {
00145     EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00146 }
00147 
00148 void AbstractCardiacCell::SetSlowValues(const std::vector<double> &rSlowValues)
00149 {
00150     EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00151 }
00152 
00153 void AbstractCardiacCell::GetSlowValues(std::vector<double>& rSlowValues)
00154 {
00155     EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00156 }
00157 
00158 bool AbstractCardiacCell::IsFastOnly()
00159 {
00160     EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00161 }
00162 
00163 unsigned AbstractCardiacCell::GetNumSlowValues()
00164 {
00165     EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00166 }
00167 
00168 void AbstractCardiacCell::AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues)
00169 {
00170     EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00171 }

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5