Chaste  Release::2024.1
MutableVertexMesh.hpp
1 /*
2 
3 Copyright (c) 2005-2021, 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 #ifndef MUTABLEVERTEXMESH_HPP_
36 #define MUTABLEVERTEXMESH_HPP_
37 
38 // Forward declaration prevents circular include chain
39 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41 
42 #include <iostream>
43 #include <map>
44 #include <algorithm>
45 
46 #include "ChasteSerialization.hpp"
47 #include <boost/serialization/vector.hpp>
48 #include <boost/serialization/base_object.hpp>
49 #include <boost/serialization/split_member.hpp>
50 
51 #include "VertexMesh.hpp"
52 #include "RandomNumberGenerator.hpp"
53 
64 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
65 class MutableVertexMesh : public VertexMesh<ELEMENT_DIM, SPACE_DIM>
66 {
67  friend class TestMutableVertexMesh;
68  friend class TestMutableVertexMeshReMesh;
69  friend class TestMutableVertexMeshRosetteMethods;
70 
71 protected:
72 
75 
81 
83  double mT2Threshold;
84 
87 
90 
93 
96 
98  std::vector<unsigned> mDeletedNodeIndices;
99 
101  std::vector<unsigned> mDeletedElementIndices;
102 
110 
115  std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT1Swaps;
116 
120  c_vector<double, SPACE_DIM> mLastT2SwapLocation;
121 
126  std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT3Swaps;
127 
132  std::vector< c_vector<double, SPACE_DIM> > mLocationsOfIntersectionSwaps;
133 
147  unsigned nodeAIndex,
148  unsigned nodeBIndex,
149  bool placeOriginalElementBelow=false);
150 
162  virtual bool CheckForSwapsFromShortEdges();
163 
172  bool CheckForIntersections();
173 
184  virtual void IdentifySwapType(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
185 
196  void PerformNodeMerge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
197 
211  void PerformT1Swap(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, std::set<unsigned>& rElementsContainingNodes);
212 
222  void PerformIntersectionSwap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
223 
234 
245  void PerformT3Swap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
246 
257  void PerformVoidRemoval(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, Node<SPACE_DIM>* pNodeC);
258 
269  virtual void HandleHighOrderJunctions(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
270 
283 
293  void PerformProtorosetteResolution(Node<SPACE_DIM>* pProtorosetteNode);
294 
305  void PerformRosetteRankDecrease(Node<SPACE_DIM>* pRosetteNode);
306 
313  void CheckForRosettes();
314 
327  c_vector<double, 2> WidenEdgeOrCorrectIntersectionLocationIfNecessary(unsigned indexA, unsigned indexB, c_vector<double,2> intersection);
328 
330  friend class boost::serialization::access;
331 
342  template<class Archive>
343  void serialize(Archive & archive, const unsigned int version)
344  {
345  // NOTE - Subclasses must archive their member variables BEFORE calling this method.
346  archive & mCellRearrangementThreshold;
347  archive & mCellRearrangementRatio;
348  archive & mT2Threshold;
353  archive & mDeletedNodeIndices;
354  archive & mDeletedElementIndices;
355  archive & mDistanceForT3SwapChecking;
357 
358  archive & boost::serialization::base_object<VertexMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
359  }
360 
361 public:
362 
379  MutableVertexMesh(std::vector<Node<SPACE_DIM>*> nodes,
380  std::vector<VertexElement<ELEMENT_DIM, SPACE_DIM>*> vertexElements,
381  double cellRearrangementThreshold=0.01,
382  double t2Threshold=0.001,
383  double cellRearrangementRatio=1.5,
384  double protorosetteFormationProbability=0.0,
385  double protorosetteResolutionProbabilityPerTimestep=0.0,
386  double rosetteResolutionProbabilityPerTimestep=0.0);
387 
392 
396  virtual ~MutableVertexMesh();
397 
403  void SetCellRearrangementThreshold(double cellRearrangementThreshold);
404 
410  void SetT2Threshold(double t2Threshold);
411 
417  void SetCellRearrangementRatio(double cellRearrangementRatio);
418 
424  void SetProtorosetteFormationProbability(double protorosetteFormationProbability);
425 
431  void SetProtorosetteResolutionProbabilityPerTimestep(double protorosetteResolutionProbabilityPerTimestep);
432 
438  void SetRosetteResolutionProbabilityPerTimestep(double rosetteResolutionProbabilityPerTimestep);
439 
446  virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point);
447 
453  void SetCheckForInternalIntersections(bool checkForInternalIntersections);
454 
458  double GetCellRearrangementThreshold() const;
459 
463  double GetT2Threshold() const;
464 
468  double GetCellRearrangementRatio() const;
469 
476 
483 
490 
499  void SetDistanceForT3SwapChecking( double distanceForT3SwapChecking );
500 
506  double GetDistanceForT3SwapChecking() const;
507 
511  unsigned GetNumNodes() const;
512 
516  unsigned GetNumElements() const;
517 
522 
526  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT1Swaps();
527 
531  c_vector<double, SPACE_DIM> GetLastT2SwapLocation();
532 
536  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT3Swaps();
537 
541  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfIntersectionSwaps();
542 
547 
552 
557 
566  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
567 
575  void DeleteElementPriorToReMesh(unsigned index);
576 
584  void DeleteNodePriorToReMesh(unsigned index);
585 
595  bool placeOriginalElementBelow=false);
596 
611  c_vector<double, SPACE_DIM> axisOfDivision,
612  bool placeOriginalElementBelow=false);
613 
621  unsigned AddElement(VertexElement<ELEMENT_DIM, SPACE_DIM>* pNewElement);
622 
635  bool CheckForT2Swaps(VertexElementMap& rElementMap);
636 
640  void Clear();
641 
648  void DivideEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
649 
659 
663  void RemoveDeletedNodes();
664 
677  virtual void ReMesh(VertexElementMap& rElementMap);
678 
685  void ReMesh();
686 };
687 
690 
691 #endif /*MUTABLEVERTEXMESH_HPP_*/
unsigned DivideElement(VertexElement< ELEMENT_DIM, SPACE_DIM > *pElement, unsigned nodeAIndex, unsigned nodeBIndex, bool placeOriginalElementBelow=false)
void SetRosetteResolutionProbabilityPerTimestep(double rosetteResolutionProbabilityPerTimestep)
void PerformIntersectionSwap(Node< SPACE_DIM > *pNode, unsigned elementIndex)
void SetDistanceForT3SwapChecking(double distanceForT3SwapChecking)
c_vector< double, 2 > WidenEdgeOrCorrectIntersectionLocationIfNecessary(unsigned indexA, unsigned indexB, c_vector< double, 2 > intersection)
std::vector< c_vector< double, SPACE_DIM > > GetLocationsOfIntersectionSwaps()
std::vector< c_vector< double, SPACE_DIM > > GetLocationsOfT3Swaps()
void RemoveDeletedNodesAndElements(VertexElementMap &rElementMap)
void PerformRosetteRankDecrease(Node< SPACE_DIM > *pRosetteNode)
std::vector< c_vector< double, SPACE_DIM > > mLocationsOfT3Swaps
double GetCellRearrangementRatio() const
unsigned DivideElementAlongGivenAxis(VertexElement< ELEMENT_DIM, SPACE_DIM > *pElement, c_vector< double, SPACE_DIM > axisOfDivision, bool placeOriginalElementBelow=false)
Definition: Node.hpp:58
bool CheckForT2Swaps(VertexElementMap &rElementMap)
std::vector< c_vector< double, SPACE_DIM > > GetLocationsOfT1Swaps()
unsigned DivideElementAlongShortAxis(VertexElement< ELEMENT_DIM, SPACE_DIM > *pElement, bool placeOriginalElementBelow=false)
void PerformNodeMerge(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
virtual bool CheckForSwapsFromShortEdges()
void SetProtorosetteResolutionProbabilityPerTimestep(double protorosetteResolutionProbabilityPerTimestep)
void ClearLocationsOfIntersectionSwaps()
void serialize(Archive &archive, const unsigned int version)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
std::vector< unsigned > mDeletedNodeIndices
void PerformVoidRemoval(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB, Node< SPACE_DIM > *pNodeC)
double mRosetteResolutionProbabilityPerTimestep
std::vector< c_vector< double, SPACE_DIM > > mLocationsOfT1Swaps
c_vector< double, SPACE_DIM > mLastT2SwapLocation
unsigned GetNumNodes() const
unsigned GetNumElements() const
bool GetCheckForInternalIntersections() const
void SetCellRearrangementThreshold(double cellRearrangementThreshold)
void PerformT3Swap(Node< SPACE_DIM > *pNode, unsigned elementIndex)
virtual void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point)
unsigned AddElement(VertexElement< ELEMENT_DIM, SPACE_DIM > *pNewElement)
void PerformProtorosetteResolution(Node< SPACE_DIM > *pProtorosetteNode)
double mProtorosetteResolutionProbabilityPerTimestep
double GetDistanceForT3SwapChecking() const
std::vector< c_vector< double, SPACE_DIM > > mLocationsOfIntersectionSwaps
void PerformRosetteRankIncrease(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
double GetT2Threshold() const
double mProtorosetteFormationProbability
void DeleteNodePriorToReMesh(unsigned index)
double GetCellRearrangementThreshold() const
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
void SetProtorosetteFormationProbability(double protorosetteFormationProbability)
virtual void HandleHighOrderJunctions(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
void DivideEdge(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
void SetCheckForInternalIntersections(bool checkForInternalIntersections)
void DeleteElementPriorToReMesh(unsigned index)
double GetProtorosetteResolutionProbabilityPerTimestep() const
void SetCellRearrangementRatio(double cellRearrangementRatio)
double GetRosetteResolutionProbabilityPerTimestep() const
void PerformT1Swap(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB, std::set< unsigned > &rElementsContainingNodes)
double GetProtorosetteFormationProbability() const
void SetT2Threshold(double t2Threshold)
virtual void IdentifySwapType(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
gcov doesn&#39;t like this file...
c_vector< double, SPACE_DIM > GetLastT2SwapLocation()
void PerformT2Swap(VertexElement< ELEMENT_DIM, SPACE_DIM > &rElement)
std::vector< unsigned > mDeletedElementIndices