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 "AbstractOdeBasedCellCycleModel.hpp"
00029
00030
00031 AbstractOdeBasedCellCycleModel::AbstractOdeBasedCellCycleModel(double lastTime)
00032 : mpOdeSystem(NULL),
00033 mLastTime(lastTime),
00034 mDivideTime(lastTime),
00035 mFinishedRunningOdes(false),
00036 mG2PhaseStartTime(DBL_MAX)
00037 {
00038 AbstractCellCycleModel::SetBirthTime(lastTime);
00039 }
00040
00041
00042 AbstractOdeBasedCellCycleModel::AbstractOdeBasedCellCycleModel(const AbstractOdeBasedCellCycleModel& rOtherModel)
00043 : AbstractCellCycleModel(rOtherModel),
00044 mpOdeSystem(NULL),
00045 mLastTime(rOtherModel.mLastTime),
00046 mDivideTime(rOtherModel.mDivideTime),
00047 mFinishedRunningOdes(rOtherModel.mFinishedRunningOdes),
00048 mG2PhaseStartTime(rOtherModel.mG2PhaseStartTime)
00049 {
00050 }
00051
00052
00053 AbstractOdeBasedCellCycleModel::~AbstractOdeBasedCellCycleModel()
00054 {
00055 if (mpOdeSystem!=NULL)
00056 {
00057 delete mpOdeSystem;
00058 }
00059 }
00060
00061
00062 void AbstractOdeBasedCellCycleModel::SetBirthTime(double birthTime)
00063 {
00064 AbstractCellCycleModel::SetBirthTime(birthTime);
00065 mLastTime = birthTime;
00066 mDivideTime = birthTime;
00067 }
00068
00069
00070 std::vector<double> AbstractOdeBasedCellCycleModel::GetProteinConcentrations() const
00071 {
00072 assert(mpOdeSystem!=NULL);
00073 return mpOdeSystem->rGetStateVariables();
00074 }
00075
00076
00077 void AbstractOdeBasedCellCycleModel::SetProteinConcentrationsForTestsOnly(double lastTime, std::vector<double> proteinConcentrations)
00078 {
00079 assert(mpOdeSystem!=NULL);
00080 assert(proteinConcentrations.size()==mpOdeSystem->rGetStateVariables().size());
00081 mLastTime = lastTime;
00082 mpOdeSystem->SetStateVariables(proteinConcentrations);
00083 }
00084
00085
00086 void AbstractOdeBasedCellCycleModel::UpdateCellCyclePhase()
00087 {
00088 assert(mpOdeSystem!=NULL);
00089
00090 double current_time = SimulationTime::Instance()->GetTime();
00091
00092
00093 if (mCurrentCellCyclePhase == M_PHASE)
00094 {
00095 double m_duration = GetMDuration();
00096 if (GetAge() >= m_duration)
00097 {
00098 mCurrentCellCyclePhase = G_ONE_PHASE;
00099 mLastTime = m_duration + mBirthTime;
00100 }
00101 else
00102 {
00103
00104 return;
00105 }
00106 }
00107
00108 if (current_time > mLastTime)
00109 {
00110 if (!mFinishedRunningOdes)
00111 {
00112
00113 mFinishedRunningOdes = SolveOdeToTime(current_time);
00114
00115
00116 for (unsigned i=0; i<mpOdeSystem->GetNumberOfStateVariables(); i++)
00117 {
00118 if (mpOdeSystem->rGetStateVariables()[i] < -DBL_EPSILON)
00119 {
00120 #define COVERAGE_IGNORE
00121 std::cout << "Protein["<< i <<"] = "<< mpOdeSystem->rGetStateVariables()[i] << "\n";
00122 EXCEPTION("A protein concentration has gone negative\nChaste predicts that the CellCycleModel numerical method is probably unstable.");
00123 #undef COVERAGE_IGNORE
00124 }
00125 }
00126
00127 if (mFinishedRunningOdes)
00128 {
00129
00130 mG1Duration = GetOdeStopTime() - mBirthTime - GetMDuration();
00131 mG2PhaseStartTime = GetOdeStopTime() + GetSDuration();
00132 mDivideTime = mG2PhaseStartTime + GetG2Duration();
00133
00134
00135 if (current_time >= mG2PhaseStartTime)
00136 {
00137 mCurrentCellCyclePhase = G_TWO_PHASE;
00138 }
00139 else
00140 {
00141 mCurrentCellCyclePhase = S_PHASE;
00142 }
00143 }
00144 mLastTime = current_time;
00145 }
00146 else
00147 {
00148
00149 if (current_time >= mG2PhaseStartTime)
00150 {
00151 mCurrentCellCyclePhase = G_TWO_PHASE;
00152 }
00153 }
00154 }
00155 }
00156
00157
00158 void AbstractOdeBasedCellCycleModel::ResetForDivision()
00159 {
00160 assert(mFinishedRunningOdes);
00161 AbstractCellCycleModel::ResetForDivision();
00162 mBirthTime = mDivideTime;
00163 mLastTime = mDivideTime;
00164 mFinishedRunningOdes = false;
00165 mG1Duration = DBL_MAX;
00166 mDivideTime = DBL_MAX;
00167 }