Chaste Release::3.1
CellCycleModelOdeSolver.hpp
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 #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 
00056 template <class CELL_CYCLE_MODEL, class ODE_SOLVER>
00057 class CellCycleModelOdeSolver : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
00058 {
00059 private:
00061     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > mpInstance;
00062 
00064     CellCycleModelOdeSolver();
00065 
00067     friend class boost::serialization::access;
00074     template<class Archive>
00075     void serialize(Archive & archive, const unsigned int version)
00076     {
00077         archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
00078         archive & mpInstance;
00079     }
00080 
00081 public:
00083     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > Instance();
00084 
00086     bool IsSetUp();
00087 
00089     void Initialise();
00090 
00098     virtual bool IsAdaptive();
00099 };
00100 
00102 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00103 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::mpInstance;
00104 
00105 
00106 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00107 CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::CellCycleModelOdeSolver()
00108     : AbstractCellCycleModelOdeSolver()
00109 {
00117 }
00118 
00119 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00120 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::Instance()
00121 {
00122     if (!mpInstance)
00123     {
00124         mpInstance.reset(new CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>);
00125     }
00126     return mpInstance;
00127 }
00128 
00129 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00130 bool CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::IsSetUp()
00131 {
00132     return mpOdeSolver;
00133 }
00134 
00135 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00136 void CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::Initialise()
00137 {
00138     mpOdeSolver.reset(new ODE_SOLVER);
00139 }
00140 
00141 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
00142 bool CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::IsAdaptive()
00143 {
00144     return AbstractCellCycleModelOdeSolver::IsAdaptive();
00145 }
00146 
00151 template<class CELL_CYCLE_MODEL>
00152 class CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
00153 {
00154 private:
00156     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > mpInstance;
00157 
00159     CellCycleModelOdeSolver();
00160 
00162     friend class boost::serialization::access;
00169     template<class Archive>
00170     void serialize(Archive & archive, const unsigned int version)
00171     {
00172         archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
00173         archive & mpInstance;
00174     }
00175 
00176 public:
00178     static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > Instance();
00179 
00181     bool IsSetUp();
00182 
00184     void Initialise();
00185 
00187     void Reset();
00188 };
00189 
00190 template<class CELL_CYCLE_MODEL>
00191 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::mpInstance;
00192 
00193 template<class CELL_CYCLE_MODEL>
00194 CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::CellCycleModelOdeSolver()
00195     : AbstractCellCycleModelOdeSolver()
00196 {
00197 }
00198 
00199 template<class CELL_CYCLE_MODEL>
00200 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Instance()
00201 {
00202     if (!mpInstance)
00203     {
00204         mpInstance.reset(new CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>);
00205     }
00206     return mpInstance;
00207 }
00208 
00209 template<class CELL_CYCLE_MODEL>
00210 bool CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::IsSetUp()
00211 {
00212     return mpOdeSolver && (mSizeOfOdeSystem != UNSIGNED_UNSET);
00213 }
00214 
00215 template<class CELL_CYCLE_MODEL>
00216 void CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Initialise()
00217 {
00218     if (mSizeOfOdeSystem == UNSIGNED_UNSET)
00219     {
00220         EXCEPTION("SetSizeOfOdeSystem() must be called before calling Initialise()");
00221     }
00222     mpOdeSolver.reset(new BackwardEulerIvpOdeSolver(mSizeOfOdeSystem));
00223 }
00224 
00225 template<class CELL_CYCLE_MODEL>
00226 void CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Reset()
00227 {
00228     mSizeOfOdeSystem = UNSIGNED_UNSET;
00229     mpOdeSolver.reset();
00230 }
00231 
00232 #endif /*CELLCYCLEMODELODESOLVER_HPP_*/