CellCycleModelOdeSolver.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00141
00142
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