Node.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef _NODE_HPP_
00037 #define _NODE_HPP_
00038 
00039 #include "UblasVectorInclude.hpp"
00040 
00041 #include <set>
00042 #include <vector>
00043 
00044 #include "ChasteSerialization.hpp"
00045 #include "ChastePoint.hpp"
00046 #include "NodeAttributes.hpp"
00047 
00048 //#include <boost/serialization/vector.hpp>
00049 //#include <boost/serialization/set.hpp>
00050 
00051 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00052 class AbstractTetrahedralMesh;
00053 
00057 template<unsigned SPACE_DIM>
00058 class Node
00059 {
00060 private:
00061 
00063     unsigned mIndex;
00064 
00066     c_vector<double, SPACE_DIM> mLocation;
00067 
00069     NodeAttributes<SPACE_DIM>* mpNodeAttributes;
00070 
00072     bool mIsBoundaryNode;
00073 
00075     bool mIsInternal;
00076 
00081     bool mIsDeleted;
00082 
00084     std::set<unsigned> mElementIndices;
00085 
00087     std::set<unsigned> mBoundaryElementIndices;
00088 
00090     friend class boost::serialization::access;
00091     friend class TestNode;
00098     template<class Archive>
00099     void serialize(Archive & archive, const unsigned int version)
00100     {
00101         //archive & mLocation; //earlier versions of boost are unable to do this. See #1709
00102 //        archive & mIndex;
00103         archive & mpNodeAttributes;
00104 //        archive & mIsBoundaryNode;
00105 //        archive & mIsInternal;
00106 //        archive & mIsDeleted;
00107 //        archive & mElementIndices;
00108 //        archive & mBoundaryElementIndices;
00109     }
00110 
00117     void CommonConstructor(unsigned index, bool isBoundaryNode);
00118 
00122     void ConstructNodeAttributes();
00123 
00127     void CheckForNodeAttributes() const;
00128 
00129 public:
00130 
00143     Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode=false);
00144 
00152     Node(unsigned index, std::vector<double> coords, bool isBoundaryNode=false);
00153 
00161     Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode=false);
00162 
00172     Node(unsigned index, bool isBoundaryNode=false, double v1=0, double v2=0, double v3=0);
00173 
00182     Node(unsigned index,  double *location, bool isBoundaryNode=false);
00183 
00187     ~Node();
00188 
00197     void SetPoint(ChastePoint<SPACE_DIM> point);
00198 
00204     void SetIndex(unsigned index);
00205 
00211     void AddNodeAttribute(double attribute);
00212 
00218     void SetAsBoundaryNode(bool value=true);
00219 
00223     ChastePoint<SPACE_DIM> GetPoint() const;
00224 
00231     const c_vector<double, SPACE_DIM>& rGetLocation() const;
00232 
00241     c_vector<double, SPACE_DIM>& rGetModifiableLocation();
00242 
00246     unsigned GetIndex() const;
00247 
00251     bool IsBoundaryNode() const;
00252 
00258     void AddElement(unsigned index);
00259 
00265     void RemoveElement(unsigned index);
00266 
00272     void RemoveBoundaryElement(unsigned index);
00273 
00279     void AddBoundaryElement(unsigned index);
00280 
00284     std::set<unsigned>& rGetContainingElementIndices();
00285 
00289     std::vector<double>& rGetNodeAttributes();
00290 
00294     unsigned GetNumNodeAttributes();
00295 
00299     bool HasNodeAttributes();
00300 
00304     std::set<unsigned>& rGetContainingBoundaryElementIndices();
00305 
00309     unsigned GetNumContainingElements() const;
00310 
00314     unsigned GetNumBoundaryElements() const;
00315 
00319     c_vector<double, SPACE_DIM>& rGetAppliedForce();
00320 
00324     void ClearAppliedForce();
00325 
00330     void AddAppliedForceContribution(c_vector<double, SPACE_DIM>& forceContribution);
00331 
00335     bool IsParticle();
00336 
00341     void SetIsParticle(bool isParticle);
00342 
00346     double GetRadius();
00347 
00353     void SetRadius(double radius);
00354 
00358     void MarkAsDeleted();
00359 
00363     bool IsDeleted() const;
00364 
00368     void MarkAsInternal();
00369 
00373     bool IsInternal() const;
00374 
00380     template <unsigned ELEMENT_DIM>
00381     bool IsFlagged(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh)
00382     {
00383         bool in_flagged_element = false;
00384         for (ContainingElementIterator it = ContainingElementsBegin();
00385              it != ContainingElementsEnd();
00386              ++it)
00387         {
00388             if (rMesh.GetElement(*it)->IsFlagged())
00389             {
00390                 in_flagged_element = true;
00391                 break;
00392             }
00393         }
00394         return in_flagged_element;
00395     }
00396 
00402     void SetRegion(unsigned region);
00403 
00408     unsigned GetRegion() const;
00409 
00413     class ContainingElementIterator
00414     {
00415     public:
00421         ContainingElementIterator(std::set<unsigned>::const_iterator indexIterator)
00422             : mIndexIterator(indexIterator)
00423         {}
00428         const unsigned& operator*() const
00429         {
00430             return *mIndexIterator;
00431         }
00437         bool operator!=(const ContainingElementIterator& rOther) const
00438         {
00439             return mIndexIterator != rOther.mIndexIterator;
00440         }
00446         bool operator==(const ContainingElementIterator& rOther) const
00447         {
00448             return !operator!=(rOther);
00449         }
00454         ContainingElementIterator& operator++()
00455         {
00456             ++mIndexIterator;
00457             return *this;
00458         }
00459     private:
00460         std::set<unsigned>::const_iterator mIndexIterator;  
00461     };
00462 
00466     ContainingElementIterator ContainingElementsBegin() const
00467     {
00468         return ContainingElementIterator(mElementIndices.begin());
00469     }
00470 
00474     ContainingElementIterator ContainingElementsEnd() const
00475     {
00476         return ContainingElementIterator(mElementIndices.end());
00477     }
00478 
00482     class ContainingBoundaryElementIterator
00483     {
00484     public:
00490         ContainingBoundaryElementIterator(std::set<unsigned>::const_iterator indexIterator)
00491             : mIndexIterator(indexIterator)
00492         {}
00497         const unsigned& operator*() const
00498         {
00499             return *mIndexIterator;
00500         }
00506         bool operator!=(const ContainingBoundaryElementIterator& rOther) const
00507         {
00508             return mIndexIterator != rOther.mIndexIterator;
00509         }
00515         bool operator==(const ContainingBoundaryElementIterator& rOther) const
00516         {
00517             return !operator!=(rOther);
00518         }
00523         ContainingBoundaryElementIterator& operator++()
00524         {
00525             ++mIndexIterator;
00526             return *this;
00527         }
00528     private:
00529         std::set<unsigned>::const_iterator mIndexIterator;  
00530     };
00531 
00535     ContainingBoundaryElementIterator ContainingBoundaryElementsBegin() const
00536     {
00537         return ContainingBoundaryElementIterator(mBoundaryElementIndices.begin());
00538     }
00539 
00543     ContainingBoundaryElementIterator ContainingBoundaryElementsEnd() const
00544     {
00545         return ContainingBoundaryElementIterator(mBoundaryElementIndices.end());
00546     }
00547 };
00548 
00549 #include "SerializationExportWrapper.hpp"
00550 // Declare identifier for the serializer
00551 EXPORT_TEMPLATE_CLASS_SAME_DIMS(Node)
00552 
00553 namespace boost
00554 {
00555 namespace serialization
00556 {
00560 template<class Archive, unsigned SPACE_DIM>
00561 inline void save_construct_data(
00562     Archive & ar, const Node<SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00563 {
00564 
00565     // Save data required to construct instance
00566     for (unsigned i = 0; i < SPACE_DIM; i++)
00567     {
00568         //we archive coordinates of mLocation one by one
00569         //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
00570         double coord = t->rGetLocation()[i];
00571         ar & coord;
00572     }
00573     unsigned index = t->GetIndex();
00574     ar << index;
00575 
00576     bool is_boundary = t->IsBoundaryNode();
00577     ar << is_boundary;
00578 }
00582 template<class Archive, unsigned SPACE_DIM>
00583 inline void load_construct_data(
00584     Archive & ar, Node<SPACE_DIM> * t, const unsigned int file_version)
00585 {
00586     // Retrieve data from archive required to construct new instance of Node
00587     c_vector<double,SPACE_DIM> location;
00588     for (unsigned i=0; i<SPACE_DIM; i++)
00589     {
00590         double coordinate;
00591         ar & coordinate;//resume coordinates one by one
00592         location[i] = coordinate;
00593     }
00594 
00595     unsigned index;
00596     ar >> index;
00597 
00598     bool is_boundary;
00599     ar >> is_boundary;
00600 
00601     // Invoke inplace constructor to initialise instance
00602     ::new(t)Node<SPACE_DIM>(index, location, is_boundary);
00603 }
00604 }
00605 } // namespace ...
00606 
00607 #endif //_NODE_HPP_

Generated by  doxygen 1.6.2