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 #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
00045 assert(voltageIndex < mNumberOfStateVariables || mNumberOfStateVariables == 0);
00046 }
00047
00048 AbstractCardiacCell::~AbstractCardiacCell()
00049 {
00050 }
00051
00052 void AbstractCardiacCell::Init()
00053 {
00054 ResetToInitialConditions();
00055 mParameters.resize(rGetParameterNames().size());
00056 }
00057
00058 void AbstractCardiacCell::SetTimestep(double dt)
00059 {
00060 mDt = dt;
00061 }
00062
00063 void AbstractCardiacCell::SolveAndUpdateState(double tStart, double tEnd)
00064 {
00065 mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
00066 }
00067
00068 OdeSolution AbstractCardiacCell::Compute(double tStart, double tEnd, double tSamp)
00069 {
00070 if (tSamp < mDt)
00071 {
00072 tSamp = mDt;
00073 }
00074 return mpOdeSolver->Solve(this, rGetStateVariables(), tStart, tEnd, mDt, tSamp);
00075 }
00076
00077 void AbstractCardiacCell::ComputeExceptVoltage(double tStart, double tEnd)
00078 {
00079 double saved_voltage = GetVoltage();
00080
00081 mSetVoltageDerivativeToZero = true;
00082 mpOdeSolver->SolveAndUpdateStateVariable(this, tStart, tEnd, mDt);
00083 mSetVoltageDerivativeToZero = false;
00084
00085 SetVoltage(saved_voltage);
00086
00087 #ifndef NDEBUG
00088
00089
00090 VerifyStateVariables();
00091 #endif // NDEBUG
00092 }
00093
00094 void AbstractCardiacCell::SetVoltage(double voltage)
00095 {
00096 SetAnyVariable(mVoltageIndex, voltage);
00097 }
00098
00099 double AbstractCardiacCell::GetVoltage()
00100 {
00101 return GetAnyVariable(mVoltageIndex);
00102 }
00103
00104 double AbstractCardiacCell::GetIntracellularCalciumConcentration()
00105 {
00106 EXCEPTION("AbstractCardiacCell::GetIntracellularCalciumConcentration() called. Either model has no [Ca_i] or method has not been implemented yet");
00107 }
00108
00109
00110
00111 #include "LuoRudy1991.hpp"
00112 #include "LuoRudy1991BackwardEuler.hpp"
00113 void AbstractCardiacCell::CheckForArchiveFix()
00114 {
00115 if (dynamic_cast<CellLuoRudy1991FromCellML*>(this) || dynamic_cast<CellLuoRudy1991FromCellMLBackwardEuler*>(this))
00116 {
00117
00118
00119
00120 assert(GetNumberOfStateVariables() == 8);
00121 unsigned var_index_map[8] = {2, 3, 1, 7, 0, 4, 5, 6};
00122 std::vector<double> old_state(this->mStateVariables);
00123 for (unsigned i=0; i<8; i++)
00124 {
00125 this->mStateVariables[var_index_map[i]] = old_state[i];
00126 }
00127
00128 this->mParameters.resize(this->rGetParameterNames().size());
00129 assert(this->mParameters.size() == 2u);
00130 this->mParameters[0] = 23.0;
00131 this->mParameters[1] = 0.282;
00132 }
00133 }
00134
00135
00136
00137
00138
00139 void AbstractCardiacCell::SetState(CellModelState state)
00140 {
00141 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00142 }
00143
00144 void AbstractCardiacCell::SetSlowValues(const std::vector<double> &rSlowValues)
00145 {
00146 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00147 }
00148
00149 void AbstractCardiacCell::GetSlowValues(std::vector<double>& rSlowValues)
00150 {
00151 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00152 }
00153
00154 bool AbstractCardiacCell::IsFastOnly()
00155 {
00156 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00157 }
00158
00159 unsigned AbstractCardiacCell::GetNumSlowValues()
00160 {
00161 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00162 }
00163
00164 void AbstractCardiacCell::AdjustOutOfRangeSlowValues(std::vector<double>& rSlowValues)
00165 {
00166 EXCEPTION("Non fast-slow cell model being used in a fast-slow problem.");
00167 }