Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 #include "AbstractOdeBasedCellCycleModel.hpp" 00037 #include <iostream> 00038 #include <cassert> 00039 #include "Exception.hpp" 00040 00041 AbstractOdeBasedCellCycleModel::AbstractOdeBasedCellCycleModel(double lastTime, 00042 boost::shared_ptr<AbstractCellCycleModelOdeSolver> pOdeSolver) 00043 : CellCycleModelOdeHandler(lastTime, pOdeSolver), 00044 mDivideTime(lastTime), 00045 mFinishedRunningOdes(false), 00046 mG2PhaseStartTime(DBL_MAX) 00047 { 00048 AbstractCellCycleModel::SetBirthTime(lastTime); 00049 } 00050 00051 AbstractOdeBasedCellCycleModel::~AbstractOdeBasedCellCycleModel() 00052 { 00053 } 00054 00055 void AbstractOdeBasedCellCycleModel::SetBirthTime(double birthTime) 00056 { 00057 AbstractCellCycleModel::SetBirthTime(birthTime); 00058 mLastTime = birthTime; 00059 mDivideTime = birthTime; 00060 } 00061 00062 std::vector<double> AbstractOdeBasedCellCycleModel::GetProteinConcentrations() const 00063 { 00064 assert(mpOdeSystem != NULL); 00065 return mpOdeSystem->rGetStateVariables(); 00066 } 00067 00068 void AbstractOdeBasedCellCycleModel::SetProteinConcentrationsForTestsOnly(double lastTime, std::vector<double> proteinConcentrations) 00069 { 00070 assert(mpOdeSystem != NULL); 00071 assert(proteinConcentrations.size()==mpOdeSystem->rGetStateVariables().size()); 00072 mLastTime = lastTime; 00073 mpOdeSystem->SetStateVariables(proteinConcentrations); 00074 } 00075 00076 void AbstractOdeBasedCellCycleModel::UpdateCellCyclePhase() 00077 { 00078 assert(mpOdeSystem != NULL); 00079 00080 double current_time = SimulationTime::Instance()->GetTime(); 00081 00082 // Update the phase from M to G1 when necessary 00083 if (mCurrentCellCyclePhase == M_PHASE) 00084 { 00085 double m_duration = GetMDuration(); 00086 if (GetAge() >= m_duration) 00087 { 00088 mCurrentCellCyclePhase = G_ONE_PHASE; 00089 mLastTime = m_duration + mBirthTime; 00090 } 00091 else 00092 { 00093 // Still dividing; don't run ODEs 00094 return; 00095 } 00096 } 00097 00098 if (current_time > mLastTime) 00099 { 00100 if (!mFinishedRunningOdes) 00101 { 00102 // Update whether a stopping event has occurred 00103 mFinishedRunningOdes = SolveOdeToTime(current_time); 00104 00105 // Check no concentrations have gone negative 00106 for (unsigned i=0; i<mpOdeSystem->GetNumberOfStateVariables(); i++) 00107 { 00108 if (mpOdeSystem->rGetStateVariables()[i] < -DBL_EPSILON) 00109 { 00110 #define COVERAGE_IGNORE 00111 EXCEPTION("A protein concentration " << i << " has gone negative (" << 00112 mpOdeSystem->rGetStateVariables()[i] << ")\n" 00113 << "Chaste predicts that the CellCycleModel numerical method is probably unstable."); 00114 #undef COVERAGE_IGNORE 00115 } 00116 } 00117 00118 if (mFinishedRunningOdes) 00119 { 00120 // Update durations of each phase 00121 mG1Duration = GetOdeStopTime() - mBirthTime - GetMDuration(); 00122 mG2PhaseStartTime = GetOdeStopTime() + GetSDuration(); 00123 mDivideTime = mG2PhaseStartTime + GetG2Duration(); 00124 00125 // Update phase 00126 if (current_time >= mG2PhaseStartTime) 00127 { 00128 mCurrentCellCyclePhase = G_TWO_PHASE; 00129 } 00130 else 00131 { 00132 mCurrentCellCyclePhase = S_PHASE; 00133 } 00134 } 00135 } 00136 else 00137 { 00138 // ODE model finished, just increasing time until division... 00139 if (current_time >= mG2PhaseStartTime) 00140 { 00141 mCurrentCellCyclePhase = G_TWO_PHASE; 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 } 00157 00158 double AbstractOdeBasedCellCycleModel::GetOdeStopTime() 00159 { 00160 double stop_time = DOUBLE_UNSET; 00161 if (mpOdeSolver->StoppingEventOccurred()) 00162 { 00163 stop_time = mpOdeSolver->GetStoppingTime(); 00164 } 00165 return stop_time; 00166 } 00167 00168 void AbstractOdeBasedCellCycleModel::SetFinishedRunningOdes(bool finishedRunningOdes) 00169 { 00170 mFinishedRunningOdes = finishedRunningOdes; 00171 } 00172 00173 void AbstractOdeBasedCellCycleModel::SetDivideTime(double divideTime) 00174 { 00175 mDivideTime = divideTime; 00176 } 00177 00178 void AbstractOdeBasedCellCycleModel::SetG2PhaseStartTime(double g2PhaseStartTime) 00179 { 00180 mG2PhaseStartTime = g2PhaseStartTime; 00181 } 00182 00183 void AbstractOdeBasedCellCycleModel::OutputCellCycleModelParameters(out_stream& rParamsFile) 00184 { 00185 // No new parameters to output 00186 00187 // Call method on direct parent class 00188 AbstractCellCycleModel::OutputCellCycleModelParameters(rParamsFile); 00189 }