00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00042
00043
00044
00045
00046
00047
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