Node.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 AbstractTetrahedralMesh;
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 
00063     bool mIsInternal;
00064 
00069     bool mIsDeleted;
00070 
00072     std::set<unsigned> mElementIndices;
00073 
00075     std::set<unsigned> mBoundaryElementIndices;
00076 
00078     std::vector<double> mNodeAttributes;
00079 
00086     void CommonConstructor(unsigned index, bool isBoundaryNode);
00087 
00088 public:
00089 
00102     Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode=false);
00103 
00111     Node(unsigned index, std::vector<double> coords, bool isBoundaryNode=false);
00112 
00120     Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode=false);
00121 
00131     Node(unsigned index, bool isBoundaryNode=false, double v1=0, double v2=0, double v3=0);
00132 
00141     Node(unsigned index,  double *location, bool isBoundaryNode=false);
00142 
00151     void SetPoint(ChastePoint<SPACE_DIM> point);
00152 
00158     void SetIndex(unsigned index);
00159 
00165     void AddNodeAttribute(double attribute);
00166 
00172     void SetAsBoundaryNode(bool value=true);
00173 
00177     ChastePoint<SPACE_DIM> GetPoint() const;
00178 
00185     const c_vector<double, SPACE_DIM>& rGetLocation() const;
00186 
00195     c_vector<double, SPACE_DIM>& rGetModifiableLocation();
00196 
00200     unsigned GetIndex() const;
00201 
00205     bool IsBoundaryNode() const;
00206 
00212     void AddElement(unsigned index);
00213 
00219     void RemoveElement(unsigned index);
00220 
00226     void RemoveBoundaryElement(unsigned index);
00227 
00233     void AddBoundaryElement(unsigned index);
00234 
00238     std::set<unsigned>& rGetContainingElementIndices();
00239 
00243     std::vector<double>& rGetNodeAttributes();
00244 
00248     std::set<unsigned>& rGetContainingBoundaryElementIndices();
00249 
00253     unsigned GetNumContainingElements() const;
00254 
00258     unsigned GetNumBoundaryElements() const;
00259 
00263     void MarkAsDeleted();
00264 
00268     bool IsDeleted() const;
00269 
00273     void MarkAsInternal();
00274 
00278     bool IsInternal() const;
00279 
00285     template <unsigned ELEMENT_DIM>
00286     bool IsFlagged(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh)
00287     {
00288         bool in_flagged_element = false;
00289         for (ContainingElementIterator it = ContainingElementsBegin();
00290              it != ContainingElementsEnd();
00291              ++it)
00292         {
00293             if (rMesh.GetElement(*it)->IsFlagged())
00294             {
00295                 in_flagged_element = true;
00296                 break;
00297             }
00298         }
00299         return in_flagged_element;
00300     }
00301 
00307     void SetRegion(unsigned region);
00308 
00312     unsigned GetRegion() const;
00313 
00317     class ContainingElementIterator
00318     {
00319     public:
00325         ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
00326             : mIndexIterator(indexIterator)
00327         {}
00331         const unsigned& operator*() const
00332         {
00333             return *mIndexIterator;
00334         }
00340         bool operator!=(const ContainingElementIterator& rOther) const
00341         {
00342             return mIndexIterator != rOther.mIndexIterator;
00343         }
00349         bool operator==(const ContainingElementIterator& rOther) const
00350         {
00351             return !operator!=(rOther);
00352         }
00356         ContainingElementIterator& operator++()
00357         {
00358             ++mIndexIterator;
00359             return *this;
00360         }
00361     private:
00362         std::set<unsigned>::const_iterator mIndexIterator;  
00363     };
00364 
00368     ContainingElementIterator ContainingElementsBegin() const
00369     {
00370         return ContainingElementIterator(mElementIndices.begin());
00371     }
00372 
00376     ContainingElementIterator ContainingElementsEnd() const
00377     {
00378         return ContainingElementIterator(mElementIndices.end());
00379     }
00380 
00384     class ContainingBoundaryElementIterator
00385     {
00386     public:
00392         ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
00393             : mIndexIterator(indexIterator)
00394         {}
00398         const unsigned& operator*() const
00399         {
00400             return *mIndexIterator;
00401         }
00407         bool operator!=(const ContainingBoundaryElementIterator& rOther) const
00408         {
00409             return mIndexIterator != rOther.mIndexIterator;
00410         }
00416         bool operator==(const ContainingBoundaryElementIterator& rOther) const
00417         {
00418             return !operator!=(rOther);
00419         }
00423         ContainingBoundaryElementIterator& operator++()
00424         {
00425             ++mIndexIterator;
00426             return *this;
00427         }
00428     private:
00429         std::set<unsigned>::const_iterator mIndexIterator;  
00430     };
00431 
00435     ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
00436     {
00437         return ContainingBoundaryElementIterator(mBoundaryElementIndices.begin());
00438     }
00439 
00443     ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
00444     {
00445         return ContainingBoundaryElementIterator(mBoundaryElementIndices.end());
00446     }
00447 };
00448 
00449 
00450 #endif //_NODE_HPP_
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3