CellCycleModelOdeSolver.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 #ifndef CELLCYCLEMODELODESOLVER_HPP_
00037 #define CELLCYCLEMODELODESOLVER_HPP_
00038 
00039 #include <boost/utility.hpp>
00040 
00041 #include "ChasteSerialization.hpp"
00042 
00043 #include "AbstractCellCycleModelOdeSolver.hpp"
00044 #include "BackwardEulerIvpOdeSolver.hpp"
00045 #include "CvodeAdaptor.hpp"
00046 
00057 template <class CELL_CYCLE_MODEL, class ODE_SOLVER>
00058 class CellCycleModelOdeSolver : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
00059 {
00060 private:
00062     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > mpInstance;
00063 
00065     CellCycleModelOdeSolver();
00066 
00068     friend class boost::serialization::access;
00075     template<class Archive>
00076     void serialize(Archive & archive, const unsigned int version)
00077     {
00078         archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
00079         archive & mpInstance;
00080     }
00081 
00082 public:
00084     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > Instance();
00085 
00087     bool IsSetUp();
00088 
00090     void Initialise();
00091 
00099     virtual bool IsAdaptive();
00100 };
00101 
00103 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00104 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::mpInstance;
00105 
00106 
00107 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00108 CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::CellCycleModelOdeSolver()
00109     : AbstractCellCycleModelOdeSolver()
00110 {
00118 }
00119 
00120 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00121 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::Instance()
00122 {
00123     if (!mpInstance)
00124     {
00125         mpInstance.reset(new CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>);
00126     }
00127     return mpInstance;
00128 }
00129 
00130 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00131 bool CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::IsSetUp()
00132 {
00133     return mpOdeSolver;
00134 }
00135 
00136 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00137 void CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::Initialise()
00138 {
00139     mpOdeSolver.reset(new ODE_SOLVER);
00140     // If this is a CVODE solver we need to tell it to reset. Otherwise
00141     // the fact this is a singleton will lead to all sorts of problems
00142     // as CVODE will have the internal state for the wrong ODE system!
00143 #ifdef CHASTE_CVODE
00144     if (boost::dynamic_pointer_cast<CvodeAdaptor>(mpOdeSolver))
00145     {
00146         (boost::static_pointer_cast<CvodeAdaptor>(mpOdeSolver))->SetForceReset(true);
00147     }
00148 #endif //CHASTE_CVODE
00149 }
00150 
00151 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00152 bool CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::IsAdaptive()
00153 {
00154     return AbstractCellCycleModelOdeSolver::IsAdaptive();
00155 }
00156 
00157 
00162 template<class CELL_CYCLE_MODEL>
00163 class CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
00164 {
00165 private:
00167     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > mpInstance;
00168 
00170     CellCycleModelOdeSolver();
00171 
00173     friend class boost::serialization::access;
00180     template<class Archive>
00181     void serialize(Archive & archive, const unsigned int version)
00182     {
00183         archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
00184         archive & mpInstance;
00185     }
00186 
00187 public:
00189     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > Instance();
00190 
00192     bool IsSetUp();
00193 
00195     void Initialise();
00196 
00198     void Reset();
00199 };
00200 
00201 template<class CELL_CYCLE_MODEL>
00202 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::mpInstance;
00203 
00204 template<class CELL_CYCLE_MODEL>
00205 CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::CellCycleModelOdeSolver()
00206     : AbstractCellCycleModelOdeSolver()
00207 {
00208 }
00209 
00210 template<class CELL_CYCLE_MODEL>
00211 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Instance()
00212 {
00213     if (!mpInstance)
00214     {
00215         mpInstance.reset(new CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>);
00216     }
00217     return mpInstance;
00218 }
00219 
00220 template<class CELL_CYCLE_MODEL>
00221 bool CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::IsSetUp()
00222 {
00223     return mpOdeSolver && (mSizeOfOdeSystem != UNSIGNED_UNSET);
00224 }
00225 
00226 template<class CELL_CYCLE_MODEL>
00227 void CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Initialise()
00228 {
00229     if (mSizeOfOdeSystem == UNSIGNED_UNSET)
00230     {
00231         EXCEPTION("SetSizeOfOdeSystem() must be called before calling Initialise()");
00232     }
00233     mpOdeSolver.reset(new BackwardEulerIvpOdeSolver(mSizeOfOdeSystem));
00234 }
00235 
00236 template<class CELL_CYCLE_MODEL>
00237 void CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Reset()
00238 {
00239     mSizeOfOdeSystem = UNSIGNED_UNSET;
00240     mpOdeSolver.reset();
00241 }
00242 
00243 #endif /*CELLCYCLEMODELODESOLVER_HPP_*/

Generated by  doxygen 1.6.2