Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
NodesOnlyMesh.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 NODESONLYMESH_HPP_
37#define NODESONLYMESH_HPP_
38
40#include <boost/serialization/base_object.hpp>
41#include <boost/serialization/map.hpp>
42
43#include "SmartPointers.hpp"
44#include "PetscTools.hpp"
45#include "DistributedBoxCollection.hpp"
46#include "MutableMesh.hpp"
51template<unsigned SPACE_DIM>
52class NodesOnlyMesh: public MutableMesh<SPACE_DIM, SPACE_DIM>
53{
54private:
55
56 friend class TestNodesOnlyMesh;
57
60
72 template<class Archive>
73 void save(Archive & archive, const unsigned int version) const
74 {
77 std::vector<unsigned> indices = GetAllNodeIndices();
78 archive & indices;
79 archive & boost::serialization::base_object<MutableMesh<SPACE_DIM, SPACE_DIM> >(*this);
80 }
81
93 template<class Archive>
94 void load(Archive & archive, const unsigned int version)
95 {
98 std::vector<unsigned> indices;
99 archive & indices;
100 archive & boost::serialization::base_object<MutableMesh<SPACE_DIM, SPACE_DIM> >(*this);
101 // Re-index the nodes according to what we've just read
102 assert(GetNumNodes() == indices.size());
103 this->mNodesMapping.clear();
104 for (unsigned i=0; i<this->mNodes.size(); i++)
105 {
106 unsigned new_index = indices[i];
107 this->mNodes[i]->SetIndex(new_index);
108 this->mNodesMapping[new_index] = i;
109 }
110 mMaxAddedNodeIndex = *(std::max_element(indices.begin(), indices.end()));
111 mIndexCounter = mMaxAddedNodeIndex + 1; // Next available fresh index
112 }
113 BOOST_SERIALIZATION_SPLIT_MEMBER()
115 std::vector<boost::shared_ptr<Node<SPACE_DIM> > > mHaloNodes;
116
119
121 std::map<unsigned, unsigned> mNodesMapping;
122
124 std::map<unsigned, unsigned> mHaloNodesMapping;
125
128
131
133 std::vector<unsigned> mDeletedGlobalNodeIndices;
134
136 std::vector<unsigned> mNodesToSendRight;
137
139 std::vector<unsigned> mNodesToSendLeft;
140
143 std::vector<bool> mLocalInitialNodes;
144
148
151
154
175 unsigned GetNextAvailableIndex();
176
179
184
190 void SetUpBoxCollection(const std::vector<Node<SPACE_DIM>* >& rNodes);
191
197 void RemoveDeletedNodes(NodeMap& map);
198
200 void UpdateNodeIndices();
201
207 void AddNodeWithFixedIndex(Node<SPACE_DIM>* pNewNode);
208
209protected:
210
212 void ClearBoxCollection();
213
222 virtual void SetUpBoxCollection(double cutOffLength, c_vector<double, 2*SPACE_DIM> domainSize, int numLocalRows = PETSC_DECIDE, c_vector<bool,SPACE_DIM> isDimPeriodic = zero_vector<bool>(SPACE_DIM));
223
226
227public:
228
231
233 virtual ~NodesOnlyMesh();
234
246 void ConstructNodesWithoutMesh(const std::vector<Node<SPACE_DIM>*>& rNodes, double maxInteractionDistance);
247
259 void ConstructNodesWithoutMesh(const std::vector<boost::shared_ptr<Node<SPACE_DIM> > >& rNodes, double maxInteractionDistance);
260
268 void ConstructNodesWithoutMesh(const AbstractMesh<SPACE_DIM,SPACE_DIM>& rGeneratingMesh, double maxInteractionDistance);
269
271 std::vector<bool>& rGetInitiallyOwnedNodes();
272
274 void Clear();
275
283 unsigned SolveNodeMapping(unsigned index) const;
284
292 Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
293
299 bool IsOwned(c_vector<double, SPACE_DIM>& location);
300
305 unsigned GetNumNodes() const;
306
312 virtual unsigned GetMaximumNodeIndex();
313
319 void SetMaximumInteractionDistance(double maxDistance);
320
325
332 double GetWidth(const unsigned& rDimension) const;
333
339 void SetCalculateNodeNeighbours(bool calculateNodeNeighbours);
340
346 void CalculateInteriorNodePairs(std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& rNodePairs);
347
353 void CalculateBoundaryNodePairs(std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& rNodePairs);
354
362 void ReMesh(NodeMap& rMap);
363
369 void SetInitialBoxCollection(const c_vector<double, 2*SPACE_DIM> domainSize, double maxInteractionDistance);
370
374 void UpdateBoxCollection();
375
380 void ResizeBoxCollection();
381
388
392 void AddNodesToBoxes();
393
397 void AddHaloNodesToBoxes();
398
403
407 std::vector<unsigned>& rGetNodesToSendLeft();
408
412 std::vector<unsigned>& rGetNodesToSendRight();
413
417 std::vector<unsigned>& rGetHaloNodesToSendRight();
418
422 std::vector<unsigned>& rGetHaloNodesToSendLeft();
423
428 void AddHaloNode(boost::shared_ptr<Node<SPACE_DIM> > pNewNode);
429
433 void ClearHaloNodes();
434
442 void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point, bool concreteMove = false);
443
450 unsigned AddNode(Node<SPACE_DIM>* pNewNode);
451
456 void AddMovedNode(boost::shared_ptr<Node<SPACE_DIM> > pMovedNode);
457
463 void DeleteNode(unsigned index);
464
470 void DeleteMovedNode(unsigned index);
471
477 void SetMinimumNodeDomainBoundarySeparation(double separation);
478
483 void LoadBalanceMesh();
484
490 void ConstructFromMeshReader(AbstractMeshReader<SPACE_DIM, SPACE_DIM>& rMeshReader);
491
496 std::vector<unsigned> GetAllNodeIndices() const;
497};
498
499#include "SerializationExportWrapper.hpp"
501
502#endif /*NODESONLYMESH_HPP_*/
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
std::vector< Node< SPACE_DIM > * > mNodes
Definition Node.hpp:59
void ClearBoxCollection()
void save(Archive &archive, const unsigned int version) const
void AddMovedNode(boost::shared_ptr< Node< SPACE_DIM > > pMovedNode)
void ConstructNodesWithoutMesh(const std::vector< Node< SPACE_DIM > * > &rNodes, double maxInteractionDistance)
double GetMaximumInteractionDistance()
void EnlargeBoxCollection()
unsigned GetNumNodes() const
virtual unsigned GetMaximumNodeIndex()
void AddNodeWithFixedIndex(Node< SPACE_DIM > *pNewNode)
void SetMaximumInteractionDistance(double maxDistance)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
void DeleteNode(unsigned index)
unsigned GetNextAvailableIndex()
void UpdateBoxCollection()
std::vector< unsigned > GetAllNodeIndices() const
void CalculateNodesOutsideLocalDomain()
void SetInitialBoxCollection(const c_vector< double, 2 *SPACE_DIM > domainSize, double maxInteractionDistance)
DistributedBoxCollection< SPACE_DIM > * GetBoxCollection()
std::vector< bool > & rGetInitiallyOwnedNodes()
void SetUpBoxCollection(const std::vector< Node< SPACE_DIM > * > &rNodes)
void SetCalculateNodeNeighbours(bool calculateNodeNeighbours)
std::map< unsigned, unsigned > mNodesMapping
void ConstructFromMeshReader(AbstractMeshReader< SPACE_DIM, SPACE_DIM > &rMeshReader)
void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point, bool concreteMove=false)
Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
std::vector< bool > mLocalInitialNodes
unsigned mIndexCounter
std::vector< unsigned > mNodesToSendRight
bool IsANodeCloseToDomainBoundary()
std::vector< unsigned > & rGetHaloNodesToSendRight()
bool mCalculateNodeNeighbours
double GetWidth(const unsigned &rDimension) const
void RemoveDeletedNodes(NodeMap &map)
void load(Archive &archive, const unsigned int version)
std::vector< unsigned > & rGetNodesToSendLeft()
unsigned SolveNodeMapping(unsigned index) const
double mMinimumNodeDomainBoundarySeparation
void CalculateBoundaryNodePairs(std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > &rNodePairs)
void ResizeBoxCollection()
void SetMinimumNodeDomainBoundarySeparation(double separation)
void AddHaloNode(boost::shared_ptr< Node< SPACE_DIM > > pNewNode)
std::vector< boost::shared_ptr< Node< SPACE_DIM > > > mHaloNodes
unsigned mMaxAddedNodeIndex
std::vector< unsigned > mNodesToSendLeft
std::vector< unsigned > & rGetHaloNodesToSendLeft()
void AddHaloNodesToBoxes()
void DeleteMovedNode(unsigned index)
friend class boost::serialization::access
DistributedBoxCollection< SPACE_DIM > * mpBoxCollection
void CalculateInteriorNodePairs(std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > &rNodePairs)
bool GetIsPeriodicAcrossProcsFromBoxCollection() const
bool IsOwned(c_vector< double, SPACE_DIM > &location)
double mMaximumInteractionDistance
std::vector< unsigned > mDeletedGlobalNodeIndices
std::map< unsigned, unsigned > mHaloNodesMapping
std::vector< unsigned > & rGetNodesToSendRight()