Chaste  Release::3.4
NodesOnlyMesh.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 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 "PetscTools.hpp"
44 #include "DistributedBoxCollection.hpp"
45 #include "MutableMesh.hpp"
46 
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 serialize(Archive & archive, const unsigned int version)
74  {
77  archive & boost::serialization::base_object<MutableMesh<SPACE_DIM, SPACE_DIM> >(*this);
78  }
79 
81  std::vector<boost::shared_ptr<Node<SPACE_DIM> > > mHaloNodes;
82 
85 
87  std::map<unsigned, unsigned> mNodesMapping;
88 
90  std::map<unsigned, unsigned> mHaloNodesMapping;
91 
93  unsigned mIndexCounter;
94 
97 
99  std::vector<unsigned> mDeletedGlobalNodeIndices;
100 
102  std::vector<unsigned> mNodesToSendRight;
103 
105  std::vector<unsigned> mNodesToSendLeft;
106 
109  std::vector<bool> mLocalInitialNodes;
110 
114 
117 
120 
141  unsigned GetNextAvailableIndex();
142 
144  void EnlargeBoxCollection();
145 
150 
156  void SetUpBoxCollection(const std::vector<Node<SPACE_DIM>* >& rNodes);
157 
163  void RemoveDeletedNodes(NodeMap& map);
164 
166  void UpdateNodeIndices();
167 
173  void AddNodeWithFixedIndex(Node<SPACE_DIM>* pNewNode);
174 
175 protected:
176 
178  void ClearBoxCollection();
179 
188  virtual void SetUpBoxCollection(double cutOffLength, c_vector<double, 2*SPACE_DIM> domainSize, int numLocalRows = PETSC_DECIDE, bool isPeriodic = false);
189 
192 
193 public:
194 
196  NodesOnlyMesh();
197 
199  virtual ~NodesOnlyMesh();
200 
212  void ConstructNodesWithoutMesh(const std::vector<Node<SPACE_DIM>*>& rNodes, double maxInteractionDistance);
213 
221  void ConstructNodesWithoutMesh(const AbstractMesh<SPACE_DIM,SPACE_DIM>& rGeneratingMesh, double maxInteractionDistance);
222 
224  std::vector<bool>& rGetInitiallyOwnedNodes();
225 
227  void Clear();
228 
236  unsigned SolveNodeMapping(unsigned index) const;
237 
245  Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
246 
252  bool IsOwned(c_vector<double, SPACE_DIM>& location);
253 
258  unsigned GetNumNodes() const;
259 
265  virtual unsigned GetMaximumNodeIndex();
266 
272  void SetMaximumInteractionDistance(double maxDistance);
273 
278 
285  double GetWidth(const unsigned& rDimension) const;
286 
292  void SetCalculateNodeNeighbours(bool calculateNodeNeighbours);
293 
300  void CalculateInteriorNodePairs(std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& rNodePairs, std::map<unsigned, std::set<unsigned> >& rNodeNeighbours);
301 
308  void CalculateBoundaryNodePairs(std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& rNodePairs, std::map<unsigned, std::set<unsigned> >& rNodeNeighbours);
309 
317  void ReMesh(NodeMap& rMap);
318 
324  void SetInitialBoxCollection(const c_vector<double, 2*SPACE_DIM> domainSize, double maxInteractionDistance);
325 
329  void UpdateBoxCollection();
330 
335  void ResizeBoxCollection();
336 
340  void AddNodesToBoxes();
341 
345  void AddHaloNodesToBoxes();
346 
351 
355  std::vector<unsigned>& rGetNodesToSendLeft();
356 
360  std::vector<unsigned>& rGetNodesToSendRight();
361 
365  std::vector<unsigned>& rGetHaloNodesToSendRight();
366 
370  std::vector<unsigned>& rGetHaloNodesToSendLeft();
371 
376  void AddHaloNode(boost::shared_ptr<Node<SPACE_DIM> > pNewNode);
377 
381  void ClearHaloNodes();
382 
390  void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point, bool concreteMove = false);
391 
398  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
399 
404  void AddMovedNode(boost::shared_ptr<Node<SPACE_DIM> > pMovedNode);
405 
411  void DeleteNode(unsigned index);
412 
418  void DeleteMovedNode(unsigned index);
419 
425  void SetMinimumNodeDomainBoundarySeparation(double separation);
426 
431  void LoadBalanceMesh();
432 
439 };
440 
443 
444 #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()
Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
double mMaximumInteractionDistance
void ConstructFromMeshReader(AbstractMeshReader< SPACE_DIM, SPACE_DIM > &rMeshReader)
void AddNodeWithFixedIndex(Node< SPACE_DIM > *pNewNode)
void SetUpBoxCollection(const std::vector< Node< SPACE_DIM > * > &rNodes)
std::vector< unsigned > & rGetHaloNodesToSendRight()
void SetCalculateNodeNeighbours(bool calculateNodeNeighbours)
void AddHaloNodesToBoxes()
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void DeleteNode(unsigned index)
double GetWidth(const unsigned &rDimension) const
double GetMaximumInteractionDistance()
void DeleteMovedNode(unsigned index)
void serialize(Archive &archive, const unsigned int version)
unsigned GetNextAvailableIndex()
void RemoveDeletedNodes(NodeMap &map)
void ResizeBoxCollection()
unsigned SolveNodeMapping(unsigned index) const
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 ConstructNodesWithoutMesh(const std::vector< Node< SPACE_DIM > * > &rNodes, double maxInteractionDistance)
void SetMinimumNodeDomainBoundarySeparation(double separation)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
DistributedBoxCollection< SPACE_DIM > * GetBoxCollection()
void CalculateBoundaryNodePairs(std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > &rNodePairs, std::map< unsigned, std::set< unsigned > > &rNodeNeighbours)
std::vector< unsigned > & rGetNodesToSendRight()
unsigned mMaxAddedNodeIndex
std::vector< boost::shared_ptr< Node< SPACE_DIM > > > mHaloNodes
std::vector< bool > mLocalInitialNodes
void CalculateInteriorNodePairs(std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > &rNodePairs, std::map< unsigned, std::set< unsigned > > &rNodeNeighbours)
double mMinimumNodeDomainBoundarySeparation
std::vector< unsigned > mDeletedGlobalNodeIndices
void AddNodesToBoxes()
std::map< unsigned, unsigned > mNodesMapping
bool IsOwned(c_vector< double, SPACE_DIM > &location)
void ClearBoxCollection()
void UpdateNodeIndices()
void AddMovedNode(boost::shared_ptr< Node< SPACE_DIM > > pMovedNode)
std::map< unsigned, unsigned > mHaloNodesMapping
virtual ~NodesOnlyMesh()
unsigned GetNumNodes() const
std::vector< unsigned > mNodesToSendRight