Node.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef _NODE_HPP_
00031 #define _NODE_HPP_
00032 
00033 //#include "TetrahedralMesh.hpp"
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     // Set of indices of elements containing this node as a vertex
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_

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5