Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
CellCycleModelOdeSolver.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
42
43#include "AbstractCellCycleModelOdeSolver.hpp"
44#include "BackwardEulerIvpOdeSolver.hpp"
45#include "CvodeAdaptor.hpp"
46
57template <class CELL_CYCLE_MODEL, class ODE_SOLVER>
58class CellCycleModelOdeSolver : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
59{
60private:
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
82public:
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
106template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
107boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, ODE_SOLVER>::mpInstance;
108
109
110template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
122
123template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
124boost::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
133template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
135{
136 return static_cast<bool>(mpOdeSolver.get());
137}
138
139template<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
154template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
159
160template<class CELL_CYCLE_MODEL, class ODE_SOLVER>
165
170template<class CELL_CYCLE_MODEL>
171class CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> : public AbstractCellCycleModelOdeSolver, private boost::noncopyable
172{
173private:
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
195public:
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
209template<class CELL_CYCLE_MODEL>
210boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::mpInstance;
211
212template<class CELL_CYCLE_MODEL>
217
218template<class CELL_CYCLE_MODEL>
219boost::shared_ptr<CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver> > CellCycleModelOdeSolver<CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver>::Instance()
220{
221 if (!mpInstance)
222 {
224 }
225 return mpInstance;
226}
227
228template<class CELL_CYCLE_MODEL>
230{
231 return mpOdeSolver && (mSizeOfOdeSystem != UNSIGNED_UNSET);
232}
233
234template<class CELL_CYCLE_MODEL>
236{
237 if (mSizeOfOdeSystem == UNSIGNED_UNSET)
238 {
239 EXCEPTION("SetSizeOfOdeSystem() must be called before calling Initialise()");
240 }
241 mpOdeSolver.reset(new BackwardEulerIvpOdeSolver(mSizeOfOdeSystem));
242}
243
244template<class CELL_CYCLE_MODEL>
246{
247 mSizeOfOdeSystem = UNSIGNED_UNSET;
248 mpOdeSolver.reset();
249}
250
251#endif /*CELLCYCLEMODELODESOLVER_HPP_*/
#define EXCEPTION(message)
const unsigned UNSIGNED_UNSET
Definition Exception.hpp:53
static boost::shared_ptr< CellCycleModelOdeSolver< CELL_CYCLE_MODEL, BackwardEulerIvpOdeSolver > > mpInstance
static boost::shared_ptr< CellCycleModelOdeSolver< CELL_CYCLE_MODEL, ODE_SOLVER > > Instance()
static boost::shared_ptr< CellCycleModelOdeSolver< CELL_CYCLE_MODEL, ODE_SOLVER > > mpInstance
friend class boost::serialization::access
void serialize(Archive &archive, const unsigned int version)