Chaste  Release::3.4
MeshBasedCellPopulation.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 MESHBASEDCELLPOPULATION_HPP_
37 #define MESHBASEDCELLPOPULATION_HPP_
38 
39 #include <map>
40 #include "AbstractCentreBasedCellPopulation.hpp"
41 #include "MutableMesh.hpp"
42 #include "VertexMesh.hpp"
43 #include "TrianglesMeshReader.hpp"
44 
45 #include "ChasteSerialization.hpp"
46 #include <boost/serialization/base_object.hpp>
47 #include <boost/serialization/set.hpp>
48 #include <boost/serialization/vector.hpp>
49 
56 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM>
57 class MeshBasedCellPopulation : public AbstractCentreBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>
58 {
59  friend class TestMeshBasedCellPopulation;
60 private:
62  friend class boost::serialization::access;
74  template<class Archive>
75  void serialize(Archive & archive, const unsigned int version)
76  {
77  archive & boost::serialization::base_object<AbstractCentreBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> >(*this);
78 
79  /*
80  * In its current form the code does not allow the direct serialization
81  * of the VertexMesh class, so instead we delete mpVoronoiTessellation.
82  */
83  delete mpVoronoiTessellation;
84  mpVoronoiTessellation = NULL;
85 
86  archive & mSpringRestLengths;
89  archive & mWriteVtkAsPoints;
90  archive & mOutputMeshInVtk;
91  archive & mHasVariableRestLength;
92 
93  this->Validate();
94  }
95 
96 protected:
97 #define COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
98 
115 
118 
124 
128  std::map<std::pair<unsigned,unsigned>, double> mSpringRestLengths;
129 
132 
135 
138 
141 
144 
146  std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > > mNodePairs;
147 
148 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
149 
155  virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
156 
161  virtual void Validate();
162 
163 public:
164 #define COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
165 
178  std::vector<CellPtr>& rCells,
179  const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
180  bool deleteMesh=false,
181  bool validate=true);
182 
189 
193  virtual ~MeshBasedCellPopulation();
194 
199 
204 
207 
216  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
217 
226  void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM>& rNewLocation);
227 
235  double GetDampingConstant(unsigned nodeIndex);
236 
242  void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
243 
251  virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
252 
265  virtual unsigned RemoveDeadCells();
266 
279  virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,SPACE_DIM>& rCellDivisionVector, CellPtr pParentCell);
280 
286  virtual void WriteResultsToFiles(const std::string& rDirectory);
287 
294  virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationWriter);
295 
302  virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationCountWriter);
303 
311  virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter, CellPtr pCell);
312 
320  virtual void Update(bool hasHadBirthsOrDeaths=true);
321 
328  void TessellateIfNeeded();
329 
335  void DivideLongSprings(double springDivisionThreshold);
336 
344  Node<SPACE_DIM>* GetNode(unsigned index);
345 
351  unsigned GetNumNodes();
352 
358  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
359 
366  double GetVolumeOfCell(CellPtr pCell);
367 
372 
377 
390  double GetVolumeOfVoronoiElement(unsigned index);
391 
402  double GetSurfaceAreaOfVoronoiElement(unsigned index);
403 
415  double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
416 
426  double GetWidth(const unsigned& rDimension);
427 
434  {
435  public:
436 
441 
446 
450  CellPtr GetCellA();
451 
455  CellPtr GetCellB();
456 
464 
470 
478 
479  private:
480 
482  std::set<std::set<unsigned> > mSpringsVisited;
483 
486 
489  };
490 
495 
500 
504  void CheckCellPointers();
505 
510 
516  void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
517 
523  std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > >& rGetNodePairs();
524 
530  void OutputCellPopulationParameters(out_stream& rParamsFile);
531 
537  void SetWriteVtkAsPoints(bool writeVtkAsPoints);
538 
542  bool GetWriteVtkAsPoints();
543 
549  void SetOutputMeshInVtk(bool outputMeshInVtk);
550 
554  bool GetOutputMeshInVtk();
555 
562  std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
563 
567  void CalculateRestLengths();
568 
575  double GetRestLength(unsigned indexA, unsigned indexB);
576 
584  void SetRestLength(unsigned indexA, unsigned indexB, double restLength);
585 
586 };
587 #undef COVERAGE_IGNORE // Avoid prototypes being treated as code by gcov
588 
591 
592 namespace boost
593 {
594 namespace serialization
595 {
599 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
600 inline void save_construct_data(
601  Archive & ar, const MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
602 {
603  // Save data required to construct instance
604  const MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh = &(t->rGetMesh());
605  ar & p_mesh;
606 }
607 
612 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
613 inline void load_construct_data(
614  Archive & ar, MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
615 {
616  // Retrieve data from archive required to construct new instance
618  ar >> p_mesh;
619 
620  // Invoke inplace constructor to initialise instance
621  ::new(t)MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>(*p_mesh);
622 }
623 }
624 } // namespace ...
625 
626 #endif /*MESHBASEDCELLPOPULATION_HPP_*/
double GetSurfaceAreaOfVoronoiElement(unsigned index)
double GetVolumeOfVoronoiElement(unsigned index)
double GetWidth(const unsigned &rDimension)
double GetVoronoiEdgeLength(unsigned index1, unsigned index2)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
virtual CellPtr AddCell(CellPtr pNewCell, const c_vector< double, SPACE_DIM > &rCellDivisionVector, CellPtr pParentCell)
Definition: Node.hpp:58
double GetDampingConstant(unsigned nodeIndex)
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > pCellWriter, CellPtr pCell)
std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > & rGetNodePairs()
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationCountWriter)
void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > &rNewLocation)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
MutableMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
bool operator!=(const typename MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM >::SpringIterator &rOther)
void serialize(Archive &archive, const unsigned int version)
double GetRestLength(unsigned indexA, unsigned indexB)
void SetWriteVtkAsPoints(bool writeVtkAsPoints)
MutableMesh< ELEMENT_DIM, SPACE_DIM >::EdgeIterator mEdgeIter
MutableMesh< ELEMENT_DIM, SPACE_DIM > * mpMutableMesh
void SetOutputMeshInVtk(bool outputMeshInVtk)
void DivideLongSprings(double springDivisionThreshold)
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationWriter)
VertexMesh< ELEMENT_DIM, SPACE_DIM > * mpVoronoiTessellation
SpringIterator(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation, typename MutableMesh< ELEMENT_DIM, SPACE_DIM >::EdgeIterator edgeIter)
virtual void Update(bool hasHadBirthsOrDeaths=true)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual void UpdateGhostNodesAfterReMesh(NodeMap &rMap)
void SetRestLength(unsigned indexA, unsigned indexB, double restLength)
void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant)
virtual void WriteResultsToFiles(const std::string &rDirectory)
std::set< unsigned > GetNeighbouringNodeIndices(unsigned index)
std::set< std::set< unsigned > > mSpringsVisited
Node< SPACE_DIM > * GetNode(unsigned index)
VertexMesh< ELEMENT_DIM, SPACE_DIM > * GetVoronoiTessellation()
MeshBasedCellPopulation(MutableMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, std::vector< CellPtr > &rCells, const std::vector< unsigned > locationIndices=std::vector< unsigned >(), bool deleteMesh=false, bool validate=true)
double GetVolumeOfCell(CellPtr pCell)
void OutputCellPopulationParameters(out_stream &rParamsFile)
std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > mNodePairs
void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter)
std::map< std::pair< unsigned, unsigned >, double > mSpringRestLengths
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation