AbstractCardiacCell.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "AbstractCardiacCell.hpp"
00036
00037 #include <cassert>
00038 #include <iostream>
00039
00040 #include "HeartConfig.hpp"
00041 #include "Exception.hpp"
00042
00043 AbstractCardiacCell::AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver> pOdeSolver,
00044 unsigned numberOfStateVariables,
00045 unsigned voltageIndex,
00046 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
00047 : AbstractCardiacCellInterface(pOdeSolver, voltageIndex, pIntracellularStimulus),
00048 AbstractOdeSystem(numberOfStateVariables),
00049 mDt(HeartConfig::Instance()->GetOdeTimeStep())
00050 {
00051
00052 assert(voltageIndex < mNumberOfStateVariables || mNumberOfStateVariables == 0);
00053 }
00054
00055 AbstractCardiacCell::~AbstractCardiacCell()
00056 {
00057 }
00058
00059 void AbstractCardiacCell::Init()
00060 {
00061 ResetToInitialConditions();
00062 mParameters.resize(rGetParameterNames().size());
00063 }
00064
00065 void AbstractCardiacCell::SetTimestep(double dt)
00066 {
00067 mDt = dt;
00068 }
00069
00070 void AbstractCardiacCell::SolveAndUpdateState(double tStart, double tEnd)
00071 {
00072 mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
00073 }
00074
00075 OdeSolution AbstractCardiacCell::Compute(double tStart, double tEnd, double tSamp)
00076 {
00077 if (tSamp < mDt)
00078 {
00079 tSamp = mDt;
00080 }
00081 return mpOdeSolver->Solve(this, rGetStateVariables(), tStart, tEnd, mDt, tSamp);
00082 }
00083
00084 void AbstractCardiacCell::ComputeExceptVoltage(double tStart, double tEnd)
00085 {
00086 double saved_voltage = GetVoltage();
00087
00088 SetVoltageDerivativeToZero(true);
00089 mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
00090 SetVoltageDerivativeToZero(false);
00091
00092 SetVoltage(saved_voltage);
00093
00094 #ifndef NDEBUG
00095
00096
00097 VerifyStateVariables();
00098 #endif // NDEBUG
00099 }
00100
00101 void AbstractCardiacCell::SetVoltage(double voltage)
00102 {
00103 SetAnyVariable(mVoltageIndex, voltage);
00104 SetFixedVoltage(voltage);
00105 }
00106
00107 double AbstractCardiacCell::GetVoltage()
00108 {
00109 return AbstractOdeSystem::GetAnyVariable(mVoltageIndex);
00110 }
00111
00112 unsigned AbstractCardiacCell::GetNumberOfStateVariables() const
00113 {
00114 return AbstractOdeSystem::GetNumberOfStateVariables();
00115 }
00116
00117 unsigned AbstractCardiacCell::GetNumberOfParameters() const
00118 {
00119 return AbstractOdeSystem::GetNumberOfParameters();
00120 }
00121
00122 std::vector<double> AbstractCardiacCell::GetStdVecStateVariables()
00123 {
00124 return AbstractOdeSystem::GetStateVariables();
00125 }
00126
00127 const std::vector<std::string>& AbstractCardiacCell::rGetStateVariableNames() const
00128 {
00129 return AbstractOdeSystem::rGetStateVariableNames();
00130 }
00131
00132 void AbstractCardiacCell::SetStateVariables(const std::vector<double>& rVariables)
00133 {
00134 AbstractOdeSystem::SetStateVariables(rVariables);
00135 }
00136
00137 void AbstractCardiacCell::SetStateVariable(unsigned index, double newValue)
00138 {
00139 AbstractOdeSystem::SetStateVariable(index, newValue);
00140 }
00141
00142 void AbstractCardiacCell::SetStateVariable(const std::string& rName, double newValue)
00143 {
00144 AbstractOdeSystem::SetStateVariable(rName, newValue);
00145 }
00146
00147 double AbstractCardiacCell::GetAnyVariable(const std::string& rName, double time)
00148 {
00149 return AbstractOdeSystem::GetAnyVariable(rName, time);
00150 }
00151
00152 double AbstractCardiacCell::GetParameter(const std::string& rParameterName)
00153 {
00154 return AbstractOdeSystem::GetParameter(rParameterName);
00155 }
00156
00157 double AbstractCardiacCell::GetParameter(unsigned parameterIndex)
00158 {
00159 return AbstractOdeSystem::GetParameter(parameterIndex);
00160 }
00161
00162 void AbstractCardiacCell::SetParameter(const std::string& rParameterName, double value)
00163 {
00164 AbstractOdeSystem::SetParameter(rParameterName,value);
00165 }
00166
00167 #include "LuoRudy1991.hpp"
00168 #include "LuoRudy1991BackwardEuler.hpp"
00169 void AbstractCardiacCell::CheckForArchiveFix()
00170 {
00171 if (dynamic_cast<CellLuoRudy1991FromCellML*>(this) || dynamic_cast<CellLuoRudy1991FromCellMLBackwardEuler*>(this))
00172 {
00173
00174 NEVER_REACHED;
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 }
00192 }
00193
00194
00195
00196
00197
00198 void AbstractCardiacCell::SetState(CellModelState state)
00199 {
00200 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00201 }
00202
00203 void AbstractCardiacCell::SetSlowValues(const std::vector<double> &rSlowValues)
00204 {
00205 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00206 }
00207
00208 void AbstractCardiacCell::GetSlowValues(std::vector<double>& rSlowValues)
00209 {
00210 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00211 }
00212
00213 bool AbstractCardiacCell::IsFastOnly()
00214 {
00215 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00216 }
00217
00218 unsigned AbstractCardiacCell::GetNumSlowValues()
00219 {
00220 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00221 }
00222
00223 void AbstractCardiacCell::AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues)
00224 {
00225 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00226 }