Chaste  Release::2024.1
NodesOnlyMesh.hpp
1 /*
2 
3 Copyright (c) 2005-2021, 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 NODESONLYMESH_HPP_
37 #define NODESONLYMESH_HPP_
38 
39 #include "ChasteSerialization.hpp"
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"
51 template<unsigned SPACE_DIM>
52 class NodesOnlyMesh: public MutableMesh<SPACE_DIM, SPACE_DIM>
53 {
54 private:
55 
56  friend class TestNodesOnlyMesh;
57 
59  friend class boost::serialization::access;
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 
127  unsigned mIndexCounter;
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 
178  void EnlargeBoxCollection();
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 
209 protected:
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 
227 public:
228 
230  NodesOnlyMesh();
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"
500 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodesOnlyMesh)
501 
502 #endif /*NODESONLYMESH_HPP_*/
bool IsANodeCloseToDomainBoundary()
bool mCalculateNodeNeighbours
std::vector< unsigned > & rGetNodesToSendLeft()
virtual unsigned GetMaximumNodeIndex()
std::vector< unsigned > & rGetHaloNodesToSendLeft()
void EnlargeBoxCollection()
void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point, bool concreteMove=false)
Definition: Node.hpp:58
unsigned mIndexCounter
void LoadBalanceMesh()
std::vector< bool > & rGetInitiallyOwnedNodes()
double mMaximumInteractionDistance
unsigned GetNumNodes() const
void ConstructFromMeshReader(AbstractMeshReader< SPACE_DIM, SPACE_DIM > &rMeshReader)
void AddNodeWithFixedIndex(Node< SPACE_DIM > *pNewNode)
Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
void SetUpBoxCollection(const std::vector< Node< SPACE_DIM > * > &rNodes)
std::vector< unsigned > & rGetHaloNodesToSendRight()
void SetCalculateNodeNeighbours(bool calculateNodeNeighbours)
void AddHaloNodesToBoxes()
void CalculateInteriorNodePairs(std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > *> > &rNodePairs)
std::vector< Node< SPACE_DIM > * > mNodes
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void DeleteNode(unsigned index)
double GetMaximumInteractionDistance()
unsigned SolveNodeMapping(unsigned index) const
void DeleteMovedNode(unsigned index)
unsigned GetNextAvailableIndex()
void RemoveDeletedNodes(NodeMap &map)
void ResizeBoxCollection()
void load(Archive &archive, const unsigned int version)
void SetInitialBoxCollection(const c_vector< double, 2 *SPACE_DIM > domainSize, double maxInteractionDistance)
DistributedBoxCollection< SPACE_DIM > * mpBoxCollection
void SetMaximumInteractionDistance(double maxDistance)
void UpdateBoxCollection()
void AddHaloNode(boost::shared_ptr< Node< SPACE_DIM > > pNewNode)
void CalculateNodesOutsideLocalDomain()
std::vector< unsigned > mNodesToSendLeft
void SetMinimumNodeDomainBoundarySeparation(double separation)
void save(Archive &archive, const unsigned int version) const
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
DistributedBoxCollection< SPACE_DIM > * GetBoxCollection()
bool GetIsPeriodicAcrossProcsFromBoxCollection() const
std::vector< unsigned > & rGetNodesToSendRight()
unsigned mMaxAddedNodeIndex
std::vector< unsigned > GetAllNodeIndices() const
std::vector< boost::shared_ptr< Node< SPACE_DIM > > > mHaloNodes
std::vector< bool > mLocalInitialNodes
double mMinimumNodeDomainBoundarySeparation
std::vector< unsigned > mDeletedGlobalNodeIndices
void AddNodesToBoxes()
std::map< unsigned, unsigned > mNodesMapping
bool IsOwned(c_vector< double, SPACE_DIM > &location)
void ClearBoxCollection()
void ConstructNodesWithoutMesh(const std::vector< Node< SPACE_DIM > *> &rNodes, double maxInteractionDistance)
void UpdateNodeIndices()
void AddMovedNode(boost::shared_ptr< Node< SPACE_DIM > > pMovedNode)
std::map< unsigned, unsigned > mHaloNodesMapping
void CalculateBoundaryNodePairs(std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > *> > &rNodePairs)
double GetWidth(const unsigned &rDimension) const
std::vector< unsigned > mNodesToSendRight