Chaste  Release::2017.1
Node.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 _NODE_HPP_
37 #define _NODE_HPP_
38 
39 #include "UblasVectorInclude.hpp"
40 
41 #include <set>
42 #include <vector>
43 
44 #include "ChasteSerialization.hpp"
45 #include "ChastePoint.hpp"
46 #include "NodeAttributes.hpp"
47 
48 //#include <boost/serialization/vector.hpp>
49 //#include <boost/serialization/set.hpp>
50 
51 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53 
57 template<unsigned SPACE_DIM>
58 class Node
59 {
60 private:
61 
63  unsigned mIndex;
64 
66  c_vector<double, SPACE_DIM> mLocation;
67 
70 
73 
76 
81  bool mIsDeleted;
82 
84  std::set<unsigned> mElementIndices;
85 
87  std::set<unsigned> mBoundaryElementIndices;
88 
91  friend class TestNode;
98  template<class Archive>
99  void serialize(Archive & archive, const unsigned int version)
100  {
101  //archive & mLocation; //earlier versions of boost are unable to do this. See #1709
102 // archive & mIndex;
103  archive & mpNodeAttributes;
104 // archive & mIsBoundaryNode;
105 // archive & mIsInternal;
106 // archive & mIsDeleted;
107 // archive & mElementIndices;
108 // archive & mBoundaryElementIndices;
109  }
110 
117  void CommonConstructor(unsigned index, bool isBoundaryNode);
118 
123 
127  void CheckForNodeAttributes() const;
128 
129 public:
130 
143  Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode=false);
144 
152  Node(unsigned index, std::vector<double> coords, bool isBoundaryNode=false);
153 
161  Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode=false);
162 
172  Node(unsigned index, bool isBoundaryNode=false, double v1=0, double v2=0, double v3=0);
173 
182  Node(unsigned index, double *location, bool isBoundaryNode=false);
183 
187  ~Node();
188 
197  void SetPoint(ChastePoint<SPACE_DIM> point);
198 
204  void SetIndex(unsigned index);
205 
211  void AddNodeAttribute(double attribute);
212 
218  void SetAsBoundaryNode(bool value=true);
219 
224 
231  const c_vector<double, SPACE_DIM>& rGetLocation() const;
232 
241  c_vector<double, SPACE_DIM>& rGetModifiableLocation();
242 
246  unsigned GetIndex() const;
247 
251  bool IsBoundaryNode() const;
252 
258  void AddElement(unsigned index);
259 
265  void RemoveElement(unsigned index);
266 
272  void RemoveBoundaryElement(unsigned index);
273 
279  void AddBoundaryElement(unsigned index);
280 
286  void AddNeighbour(unsigned index);
287 
291  void ClearNeighbours();
292 
297 
303  bool NeighboursIsEmpty();
304 
310  void SetNeighboursSetUp(bool flag);
311 
315  bool GetNeighboursSetUp();
316 
320  std::vector<unsigned>& rGetNeighbours();
321 
325  std::set<unsigned>& rGetContainingElementIndices();
326 
330  std::vector<double>& rGetNodeAttributes();
331 
335  unsigned GetNumNodeAttributes();
336 
340  bool HasNodeAttributes();
341 
345  std::set<unsigned>& rGetContainingBoundaryElementIndices();
346 
350  unsigned GetNumContainingElements() const;
351 
355  unsigned GetNumBoundaryElements() const;
356 
360  c_vector<double, SPACE_DIM>& rGetAppliedForce();
361 
365  void ClearAppliedForce();
366 
371  void AddAppliedForceContribution(const c_vector<double, SPACE_DIM>& rForceContribution);
372 
376  bool IsParticle();
377 
382  void SetIsParticle(bool isParticle);
383 
387  double GetRadius();
388 
394  void SetRadius(double radius);
395 
399  void MarkAsDeleted();
400 
404  bool IsDeleted() const;
405 
409  void MarkAsInternal();
410 
414  bool IsInternal() const;
415 
421  void SetRegion(unsigned region);
422 
427  unsigned GetRegion() const;
428 
433  {
434  public:
440  ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
441  : mIndexIterator(indexIterator)
442  {}
447  const unsigned& operator*() const
448  {
449  return *mIndexIterator;
450  }
456  bool operator!=(const ContainingElementIterator& rOther) const
457  {
458  return mIndexIterator != rOther.mIndexIterator;
459  }
465  bool operator==(const ContainingElementIterator& rOther) const
466  {
467  return !operator!=(rOther);
468  }
474  {
475  ++mIndexIterator;
476  return *this;
477  }
478  private:
479  std::set<unsigned>::const_iterator mIndexIterator;
480  };
481 
486  {
487  return ContainingElementIterator(mElementIndices.begin());
488  }
489 
494  {
495  return ContainingElementIterator(mElementIndices.end());
496  }
497 
502  {
503  public:
509  ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
510  : mIndexIterator(indexIterator)
511  {}
516  const unsigned& operator*() const
517  {
518  return *mIndexIterator;
519  }
526  {
527  return mIndexIterator != rOther.mIndexIterator;
528  }
535  {
536  return !operator!=(rOther);
537  }
543  {
544  ++mIndexIterator;
545  return *this;
546  }
547  private:
548  std::set<unsigned>::const_iterator mIndexIterator;
549  };
550 
555  {
556  return ContainingBoundaryElementIterator(mBoundaryElementIndices.begin());
557  }
558 
563  {
564  return ContainingBoundaryElementIterator(mBoundaryElementIndices.end());
565  }
566 };
567 
569 // Declare identifier for the serializer
571 
572 namespace boost
573 {
574 namespace serialization
575 {
579 template<class Archive, unsigned SPACE_DIM>
580 inline void save_construct_data(
581  Archive & ar, const Node<SPACE_DIM> * t, const unsigned int file_version)
582 {
583 
584  // Save data required to construct instance
585  for (unsigned i = 0; i < SPACE_DIM; i++)
586  {
587  //we archive coordinates of mLocation one by one
588  //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
589  double coord = t->rGetLocation()[i];
590  ar & coord;
591  }
592  unsigned index = t->GetIndex();
593  ar << index;
594 
595  bool is_boundary = t->IsBoundaryNode();
596  ar << is_boundary;
597 }
598 
602 template<class Archive, unsigned SPACE_DIM>
603 inline void load_construct_data(
604  Archive & ar, Node<SPACE_DIM> * t, const unsigned int file_version)
605 {
606  // Retrieve data from archive required to construct new instance of Node
607  c_vector<double,SPACE_DIM> location;
608  for (unsigned i=0; i<SPACE_DIM; i++)
609  {
610  double coordinate;
611  ar & coordinate;//resume coordinates one by one
612  location[i] = coordinate;
613  }
614 
615  unsigned index;
616  ar >> index;
617 
618  bool is_boundary;
619  ar >> is_boundary;
620 
621  // Invoke inplace constructor to initialise instance
622  ::new(t)Node<SPACE_DIM>(index, location, is_boundary);
623 }
624 
625 }
626 } // namespace ...
627 
628 #endif //_NODE_HPP_
void CheckForNodeAttributes() const
Definition: Node.cpp:388
ContainingBoundaryElementIterator(std::set< unsigned >::const_iterator indexIterator)
Definition: Node.hpp:509
const unsigned & operator*() const
Definition: Node.hpp:516
bool IsInternal() const
Definition: Node.cpp:424
NodeAttributes< SPACE_DIM > * mpNodeAttributes
Definition: Node.hpp:69
void SetPoint(ChastePoint< SPACE_DIM > point)
Definition: Node.cpp:115
Node(unsigned index, ChastePoint< SPACE_DIM > point, bool isBoundaryNode=false)
Definition: Node.cpp:56
std::set< unsigned >::const_iterator mIndexIterator
Definition: Node.hpp:479
bool mIsInternal
Definition: Node.hpp:75
void ConstructNodeAttributes()
Definition: Node.cpp:397
Definition: Node.hpp:58
bool operator!=(const ContainingBoundaryElementIterator &rOther) const
Definition: Node.hpp:525
void SetAsBoundaryNode(bool value=true)
Definition: Node.cpp:127
void MarkAsInternal()
Definition: Node.cpp:418
void RemoveElement(unsigned index)
Definition: Node.cpp:274
void CommonConstructor(unsigned index, bool isBoundaryNode)
Definition: Node.cpp:46
bool operator==(const ContainingElementIterator &rOther) const
Definition: Node.hpp:465
bool mIsDeleted
Definition: Node.hpp:81
ContainingElementIterator(std::set< unsigned >::const_iterator indexIterator)
Definition: Node.hpp:440
void AddNodeAttribute(double attribute)
Definition: Node.cpp:170
void SetRadius(double radius)
Definition: Node.cpp:256
friend class boost::serialization::access
Definition: Node.hpp:90
bool IsBoundaryNode() const
Definition: Node.cpp:164
unsigned GetNumBoundaryElements() const
Definition: Node.cpp:318
void RemoveBoundaryElement(unsigned index)
Definition: Node.cpp:284
void ClearNeighbours()
Definition: Node.cpp:336
std::set< unsigned > & rGetContainingElementIndices()
Definition: Node.cpp:300
void SetIndex(unsigned index)
Definition: Node.cpp:121
bool IsParticle()
Definition: Node.cpp:232
void serialize(Archive &archive, const unsigned int version)
Definition: Node.hpp:99
std::vector< double > & rGetNodeAttributes()
Definition: Node.cpp:178
bool operator==(const ContainingBoundaryElementIterator &rOther) const
Definition: Node.hpp:534
void ClearAppliedForce()
Definition: Node.cpp:216
unsigned GetNumNodeAttributes()
Definition: Node.cpp:186
c_vector< double, SPACE_DIM > mLocation
Definition: Node.hpp:66
unsigned GetRegion() const
Definition: Node.cpp:437
std::set< unsigned >::const_iterator mIndexIterator
Definition: Node.hpp:548
bool HasNodeAttributes()
Definition: Node.cpp:202
void SetNeighboursSetUp(bool flag)
Definition: Node.cpp:360
ContainingElementIterator ContainingElementsBegin() const
Definition: Node.hpp:485
bool operator!=(const ContainingElementIterator &rOther) const
Definition: Node.hpp:456
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void AddAppliedForceContribution(const c_vector< double, SPACE_DIM > &rForceContribution)
Definition: Node.cpp:224
void SetIsParticle(bool isParticle)
Definition: Node.cpp:240
std::set< unsigned > & rGetContainingBoundaryElementIndices()
Definition: Node.cpp:306
void AddNeighbour(unsigned index)
Definition: Node.cpp:328
std::set< unsigned > mBoundaryElementIndices
Definition: Node.hpp:87
ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
Definition: Node.hpp:562
void SetRegion(unsigned region)
Definition: Node.cpp:430
std::vector< unsigned > & rGetNeighbours()
Definition: Node.cpp:376
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition: Node.cpp:139
void AddElement(unsigned index)
Definition: Node.cpp:268
unsigned mIndex
Definition: Node.hpp:63
bool GetNeighboursSetUp()
Definition: Node.cpp:368
ChastePoint< SPACE_DIM > GetPoint() const
Definition: Node.cpp:133
void RemoveDuplicateNeighbours()
Definition: Node.cpp:344
void AddBoundaryElement(unsigned index)
Definition: Node.cpp:294
ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
Definition: Node.hpp:554
c_vector< double, SPACE_DIM > & rGetAppliedForce()
Definition: Node.cpp:208
unsigned GetNumContainingElements() const
Definition: Node.cpp:312
unsigned GetIndex() const
Definition: Node.cpp:158
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition: Node.cpp:151
void MarkAsDeleted()
Definition: Node.cpp:406
bool IsDeleted() const
Definition: Node.cpp:412
const unsigned & operator*() const
Definition: Node.hpp:447
gcov doesn&#39;t like this file...
ContainingElementIterator ContainingElementsEnd() const
Definition: Node.hpp:493
~Node()
Definition: Node.cpp:105
bool mIsBoundaryNode
Definition: Node.hpp:72
bool NeighboursIsEmpty()
Definition: Node.cpp:352
double GetRadius()
Definition: Node.cpp:248
ContainingElementIterator & operator++()
Definition: Node.hpp:473
ContainingBoundaryElementIterator & operator++()
Definition: Node.hpp:542
std::set< unsigned > mElementIndices
Definition: Node.hpp:84