Chaste  Release::3.4
CellCycleModelOdeSolver.hpp
1 /*
2 
3 Copyright (c) 2005-2016, 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 };
101 
103 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
104 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::mpInstance;
105 
106 
107 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
110 {
118 }
119 
120 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
121 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::Instance()
122 {
123  if (!mpInstance)
124  {
126  }
127  return mpInstance;
128 }
129 
130 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
132 {
133  return mpOdeSolver;
134 }
135 
136 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
138 {
139  mpOdeSolver.reset(new ODE_SOLVER);
140  // If this is a CVODE solver we need to tell it to reset. Otherwise
141  // the fact this is a singleton will lead to all sorts of problems
142  // as CVODE will have the internal state for the wrong ODE system!
143 #ifdef CHASTE_CVODE
144  if (boost::dynamic_pointer_cast<CvodeAdaptor>(mpOdeSolver))
145  {
146  (boost::static_pointer_cast<CvodeAdaptor>(mpOdeSolver))->SetForceReset(true);
147  }
148 #endif //CHASTE_CVODE
149 }
150 
151 template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
153 {
155 }
156 
157 
162 template<class CELL_CYCLE_MODEL>
163 class CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
164 {
165 private:
167  static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > mpInstance;
168 
171 
173  friend class boost::serialization::access;
180  template<class Archive>
181  void serialize(Archive & archive, const unsigned int version)
182  {
183  archive & boost::serialization::base_object<AbstractCellCycleModelOdeSolver>(*this);
184  archive & mpInstance;
185  }
186 
187 public:
189  static boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > Instance();
190 
192  bool IsSetUp();
193 
195  void Initialise();
196 
198  void Reset();
199 };
200 
201 template<class CELL_CYCLE_MODEL>
202 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::mpInstance;
203 
204 template<class CELL_CYCLE_MODEL>
207 {
208 }
209 
210 template<class CELL_CYCLE_MODEL>
211 boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Instance()
212 {
213  if (!mpInstance)
214  {
216  }
217  return mpInstance;
218 }
219 
220 template<class CELL_CYCLE_MODEL>
222 {
224 }
225 
226 template<class CELL_CYCLE_MODEL>
228 {
230  {
231  EXCEPTION("SetSizeOfOdeSystem() must be called before calling Initialise()");
232  }
234 }
235 
236 template<class CELL_CYCLE_MODEL>
238 {
240  mpOdeSolver.reset();
241 }
242 
243 #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