AbstractOdeBasedCellCycleModel.cpp

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(const AbstractOdeBasedCellCycleModel& rOtherModel)
00043     : AbstractCellCycleModel(rOtherModel),
00044       mpOdeSystem(NULL), // Must be done by subclasses
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     // Update the phase from M to G1 when necessary
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             // Still dividing; don't run ODEs
00104             return;
00105         }
00106     }
00107 
00108     if (current_time > mLastTime)
00109     {
00110         if (!mFinishedRunningOdes)
00111         {
00112             // Update whether a stopping event has occurred
00113             mFinishedRunningOdes = SolveOdeToTime(current_time);
00114 
00115             // Check no concentrations have gone negative
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                 // Update durations of each phase
00130                 mG1Duration = GetOdeStopTime() - mBirthTime - GetMDuration();
00131                 mG2PhaseStartTime = GetOdeStopTime() + GetSDuration();
00132                 mDivideTime = mG2PhaseStartTime + GetG2Duration();
00133 
00134                 // Update phase
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;   // This is the last time the ODEs were evaluated.
00145         }
00146         else
00147         {
00148             // ODE model finished, just increasing time until division...
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 }

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5