Chaste  Release::2018.1
CellCycleModelOdeSolver.hpp
1 /*
2 
3 Copyright (c) 2005-2018, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef CELLCYCLEMODELODESOLVER_HPP_
37 #define CELLCYCLEMODELODESOLVER_HPP_
38 
39 #include <boost/utility.hpp>
40 
41 #include "ChasteSerialization.hpp"
42 
43 #include "AbstractCellCycleModelOdeSolver.hpp"
44 #include "BackwardEulerIvpOdeSolver.hpp"
45 #include "CvodeAdaptor.hpp"
46 
57 template <class CELL_CYCLE_MODEL, class ODE_SOLVER>
58 class CellCycleModelOdeSolver : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
59 {
60 private:
62  static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > mpInstance;
63 
66 
75  template<class Archive>
76  void serialize(Archive & archive, const unsigned int version)
77  {
78  archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
79  archive & mpInstance;
80  }
81 
82 public:
84  static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > Instance();
85 
87  bool IsSetUp();
88 
90  void Initialise();
91 
99  virtual bool IsAdaptive();
100 
102  void Reset();
103 };
104 
106 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
107 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::mpInstance;
108 
109 
110 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
113 {
121 }
122 
123 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
124 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::Instance()
125 {
126  if (!mpInstance)
127  {
129  }
130  return mpInstance;
131 }
132 
133 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
135 {
136  return static_cast<bool>(mpOdeSolver.get());
137 }
138 
139 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
141 {
142  mpOdeSolver.reset(new ODE_SOLVER);
143  // If this is a CVODE solver we need to tell it to reset. Otherwise
144  // the fact this is a singleton will lead to all sorts of problems
145  // as CVODE will have the internal state for the wrong ODE system!
146 #ifdef CHASTE_CVODE
147  if (boost::dynamic_pointer_cast<CvodeAdaptor>(mpOdeSolver))
148  {
149  (boost::static_pointer_cast<CvodeAdaptor>(mpOdeSolver))->SetForceReset(true);
150  }
151 #endif //CHASTE_CVODE
152 }
153 
154 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
156 {
158 }
159 
160 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
162 {
164 }
165 
170 template<class CELL_CYCLE_MODEL>
171 class CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
172 {
173 private:
175  static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > mpInstance;
176 
179 
181  friend class boost::serialization::access;
188  template<class Archive>
189  void serialize(Archive & archive, const unsigned int version)
190  {
191  archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
192  archive & mpInstance;
193  }
194 
195 public:
197  static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > Instance();
198 
200  bool IsSetUp();
201 
203  void Initialise();
204 
206  void Reset();
207 };
208 
209 template<class CELL_CYCLE_MODEL>
210 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::mpInstance;
211 
212 template<class CELL_CYCLE_MODEL>
215 {
216 }
217 
218 template<class CELL_CYCLE_MODEL>
219 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Instance()
220 {
221  if (!mpInstance)
222  {
224  }
225  return mpInstance;
226 }
227 
228 template<class CELL_CYCLE_MODEL>
230 {
232 }
233 
234 template<class CELL_CYCLE_MODEL>
236 {
238  {
239  EXCEPTION("SetSizeOfOdeSystem() must be called before calling Initialise()");
240  }
242 }
243 
244 template<class CELL_CYCLE_MODEL>
246 {
248  mpOdeSolver.reset();
249 }
250 
251 #endif /*CELLCYCLEMODELODESOLVER_HPP_*/
friend class boost::serialization::access
#define EXCEPTION(message)
Definition: Exception.hpp:143
static boost::shared_ptr< CellCycleModelOdeSolver< CELL_CYCLE_MODEL, ODE_SOLVER > > mpInstance
static boost::shared_ptr< CellCycleModelOdeSolver< CELL_CYCLE_MODEL, ODE_SOLVER > > Instance()
const unsigned UNSIGNED_UNSET
Definition: Exception.hpp:52
void serialize(Archive &archive, const unsigned int version)
static boost::shared_ptr< CellCycleModelOdeSolver< CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver > > mpInstance
boost::shared_ptr< AbstractIvpOdeSolver > mpOdeSolver