Node.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _NODE_HPP_
00037 #define _NODE_HPP_
00038
00039 #include "UblasVectorInclude.hpp"
00040
00041 #include <set>
00042 #include <vector>
00043
00044 #include "ChasteSerialization.hpp"
00045 #include "ChastePoint.hpp"
00046 #include "NodeAttributes.hpp"
00047
00048
00049
00050
00051 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00052 class AbstractTetrahedralMesh;
00053
00057 template<unsigned SPACE_DIM>
00058 class Node
00059 {
00060 private:
00061
00063 unsigned mIndex;
00064
00066 c_vector<double, SPACE_DIM> mLocation;
00067
00069 NodeAttributes<SPACE_DIM>* mpNodeAttributes;
00070
00072 bool mIsBoundaryNode;
00073
00075 bool mIsInternal;
00076
00081 bool mIsDeleted;
00082
00084 std::set<unsigned> mElementIndices;
00085
00087 std::set<unsigned> mBoundaryElementIndices;
00088
00090 friend class boost::serialization::access;
00091 friend class TestNode;
00098 template<class Archive>
00099 void serialize(Archive & archive, const unsigned int version)
00100 {
00101
00102
00103 archive & mpNodeAttributes;
00104
00105
00106
00107
00108
00109 }
00110
00117 void CommonConstructor(unsigned index, bool isBoundaryNode);
00118
00122 void ConstructNodeAttributes();
00123
00127 void CheckForNodeAttributes() const;
00128
00129 public:
00130
00143 Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode=false);
00144
00152 Node(unsigned index, std::vector<double> coords, bool isBoundaryNode=false);
00153
00161 Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode=false);
00162
00172 Node(unsigned index, bool isBoundaryNode=false, double v1=0, double v2=0, double v3=0);
00173
00182 Node(unsigned index, double *location, bool isBoundaryNode=false);
00183
00187 ~Node();
00188
00197 void SetPoint(ChastePoint<SPACE_DIM> point);
00198
00204 void SetIndex(unsigned index);
00205
00211 void AddNodeAttribute(double attribute);
00212
00218 void SetAsBoundaryNode(bool value=true);
00219
00223 ChastePoint<SPACE_DIM> GetPoint() const;
00224
00231 const c_vector<double, SPACE_DIM>& rGetLocation() const;
00232
00241 c_vector<double, SPACE_DIM>& rGetModifiableLocation();
00242
00246 unsigned GetIndex() const;
00247
00251 bool IsBoundaryNode() const;
00252
00258 void AddElement(unsigned index);
00259
00265 void RemoveElement(unsigned index);
00266
00272 void RemoveBoundaryElement(unsigned index);
00273
00279 void AddBoundaryElement(unsigned index);
00280
00284 std::set<unsigned>& rGetContainingElementIndices();
00285
00289 std::vector<double>& rGetNodeAttributes();
00290
00294 unsigned GetNumNodeAttributes();
00295
00299 bool HasNodeAttributes();
00300
00304 std::set<unsigned>& rGetContainingBoundaryElementIndices();
00305
00309 unsigned GetNumContainingElements() const;
00310
00314 unsigned GetNumBoundaryElements() const;
00315
00319 c_vector<double, SPACE_DIM>& rGetAppliedForce();
00320
00324 void ClearAppliedForce();
00325
00330 void AddAppliedForceContribution(c_vector<double, SPACE_DIM>& forceContribution);
00331
00335 bool IsParticle();
00336
00341 void SetIsParticle(bool isParticle);
00342
00346 double GetRadius();
00347
00353 void SetRadius(double radius);
00354
00358 void MarkAsDeleted();
00359
00363 bool IsDeleted() const;
00364
00368 void MarkAsInternal();
00369
00373 bool IsInternal() const;
00374
00380 template <unsigned ELEMENT_DIM>
00381 bool IsFlagged(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh)
00382 {
00383 bool in_flagged_element = false;
00384 for (ContainingElementIterator it = ContainingElementsBegin();
00385 it != ContainingElementsEnd();
00386 ++it)
00387 {
00388 if (rMesh.GetElement(*it)->IsFlagged())
00389 {
00390 in_flagged_element = true;
00391 break;
00392 }
00393 }
00394 return in_flagged_element;
00395 }
00396
00402 void SetRegion(unsigned region);
00403
00408 unsigned GetRegion() const;
00409
00413 class ContainingElementIterator
00414 {
00415 public:
00421 ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
00422 : mIndexIterator(indexIterator)
00423 {}
00428 const unsigned& operator*() const
00429 {
00430 return *mIndexIterator;
00431 }
00437 bool operator!=(const ContainingElementIterator& rOther) const
00438 {
00439 return mIndexIterator != rOther.mIndexIterator;
00440 }
00446 bool operator==(const ContainingElementIterator& rOther) const
00447 {
00448 return !operator!=(rOther);
00449 }
00454 ContainingElementIterator& operator++()
00455 {
00456 ++mIndexIterator;
00457 return *this;
00458 }
00459 private:
00460 std::set<unsigned>::const_iterator mIndexIterator;
00461 };
00462
00466 ContainingElementIterator ContainingElementsBegin() const
00467 {
00468 return ContainingElementIterator(mElementIndices.begin());
00469 }
00470
00474 ContainingElementIterator ContainingElementsEnd() const
00475 {
00476 return ContainingElementIterator(mElementIndices.end());
00477 }
00478
00482 class ContainingBoundaryElementIterator
00483 {
00484 public:
00490 ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
00491 : mIndexIterator(indexIterator)
00492 {}
00497 const unsigned& operator*() const
00498 {
00499 return *mIndexIterator;
00500 }
00506 bool operator!=(const ContainingBoundaryElementIterator& rOther) const
00507 {
00508 return mIndexIterator != rOther.mIndexIterator;
00509 }
00515 bool operator==(const ContainingBoundaryElementIterator& rOther) const
00516 {
00517 return !operator!=(rOther);
00518 }
00523 ContainingBoundaryElementIterator& operator++()
00524 {
00525 ++mIndexIterator;
00526 return *this;
00527 }
00528 private:
00529 std::set<unsigned>::const_iterator mIndexIterator;
00530 };
00531
00535 ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
00536 {
00537 return ContainingBoundaryElementIterator(mBoundaryElementIndices.begin());
00538 }
00539
00543 ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
00544 {
00545 return ContainingBoundaryElementIterator(mBoundaryElementIndices.end());
00546 }
00547 };
00548
00549 #include "SerializationExportWrapper.hpp"
00550
00551 EXPORT_TEMPLATE_CLASS_SAME_DIMS(Node)
00552
00553 namespace boost
00554 {
00555 namespace serialization
00556 {
00560 template<class Archive, unsigned SPACE_DIM>
00561 inline void save_construct_data(
00562 Archive & ar, const Node<SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00563 {
00564
00565
00566 for (unsigned i = 0; i < SPACE_DIM; i++)
00567 {
00568
00569
00570 double coord = t->rGetLocation()[i];
00571 ar & coord;
00572 }
00573 unsigned index = t->GetIndex();
00574 ar << index;
00575
00576 bool is_boundary = t->IsBoundaryNode();
00577 ar << is_boundary;
00578 }
00582 template<class Archive, unsigned SPACE_DIM>
00583 inline void load_construct_data(
00584 Archive & ar, Node<SPACE_DIM> * t, const unsigned int file_version)
00585 {
00586
00587 c_vector<double,SPACE_DIM> location;
00588 for (unsigned i=0; i<SPACE_DIM; i++)
00589 {
00590 double coordinate;
00591 ar & coordinate;
00592 location[i] = coordinate;
00593 }
00594
00595 unsigned index;
00596 ar >> index;
00597
00598 bool is_boundary;
00599 ar >> is_boundary;
00600
00601
00602 ::new(t)Node<SPACE_DIM>(index, location, is_boundary);
00603 }
00604 }
00605 }
00606
00607 #endif //_NODE_HPP_