NodesOnlyMesh.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 NODESONLYMESH_HPP_
00037 #define NODESONLYMESH_HPP_
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/base_object.hpp>
00041 #include <boost/serialization/map.hpp>
00042 
00043 #include "PetscTools.hpp"
00044 #include "DistributedBoxCollection.hpp"
00045 #include "MutableMesh.hpp"
00046 
00051 template<unsigned SPACE_DIM>
00052 class NodesOnlyMesh: public MutableMesh<SPACE_DIM, SPACE_DIM>
00053 {
00054 private:
00055 
00056     friend class TestNodesOnlyMesh;
00057 
00059     friend class boost::serialization::access;
00060 
00072     template<class Archive>
00073     void serialize(Archive & archive, const unsigned int version)
00074     {
00075         archive & mMaximumInteractionDistance;
00076         archive & mMinimumNodeDomainBoundarySeparation;
00077         archive & boost::serialization::base_object<MutableMesh<SPACE_DIM, SPACE_DIM> >(*this);
00078     }
00079 
00081     std::vector<boost::shared_ptr<Node<SPACE_DIM> > > mHaloNodes;
00082 
00084     double mMaximumInteractionDistance;
00085 
00087     std::map<unsigned, unsigned> mNodesMapping;
00088 
00090     std::map<unsigned, unsigned> mHaloNodesMapping;
00091 
00093     unsigned mIndexCounter;
00094 
00096     double mMinimumNodeDomainBoundarySeparation;
00097 
00099     std::vector<unsigned> mDeletedGlobalNodeIndices;
00100 
00102     std::vector<unsigned> mNodesToSendRight;
00103 
00105     std::vector<unsigned> mNodesToSendLeft;
00106 
00109     std::vector<bool> mLocalInitialNodes;
00110 
00113     unsigned mMaxAddedNodeIndex;
00114 
00116     DistributedBoxCollection<SPACE_DIM>* mpBoxCollection;
00117 
00119     bool mCalculateNodeNeighbours;
00120 
00141     unsigned GetNextAvailableIndex();
00142 
00144     void EnlargeBoxCollection();
00145 
00149     bool IsANodeCloseToDomainBoundary();
00150 
00156      void SetUpBoxCollection(const std::vector<Node<SPACE_DIM>* >& rNodes);
00157 
00163      void RemoveDeletedNodes(NodeMap& map);
00164 
00166      void UpdateNodeIndices();
00167 
00173      void AddNodeWithFixedIndex(Node<SPACE_DIM>* pNewNode);
00174 
00175 protected:
00176 
00178     void ClearBoxCollection();
00179 
00188      virtual void SetUpBoxCollection(double cutOffLength, c_vector<double, 2*SPACE_DIM> domainSize, int numLocalRows = PETSC_DECIDE, bool isPeriodic = false);
00189 
00191      DistributedBoxCollection<SPACE_DIM>* GetBoxCollection();
00192 
00193 public:
00194 
00196     NodesOnlyMesh();
00197 
00199     virtual ~NodesOnlyMesh();
00200 
00212     void ConstructNodesWithoutMesh(const std::vector<Node<SPACE_DIM>*>& rNodes, double maxInteractionDistance);
00213 
00221     void ConstructNodesWithoutMesh(const AbstractMesh<SPACE_DIM,SPACE_DIM>& rGeneratingMesh, double maxInteractionDistance);
00222 
00224     std::vector<bool>& rGetInitiallyOwnedNodes();
00225 
00227     void Clear();
00228 
00236     unsigned SolveNodeMapping(unsigned index) const;
00237 
00245     Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
00246 
00252     bool IsOwned(c_vector<double, SPACE_DIM>& location);
00253 
00258     unsigned GetNumNodes() const;
00259 
00265     virtual unsigned GetMaximumNodeIndex();
00266 
00272     void SetMaximumInteractionDistance(double maxDistance);
00273 
00277     double GetMaximumInteractionDistance();
00278 
00285     double GetWidth(const unsigned& rDimension) const;
00286 
00292     void SetCalculateNodeNeighbours(bool calculateNodeNeighbours);
00293 
00300     void CalculateInteriorNodePairs(std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& rNodePairs, std::map<unsigned, std::set<unsigned> >& rNodeNeighbours);
00301 
00308     void CalculateBoundaryNodePairs(std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& rNodePairs, std::map<unsigned, std::set<unsigned> >& rNodeNeighbours);
00309 
00317     void ReMesh(NodeMap& rMap);
00318 
00324     void SetInitialBoxCollection(const c_vector<double, 2*SPACE_DIM> domainSize, double maxInteractionDistance);
00325 
00329     void UpdateBoxCollection();
00330 
00335     void ResizeBoxCollection();
00336 
00340     void AddNodesToBoxes();
00341 
00345     void AddHaloNodesToBoxes();
00346 
00350     void CalculateNodesOutsideLocalDomain();
00351 
00355     std::vector<unsigned>& rGetNodesToSendLeft();
00356 
00360     std::vector<unsigned>& rGetNodesToSendRight();
00361 
00365     std::vector<unsigned>& rGetHaloNodesToSendRight();
00366 
00370     std::vector<unsigned>& rGetHaloNodesToSendLeft();
00371 
00376     void AddHaloNode(boost::shared_ptr<Node<SPACE_DIM> > pNewNode);
00377 
00381     void ClearHaloNodes();
00382 
00389     unsigned AddNode(Node<SPACE_DIM>* pNewNode);
00390 
00395     void AddMovedNode(boost::shared_ptr<Node<SPACE_DIM> > pMovedNode);
00396 
00402     void DeleteNode(unsigned index);
00403 
00409     void DeleteMovedNode(unsigned index);
00410 
00416     void SetMinimumNodeDomainBoundarySeparation(double separation);
00417 
00422     void LoadBalanceMesh();
00423 
00429     void ConstructFromMeshReader(AbstractMeshReader<SPACE_DIM, SPACE_DIM>& rMeshReader);
00430 };
00431 
00432 #include "SerializationExportWrapper.hpp"
00433 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodesOnlyMesh)
00434 
00435 #endif /*NODESONLYMESH_HPP_*/

Generated by  doxygen 1.6.2