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 #ifndef _NODE_HPP_
00031 #define _NODE_HPP_
00032
00033
00034 #include "ChastePoint.hpp"
00035 #include <set>
00036
00037 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00038 class TetrahedralMesh;
00039
00043 template<unsigned SPACE_DIM>
00044 class Node
00045 {
00046 private:
00047 unsigned mIndex;
00048 unsigned mRegion;
00049
00050 c_vector<double, SPACE_DIM> mLocation;
00051
00052 bool mIsBoundaryNode;
00053 bool mIsDeleted;
00054
00055
00056 std::set<unsigned> mElementIndices;
00057 std::set<unsigned> mBoundaryElementIndices;
00058
00062 void CommonConstructor(unsigned index, bool isBoundaryNode);
00063
00064 public:
00069 Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode=false);
00070
00071 Node(unsigned index, std::vector<double> coords, bool isBoundaryNode=false);
00072
00073 Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode=false);
00074
00075 Node(unsigned index, bool isBoundaryNode=false, double v1=0, double v2=0, double v3=0);
00076
00081 void SetPoint(ChastePoint<SPACE_DIM> point);
00082
00086 void SetIndex(unsigned index);
00087
00088 void SetAsBoundaryNode(bool value=true);
00089
00090 ChastePoint<SPACE_DIM> GetPoint() const;
00091
00096 const c_vector<double, SPACE_DIM>& rGetLocation() const;
00097
00104 c_vector<double, SPACE_DIM> &rGetModifiableLocation();
00105
00106 unsigned GetIndex() const;
00107
00108 bool IsBoundaryNode() const;
00109
00115 void AddElement(unsigned index);
00116
00122 void RemoveElement(unsigned index);
00123
00129 void RemoveBoundaryElement(unsigned index);
00130
00136 void AddBoundaryElement(unsigned index);
00137
00141 std::set<unsigned> &rGetContainingElementIndices();
00142
00146 std::set<unsigned> &rGetContainingBoundaryElementIndices();
00147
00148 unsigned GetNumContainingElements() const;
00149
00150 unsigned GetNumBoundaryElements() const;
00151
00155 void MarkAsDeleted();
00156
00157 bool IsDeleted() const;
00158
00162 template <unsigned ELEMENT_DIM>
00163 bool IsFlagged(TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh)
00164 {
00165 bool in_flagged_element = false;
00166 for (ContainingElementIterator it = ContainingElementsBegin();
00167 it != ContainingElementsEnd();
00168 ++it)
00169 {
00170 if (rMesh.GetElement(*it)->IsFlagged())
00171 {
00172 in_flagged_element = true;
00173 break;
00174 }
00175 }
00176 return in_flagged_element;
00177 }
00178
00179 void SetRegion(unsigned region);
00180
00181 unsigned GetRegion() const;
00182
00186 class ContainingElementIterator
00187 {
00188 public:
00189 ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
00190 : mIndexIterator(indexIterator)
00191 {}
00192
00193 const unsigned& operator*() const
00194 {
00195 return *mIndexIterator;
00196 }
00197
00198 bool operator!=(const ContainingElementIterator& other) const
00199 {
00200 return mIndexIterator != other.mIndexIterator;
00201 }
00202 bool operator==(const ContainingElementIterator& other) const
00203 {
00204 return !operator!=(other);
00205 }
00206
00207 ContainingElementIterator& operator++()
00208 {
00209 ++mIndexIterator;
00210 return *this;
00211 }
00212 private:
00213 std::set<unsigned>::const_iterator mIndexIterator;
00214 };
00215
00216 ContainingElementIterator ContainingElementsBegin() const
00217 {
00218 return ContainingElementIterator(mElementIndices.begin());
00219 }
00220
00221 ContainingElementIterator ContainingElementsEnd() const
00222 {
00223 return ContainingElementIterator(mElementIndices.end());
00224 }
00225
00229 class ContainingBoundaryElementIterator
00230 {
00231 public:
00232 ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
00233 : mIndexIterator(indexIterator)
00234 {}
00235
00236
00237 const unsigned& operator*() const
00238 {
00239 return *mIndexIterator;
00240 }
00241
00242 bool operator!=(const ContainingBoundaryElementIterator& other) const
00243 {
00244 return mIndexIterator != other.mIndexIterator;
00245 }
00246 bool operator==(const ContainingBoundaryElementIterator& other) const
00247 {
00248 return !operator!=(other);
00249 }
00250
00251 ContainingBoundaryElementIterator& operator++()
00252 {
00253 ++mIndexIterator;
00254 return *this;
00255 }
00256 private:
00257 std::set<unsigned>::const_iterator mIndexIterator;
00258 };
00259
00260 ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
00261 {
00262 return ContainingBoundaryElementIterator(mBoundaryElementIndices.begin());
00263 }
00264
00265 ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
00266 {
00267 return ContainingBoundaryElementIterator(mBoundaryElementIndices.end());
00268 }
00269 };
00270
00271
00272 #endif //_NODE_HPP_