AbstractBackwardEulerCardiacCell.hpp
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 #ifndef ABSTRACTBACKWARDEULERCARDIACCELL_HPP_
00031 #define ABSTRACTBACKWARDEULERCARDIACCELL_HPP_
00032
00033 #include "ChasteSerialization.hpp"
00034 #include <boost/serialization/base_object.hpp>
00035 #include "ClassIsAbstract.hpp"
00036 #include "AbstractCardiacCell.hpp"
00037 #include "Exception.hpp"
00038
00039 #include <cassert>
00040 #include <cmath>
00041
00056 template<unsigned SIZE>
00057 class AbstractBackwardEulerCardiacCell : public AbstractCardiacCell
00058 {
00059 private:
00061 friend class boost::serialization::access;
00068 template<class Archive>
00069 void serialize(Archive & archive, const unsigned int version)
00070 {
00071
00072 archive & boost::serialization::base_object<AbstractCardiacCell>(*this);
00073 }
00074 public:
00075
00091 AbstractBackwardEulerCardiacCell(
00092 unsigned numberOfStateVariables,
00093 unsigned voltageIndex,
00094 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
00095
00097 virtual ~AbstractBackwardEulerCardiacCell();
00098
00106 virtual void ComputeResidual(double time, const double rCurrentGuess[SIZE], double rResidual[SIZE])=0;
00107
00115 virtual void ComputeJacobian(double time, const double rCurrentGuess[SIZE], double rJacobian[SIZE][SIZE])=0;
00116
00128 virtual OdeSolution Compute(double tStart, double tEnd);
00129
00139 virtual void ComputeExceptVoltage(double tStart, double tEnd);
00140
00141 private:
00142 #define COVERAGE_IGNORE
00143
00150 void EvaluateYDerivatives(double time, const std::vector<double> &rY, std::vector<double> &rDY)
00151 {
00152 NEVER_REACHED;
00153 }
00154 #undef COVERAGE_IGNORE
00155
00156 protected:
00165 virtual void ComputeOneStepExceptVoltage(double tStart)=0;
00166
00174 virtual void UpdateTransmembranePotential(double time)=0;
00175 };
00176
00177
00178
00179
00180
00181
00182
00183
00184 template <unsigned SIZE>
00185 AbstractBackwardEulerCardiacCell<SIZE>::AbstractBackwardEulerCardiacCell(
00186 unsigned numberOfStateVariables,
00187 unsigned voltageIndex,
00188 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
00189 : AbstractCardiacCell(boost::shared_ptr<AbstractIvpOdeSolver>(),
00190 numberOfStateVariables,
00191 voltageIndex,
00192 pIntracellularStimulus)
00193 {}
00194
00195 template <unsigned SIZE>
00196 AbstractBackwardEulerCardiacCell<SIZE>::~AbstractBackwardEulerCardiacCell()
00197 {}
00198
00199 template <unsigned SIZE>
00200 OdeSolution AbstractBackwardEulerCardiacCell<SIZE>::Compute(double tStart, double tEnd)
00201 {
00202
00203
00204
00205
00206
00207 double _n_steps = (tEnd - tStart) / mDt;
00208 unsigned n_steps = (unsigned) round(_n_steps);
00209 assert(fabs(tStart+n_steps*mDt - tEnd) < 1e-12);
00210
00211
00212 OdeSolution solutions;
00213 solutions.SetNumberOfTimeSteps(n_steps);
00214 solutions.rGetSolutions().push_back(rGetStateVariables());
00215 solutions.rGetTimes().push_back(tStart);
00216 solutions.SetOdeSystemInformation(this->mpSystemInfo);
00217
00218
00219 double curr_time;
00220 for (unsigned i=0; i<n_steps; i++)
00221 {
00222 curr_time = tStart + i*mDt;
00223
00224
00225 UpdateTransmembranePotential(curr_time);
00226
00227
00228 ComputeOneStepExceptVoltage(curr_time);
00229
00230
00231 solutions.rGetSolutions().push_back(rGetStateVariables());
00232 solutions.rGetTimes().push_back(curr_time+mDt);
00233
00234
00235 VerifyStateVariables();
00236 }
00237
00238 return solutions;
00239 }
00240
00241 template <unsigned SIZE>
00242 void AbstractBackwardEulerCardiacCell<SIZE>::ComputeExceptVoltage(double tStart, double tEnd)
00243 {
00244
00245
00246
00247 double _n_steps = (tEnd - tStart) / mDt;
00248 unsigned n_steps = (unsigned) round(_n_steps);
00249 assert(fabs(tStart+n_steps*mDt - tEnd) < 1e-12);
00250
00251
00252 double curr_time;
00253 for (unsigned i=0; i<n_steps; i++)
00254 {
00255 curr_time = tStart + i*mDt;
00256
00257
00258 ComputeOneStepExceptVoltage(curr_time);
00259
00260
00261 VerifyStateVariables();
00262 }
00263 }
00264
00265 TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(AbstractBackwardEulerCardiacCell);
00266
00267 #endif