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 #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_

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5