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 #ifndef _NODE_HPP_
00030 #define _NODE_HPP_
00031
00032 #include "UblasVectorInclude.hpp"
00033
00034 #include <set>
00035 #include <vector>
00036
00037 #include "ChastePoint.hpp"
00038
00039 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00040 class TetrahedralMesh;
00041
00045 template<unsigned SPACE_DIM>
00046 class Node
00047 {
00048 private:
00049
00051 unsigned mIndex;
00052
00054 unsigned mRegion;
00055
00057 c_vector<double, SPACE_DIM> mLocation;
00058
00060 bool mIsBoundaryNode;
00061
00066 bool mIsDeleted;
00067
00069 std::set<unsigned> mElementIndices;
00070
00072 std::set<unsigned> mBoundaryElementIndices;
00073
00080 void CommonConstructor(unsigned index, bool isBoundaryNode);
00081
00082 public:
00083
00096 Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode=false);
00097
00105 Node(unsigned index, std::vector<double> coords, bool isBoundaryNode=false);
00106
00114 Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode=false);
00115
00125 Node(unsigned index, bool isBoundaryNode=false, double v1=0, double v2=0, double v3=0);
00126
00135 void SetPoint(ChastePoint<SPACE_DIM> point);
00136
00142 void SetIndex(unsigned index);
00143
00149 void SetAsBoundaryNode(bool value=true);
00150
00154 ChastePoint<SPACE_DIM> GetPoint() const;
00155
00162 const c_vector<double, SPACE_DIM>& rGetLocation() const;
00163
00172 c_vector<double, SPACE_DIM>& rGetModifiableLocation();
00173
00177 unsigned GetIndex() const;
00178
00182 bool IsBoundaryNode() const;
00183
00189 void AddElement(unsigned index);
00190
00196 void RemoveElement(unsigned index);
00197
00203 void RemoveBoundaryElement(unsigned index);
00204
00210 void AddBoundaryElement(unsigned index);
00211
00215 std::set<unsigned>& rGetContainingElementIndices();
00216
00220 std::set<unsigned>& rGetContainingBoundaryElementIndices();
00221
00225 unsigned GetNumContainingElements() const;
00226
00230 unsigned GetNumBoundaryElements() const;
00231
00235 void MarkAsDeleted();
00236
00240 bool IsDeleted() const;
00241
00247 template <unsigned ELEMENT_DIM>
00248 bool IsFlagged(TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh)
00249 {
00250 bool in_flagged_element = false;
00251 for (ContainingElementIterator it = ContainingElementsBegin();
00252 it != ContainingElementsEnd();
00253 ++it)
00254 {
00255 if (rMesh.GetElement(*it)->IsFlagged())
00256 {
00257 in_flagged_element = true;
00258 break;
00259 }
00260 }
00261 return in_flagged_element;
00262 }
00263
00269 void SetRegion(unsigned region);
00270
00274 unsigned GetRegion() const;
00275
00279 class ContainingElementIterator
00280 {
00281 public:
00287 ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
00288 : mIndexIterator(indexIterator)
00289 {}
00293 const unsigned& operator*() const
00294 {
00295 return *mIndexIterator;
00296 }
00302 bool operator!=(const ContainingElementIterator& rOther) const
00303 {
00304 return mIndexIterator != rOther.mIndexIterator;
00305 }
00311 bool operator==(const ContainingElementIterator& rOther) const
00312 {
00313 return !operator!=(rOther);
00314 }
00318 ContainingElementIterator& operator++()
00319 {
00320 ++mIndexIterator;
00321 return *this;
00322 }
00323 private:
00324 std::set<unsigned>::const_iterator mIndexIterator;
00325 };
00326
00330 ContainingElementIterator ContainingElementsBegin() const
00331 {
00332 return ContainingElementIterator(mElementIndices.begin());
00333 }
00334
00338 ContainingElementIterator ContainingElementsEnd() const
00339 {
00340 return ContainingElementIterator(mElementIndices.end());
00341 }
00342
00346 class ContainingBoundaryElementIterator
00347 {
00348 public:
00354 ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
00355 : mIndexIterator(indexIterator)
00356 {}
00360 const unsigned& operator*() const
00361 {
00362 return *mIndexIterator;
00363 }
00369 bool operator!=(const ContainingBoundaryElementIterator& rOther) const
00370 {
00371 return mIndexIterator != rOther.mIndexIterator;
00372 }
00378 bool operator==(const ContainingBoundaryElementIterator& rOther) const
00379 {
00380 return !operator!=(rOther);
00381 }
00385 ContainingBoundaryElementIterator& operator++()
00386 {
00387 ++mIndexIterator;
00388 return *this;
00389 }
00390 private:
00391 std::set<unsigned>::const_iterator mIndexIterator;
00392 };
00393
00397 ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
00398 {
00399 return ContainingBoundaryElementIterator(mBoundaryElementIndices.begin());
00400 }
00401
00405 ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
00406 {
00407 return ContainingBoundaryElementIterator(mBoundaryElementIndices.end());
00408 }
00409 };
00410
00411
00412 #endif //_NODE_HPP_