Chaste  Release::2017.1
AbstractCellBasedSimulation.hpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 ABSTRACTCELLBASEDSIMULATION_HPP_
37 #define ABSTRACTCELLBASEDSIMULATION_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include <boost/serialization/vector.hpp>
41 #include <boost/serialization/string.hpp>
42 
43 #include <vector>
44 
45 #include "AbstractCellKiller.hpp"
46 #include "AbstractCellBasedSimulationModifier.hpp"
47 #include "AbstractForce.hpp"
48 #include "RandomNumberGenerator.hpp"
49 
50 // Forward declaration prevents circular include chain
51 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM> class AbstractCellPopulation;
52 
67 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM>
69 {
70  // Allow tests to access private members, in order to test computation of private functions e.g. DoCellBirth()
71  friend class TestCryptSimulation2d;
72  friend class TestOffLatticeSimulation3d;
73  friend class TestOffLatticeSimulation;
74 
75 private:
76 
78  friend class boost::serialization::access;
79 
86  template<class Archive>
87  void serialize(Archive & archive, const unsigned int version)
88  {
90  archive & p_time_wrapper;
91 
93  archive & p_rng_wrapper;
94 
95  archive & mDt;
96  archive & mEndTime;
97  archive & mNoBirth;
98  archive & mUpdateCellPopulation;
99  archive & mOutputDirectory;
100  archive & mNumBirths;
101  archive & mNumDeaths;
102  archive & mOutputDivisionLocations;
103  archive & mOutputCellVelocities;
104  archive & mCellKillers;
105  archive & mSimulationModifiers;
106  archive & mSamplingTimestepMultiple;
107  }
108 
109 protected:
110 
112  double mDt;
113 
115  double mEndTime;
116 
119 
122 
125 
127  bool mNoBirth;
128 
131 
133  std::string mOutputDirectory;
134 
137 
139  out_stream mpVizSetupFile;
140 
142  unsigned mNumBirths;
143 
145  unsigned mNumDeaths;
146 
149 
152 
158 
161 
163  std::vector<boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > > mCellKillers;
164 
166  std::vector<boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM, SPACE_DIM> > > mSimulationModifiers;
167 
173 
178  {
179  }
180 
196  virtual unsigned DoCellBirth();
197 
206  unsigned DoCellRemoval();
207 
211  virtual void SetupSolve()
212  {
213  }
214 
221  virtual bool StoppingEventHasOccurred();
222 
226  virtual void UpdateCellPopulation();
227 
241  virtual void UpdateCellLocationsAndTopology()=0;
242 
246  void OutputSimulationSetup();
247 
257  virtual void OutputAdditionalSimulationSetup(out_stream& rParamsFile)=0;
258 
259 public:
260 
270  bool deleteCellPopulationInDestructor=false,
271  bool initialiseCells=true);
272 
279 
286  std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
287 
291  double GetDt();
292 
296  unsigned GetNumBirths();
297 
301  unsigned GetNumDeaths();
302 
306  std::string GetOutputDirectory();
307 
313  void SetDt(double dt);
314 
320  void SetEndTime(double endTime);
321 
327  void SetOutputDirectory(std::string outputDirectory);
328 
335  void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
336 
342  void SetNoBirth(bool noBirth);
343 
349  void SetUpdateCellPopulationRule(bool updateCellPopulation);
350 
357 
363  void AddCellKiller(boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > pCellKiller);
364 
368  void RemoveAllCellKillers();
369 
375  void AddSimulationModifier(boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM,SPACE_DIM> > pSimulationModifier);
376 
380  std::vector<boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM, SPACE_DIM> > >* GetSimulationModifiers();
381 
436  void Solve();
437 
442 
447 
452 
458  void SetOutputDivisionLocations(bool outputDivisionLocations);
459 
464 
470  void SetOutputCellVelocities(bool outputCellVelocities);
471 
480  virtual void OutputSimulationParameters(out_stream& rParamsFile)=0;
481 };
482 
483 #endif /*ABSTRACTCELLBASEDSIMULATION_HPP_*/
void AddCellKiller(boost::shared_ptr< AbstractCellKiller< SPACE_DIM > > pCellKiller)
static SimulationTime * Instance()
AbstractCellBasedSimulation(AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation, bool deleteCellPopulationInDestructor=false, bool initialiseCells=true)
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & rGetCellPopulation()
void SetOutputCellVelocities(bool outputCellVelocities)
void serialize(Archive &archive, const unsigned int version)
virtual void OutputAdditionalSimulationSetup(out_stream &rParamsFile)=0
void SetUpdateCellPopulationRule(bool updateCellPopulation)
std::vector< boost::shared_ptr< AbstractCellKiller< SPACE_DIM > > > mCellKillers
void SetOutputDivisionLocations(bool outputDivisionLocations)
virtual void OutputSimulationParameters(out_stream &rParamsFile)=0
virtual void UpdateCellLocationsAndTopology()=0
void SetOutputDirectory(std::string outputDirectory)
static RandomNumberGenerator * Instance()
std::vector< double > GetNodeLocation(const unsigned &rNodeIndex)
void AddSimulationModifier(boost::shared_ptr< AbstractCellBasedSimulationModifier< ELEMENT_DIM, SPACE_DIM > > pSimulationModifier)
SerializableSingleton< SINGLETON_CLASS > * GetSerializationWrapper() const
std::vector< boost::shared_ptr< AbstractCellBasedSimulationModifier< ELEMENT_DIM, SPACE_DIM > > > mSimulationModifiers
std::vector< boost::shared_ptr< AbstractCellBasedSimulationModifier< ELEMENT_DIM, SPACE_DIM > > > * GetSimulationModifiers()
void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple)
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation