Chaste  Release::3.4
MutableVertexMesh.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 #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 
107  std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT1Swaps;
108 
112  c_vector<double, SPACE_DIM> mLastT2SwapLocation;
113 
118  std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT3Swaps;
119 
133  unsigned nodeAIndex,
134  unsigned nodeBIndex,
135  bool placeOriginalElementBelow=false);
136 
149 
158  bool CheckForIntersections();
159 
170  virtual void IdentifySwapType(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
171 
182  void PerformNodeMerge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
183 
197  void PerformT1Swap(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, std::set<unsigned>& rElementsContainingNodes);
198 
208  void PerformIntersectionSwap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
209 
220 
231  void PerformT3Swap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
232 
243  void PerformVoidRemoval(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, Node<SPACE_DIM>* pNodeC);
244 
255  virtual void HandleHighOrderJunctions(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
256 
269 
279  void PerformProtorosetteResolution(Node<SPACE_DIM>* pProtorosetteNode);
280 
291  void PerformRosetteRankDecrease(Node<SPACE_DIM>* pRosetteNode);
292 
299  void CheckForRosettes();
300 
313  c_vector<double, 2> WidenEdgeOrCorrectIntersectionLocationIfNecessary(unsigned indexA, unsigned indexB, c_vector<double,2> intersection);
314 
316  friend class boost::serialization::access;
317 
328  template<class Archive>
329  void serialize(Archive & archive, const unsigned int version)
330  {
331  // NOTE - Subclasses must archive their member variables BEFORE calling this method.
332  archive & mCellRearrangementThreshold;
333  archive & mCellRearrangementRatio;
334  archive & mT2Threshold;
339  archive & mDeletedNodeIndices;
340  archive & mDeletedElementIndices;
342 
343  archive & boost::serialization::base_object<VertexMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
344  }
345 
346 public:
347 
364  MutableVertexMesh(std::vector<Node<SPACE_DIM>*> nodes,
365  std::vector<VertexElement<ELEMENT_DIM, SPACE_DIM>*> vertexElements,
366  double cellRearrangementThreshold=0.01,
367  double t2Threshold=0.001,
368  double cellRearrangementRatio=1.5,
369  double protorosetteFormationProbability=0.0,
370  double protorosetteResolutionProbabilityPerTimestep=0.0,
371  double rosetteResolutionProbabilityPerTimestep=0.0);
372 
377 
381  virtual ~MutableVertexMesh();
382 
388  void SetCellRearrangementThreshold(double cellRearrangementThreshold);
389 
395  void SetT2Threshold(double t2Threshold);
396 
402  void SetCellRearrangementRatio(double cellRearrangementRatio);
403 
409  void SetProtorosetteFormationProbability(double protorosetteFormationProbability);
410 
416  void SetProtorosetteResolutionProbabilityPerTimestep(double protorosetteResolutionProbabilityPerTimestep);
417 
423  void SetRosetteResolutionProbabilityPerTimestep(double rosetteResolutionProbabilityPerTimestep);
424 
431  virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point);
432 
438  void SetCheckForInternalIntersections(bool checkForInternalIntersections);
439 
443  double GetCellRearrangementThreshold() const;
444 
448  double GetT2Threshold() const;
449 
453  double GetCellRearrangementRatio() const;
454 
461 
468 
475 
479  unsigned GetNumNodes() const;
480 
484  unsigned GetNumElements() const;
485 
490 
494  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT1Swaps();
495 
499  c_vector<double, SPACE_DIM> GetLastT2SwapLocation();
500 
504  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT3Swaps();
505 
510 
515 
524  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
525 
533  void DeleteElementPriorToReMesh(unsigned index);
534 
542  void DeleteNodePriorToReMesh(unsigned index);
543 
553  bool placeOriginalElementBelow=false);
554 
569  c_vector<double, SPACE_DIM> axisOfDivision,
570  bool placeOriginalElementBelow=false);
571 
579  unsigned AddElement(VertexElement<ELEMENT_DIM, SPACE_DIM>* pNewElement);
580 
593  bool CheckForT2Swaps(VertexElementMap& rElementMap);
594 
598  void Clear();
599 
606  void DivideEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
607 
617 
621  void RemoveDeletedNodes();
622 
635  virtual void ReMesh(VertexElementMap& rElementMap);
636 
643  void ReMesh();
644 };
645 
648 
649 #endif /*MUTABLEVERTEXMESH_HPP_*/
unsigned DivideElement(VertexElement< ELEMENT_DIM, SPACE_DIM > *pElement, unsigned nodeAIndex, unsigned nodeBIndex, bool placeOriginalElementBelow=false)
void SetRosetteResolutionProbabilityPerTimestep(double rosetteResolutionProbabilityPerTimestep)
double GetRosetteResolutionProbabilityPerTimestep() const
void PerformIntersectionSwap(Node< SPACE_DIM > *pNode, unsigned elementIndex)
double GetCellRearrangementRatio() const
c_vector< double, 2 > WidenEdgeOrCorrectIntersectionLocationIfNecessary(unsigned indexA, unsigned indexB, c_vector< double, 2 > intersection)
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
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)
void SetProtorosetteResolutionProbabilityPerTimestep(double protorosetteResolutionProbabilityPerTimestep)
double GetT2Threshold() const
void serialize(Archive &archive, const unsigned int version)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
std::vector< unsigned > mDeletedNodeIndices
double GetCellRearrangementThreshold() const
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
bool GetCheckForInternalIntersections() const
void SetCellRearrangementThreshold(double cellRearrangementThreshold)
double GetProtorosetteResolutionProbabilityPerTimestep() const
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
unsigned GetNumNodes() const
void PerformRosetteRankIncrease(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
double mProtorosetteFormationProbability
void DeleteNodePriorToReMesh(unsigned index)
double GetProtorosetteFormationProbability() 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)
unsigned GetNumElements() const
void SetCellRearrangementRatio(double cellRearrangementRatio)
void PerformT1Swap(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB, std::set< unsigned > &rElementsContainingNodes)
void SetT2Threshold(double t2Threshold)
virtual void IdentifySwapType(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
c_vector< double, SPACE_DIM > GetLastT2SwapLocation()
void PerformT2Swap(VertexElement< ELEMENT_DIM, SPACE_DIM > &rElement)
std::vector< unsigned > mDeletedElementIndices