Chaste  Release::3.4
MutableMesh.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 MUTABLEMESH_HPP_
37 #define MUTABLEMESH_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include <boost/serialization/base_object.hpp>
41 #include <boost/serialization/split_member.hpp>
42 
43 #include "TetrahedralMesh.hpp"
44 #include "NodeMap.hpp"
45 
49 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
50 class MutableMesh : public TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>
51 {
53  friend class boost::serialization::access;
54 
61  template<class Archive>
62  void save(Archive & archive, const unsigned int version) const
63  {
64  archive & boost::serialization::base_object<TetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
65 
66  // Assume that the first node is indicative of the rest.
67  bool does_have_attributes = this->mNodes[0]->HasNodeAttributes();
68 
69  archive & does_have_attributes;
70 
71  if (does_have_attributes)
72  {
73  for (unsigned i=0; i<this->mNodes.size(); i++)
74  {
75  double radius;
76  radius = this->mNodes[i]->GetRadius();
77  archive & radius;
78 
79  bool is_particle;
80  is_particle = this->mNodes[i]->IsParticle();
81  archive & is_particle;
82  }
83  }
84  }
85 
92  template<class Archive>
93  void load(Archive & archive, const unsigned int version)
94  {
95  archive & boost::serialization::base_object<TetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
96 
97  bool does_have_attributes;
98 
99  archive & does_have_attributes;
100 
101  if (does_have_attributes)
102  {
103  for (unsigned i=0; i<this->mNodes.size(); i++)
104  {
105  double radius;
106  archive & radius;
107  this->mNodes[i]->SetRadius(radius);
108 
109  bool is_particle;
110  archive & is_particle;
111 
112  if (is_particle)
113  {
114  this->mNodes[i]->SetIsParticle(true);
115  }
116  }
117  }
118 
119  // If ELEMENT_DIM=SPACEDIM Do a remesh after archiving has finished to get right number of boundary nodes etc.
120  // NOTE - Subclasses must archive their member variables BEFORE calling this method.
121  if(ELEMENT_DIM==SPACE_DIM)
122  {
123  NodeMap map(this->GetNumNodes());
124  this->ReMesh(map);
125  assert(map.IsIdentityMap()); // Otherwise the mesh will get VERY confused.
126  }
127  }
128  BOOST_SERIALIZATION_SPLIT_MEMBER()
129 
130 protected:
131 
136  std::vector<unsigned> mDeletedElementIndices;
137 
142  std::vector<unsigned> mDeletedBoundaryElementIndices;
143 
148  std::vector<unsigned> mDeletedNodeIndices;
149 
152 
153 private:
154 
155 #define COVERAGE_IGNORE
156 
164  bool CheckIsVoronoi(Element<ELEMENT_DIM, SPACE_DIM>* pElement, double maxPenetration);
165 #undef COVERAGE_IGNORE
166 
167 public:
168 
172  MutableMesh();
173 
179  MutableMesh(std::vector<Node<SPACE_DIM> *> nodes);
180 
184  virtual ~MutableMesh();
185 
189  void Clear();
190 
194  unsigned GetNumNodes() const;
195 
199  unsigned GetNumElements() const;
200 
204  unsigned GetNumBoundaryElements() const;
205 
207 
214  void RescaleMeshFromBoundaryNode(ChastePoint<1> updatedPoint, unsigned boundaryNodeIndex);
215 
224  virtual unsigned AddNode(Node<SPACE_DIM>* pNewNode);
225 
232  unsigned AddElement(Element<ELEMENT_DIM,SPACE_DIM>* pNewElement);
233 
242  virtual void SetNode(unsigned index, ChastePoint<SPACE_DIM> point, bool concreteMove=true);
243 
253  void MoveMergeNode(unsigned index, unsigned targetIndex, bool concreteMove=true);
254 
255 #define COVERAGE_IGNORE
256 
262  virtual void DeleteNode(unsigned index);
263 
269  virtual void DeleteElement(unsigned index);
270 #undef COVERAGE_IGNORE
271 
280  void DeleteNodePriorToReMesh(unsigned index);
281 
290 
303  void DeleteBoundaryNodeAt(unsigned index);
304 
305 #define COVERAGE_IGNORE
306 
312  void ReIndex(NodeMap& map);
313 #undef COVERAGE_IGNORE
314 
320  virtual void ReMesh(NodeMap& map);
321 
327  void ReMesh();
328 
329 #define COVERAGE_IGNORE
330 
335  std::vector<c_vector<unsigned, 5> > SplitLongEdges(double cutoffLength);
336 #undef COVERAGE_IGNORE
337 
338 #define COVERAGE_IGNORE
339 
346  c_vector<unsigned, 3> SplitEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
347 #undef COVERAGE_IGNORE
348 
349 #define COVERAGE_IGNORE
350 
358  bool CheckIsVoronoi(double maxPenetration=0.0);
359 #undef COVERAGE_IGNORE
360 };
361 
364 
365 #endif /*MUTABLEMESH_HPP_*/
std::vector< c_vector< unsigned, 5 > > SplitLongEdges(double cutoffLength)
Definition: Node.hpp:58
std::vector< unsigned > mDeletedBoundaryElementIndices
void DeleteNodePriorToReMesh(unsigned index)
unsigned RefineElement(Element< ELEMENT_DIM, SPACE_DIM > *pElement, ChastePoint< SPACE_DIM > point)
void RescaleMeshFromBoundaryNode(ChastePoint< 1 > updatedPoint, unsigned boundaryNodeIndex)
void ReIndex(NodeMap &map)
bool CheckIsVoronoi(Element< ELEMENT_DIM, SPACE_DIM > *pElement, double maxPenetration)
virtual void SetNode(unsigned index, ChastePoint< SPACE_DIM > point, bool concreteMove=true)
unsigned GetNumElements() const
virtual unsigned AddNode(Node< SPACE_DIM > *pNewNode)
Definition: MutableMesh.cpp:80
unsigned GetNumNodes() const
std::vector< unsigned > mDeletedNodeIndices
virtual void DeleteNode(unsigned index)
std::vector< Node< SPACE_DIM > * > mNodes
void load(Archive &archive, const unsigned int version)
Definition: MutableMesh.hpp:93
void save(Archive &archive, const unsigned int version) const
Definition: MutableMesh.hpp:62
virtual void DeleteElement(unsigned index)
bool IsIdentityMap()
Definition: NodeMap.cpp:99
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
unsigned AddElement(Element< ELEMENT_DIM, SPACE_DIM > *pNewElement)
void MoveMergeNode(unsigned index, unsigned targetIndex, bool concreteMove=true)
unsigned GetNumBoundaryElements() const
c_vector< unsigned, 3 > SplitEdge(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
void DeleteBoundaryNodeAt(unsigned index)
virtual ~MutableMesh()
Definition: MutableMesh.cpp:74
std::vector< unsigned > mDeletedElementIndices