ParallelTetrahedralMesh.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 PARALLELTETRAHEDRALMESH_HPP_
00030 #define PARALLELTETRAHEDRALMESH_HPP_
00031 
00032 #include <map>
00033 #include <vector>
00034 #include <set>
00035 
00036 #include "AbstractTetrahedralMesh.hpp"
00037 #include "Node.hpp"
00038 #include "AbstractMeshReader.hpp"
00039 
00040 /*
00041  *  The following definition fixes an odd incompatibility of METIS 4.0 and Chaste. Since
00042  * the library was compiled with a plain-C compiler, it fails to link using a C++ compiler.
00043  * Note that METIS 4.0 fails to compile with g++ or icpc, so a C compiler should be used.
00044  *
00045  * Somebody had this problem before: http://www-users.cs.umn.edu/~karypis/.discus/messages/15/113.html?1119486445
00046  *
00047  * Note that it is necessary to define the function header before the #include statement.
00048 */
00049 extern "C" {
00050 extern void METIS_PartMeshNodal(int*, int*, int*, int*, int*, int*, int*, int*, int*);
00051 };
00052 #include "metis.h"
00053 
00061 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00062 class ParallelTetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00063 {
00064     friend class TestParallelTetrahedralMesh;
00065 
00066 public:
00067 
00073     typedef enum
00074     {
00075         DUMB=0,
00076         METIS_BINARY,
00077         METIS_LIBRARY
00078     } PartitionType;
00079 
00080 private:
00081 
00083     unsigned mTotalNumElements;
00084 
00086     unsigned mTotalNumBoundaryElements;
00087 
00089     unsigned mTotalNumNodes;
00090 
00092     std::vector<Node<SPACE_DIM>* > mHaloNodes;
00093 
00095     std::map<unsigned, unsigned> mNodesMapping;
00096 
00098     std::map<unsigned, unsigned> mHaloNodesMapping;
00099 
00101     std::map<unsigned, unsigned> mElementsMapping;
00102 
00104     std::map<unsigned, unsigned> mBoundaryElementsMapping;
00105 
00107     PartitionType mMetisPartitioning;
00108 
00109 public:
00110 
00116     ParallelTetrahedralMesh(PartitionType metisPartitioning=METIS_LIBRARY);
00117 
00121     virtual ~ParallelTetrahedralMesh();
00122 
00130     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader,
00131                                  bool cullInternalFaces=false);
00132 
00137     unsigned GetNumLocalNodes() const;
00138     
00143     unsigned GetNumLocalElements() const;
00144 
00148     unsigned GetNumNodes() const;
00149 
00153     unsigned GetNumElements() const;
00154     
00158     unsigned GetNumBoundaryElements() const;
00159 
00169     void SetElementOwnerships(unsigned lo, unsigned hi);
00170 
00171 private:
00172 
00178     void RegisterNode(unsigned index);
00179 
00185     void RegisterHaloNode(unsigned index);
00186     
00192     void RegisterElement(unsigned index);
00193 
00199     void RegisterBoundaryElement(unsigned index);
00200 
00206     unsigned SolveNodeMapping(unsigned index) const;
00207 
00213     unsigned SolveHaloNodeMapping(unsigned index);
00214 
00220     unsigned SolveElementMapping(unsigned index) const;
00221 
00227     unsigned SolveBoundaryElementMapping(unsigned index) const;
00228 
00243     void ComputeMeshPartitioning(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00244                                  std::set<unsigned>& rNodesOwned,
00245                                  std::set<unsigned>& rHaloNodesOwned,
00246                                  std::set<unsigned>& rElementsOwned,
00247                                  std::vector<unsigned>& rProcessorsOffset,
00248                                  std::vector<unsigned>& rNodePermutation);
00249 
00257     void DumbNodePartitioning(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00258                               std::set<unsigned>& rNodesOwned);
00259 
00270     void MetisBinaryNodePartitioning(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00271                                      std::set<unsigned>& rNodesOwned, 
00272                                      std::vector<unsigned>& rProcessorsOffset,
00273                                      std::vector<unsigned>& rNodePermutation);
00274 
00285     void MetisLibraryNodePartitioning(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00286                                       std::set<unsigned>& rNodesOwned, 
00287                                       std::vector<unsigned>& rProcessorsOffset,
00288                                       std::vector<unsigned>& rNodePermutation);
00289 
00295     void ReorderNodes(std::vector<unsigned>& rNodePermutation);
00296 };
00297 
00298 #endif /*PARALLELTETRAHEDRALMESH_HPP_*/

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