Chaste  Release::2017.1
MeshBasedCellPopulation.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 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 = nullptr;
85 
86  archive & mSpringRestLengths;
89  archive & mWriteVtkAsPoints;
90  archive & mOutputMeshInVtk;
91  archive & mHasVariableRestLength;
92 
93  this->Validate();
94  }
95 
96 protected:
113 
116 
122 
126  std::map<std::pair<unsigned,unsigned>, double> mSpringRestLengths;
127 
130 
133 
136 
139 
142 
144  std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > > mNodePairs;
145 
151  virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
152 
157  virtual void Validate();
158 
159 public:
172  std::vector<CellPtr>& rCells,
173  const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
174  bool deleteMesh=false,
175  bool validate=true);
176 
183 
187  virtual ~MeshBasedCellPopulation();
188 
193 
198 
207 
210 
219  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
220 
229  void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM>& rNewLocation);
230 
238  double GetDampingConstant(unsigned nodeIndex);
239 
245  void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
246 
254  virtual void OpenWritersFiles(OutputFileHandler& rOutputFileHandler);
255 
268  virtual unsigned RemoveDeadCells();
269 
281  virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell);
282 
288  virtual void WriteResultsToFiles(const std::string& rDirectory);
289 
296  virtual void AcceptPopulationWriter(boost::shared_ptr<AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationWriter);
297 
304  virtual void AcceptPopulationCountWriter(boost::shared_ptr<AbstractCellPopulationCountWriter<ELEMENT_DIM, SPACE_DIM> > pPopulationCountWriter);
305 
313  virtual void AcceptCellWriter(boost::shared_ptr<AbstractCellWriter<ELEMENT_DIM, SPACE_DIM> > pCellWriter, CellPtr pCell);
314 
322  virtual void Update(bool hasHadBirthsOrDeaths=true);
323 
330  void TessellateIfNeeded();
331 
337  void DivideLongSprings(double springDivisionThreshold);
338 
346  Node<SPACE_DIM>* GetNode(unsigned index);
347 
353  unsigned GetNumNodes();
354 
360  virtual void WriteVtkResultsToFile(const std::string& rDirectory);
361 
368  double GetVolumeOfCell(CellPtr pCell);
369 
374 
379 
392  double GetVolumeOfVoronoiElement(unsigned index);
393 
404  double GetSurfaceAreaOfVoronoiElement(unsigned index);
405 
417  double GetVoronoiEdgeLength(unsigned index1, unsigned index2);
418 
428  double GetWidth(const unsigned& rDimension);
429 
437  virtual void WriteDataToVisualizerSetupFile(out_stream& pVizSetupFile);
438 
445  {
446  public:
447 
452 
457 
461  CellPtr GetCellA();
462 
466  CellPtr GetCellB();
467 
475 
481 
489 
490  private:
491 
493  std::set<std::set<unsigned> > mSpringsVisited;
494 
497 
500  };
501 
506 
511 
515  void CheckCellPointers();
516 
521 
527  void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter);
528 
534  std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > >& rGetNodePairs();
535 
541  void OutputCellPopulationParameters(out_stream& rParamsFile);
542 
548  void SetWriteVtkAsPoints(bool writeVtkAsPoints);
549 
553  bool GetWriteVtkAsPoints();
554 
560  void SetOutputMeshInVtk(bool outputMeshInVtk);
561 
565  bool GetOutputMeshInVtk();
566 
573  std::set<unsigned> GetNeighbouringNodeIndices(unsigned index);
574 
578  void CalculateRestLengths();
579 
586  double GetRestLength(unsigned indexA, unsigned indexB);
587 
595  void SetRestLength(unsigned indexA, unsigned indexB, double restLength);
596 
597 };
598 
601 
602 namespace boost
603 {
604 namespace serialization
605 {
609 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
610 inline void save_construct_data(
611  Archive & ar, const MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
612 {
613  // Save data required to construct instance
614  const MutableMesh<ELEMENT_DIM, SPACE_DIM>* p_mesh = &(t->rGetMesh());
615  ar & p_mesh;
616 }
617 
622 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
623 inline void load_construct_data(
624  Archive & ar, MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
625 {
626  // Retrieve data from archive required to construct new instance
628  ar >> p_mesh;
629 
630  // Invoke inplace constructor to initialise instance
631  ::new(t)MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>(*p_mesh);
632 }
633 }
634 } // namespace ...
635 
636 #endif /*MESHBASEDCELLPOPULATION_HPP_*/
double GetSurfaceAreaOfVoronoiElement(unsigned index)
double GetVolumeOfVoronoiElement(unsigned index)
double GetWidth(const unsigned &rDimension)
double GetVoronoiEdgeLength(unsigned index1, unsigned index2)
virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
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 WriteDataToVisualizerSetupFile(out_stream &pVizSetupFile)
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)
gcov doesn&#39;t like this file...
std::map< std::pair< unsigned, unsigned >, double > mSpringRestLengths
virtual TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * GetTetrahedralMeshForPdeModifier()
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation