Chaste  Release::3.4
CaBasedCellPopulation.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 CABASEDCELLPOPULATION_HPP_
37 #define CABASEDCELLPOPULATION_HPP_
38 
39 #include "AbstractOnLatticeCellPopulation.hpp"
40 #include "PottsMesh.hpp"
41 #include "VertexMesh.hpp"
42 #include "AbstractCaUpdateRule.hpp"
43 #include "AbstractCaSwitchingUpdateRule.hpp"
44 #include "AbstractCaBasedDivisionRule.hpp"
45 
46 
47 #include "ChasteSerialization.hpp"
48 #include <boost/serialization/base_object.hpp>
49 #include <boost/serialization/vector.hpp>
50 
51 template<unsigned DIM> class AbstractCaBasedDivisionRule; // Circular definition thing.
52 
53 template<unsigned DIM>
54 class AbstractCaUpdateRule; // Circular definition
55 
69 template<unsigned DIM>
71 {
72  friend class TestCaBasedCellPopulation;
73 
74 private:
75 
78 
81  std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > > mUpdateRuleCollection;
82 
85  std::vector<boost::shared_ptr<AbstractCaSwitchingUpdateRule<DIM> > > mSwitchingUpdateRuleCollection;
86 
88  std::vector<unsigned> mAvailableSpaces;
89 
92  boost::shared_ptr<AbstractCaBasedDivisionRule<DIM> > mpCaBasedDivisionRule;
93 
99  void SetEmptySites(const std::set<unsigned>& rEmptySiteIndices);
100 
101  friend class boost::serialization::access;
113  template<class Archive>
114  void serialize(Archive & archive, const unsigned int version)
115  {
116 #define COVERAGE_IGNORE
117  archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
118  archive & mLatticeCarryingCapacity;
119  archive & mUpdateRuleCollection;
120  archive & mAvailableSpaces;
121  archive & mpCaBasedDivisionRule;
122 #undef COVERAGE_IGNORE
123  }
124 
130  void Validate();
131 
139  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
140 
141 public:
142 
158  std::vector<CellPtr>& rCells,
159  const std::vector<unsigned> locationIndices,
160  unsigned latticeCarryingCapacity=1u,
161  bool deleteMesh=false,
162  bool validate=false);
163 
170 
174  virtual ~CaBasedCellPopulation();
175 
179  std::vector<unsigned>& rGetAvailableSpaces();
180 
191  virtual bool IsSiteAvailable(unsigned index, CellPtr pCell);
192 
197 
201  const PottsMesh<DIM>& rGetMesh() const;
202 
210  Node<DIM>* GetNode(unsigned index);
211 
217  unsigned GetNumNodes();
218 
231  std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell);
232 
241  c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
242 
250  void AddCellUsingLocationIndex(unsigned index, CellPtr pCell);
251 
259  void RemoveCellUsingLocationIndex(unsigned index, CellPtr pCell);
260 
268  Node<DIM>* GetNodeCorrespondingToCell(CellPtr pCell);
269 
280  CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
281 
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 
389  void AddUpdateRule(boost::shared_ptr<AbstractCaUpdateRule<DIM> > pUpdateRule);
390 
394  void RemoveAllUpdateRules();
395 
401  const std::vector<boost::shared_ptr<AbstractCaUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
402 
408  void AddSwitchingUpdateRule(boost::shared_ptr<AbstractCaSwitchingUpdateRule<DIM> > pUpdateRule);
409 
414 
420  const std::vector<boost::shared_ptr<AbstractCaSwitchingUpdateRule<DIM> > >& rGetSwitchingUpdateRuleCollection() const;
421 
430  void OutputCellPopulationParameters(out_stream& rParamsFile);
431 
440  bool IsRoomToDivide(CellPtr pCell);
441 
442 
446  boost::shared_ptr<AbstractCaBasedDivisionRule<DIM> > GetCaBasedDivisionRule();
447 
453  void SetCaBasedDivisionRule(boost::shared_ptr<AbstractCaBasedDivisionRule<DIM> > pCaBasedDivisionRule);
454 
455 
456 };
457 
460 
461 // No archiving yet so untested
462 #define COVERAGE_IGNORE
463 namespace boost
464 {
465 namespace serialization
466 {
470 template<class Archive, unsigned DIM>
471 inline void save_construct_data(
472  Archive & ar, const CaBasedCellPopulation<DIM> * t, const unsigned int file_version)
473 {
474  // Save data required to construct instance
475  const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
476  ar & p_mesh;
477 }
478 
483 template<class Archive, unsigned DIM>
484 inline void load_construct_data(
485  Archive & ar, CaBasedCellPopulation<DIM> * t, const unsigned int file_version)
486 {
487  // Retrieve data from archive required to construct new instance
488  PottsMesh<DIM>* p_mesh;
489  ar >> p_mesh;
490 
491  // Invoke inplace constructor to initialise instance
492  ::new(t)CaBasedCellPopulation<DIM>(*p_mesh);
493 }
494 }
495 } // namespace ...
496 #undef COVERAGE_IGNORE
497 
498 #endif /*CABASEDCELLPOPULATION_HPP_*/
bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)
boost::shared_ptr< AbstractCaBasedDivisionRule< DIM > > GetCaBasedDivisionRule()
std::vector< boost::shared_ptr< AbstractCaSwitchingUpdateRule< DIM > > > mSwitchingUpdateRuleCollection
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)
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
const std::vector< boost::shared_ptr< AbstractCaUpdateRule< DIM > > > & rGetUpdateRuleCollection() const
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)
void SetCaBasedDivisionRule(boost::shared_ptr< AbstractCaBasedDivisionRule< DIM > > pCaBasedDivisionRule)
std::vector< boost::shared_ptr< AbstractCaUpdateRule< DIM > > > mUpdateRuleCollection
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
std::set< unsigned > GetNeighbouringLocationIndices(CellPtr pCell)
void Update(bool hasHadBirthsOrDeaths=true)
const std::vector< boost::shared_ptr< AbstractCaSwitchingUpdateRule< DIM > > > & rGetSwitchingUpdateRuleCollection() const
void AddSwitchingUpdateRule(boost::shared_ptr< AbstractCaSwitchingUpdateRule< DIM > > pUpdateRule)
void serialize(Archive &archive, const unsigned int version)
void AddUpdateRule(boost::shared_ptr< AbstractCaUpdateRule< DIM > > pUpdateRule)
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, const c_vector< double, DIM > &rCellDivisionVector, CellPtr pParentCell=CellPtr())
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< DIM, DIM > > pCellWriter, CellPtr pCell)
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)