Chaste  Release::3.4
AbstractCellBasedSimulation.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 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 "CellBasedPdeHandler.hpp"
46 #include "AbstractCellKiller.hpp"
47 #include "AbstractCellBasedSimulationModifier.hpp"
48 #include "AbstractForce.hpp"
49 #include "RandomNumberGenerator.hpp"
50 
65 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM>
67 {
68  // Allow tests to access private members, in order to test computation of private functions e.g. DoCellBirth()
69  friend class TestCryptSimulation2d;
70  friend class TestOffLatticeSimulation3d;
71  friend class TestOffLatticeSimulation;
72 
73 private:
74 
76  friend class boost::serialization::access;
77 
84  template<class Archive>
85  void serialize(Archive & archive, const unsigned int version)
86  {
88  archive & p_time_wrapper;
89 
91  archive & p_rng_wrapper;
92 
93  archive & mDt;
94  archive & mEndTime;
95  archive & mNoBirth;
96  archive & mUpdateCellPopulation;
97  archive & mOutputDirectory;
98  archive & mNumBirths;
99  archive & mNumDeaths;
100  archive & mOutputDivisionLocations;
101  archive & mOutputCellVelocities;
102  archive & mCellKillers;
103  archive & mSimulationModifiers;
104  archive & mSamplingTimestepMultiple;
105  archive & mpCellBasedPdeHandler;
106  }
107 
108 protected:
109 
111  double mDt;
112 
114  double mEndTime;
115 
118 
121 
124 
126  bool mNoBirth;
127 
130 
132  std::string mOutputDirectory;
133 
136 
138  out_stream mpVizSetupFile;
139 
141  unsigned mNumBirths;
142 
144  unsigned mNumDeaths;
145 
148 
151 
157 
160 
162  std::vector<boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > > mCellKillers;
163 
165  std::vector<boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM, SPACE_DIM> > > mSimulationModifiers;
166 
172 
177 
182  {
183  }
184 
200  virtual unsigned DoCellBirth();
201 
213  virtual c_vector<double, SPACE_DIM> CalculateCellDivisionVector(CellPtr pParentCell)=0;
214 
223  unsigned DoCellRemoval();
224 
228  virtual void SetupSolve()
229  {
230  }
231 
238  virtual bool StoppingEventHasOccurred();
239 
243  virtual void UpdateCellPopulation();
244 
257  virtual void UpdateCellLocationsAndTopology()=0;
258 
262  void OutputSimulationSetup();
263 
270  virtual void OutputAdditionalSimulationSetup(out_stream& rParamsFile)
271  {
272  }
273 
274 public:
275 
285  bool deleteCellPopulationInDestructor=false,
286  bool initialiseCells=true);
287 
294 
300  void SetCellBasedPdeHandler(CellBasedPdeHandler<SPACE_DIM>* pCellBasedPdeHandler);
301 
306 
313  std::vector<double> GetNodeLocation(const unsigned& rNodeIndex);
314 
318  double GetDt();
319 
323  unsigned GetNumBirths();
324 
328  unsigned GetNumDeaths();
329 
333  std::string GetOutputDirectory();
334 
340  void SetDt(double dt);
341 
347  void SetEndTime(double endTime);
348 
354  void SetOutputDirectory(std::string outputDirectory);
355 
362  void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple);
363 
369  void SetNoBirth(bool noBirth);
370 
376  void SetUpdateCellPopulationRule(bool updateCellPopulation);
377 
384 
390  void AddCellKiller(boost::shared_ptr<AbstractCellKiller<SPACE_DIM> > pCellKiller);
391 
395  void RemoveAllCellKillers();
396 
402  void AddSimulationModifier(boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM,SPACE_DIM> > pSimulationModifier);
403 
407  std::vector<boost::shared_ptr<AbstractCellBasedSimulationModifier<ELEMENT_DIM, SPACE_DIM> > >* GetSimulationModifiers();
408 
463  void Solve();
464 
469 
474 
479 
485  void SetOutputDivisionLocations(bool outputDivisionLocations);
486 
491 
497  void SetOutputCellVelocities(bool outputCellVelocities);
498 
507  virtual void OutputSimulationParameters(out_stream& rParamsFile)=0;
508 };
509 
510 #endif /*ABSTRACTCELLBASEDSIMULATION_HPP_*/
CellBasedPdeHandler< SPACE_DIM > * GetCellBasedPdeHandler()
void AddCellKiller(boost::shared_ptr< AbstractCellKiller< SPACE_DIM > > pCellKiller)
CellBasedPdeHandler< SPACE_DIM > * mpCellBasedPdeHandler
virtual c_vector< double, SPACE_DIM > CalculateCellDivisionVector(CellPtr pParentCell)=0
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)
void SetUpdateCellPopulationRule(bool updateCellPopulation)
std::vector< boost::shared_ptr< AbstractCellKiller< SPACE_DIM > > > mCellKillers
virtual void OutputAdditionalSimulationSetup(out_stream &rParamsFile)
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 SetCellBasedPdeHandler(CellBasedPdeHandler< SPACE_DIM > *pCellBasedPdeHandler)
void SetSamplingTimestepMultiple(unsigned samplingTimestepMultiple)
AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation