00001 /* 00002 00003 Copyright (C) University of Oxford, 2005-2011 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 00029 #include "AbstractOdeBasedCellCycleModel.hpp" 00030 #include <iostream> 00031 #include <cassert> 00032 #include "Exception.hpp" 00033 00034 AbstractOdeBasedCellCycleModel::AbstractOdeBasedCellCycleModel(double lastTime, 00035 boost::shared_ptr<AbstractCellCycleModelOdeSolver> pOdeSolver) 00036 : CellCycleModelOdeHandler(lastTime, pOdeSolver), 00037 mDivideTime(lastTime), 00038 mFinishedRunningOdes(false), 00039 mG2PhaseStartTime(DBL_MAX) 00040 { 00041 AbstractCellCycleModel::SetBirthTime(lastTime); 00042 } 00043 00044 AbstractOdeBasedCellCycleModel::~AbstractOdeBasedCellCycleModel() 00045 { 00046 } 00047 00048 void AbstractOdeBasedCellCycleModel::SetBirthTime(double birthTime) 00049 { 00050 AbstractCellCycleModel::SetBirthTime(birthTime); 00051 mLastTime = birthTime; 00052 mDivideTime = birthTime; 00053 } 00054 00055 std::vector<double> AbstractOdeBasedCellCycleModel::GetProteinConcentrations() const 00056 { 00057 assert(mpOdeSystem != NULL); 00058 return mpOdeSystem->rGetStateVariables(); 00059 } 00060 00061 void AbstractOdeBasedCellCycleModel::SetProteinConcentrationsForTestsOnly(double lastTime, std::vector<double> proteinConcentrations) 00062 { 00063 assert(mpOdeSystem != NULL); 00064 assert(proteinConcentrations.size()==mpOdeSystem->rGetStateVariables().size()); 00065 mLastTime = lastTime; 00066 mpOdeSystem->SetStateVariables(proteinConcentrations); 00067 } 00068 00069 void AbstractOdeBasedCellCycleModel::UpdateCellCyclePhase() 00070 { 00071 assert(mpOdeSystem != NULL); 00072 00073 double current_time = SimulationTime::Instance()->GetTime(); 00074 00075 // Update the phase from M to G1 when necessary 00076 if (mCurrentCellCyclePhase == M_PHASE) 00077 { 00078 double m_duration = GetMDuration(); 00079 if (GetAge() >= m_duration) 00080 { 00081 mCurrentCellCyclePhase = G_ONE_PHASE; 00082 mLastTime = m_duration + mBirthTime; 00083 } 00084 else 00085 { 00086 // Still dividing; don't run ODEs 00087 return; 00088 } 00089 } 00090 00091 if (current_time > mLastTime) 00092 { 00093 if (!mFinishedRunningOdes) 00094 { 00095 // Update whether a stopping event has occurred 00096 mFinishedRunningOdes = SolveOdeToTime(current_time); 00097 00098 // Check no concentrations have gone negative 00099 for (unsigned i=0; i<mpOdeSystem->GetNumberOfStateVariables(); i++) 00100 { 00101 if (mpOdeSystem->rGetStateVariables()[i] < -DBL_EPSILON) 00102 { 00103 #define COVERAGE_IGNORE 00104 EXCEPTION("A protein concentration " << i << " has gone negative (" << 00105 mpOdeSystem->rGetStateVariables()[i] << ")\n" 00106 << "Chaste predicts that the CellCycleModel numerical method is probably unstable."); 00107 #undef COVERAGE_IGNORE 00108 } 00109 } 00110 00111 if (mFinishedRunningOdes) 00112 { 00113 // Update durations of each phase 00114 mG1Duration = GetOdeStopTime() - mBirthTime - GetMDuration(); 00115 mG2PhaseStartTime = GetOdeStopTime() + GetSDuration(); 00116 mDivideTime = mG2PhaseStartTime + GetG2Duration(); 00117 00118 // Update phase 00119 if (current_time >= mG2PhaseStartTime) 00120 { 00121 mCurrentCellCyclePhase = G_TWO_PHASE; 00122 } 00123 else 00124 { 00125 mCurrentCellCyclePhase = S_PHASE; 00126 } 00127 } 00128 } 00129 else 00130 { 00131 // ODE model finished, just increasing time until division... 00132 if (current_time >= mG2PhaseStartTime) 00133 { 00134 mCurrentCellCyclePhase = G_TWO_PHASE; 00135 } 00136 } 00137 } 00138 } 00139 00140 void AbstractOdeBasedCellCycleModel::ResetForDivision() 00141 { 00142 assert(mFinishedRunningOdes); 00143 AbstractCellCycleModel::ResetForDivision(); 00144 mBirthTime = mDivideTime; 00145 mLastTime = mDivideTime; 00146 mFinishedRunningOdes = false; 00147 mG1Duration = DBL_MAX; 00148 mDivideTime = DBL_MAX; 00149 } 00150 00151 double AbstractOdeBasedCellCycleModel::GetOdeStopTime() 00152 { 00153 double stop_time = DOUBLE_UNSET; 00154 if (mpOdeSolver->StoppingEventOccurred()) 00155 { 00156 stop_time = mpOdeSolver->GetStoppingTime(); 00157 } 00158 return stop_time; 00159 } 00160 00161 void AbstractOdeBasedCellCycleModel::SetFinishedRunningOdes(bool finishedRunningOdes) 00162 { 00163 mFinishedRunningOdes = finishedRunningOdes; 00164 } 00165 00166 void AbstractOdeBasedCellCycleModel::SetDivideTime(double divideTime) 00167 { 00168 mDivideTime = divideTime; 00169 } 00170 00171 void AbstractOdeBasedCellCycleModel::SetG2PhaseStartTime(double g2PhaseStartTime) 00172 { 00173 mG2PhaseStartTime = g2PhaseStartTime; 00174 } 00175 00176 void AbstractOdeBasedCellCycleModel::OutputCellCycleModelParameters(out_stream& rParamsFile) 00177 { 00178 // No new parameters to output 00179 00180 // Call method on direct parent class 00181 AbstractCellCycleModel::OutputCellCycleModelParameters(rParamsFile); 00182 }