AbstractCvodeCell.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
00036 #ifdef CHASTE_CVODE
00037
00038 #include <sstream>
00039 #include <iostream>
00040 #include <cmath>
00041
00042 #include "AbstractCvodeCell.hpp"
00043 #include "Exception.hpp"
00044 #include "HeartConfig.hpp"
00045 #include "VectorHelperFunctions.hpp"
00046
00047
00048 AbstractCvodeCell::AbstractCvodeCell(boost::shared_ptr<AbstractIvpOdeSolver> ,
00049 unsigned numberOfStateVariables,
00050 unsigned voltageIndex,
00051 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
00052 : AbstractCardiacCellInterface(boost::shared_ptr<AbstractIvpOdeSolver>(), voltageIndex, pIntracellularStimulus),
00053 AbstractCvodeSystem(numberOfStateVariables),
00054 mMaxDt(DOUBLE_UNSET)
00055 {
00056 }
00057
00058
00059 AbstractCvodeCell::~AbstractCvodeCell()
00060 {
00061 }
00062
00063 double AbstractCvodeCell::GetVoltage()
00064 {
00065 assert(mStateVariables);
00066 return AbstractCvodeSystem::GetAnyVariable(mVoltageIndex);
00067 }
00068
00069 void AbstractCvodeCell::SetVoltage(double voltage)
00070 {
00071 assert(mStateVariables);
00072 SetAnyVariable(mVoltageIndex, voltage);
00073 SetFixedVoltage(voltage);
00074 }
00075
00076
00077 void AbstractCvodeCell::SetMaxTimestep(double maxDt)
00078 {
00079 SetTimestep(maxDt);
00080 }
00081
00082 void AbstractCvodeCell::SetTimestep(double maxDt)
00083 {
00084 mMaxDt = maxDt;
00085 }
00086
00087 double AbstractCvodeCell::GetTimestep()
00088 {
00089 return mMaxDt;
00090 }
00091
00092
00093 void AbstractCvodeCell::SolveAndUpdateState(double tStart, double tEnd)
00094 {
00095 if (mMaxDt == DOUBLE_UNSET)
00096 {
00097 SetTimestep(HeartConfig::Instance()->GetPrintingTimeStep());
00098 }
00099 Solve(tStart, tEnd, mMaxDt);
00100 }
00101
00102 OdeSolution AbstractCvodeCell::Compute(double tStart, double tEnd, double tSamp)
00103 {
00104 if (tSamp == 0.0)
00105 {
00106 tSamp = HeartConfig::Instance()->GetPrintingTimeStep();
00107 }
00108 if (mMaxDt == DOUBLE_UNSET)
00109 {
00110 SetTimestep(tSamp);
00111 }
00112 return Solve(tStart, tEnd, mMaxDt, tSamp);
00113 }
00114
00115
00116 void AbstractCvodeCell::ComputeExceptVoltage(double tStart, double tEnd)
00117 {
00118 double saved_voltage = GetVoltage();
00119
00120 AbstractCardiacCellInterface::SetVoltageDerivativeToZero(true);
00121 SolveAndUpdateState(tStart, tEnd);
00122 AbstractCardiacCellInterface::SetVoltageDerivativeToZero(false);
00123
00124 SetVoltage(saved_voltage);
00125
00126 #ifndef NDEBUG
00127
00128
00129 VerifyStateVariables();
00130 #endif // NDEBUG
00131 }
00132
00133
00134 void AbstractCvodeCell::SetVoltageDerivativeToZero(bool clamp)
00135 {
00136 if (clamp != mSetVoltageDerivativeToZero)
00137 {
00138 ResetSolver();
00139 }
00140 AbstractCardiacCellInterface::SetVoltageDerivativeToZero(clamp);
00141 }
00142
00143 unsigned AbstractCvodeCell::GetNumberOfStateVariables() const
00144 {
00145 return AbstractCvodeSystem::GetNumberOfStateVariables();
00146 }
00147
00148 unsigned AbstractCvodeCell::GetNumberOfParameters() const
00149 {
00150 return AbstractCvodeSystem::GetNumberOfParameters();
00151 }
00152
00153 std::vector<double> AbstractCvodeCell::GetStdVecStateVariables()
00154 {
00155 std::vector<double> state_variables(GetNumberOfStateVariables());
00156 CopyToStdVector(AbstractCvodeSystem::rGetStateVariables(), state_variables);
00157 return state_variables;
00158 }
00159
00160 const std::vector<std::string>& AbstractCvodeCell::rGetStateVariableNames() const
00161 {
00162 return AbstractCvodeSystem::rGetStateVariableNames();
00163 }
00164
00165 void AbstractCvodeCell::SetStateVariables(const std::vector<double>& rVariables)
00166 {
00167 N_Vector vars = MakeNVector(rVariables);
00168 AbstractCvodeSystem::SetStateVariables(vars);
00169 DeleteVector(vars);
00170 }
00171
00172 void AbstractCvodeCell::SetStateVariables(const N_Vector& rVariables)
00173 {
00174 AbstractCvodeSystem::SetStateVariables(rVariables);
00175 }
00176
00177 void AbstractCvodeCell::SetStateVariable(unsigned index, double newValue)
00178 {
00179 AbstractCvodeSystem::SetStateVariable(index, newValue);
00180 }
00181
00182 void AbstractCvodeCell::SetStateVariable(const std::string& rName, double newValue)
00183 {
00184 AbstractCvodeSystem::SetStateVariable(rName, newValue);
00185 }
00186
00187 double AbstractCvodeCell::GetAnyVariable(const std::string& rName, double time)
00188 {
00189 return AbstractCvodeSystem::GetAnyVariable(rName,time);
00190 }
00191
00192 double AbstractCvodeCell::GetParameter(const std::string& rParameterName)
00193 {
00194 return AbstractCvodeSystem::GetParameter(rParameterName);
00195 }
00196
00197 double AbstractCvodeCell::GetParameter(unsigned parameterIndex)
00198 {
00199 return AbstractCvodeSystem::GetParameter(parameterIndex);
00200 }
00201
00202 void AbstractCvodeCell::SetParameter(const std::string& rParameterName, double value)
00203 {
00204 AbstractCvodeSystem::SetParameter(rParameterName,value);
00205 }
00206
00207 #endif // CHASTE_CVODE