Chaste  Release::3.4
PottsBasedCellPopulation.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 POTTSBASEDCELLPOPULATION_HPP_
37 #define POTTSBASEDCELLPOPULATION_HPP_
38 
39 #include "AbstractOnLatticeCellPopulation.hpp"
40 #include "PottsMesh.hpp"
41 #include "VertexMesh.hpp"
42 #include "AbstractPottsUpdateRule.hpp"
43 #include "MutableMesh.hpp"
44 
45 #include "ChasteSerialization.hpp"
46 #include <boost/serialization/base_object.hpp>
47 #include <boost/serialization/vector.hpp>
48 
49 template<unsigned DIM>
50 class AbstractPottsUpdateRule; // Circular definition
51 
62 template<unsigned DIM>
64 {
65  friend class TestPottsBasedCellPopulation;
66 
67 private:
68 
75 
81 
87 
89  std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > > mUpdateRuleCollection;
90 
92  double mTemperature;
93 
99 
100  friend class boost::serialization::access;
112  template<class Archive>
113  void serialize(Archive & archive, const unsigned int version)
114  {
115 #define COVERAGE_IGNORE
116  archive & boost::serialization::base_object<AbstractOnLatticeCellPopulation<DIM> >(*this);
117 
118  /*
119  * In its current form the code does not allow the direct serialization
120  * of the PottsMesh class, so instead we delete mpVoronoiTessellation.
121  */
122  delete mpElementTessellation;
123  mpElementTessellation = NULL;
124 
125  archive & mUpdateRuleCollection;
126  archive & mTemperature;
127  archive & mNumSweepsPerTimestep;
128 
129 #undef COVERAGE_IGNORE
130  }
131 
136  void Validate();
137 
147  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
148 
149 public:
150 
165  std::vector<CellPtr>& rCells,
166  bool deleteMesh=false,
167  bool validate=true,
168  const std::vector<unsigned> locationIndices=std::vector<unsigned>());
169 
176 
180  virtual ~PottsBasedCellPopulation();
181 
186 
190  const PottsMesh<DIM>& rGetMesh() const;
191 
199  PottsElement<DIM>* GetElement(unsigned elementIndex);
200 
204  unsigned GetNumElements();
205 
213  Node<DIM>* GetNode(unsigned index);
214 
220  unsigned GetNumNodes();
221 
230  std::set<unsigned> GetNeighbouringLocationIndices(CellPtr pCell);
231 
240  c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell);
241 
250 
261  CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr());
262 
272  unsigned RemoveDeadCells();
273 
279  void UpdateCellLocations(double dt);
280 
287  bool IsCellAssociatedWithADeletedLocation(CellPtr pCell);
288 
295  void Update(bool hasHadBirthsOrDeaths=true);
296 
304  virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
305 
311  virtual void WriteResultsToFiles(const std::string& rDirectory);
312 
319  virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<DIM, DIM> > pPopulationWriter);
320 
327  virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<DIM, DIM> > pPopulationCountWriter);
328 
336  virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<DIM, DIM> > pCellWriter, CellPtr pCell);
337 
344  double GetVolumeOfCell(CellPtr pCell);
345 
355  double GetWidth(const unsigned& rDimension);
356 
362  void AddUpdateRule(boost::shared_ptr<AbstractPottsUpdateRule<DIM> > pUpdateRule);
363 
367  void RemoveAllUpdateRules();
368 
374  const std::vector<boost::shared_ptr<AbstractPottsUpdateRule<DIM> > >& rGetUpdateRuleCollection() const;
375 
384  void OutputCellPopulationParameters(out_stream& rParamsFile);
385 
391  void SetTemperature(double temperature);
392 
396  double GetTemperature();
397 
403  void SetNumSweepsPerTimestep(unsigned numSweepsPerTimestep);
404 
408  unsigned GetNumSweepsPerTimestep();
409 
414 
419 
423  void CreateMutableMesh();
424 
429 };
430 
433 
434 namespace boost
435 {
436 namespace serialization
437 {
441 template<class Archive, unsigned DIM>
442 inline void save_construct_data(
443  Archive & ar, const PottsBasedCellPopulation<DIM> * t, const unsigned int file_version)
444 {
445  // Save data required to construct instance
446  const PottsMesh<DIM>* p_mesh = &(t->rGetMesh());
447  ar & p_mesh;
448 }
449 
454 template<class Archive, unsigned DIM>
455 inline void load_construct_data(
456  Archive & ar, PottsBasedCellPopulation<DIM> * t, const unsigned int file_version)
457 {
458  // Retrieve data from archive required to construct new instance
459  PottsMesh<DIM>* p_mesh;
460  ar >> p_mesh;
461 
462  // Invoke inplace constructor to initialise instance
463  ::new(t)PottsBasedCellPopulation<DIM>(*p_mesh);
464 }
465 }
466 } // namespace ...
467 
468 #endif /*POTTSBASEDCELLPOPULATION_HPP_*/
Definition: Node.hpp:58
Node< DIM > * GetNode(unsigned index)
MutableMesh< DIM, DIM > * mpMutableMesh
VertexMesh< DIM, DIM > * GetElementTessellation()
std::set< unsigned > GetNeighbouringLocationIndices(CellPtr pCell)
PottsElement< DIM > * GetElementCorrespondingToCell(CellPtr pCell)
const std::vector< boost::shared_ptr< AbstractPottsUpdateRule< DIM > > > & rGetUpdateRuleCollection() const
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< DIM, DIM > > pPopulationCountWriter)
c_vector< double, DIM > GetLocationOfCellCentre(CellPtr pCell)
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< DIM, DIM > > pCellWriter, CellPtr pCell)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void OutputCellPopulationParameters(out_stream &rParamsFile)
void SetTemperature(double temperature)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
void AddUpdateRule(boost::shared_ptr< AbstractPottsUpdateRule< DIM > > pUpdateRule)
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< DIM, DIM > > pPopulationWriter)
void Update(bool hasHadBirthsOrDeaths=true)
CellPtr AddCell(CellPtr pNewCell, const c_vector< double, DIM > &rCellDivisionVector, CellPtr pParentCell=CellPtr())
double GetVolumeOfCell(CellPtr pCell)
void serialize(Archive &archive, const unsigned int version)
virtual void WriteResultsToFiles(const std::string &rDirectory)
MutableMesh< DIM, DIM > * GetMutableMesh()
PottsElement< DIM > * GetElement(unsigned elementIndex)
double GetWidth(const unsigned &rDimension)
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
std::vector< boost::shared_ptr< AbstractPottsUpdateRule< DIM > > > mUpdateRuleCollection
void SetNumSweepsPerTimestep(unsigned numSweepsPerTimestep)
VertexMesh< DIM, DIM > * mpElementTessellation
PottsBasedCellPopulation(PottsMesh< DIM > &rMesh, std::vector< CellPtr > &rCells, bool deleteMesh=false, bool validate=true, const std::vector< unsigned > locationIndices=std::vector< unsigned >())
bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)