Chaste  Release::2017.1
MutableMesh.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 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==SPACE_DIM 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 
163  bool CheckIsVoronoi(Element<ELEMENT_DIM, SPACE_DIM>* pElement, double maxPenetration);
164 
165 
166 public:
167 
171  MutableMesh();
172 
178  MutableMesh(std::vector<Node<SPACE_DIM> *> nodes);
179 
183  virtual ~MutableMesh();
184 
188  void Clear();
189 
193  unsigned GetNumNodes() const;
194 
198  unsigned GetNumElements() const;
199 
203  unsigned GetNumBoundaryElements() const;
204 
206 
213  void RescaleMeshFromBoundaryNode(ChastePoint<1> updatedPoint, unsigned boundaryNodeIndex);
214 
223  virtual unsigned AddNode(Node<SPACE_DIM>* pNewNode);
224 
231  unsigned AddElement(Element<ELEMENT_DIM,SPACE_DIM>* pNewElement);
232 
241  virtual void SetNode(unsigned index, ChastePoint<SPACE_DIM> point, bool concreteMove=true);
242 
252  void MoveMergeNode(unsigned index, unsigned targetIndex, bool concreteMove=true);
253 
260  virtual void DeleteNode(unsigned index);
261 
267  virtual void DeleteElement(unsigned index);
268 
277  void DeleteNodePriorToReMesh(unsigned index);
278 
287 
300  void DeleteBoundaryNodeAt(unsigned index);
301 
308  void ReIndex(NodeMap& map);
309 
310 
316  virtual void ReMesh(NodeMap& map);
317 
323  void ReMesh();
324 
325 
331  std::vector<c_vector<unsigned, 5> > SplitLongEdges(double cutoffLength);
332 
340  c_vector<unsigned, 3> SplitEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
341 
350  bool CheckIsVoronoi(double maxPenetration=0.0);
351 };
352 
355 
356 #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:100
#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)
gcov doesn&#39;t like this file...
void DeleteBoundaryNodeAt(unsigned index)
virtual ~MutableMesh()
Definition: MutableMesh.cpp:74
std::vector< unsigned > mDeletedElementIndices