00001 /* 00002 00003 Copyright (C) University of Oxford, 2005-2009 00004 00005 University of Oxford means the Chancellor, Masters and Scholars of the 00006 University of Oxford, having an administrative office at Wellington 00007 Square, Oxford OX1 2JD, UK. 00008 00009 This file is part of Chaste. 00010 00011 Chaste is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU Lesser General Public License as published 00013 by the Free Software Foundation, either version 2.1 of the License, or 00014 (at your option) any later version. 00015 00016 Chaste is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00019 License for more details. The offer of Chaste under the terms of the 00020 License is subject to the License being interpreted in accordance with 00021 English Law and subject to any action against the University of Oxford 00022 being under the jurisdiction of the English Courts. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>. 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() 00043 { 00044 if (mpOdeSystem!=NULL) 00045 { 00046 delete mpOdeSystem; 00047 } 00048 } 00049 00050 00051 void AbstractOdeBasedCellCycleModel::SetBirthTime(double birthTime) 00052 { 00053 AbstractCellCycleModel::SetBirthTime(birthTime); 00054 mLastTime = birthTime; 00055 mDivideTime = birthTime; 00056 } 00057 00058 00059 std::vector<double> AbstractOdeBasedCellCycleModel::GetProteinConcentrations() const 00060 { 00061 assert(mpOdeSystem!=NULL); 00062 return mpOdeSystem->rGetStateVariables(); 00063 } 00064 00065 00066 void AbstractOdeBasedCellCycleModel::SetProteinConcentrationsForTestsOnly(double lastTime, std::vector<double> proteinConcentrations) 00067 { 00068 assert(mpOdeSystem!=NULL); 00069 assert(proteinConcentrations.size()==mpOdeSystem->rGetStateVariables().size()); 00070 mLastTime = lastTime; 00071 mpOdeSystem->SetStateVariables(proteinConcentrations); 00072 } 00073 00074 00075 void AbstractOdeBasedCellCycleModel::UpdateCellCyclePhase() 00076 { 00077 assert(mpOdeSystem!=NULL); 00078 00079 double current_time = SimulationTime::Instance()->GetTime(); 00080 00081 // Update the phase from M to G1 when necessary 00082 if (mCurrentCellCyclePhase == M_PHASE) 00083 { 00084 double m_duration = GetMDuration(); 00085 if (GetAge() >= m_duration) 00086 { 00087 mCurrentCellCyclePhase = G_ONE_PHASE; 00088 mLastTime = m_duration + mBirthTime; 00089 } 00090 else 00091 { 00092 // Still dividing; don't run ODEs 00093 return; 00094 } 00095 } 00096 00097 if (current_time > mLastTime) 00098 { 00099 if (!mFinishedRunningOdes) 00100 { 00101 // Update whether a stopping event has occurred 00102 mFinishedRunningOdes = SolveOdeToTime(current_time); 00103 00104 // Check no concentrations have gone negative 00105 for (unsigned i=0; i<mpOdeSystem->GetNumberOfStateVariables(); i++) 00106 { 00107 if (mpOdeSystem->rGetStateVariables()[i] < -DBL_EPSILON) 00108 { 00109 #define COVERAGE_IGNORE 00110 std::cout << "Protein["<< i <<"] = "<< mpOdeSystem->rGetStateVariables()[i] << "\n"; 00111 EXCEPTION("A protein concentration has gone negative\nChaste predicts that the CellCycleModel numerical method is probably unstable."); 00112 #undef COVERAGE_IGNORE 00113 } 00114 } 00115 00116 if (mFinishedRunningOdes) 00117 { 00118 // Update durations of each phase 00119 mG1Duration = GetOdeStopTime() - mBirthTime - GetMDuration(); 00120 mG2PhaseStartTime = GetOdeStopTime() + GetSDuration(); 00121 mDivideTime = mG2PhaseStartTime + GetG2Duration(); 00122 00123 // Update phase 00124 if (current_time >= mG2PhaseStartTime) 00125 { 00126 mCurrentCellCyclePhase = G_TWO_PHASE; 00127 } 00128 else 00129 { 00130 mCurrentCellCyclePhase = S_PHASE; 00131 } 00132 } 00133 mLastTime = current_time; // This is the last time the ODEs were evaluated. 00134 } 00135 else 00136 { 00137 // ODE model finished, just increasing time until division... 00138 if (current_time >= mG2PhaseStartTime) 00139 { 00140 mCurrentCellCyclePhase = G_TWO_PHASE; 00141 } 00142 } 00143 } 00144 } 00145 00146 00147 void AbstractOdeBasedCellCycleModel::ResetForDivision() 00148 { 00149 assert(mFinishedRunningOdes); 00150 AbstractCellCycleModel::ResetForDivision(); 00151 mBirthTime = mDivideTime; 00152 mLastTime = mDivideTime; 00153 mFinishedRunningOdes = false; 00154 mG1Duration = DBL_MAX; 00155 mDivideTime = DBL_MAX; 00156 }