Chaste  Release::2017.1
CaBasedCellPopulation.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 CABASEDCELLPOPULATION_HPP_
37 #define CABASEDCELLPOPULATION_HPP_
38 
39 #include "AbstractOnLatticeCellPopulation.hpp"
40 #include "PottsMesh.hpp"
41 #include "VertexMesh.hpp"
42 #include "AbstractUpdateRule.hpp"
43 #include "AbstractCaBasedDivisionRule.hpp"
44 
45 #include "ChasteSerialization.hpp"
46 #include <boost/serialization/base_object.hpp>
47 #include <boost/serialization/vector.hpp>
48 
49 template<unsigned DIM> class AbstractCaBasedDivisionRule; // Circular definition thing.
50 
63 template<unsigned DIM>
65 {
66  friend class TestCaBasedCellPopulation;
67 
68 private:
69 
72 
77  std::vector<boost::shared_ptr<AbstractUpdateRule<DIM> > > mSwitchingUpdateRuleCollection;
78 
80  std::vector<unsigned> mAvailableSpaces;
81 
84  boost::shared_ptr<AbstractCaBasedDivisionRule<DIM> > mpCaBasedDivisionRule;
85 
91  void SetEmptySites(const std::set<unsigned>& rEmptySiteIndices);
92 
93  friend class boost::serialization::access;
105  template<class Archive>
106  void serialize(Archive & archive, const unsigned int version)
107  {
108  archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
110  archive & mLatticeCarryingCapacity;
111  archive & mAvailableSpaces;
112  archive & mpCaBasedDivisionRule;
113  }
114 
120  void Validate();
121 
129  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
130 
131 public:
132 
148  std::vector<CellPtr>& rCells,
149  const std::vector<unsigned> locationIndices,
150  unsigned latticeCarryingCapacity=1u,
151  bool deleteMesh=false,
152  bool validate=false);
153 
160 
164  virtual ~CaBasedCellPopulation();
165 
169  std::vector<unsigned>& rGetAvailableSpaces();
170 
181  virtual bool IsSiteAvailable(unsigned index, CellPtr pCell);
182 
187 
191  const PottsMesh<DIM>& rGetMesh() const;
192 
201 
209  Node<DIM>* GetNode(unsigned index);
210 
216  unsigned GetNumNodes();
217 
230  std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell);
231 
240  c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
241 
249  void AddCellUsingLocationIndex(unsigned index, CellPtr pCell);
250 
258  void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell);
259 
267  Node<DIM>* GetNodeCorrespondingToCell(CellPtr pCell);
268 
278  CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr());
279 
291  double virtual EvaluateDivisionPropensity(unsigned currentNodeIndex,
292  unsigned targetNodeIndex,
293  CellPtr pCell);
303  unsigned RemoveDeadCells();
304 
312  virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
313 
319  void UpdateCellLocations(double dt);
320 
327  bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
328 
336  void Update(bool hasHadBirthsOrDeaths=true);
337 
344  virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
345 
352  virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
353 
361  virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
362 
369  double GetVolumeOfCell(CellPtr pCell);
370 
382  double GetWidth(const unsigned& rDimension);
383 
390  void RemoveAllUpdateRules();
391 
400  void OutputCellPopulationParameters(out_stream& rParamsFile);
401 
410  bool IsRoomToDivide(CellPtr pCell);
411 
415  boost::shared_ptr<AbstractCaBasedDivisionRule<DIM> > GetCaBasedDivisionRule();
416 
422  void SetCaBasedDivisionRule(boost::shared_ptr<AbstractCaBasedDivisionRule<DIM> > pCaBasedDivisionRule);
423 
429  virtual void AddUpdateRule(boost::shared_ptr<AbstractUpdateRule<DIM> > pUpdateRule);
430 
440  virtual const std::vector<boost::shared_ptr<AbstractUpdateRule<DIM> > > GetUpdateRuleCollection() const;
441 
457  virtual double GetCellDataItemAtPdeNode(unsigned pdeNodeIndex,
458  std::string& rVariableName,
459  bool dirichletBoundaryConditionApplies=false,
460  double dirichletBoundaryValue=0.0);
461 
471  virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex);
472 };
473 
476 
477 
478 namespace boost
479 {
480 namespace serialization
481 {
485 template<class Archive, unsigned DIM>
486 inline void save_construct_data(
487  Archive & ar, const CaBasedCellPopulation<DIM> * t, const unsigned int file_version)
488 {
489  // Save data required to construct instance
490  const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
491  ar & p_mesh;
492 }
493 
498 template<class Archive, unsigned DIM>
499 inline void load_construct_data(
500  Archive & ar, CaBasedCellPopulation<DIM> * t, const unsigned int file_version)
501 {
502  // Retrieve data from archive required to construct new instance
503  PottsMesh<DIM>* p_mesh;
504  ar >> p_mesh;
505 
506  // Invoke inplace constructor to initialise instance
507  ::new(t)CaBasedCellPopulation<DIM>(*p_mesh);
508 }
509 }
510 } // namespace ...
511 
512 
513 #endif /*CABASEDCELLPOPULATION_HPP_*/
bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)
boost::shared_ptr< AbstractCaBasedDivisionRule< DIM > > GetCaBasedDivisionRule()
std::vector< unsigned > mAvailableSpaces
std::vector< unsigned > & rGetAvailableSpaces()
void AddCellUsingLocationIndex(unsigned index, CellPtr pCell)
virtual double EvaluateDivisionPropensity(unsigned currentNodeIndex, unsigned targetNodeIndex, CellPtr pCell)
Definition: Node.hpp:58
PottsMesh< DIM > & rGetMesh()
void OutputCellPopulationParameters(out_stream &rParamsFile)
virtual bool IsPdeNodeAssociatedWithNonApoptoticCell(unsigned pdeNodeIndex)
Node< DIM > * GetNode(unsigned index)
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< DIM, DIM > > pPopulationCountWriter)
virtual bool IsSiteAvailable(unsigned index, CellPtr pCell)
boost::shared_ptr< AbstractCaBasedDivisionRule< DIM > > mpCaBasedDivisionRule
void SetEmptySites(const std::set< unsigned > &rEmptySiteIndices)
void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
CaBasedCellPopulation(PottsMesh< DIM > &rMesh, std::vector< CellPtr > &rCells, const std::vector< unsigned > locationIndices, unsigned latticeCarryingCapacity=1u, bool deleteMesh=false, bool validate=false)
bool IsRoomToDivide(CellPtr pCell)
virtual TetrahedralMesh< DIM, DIM > * GetTetrahedralMeshForPdeModifier()
void SetCaBasedDivisionRule(boost::shared_ptr< AbstractCaBasedDivisionRule< DIM > > pCaBasedDivisionRule)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
std::set< unsigned > GetNeighbouringLocationIndices(CellPtr pCell)
void Update(bool hasHadBirthsOrDeaths=true)
void serialize(Archive &archive, const unsigned int version)
virtual double GetCellDataItemAtPdeNode(unsigned pdeNodeIndex, std::string &rVariableName, bool dirichletBoundaryConditionApplies=false, double dirichletBoundaryValue=0.0)
std::vector< boost::shared_ptr< AbstractUpdateRule< DIM > > > mSwitchingUpdateRuleCollection
Node< DIM > * GetNodeCorrespondingToCell(CellPtr pCell)
c_vector< double, DIM > GetLocationOfCellCentre(CellPtr pCell)
double GetWidth(const unsigned &rDimension)
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< DIM, DIM > > pPopulationWriter)
double GetVolumeOfCell(CellPtr pCell)
CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr())
gcov doesn&#39;t like this file...
virtual void AddUpdateRule(boost::shared_ptr< AbstractUpdateRule< DIM > > pUpdateRule)
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< DIM, DIM > > pCellWriter, CellPtr pCell)
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
virtual const std::vector< boost::shared_ptr< AbstractUpdateRule< DIM > > > GetUpdateRuleCollection() const