37 #ifndef ABSTRACTBACKWARDEULERCARDIACCELL_HPP_
38 #define ABSTRACTBACKWARDEULERCARDIACCELL_HPP_
44 #include <boost/serialization/base_object.hpp>
47 #include "AbstractCardiacCell.hpp"
50 #include "TimeStepper.hpp"
66 template<
unsigned SIZE>
78 template<
class Archive>
79 void serialize(Archive & archive,
const unsigned int version)
82 archive & boost::serialization::base_object<AbstractCardiacCell>(*this);
102 unsigned numberOfStateVariables,
103 unsigned voltageIndex,
104 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus);
116 virtual void ComputeResidual(
double time,
const double rCurrentGuess[SIZE],
double rResidual[SIZE])=0;
125 virtual void ComputeJacobian(
double time,
const double rCurrentGuess[SIZE],
double rJacobian[SIZE][SIZE])=0;
162 #define COVERAGE_IGNORE
174 #undef COVERAGE_IGNORE
207 template <
unsigned SIZE>
209 unsigned numberOfStateVariables,
210 unsigned voltageIndex,
211 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
213 numberOfStateVariables,
215 pIntracellularStimulus)
218 template <
unsigned SIZE>
222 template <
unsigned SIZE>
235 double _n_steps = (tEnd - tStart) / tSamp;
236 const unsigned n_steps = (
unsigned) floor(_n_steps+0.5);
237 assert(fabs(tStart+n_steps*tSamp - tEnd) < 1e-12);
238 const unsigned n_small_steps = (
unsigned) floor(tSamp/mDt+0.5);
239 assert(fabs(mDt*n_small_steps - tSamp) < 1e-12);
249 double curr_time = tStart;
250 for (
unsigned i=0; i<n_steps; i++)
252 for (
unsigned j=0; j<n_small_steps; j++)
254 curr_time = tStart + i*tSamp + j*mDt;
257 UpdateTransmembranePotential(curr_time);
260 ComputeOneStepExceptVoltage(curr_time);
263 VerifyStateVariables();
268 solutions.
rGetTimes().push_back(curr_time+mDt);
274 template <
unsigned SIZE>
281 unsigned n_steps = (
unsigned)((tEnd - tStart) / mDt + 0.5);
282 assert(fabs(tStart + n_steps*mDt - tEnd) < 1e-12);
286 for (
unsigned i=0; i<n_steps; i++)
288 curr_time = tStart + i*mDt;
291 ComputeOneStepExceptVoltage(curr_time);
295 VerifyStateVariables();
300 template<
unsigned SIZE>
307 double time = stepper.
GetTime();
310 UpdateTransmembranePotential(time);
313 ComputeOneStepExceptVoltage(time);
316 VerifyStateVariables();
336 friend class boost::serialization::access;
343 template<
class Archive>
344 void serialize(Archive & archive,
const unsigned int version)
347 archive & boost::serialization::base_object<AbstractCardiacCell>(*this);
360 unsigned voltageIndex,
361 boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus)
363 numberOfStateVariables,
365 pIntracellularStimulus)
396 double _n_steps = (tEnd - tStart) / tSamp;
397 const unsigned n_steps = (
unsigned) floor(_n_steps+0.5);
398 assert(fabs(tStart+n_steps*tSamp - tEnd) < 1e-12);
399 const unsigned n_small_steps = (
unsigned) floor(tSamp/
mDt+0.5);
400 assert(fabs(
mDt*n_small_steps - tSamp) < 1e-12);
410 double curr_time = tStart;
411 for (
unsigned i=0; i<n_steps; i++)
413 for (
unsigned j=0; j<n_small_steps; j++)
415 curr_time = tStart + i*tSamp + j*
mDt;
450 unsigned n_steps = (
unsigned)((tEnd - tStart) /
mDt + 0.5);
451 assert(fabs(tStart + n_steps*
mDt - tEnd) < 1e-12);
455 for (
unsigned i=0; i<n_steps; i++)
457 curr_time = tStart + i*
mDt;
482 double time = stepper.
GetTime();
498 #define COVERAGE_IGNORE
510 #undef COVERAGE_IGNORE
536 #include "OutputFileHandler.hpp"
537 #include <boost/foreach.hpp>
538 template<
unsigned SIZE>
539 void DumpJacobianToFile(
double time,
const double rCurrentGuess[SIZE],
double rJacobian[SIZE][SIZE],
540 const std::vector<double>& rY)
543 out_stream p_file = handler.OpenOutputFile(
"J.txt", std::ios::app);
544 (*p_file) <<
"At " << time <<
" " << SIZE << std::endl;
546 BOOST_FOREACH(
double y, rY)
548 (*p_file) <<
" " << y;
550 (*p_file) << std::endl;
551 (*p_file) <<
"rCurrentGuess";
552 for (
unsigned i=0; i<SIZE; i++)
554 (*p_file) <<
" " << rCurrentGuess[i];
556 (*p_file) << std::endl;
557 (*p_file) <<
"rJacobian";
558 for (
unsigned i=0; i<SIZE; i++)
560 for (
unsigned j=0; j<SIZE; j++)
562 (*p_file) <<
" " << rJacobian[i][j];
565 (*p_file) << std::endl;
void ComputeExceptVoltage(double tStart, double tEnd)
OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)
friend class boost::serialization::access
OdeSolution Compute(double tStart, double tEnd, double tSamp=0.0)
#define TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(T)
std::vector< std::vector< double > > & rGetSolutions()
void SolveAndUpdateState(double tStart, double tEnd)
std::vector< double > & rGetStateVariables()
AbstractBackwardEulerCardiacCell(unsigned numberOfStateVariables, unsigned voltageIndex, boost::shared_ptr< AbstractStimulusFunction > pIntracellularStimulus)
void EvaluateYDerivatives(double time, const std::vector< double > &rY, std::vector< double > &rDY)
void AdvanceOneTimeStep()
void serialize(Archive &archive, const unsigned int version)
void SetOdeSystemInformation(boost::shared_ptr< const AbstractOdeSystemInformation > pOdeSystemInfo)
virtual ~AbstractBackwardEulerCardiacCell()
AbstractBackwardEulerCardiacCell(unsigned numberOfStateVariables, unsigned voltageIndex, boost::shared_ptr< AbstractStimulusFunction > pIntracellularStimulus)
virtual void ComputeResidual(double time, const double rCurrentGuess[SIZE], double rResidual[SIZE])=0
virtual void UpdateTransmembranePotential(double time)=0
void SolveAndUpdateState(double tStart, double tEnd)
virtual ~AbstractBackwardEulerCardiacCell()
virtual void VerifyStateVariables()
void ComputeExceptVoltage(double tStart, double tEnd)
std::vector< double > & rGetTimes()
void EvaluateYDerivatives(double time, const std::vector< double > &rY, std::vector< double > &rDY)
void serialize(Archive &archive, const unsigned int version)
boost::shared_ptr< AbstractOdeSystemInformation > mpSystemInfo
virtual void ComputeOneStepExceptVoltage(double tStart)=0
void SetNumberOfTimeSteps(unsigned numTimeSteps)
virtual void ComputeJacobian(double time, const double rCurrentGuess[SIZE], double rJacobian[SIZE][SIZE])=0