Chaste  Release::2017.1
MutableVertexMesh.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 #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 
141  unsigned nodeAIndex,
142  unsigned nodeBIndex,
143  bool placeOriginalElementBelow=false);
144 
156  virtual bool CheckForSwapsFromShortEdges();
157 
166  bool CheckForIntersections();
167 
178  virtual void IdentifySwapType(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
179 
190  void PerformNodeMerge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
191 
205  void PerformT1Swap(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, std::set<unsigned>& rElementsContainingNodes);
206 
216  void PerformIntersectionSwap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
217 
228 
239  void PerformT3Swap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
240 
251  void PerformVoidRemoval(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, Node<SPACE_DIM>* pNodeC);
252 
263  virtual void HandleHighOrderJunctions(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
264 
277 
287  void PerformProtorosetteResolution(Node<SPACE_DIM>* pProtorosetteNode);
288 
299  void PerformRosetteRankDecrease(Node<SPACE_DIM>* pRosetteNode);
300 
307  void CheckForRosettes();
308 
321  c_vector<double, 2> WidenEdgeOrCorrectIntersectionLocationIfNecessary(unsigned indexA, unsigned indexB, c_vector<double,2> intersection);
322 
324  friend class boost::serialization::access;
325 
336  template<class Archive>
337  void serialize(Archive & archive, const unsigned int version)
338  {
339  // NOTE - Subclasses must archive their member variables BEFORE calling this method.
340  archive & mCellRearrangementThreshold;
341  archive & mCellRearrangementRatio;
342  archive & mT2Threshold;
347  archive & mDeletedNodeIndices;
348  archive & mDeletedElementIndices;
349  archive & mDistanceForT3SwapChecking;
351 
352  archive & boost::serialization::base_object<VertexMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
353  }
354 
355 public:
356 
373  MutableVertexMesh(std::vector<Node<SPACE_DIM>*> nodes,
374  std::vector<VertexElement<ELEMENT_DIM, SPACE_DIM>*> vertexElements,
375  double cellRearrangementThreshold=0.01,
376  double t2Threshold=0.001,
377  double cellRearrangementRatio=1.5,
378  double protorosetteFormationProbability=0.0,
379  double protorosetteResolutionProbabilityPerTimestep=0.0,
380  double rosetteResolutionProbabilityPerTimestep=0.0);
381 
386 
390  virtual ~MutableVertexMesh();
391 
397  void SetCellRearrangementThreshold(double cellRearrangementThreshold);
398 
404  void SetT2Threshold(double t2Threshold);
405 
411  void SetCellRearrangementRatio(double cellRearrangementRatio);
412 
418  void SetProtorosetteFormationProbability(double protorosetteFormationProbability);
419 
425  void SetProtorosetteResolutionProbabilityPerTimestep(double protorosetteResolutionProbabilityPerTimestep);
426 
432  void SetRosetteResolutionProbabilityPerTimestep(double rosetteResolutionProbabilityPerTimestep);
433 
440  virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point);
441 
447  void SetCheckForInternalIntersections(bool checkForInternalIntersections);
448 
452  double GetCellRearrangementThreshold() const;
453 
457  double GetT2Threshold() const;
458 
462  double GetCellRearrangementRatio() const;
463 
470 
477 
484 
493  void SetDistanceForT3SwapChecking( double distanceForT3SwapChecking );
494 
500  double GetDistanceForT3SwapChecking() const;
501 
505  unsigned GetNumNodes() const;
506 
510  unsigned GetNumElements() const;
511 
516 
520  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT1Swaps();
521 
525  c_vector<double, SPACE_DIM> GetLastT2SwapLocation();
526 
530  std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT3Swaps();
531 
536 
541 
550  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
551 
559  void DeleteElementPriorToReMesh(unsigned index);
560 
568  void DeleteNodePriorToReMesh(unsigned index);
569 
579  bool placeOriginalElementBelow=false);
580 
595  c_vector<double, SPACE_DIM> axisOfDivision,
596  bool placeOriginalElementBelow=false);
597 
605  unsigned AddElement(VertexElement<ELEMENT_DIM, SPACE_DIM>* pNewElement);
606 
619  bool CheckForT2Swaps(VertexElementMap& rElementMap);
620 
624  void Clear();
625 
632  void DivideEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
633 
643 
647  void RemoveDeletedNodes();
648 
661  virtual void ReMesh(VertexElementMap& rElementMap);
662 
669  void ReMesh();
670 };
671 
674 
675 #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
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 > > 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)
virtual bool CheckForSwapsFromShortEdges()
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
double GetDistanceForT3SwapChecking() const
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)
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