Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
Node.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 _NODE_HPP_
37#define _NODE_HPP_
38
40
41#include <set>
42#include <vector>
43
45#include "ChastePoint.hpp"
46#include "NodeAttributes.hpp"
47
48//#include <boost/serialization/vector.hpp>
49//#include <boost/serialization/set.hpp>
50
51template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53
57template<unsigned SPACE_DIM>
58class Node
59{
60private:
61
63 unsigned mIndex;
64
66 c_vector<double, SPACE_DIM> mLocation = {};
67
70
73
76
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
129public:
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
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 {
476 return *this;
477 }
478 private:
479 std::set<unsigned>::const_iterator mIndexIterator;
480 };
481
489
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 {
545 return *this;
546 }
547 private:
548 std::set<unsigned>::const_iterator mIndexIterator;
549 };
550
558
566};
567
569// Declare identifier for the serializer
571
572namespace boost
573{
574namespace serialization
575{
579template<class Archive, unsigned SPACE_DIM>
580inline 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
602template<class Archive, unsigned SPACE_DIM>
603inline 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_
gcov doesn't like this file...
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
bool operator!=(const ContainingBoundaryElementIterator &rOther) const
Definition Node.hpp:525
ContainingBoundaryElementIterator & operator++()
Definition Node.hpp:542
std::set< unsigned >::const_iterator mIndexIterator
Definition Node.hpp:548
const unsigned & operator*() const
Definition Node.hpp:516
bool operator==(const ContainingBoundaryElementIterator &rOther) const
Definition Node.hpp:534
ContainingBoundaryElementIterator(std::set< unsigned >::const_iterator indexIterator)
Definition Node.hpp:509
bool operator!=(const ContainingElementIterator &rOther) const
Definition Node.hpp:456
ContainingElementIterator & operator++()
Definition Node.hpp:473
ContainingElementIterator(std::set< unsigned >::const_iterator indexIterator)
Definition Node.hpp:440
bool operator==(const ContainingElementIterator &rOther) const
Definition Node.hpp:465
const unsigned & operator*() const
Definition Node.hpp:447
std::set< unsigned >::const_iterator mIndexIterator
Definition Node.hpp:479
Definition Node.hpp:59
void ClearAppliedForce()
Definition Node.cpp:216
void SetPoint(ChastePoint< SPACE_DIM > point)
Definition Node.cpp:115
ContainingElementIterator ContainingElementsEnd() const
Definition Node.hpp:493
std::set< unsigned > & rGetContainingElementIndices()
Definition Node.cpp:300
void SetRegion(unsigned region)
Definition Node.cpp:430
void AddNodeAttribute(double attribute)
Definition Node.cpp:170
c_vector< double, SPACE_DIM > & rGetAppliedForce()
Definition Node.cpp:208
std::set< unsigned > mBoundaryElementIndices
Definition Node.hpp:87
std::vector< double > & rGetNodeAttributes()
Definition Node.cpp:178
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition Node.cpp:151
void AddNeighbour(unsigned index)
Definition Node.cpp:328
std::set< unsigned > mElementIndices
Definition Node.hpp:84
void SetIndex(unsigned index)
Definition Node.cpp:121
void RemoveDuplicateNeighbours()
Definition Node.cpp:344
void ClearNeighbours()
Definition Node.cpp:336
bool IsInternal() const
Definition Node.cpp:424
void SetRadius(double radius)
Definition Node.cpp:256
ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
Definition Node.hpp:562
bool HasNodeAttributes()
Definition Node.cpp:202
unsigned GetNumContainingElements() const
Definition Node.cpp:312
std::set< unsigned > & rGetContainingBoundaryElementIndices()
Definition Node.cpp:306
void AddElement(unsigned index)
Definition Node.cpp:268
ContainingElementIterator ContainingElementsBegin() const
Definition Node.hpp:485
~Node()
Definition Node.cpp:105
bool mIsBoundaryNode
Definition Node.hpp:72
void CommonConstructor(unsigned index, bool isBoundaryNode)
Definition Node.cpp:46
unsigned GetNumBoundaryElements() const
Definition Node.cpp:318
void MarkAsDeleted()
Definition Node.cpp:406
unsigned mIndex
Definition Node.hpp:63
void AddBoundaryElement(unsigned index)
Definition Node.cpp:294
bool IsDeleted() const
Definition Node.cpp:412
NodeAttributes< SPACE_DIM > * mpNodeAttributes
Definition Node.hpp:69
void RemoveBoundaryElement(unsigned index)
Definition Node.cpp:284
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition Node.cpp:139
bool GetNeighboursSetUp()
Definition Node.cpp:368
bool IsBoundaryNode() const
Definition Node.cpp:164
bool mIsDeleted
Definition Node.hpp:81
bool mIsInternal
Definition Node.hpp:75
ChastePoint< SPACE_DIM > GetPoint() const
Definition Node.cpp:133
unsigned GetIndex() const
Definition Node.cpp:158
void SetAsBoundaryNode(bool value=true)
Definition Node.cpp:127
void AddAppliedForceContribution(const c_vector< double, SPACE_DIM > &rForceContribution)
Definition Node.cpp:224
bool IsParticle()
Definition Node.cpp:232
unsigned GetNumNodeAttributes()
Definition Node.cpp:186
friend class boost::serialization::access
Definition Node.hpp:90
void SetIsParticle(bool isParticle)
Definition Node.cpp:240
std::vector< unsigned > & rGetNeighbours()
Definition Node.cpp:376
double GetRadius()
Definition Node.cpp:248
bool NeighboursIsEmpty()
Definition Node.cpp:352
void SetNeighboursSetUp(bool flag)
Definition Node.cpp:360
void ConstructNodeAttributes()
Definition Node.cpp:397
void CheckForNodeAttributes() const
Definition Node.cpp:388
void serialize(Archive &archive, const unsigned int version)
Definition Node.hpp:99
unsigned GetRegion() const
Definition Node.cpp:437
c_vector< double, SPACE_DIM > mLocation
Definition Node.hpp:66
void RemoveElement(unsigned index)
Definition Node.cpp:274
void MarkAsInternal()
Definition Node.cpp:418
ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
Definition Node.hpp:554