Chaste  Release::3.4
Node.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 _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 
284  std::set<unsigned>& rGetContainingElementIndices();
285 
289  std::vector<double>& rGetNodeAttributes();
290 
294  unsigned GetNumNodeAttributes();
295 
299  bool HasNodeAttributes();
300 
304  std::set<unsigned>& rGetContainingBoundaryElementIndices();
305 
309  unsigned GetNumContainingElements() const;
310 
314  unsigned GetNumBoundaryElements() const;
315 
319  c_vector<double, SPACE_DIM>& rGetAppliedForce();
320 
324  void ClearAppliedForce();
325 
330  void AddAppliedForceContribution(c_vector<double, SPACE_DIM>& forceContribution);
331 
335  bool IsParticle();
336 
341  void SetIsParticle(bool isParticle);
342 
346  double GetRadius();
347 
353  void SetRadius(double radius);
354 
358  void MarkAsDeleted();
359 
363  bool IsDeleted() const;
364 
368  void MarkAsInternal();
369 
373  bool IsInternal() const;
374 
380  void SetRegion(unsigned region);
381 
386  unsigned GetRegion() const;
387 
392  {
393  public:
399  ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
400  : mIndexIterator(indexIterator)
401  {}
406  const unsigned& operator*() const
407  {
408  return *mIndexIterator;
409  }
415  bool operator!=(const ContainingElementIterator& rOther) const
416  {
417  return mIndexIterator != rOther.mIndexIterator;
418  }
424  bool operator==(const ContainingElementIterator& rOther) const
425  {
426  return !operator!=(rOther);
427  }
433  {
434  ++mIndexIterator;
435  return *this;
436  }
437  private:
438  std::set<unsigned>::const_iterator mIndexIterator;
439  };
440 
445  {
447  }
448 
453  {
455  }
456 
461  {
462  public:
468  ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
469  : mIndexIterator(indexIterator)
470  {}
475  const unsigned& operator*() const
476  {
477  return *mIndexIterator;
478  }
485  {
486  return mIndexIterator != rOther.mIndexIterator;
487  }
494  {
495  return !operator!=(rOther);
496  }
502  {
503  ++mIndexIterator;
504  return *this;
505  }
506  private:
507  std::set<unsigned>::const_iterator mIndexIterator;
508  };
509 
514  {
516  }
517 
522  {
524  }
525 };
526 
528 // Declare identifier for the serializer
530 
531 namespace boost
532 {
533 namespace serialization
534 {
538 template<class Archive, unsigned SPACE_DIM>
539 inline void save_construct_data(
540  Archive & ar, const Node<SPACE_DIM> * t, const unsigned int file_version)
541 {
542 
543  // Save data required to construct instance
544  for (unsigned i = 0; i < SPACE_DIM; i++)
545  {
546  //we archive coordinates of mLocation one by one
547  //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
548  double coord = t->rGetLocation()[i];
549  ar & coord;
550  }
551  unsigned index = t->GetIndex();
552  ar << index;
553 
554  bool is_boundary = t->IsBoundaryNode();
555  ar << is_boundary;
556 }
557 
561 template<class Archive, unsigned SPACE_DIM>
562 inline void load_construct_data(
563  Archive & ar, Node<SPACE_DIM> * t, const unsigned int file_version)
564 {
565  // Retrieve data from archive required to construct new instance of Node
566  c_vector<double,SPACE_DIM> location;
567  for (unsigned i=0; i<SPACE_DIM; i++)
568  {
569  double coordinate;
570  ar & coordinate;//resume coordinates one by one
571  location[i] = coordinate;
572  }
573 
574  unsigned index;
575  ar >> index;
576 
577  bool is_boundary;
578  ar >> is_boundary;
579 
580  // Invoke inplace constructor to initialise instance
581  ::new(t)Node<SPACE_DIM>(index, location, is_boundary);
582 }
583 
584 }
585 } // namespace ...
586 
587 #endif //_NODE_HPP_
void CheckForNodeAttributes() const
Definition: Node.cpp:329
ContainingBoundaryElementIterator(std::set< unsigned >::const_iterator indexIterator)
Definition: Node.hpp:468
const unsigned & operator*() const
Definition: Node.hpp:475
bool IsInternal() const
Definition: Node.cpp:365
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:438
bool mIsInternal
Definition: Node.hpp:75
void ConstructNodeAttributes()
Definition: Node.cpp:338
Definition: Node.hpp:58
bool operator!=(const ContainingBoundaryElementIterator &rOther) const
Definition: Node.hpp:484
void SetAsBoundaryNode(bool value=true)
Definition: Node.cpp:127
void MarkAsInternal()
Definition: Node.cpp:359
void RemoveElement(unsigned index)
Definition: Node.cpp:275
void CommonConstructor(unsigned index, bool isBoundaryNode)
Definition: Node.cpp:46
void AddAppliedForceContribution(c_vector< double, SPACE_DIM > &forceContribution)
Definition: Node.cpp:225
bool operator==(const ContainingElementIterator &rOther) const
Definition: Node.hpp:424
bool mIsDeleted
Definition: Node.hpp:81
ContainingElementIterator(std::set< unsigned >::const_iterator indexIterator)
Definition: Node.hpp:399
void AddNodeAttribute(double attribute)
Definition: Node.cpp:171
void SetRadius(double radius)
Definition: Node.cpp:257
friend class boost::serialization::access
Definition: Node.hpp:90
bool IsBoundaryNode() const
Definition: Node.cpp:165
unsigned GetNumBoundaryElements() const
Definition: Node.cpp:319
void RemoveBoundaryElement(unsigned index)
Definition: Node.cpp:285
std::set< unsigned > & rGetContainingElementIndices()
Definition: Node.cpp:301
void SetIndex(unsigned index)
Definition: Node.cpp:121
bool IsParticle()
Definition: Node.cpp:233
void serialize(Archive &archive, const unsigned int version)
Definition: Node.hpp:99
std::vector< double > & rGetNodeAttributes()
Definition: Node.cpp:179
bool operator==(const ContainingBoundaryElementIterator &rOther) const
Definition: Node.hpp:493
void ClearAppliedForce()
Definition: Node.cpp:217
unsigned GetNumNodeAttributes()
Definition: Node.cpp:187
c_vector< double, SPACE_DIM > mLocation
Definition: Node.hpp:66
unsigned GetRegion() const
Definition: Node.cpp:378
std::set< unsigned >::const_iterator mIndexIterator
Definition: Node.hpp:507
bool HasNodeAttributes()
Definition: Node.cpp:203
ContainingElementIterator ContainingElementsBegin() const
Definition: Node.hpp:444
bool operator!=(const ContainingElementIterator &rOther) const
Definition: Node.hpp:415
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void SetIsParticle(bool isParticle)
Definition: Node.cpp:241
std::set< unsigned > & rGetContainingBoundaryElementIndices()
Definition: Node.cpp:307
std::set< unsigned > mBoundaryElementIndices
Definition: Node.hpp:87
ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
Definition: Node.hpp:521
void SetRegion(unsigned region)
Definition: Node.cpp:371
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition: Node.cpp:140
void AddElement(unsigned index)
Definition: Node.cpp:269
unsigned mIndex
Definition: Node.hpp:63
ChastePoint< SPACE_DIM > GetPoint() const
Definition: Node.cpp:134
void AddBoundaryElement(unsigned index)
Definition: Node.cpp:295
ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
Definition: Node.hpp:513
c_vector< double, SPACE_DIM > & rGetAppliedForce()
Definition: Node.cpp:209
unsigned GetNumContainingElements() const
Definition: Node.cpp:313
unsigned GetIndex() const
Definition: Node.cpp:159
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition: Node.cpp:152
void MarkAsDeleted()
Definition: Node.cpp:347
bool IsDeleted() const
Definition: Node.cpp:353
const unsigned & operator*() const
Definition: Node.hpp:406
ContainingElementIterator ContainingElementsEnd() const
Definition: Node.hpp:452
~Node()
Definition: Node.cpp:105
bool mIsBoundaryNode
Definition: Node.hpp:72
double GetRadius()
Definition: Node.cpp:249
ContainingElementIterator & operator++()
Definition: Node.hpp:432
ContainingBoundaryElementIterator & operator++()
Definition: Node.hpp:501
std::set< unsigned > mElementIndices
Definition: Node.hpp:84