Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
MutableMesh.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
40#include <boost/serialization/base_object.hpp>
41#include <boost/serialization/split_member.hpp>
42
43#include "TetrahedralMesh.hpp"
44#include "NodeMap.hpp"
45
49template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
50class MutableMesh : public TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>
51{
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
130protected:
131
136 std::vector<unsigned> mDeletedElementIndices;
137
142 std::vector<unsigned> mDeletedBoundaryElementIndices;
143
148 std::vector<unsigned> mDeletedNodeIndices;
149
152
153private:
154
163 bool CheckIsVoronoi(Element<ELEMENT_DIM, SPACE_DIM>* pElement, double maxPenetration);
164
165
166public:
167
171 MutableMesh();
172
181 MutableMesh(std::vector<Node<SPACE_DIM> *> nodes);
182
186 virtual ~MutableMesh();
187
191 void Clear();
192
196 unsigned GetNumNodes() const;
197
201 unsigned GetNumElements() const;
202
206 unsigned GetNumBoundaryElements() const;
207
209
216 void RescaleMeshFromBoundaryNode(ChastePoint<1> updatedPoint, unsigned boundaryNodeIndex);
217
226 virtual unsigned AddNode(Node<SPACE_DIM>* pNewNode);
227
234 unsigned AddElement(Element<ELEMENT_DIM,SPACE_DIM>* pNewElement);
235
244 virtual void SetNode(unsigned index, ChastePoint<SPACE_DIM> point, bool concreteMove=true);
245
255 void MoveMergeNode(unsigned index, unsigned targetIndex, bool concreteMove=true);
256
263 virtual void DeleteNode(unsigned index);
264
270 virtual void DeleteElement(unsigned index);
271
280 void DeleteNodePriorToReMesh(unsigned index);
281
289 unsigned RefineElement(Element<ELEMENT_DIM,SPACE_DIM>* pElement, ChastePoint<SPACE_DIM> point);
290
303 void DeleteBoundaryNodeAt(unsigned index);
304
311 void ReIndex(NodeMap& map);
312
313
319 virtual void ReMesh(NodeMap& map);
320
326 void ReMesh();
327
328
334 std::vector<c_vector<unsigned, 5> > SplitLongEdges(double cutoffLength);
335
343 c_vector<unsigned, 3> SplitEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
344
353 bool CheckIsVoronoi(double maxPenetration=0.0);
354};
355
356#include "SerializationExportWrapper.hpp"
358
359#endif /*MUTABLEMESH_HPP_*/
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
std::vector< Node< SPACE_DIM > * > mNodes
void save(Archive &archive, const unsigned int version) const
unsigned GetNumElements() const
bool CheckIsVoronoi(Element< ELEMENT_DIM, SPACE_DIM > *pElement, double maxPenetration)
c_vector< unsigned, 3 > SplitEdge(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
void ReIndex(NodeMap &map)
unsigned AddElement(Element< ELEMENT_DIM, SPACE_DIM > *pNewElement)
unsigned GetNumNodes() const
void DeleteNodePriorToReMesh(unsigned index)
virtual void SetNode(unsigned index, ChastePoint< SPACE_DIM > point, bool concreteMove=true)
std::vector< unsigned > mDeletedBoundaryElementIndices
virtual void DeleteNode(unsigned index)
void RescaleMeshFromBoundaryNode(ChastePoint< 1 > updatedPoint, unsigned boundaryNodeIndex)
void DeleteBoundaryNodeAt(unsigned index)
std::vector< c_vector< unsigned, 5 > > SplitLongEdges(double cutoffLength)
unsigned RefineElement(Element< ELEMENT_DIM, SPACE_DIM > *pElement, ChastePoint< SPACE_DIM > point)
friend class boost::serialization::access
std::vector< unsigned > mDeletedElementIndices
unsigned GetNumBoundaryElements() const
void load(Archive &archive, const unsigned int version)
std::vector< unsigned > mDeletedNodeIndices
virtual unsigned AddNode(Node< SPACE_DIM > *pNewNode)
void MoveMergeNode(unsigned index, unsigned targetIndex, bool concreteMove=true)
virtual void DeleteElement(unsigned index)
bool IsIdentityMap()
Definition NodeMap.cpp:100
Definition Node.hpp:59