Memosa-FVM  0.2
MeshPartitioner.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef MeshPartitioner_H
6 #define MeshPartitioner_H
7 
8 #include <vector>
9 #include <map>
10 #include <string>
11 #include "Mesh.h"
12 #include "Array.h"
13 #include "Vector.h"
14 #include <mpi.h>
15 #include<set>
16 #include<fstream>
17 
18 using namespace std;
19 
20 //Warning globalToLocal seems have a bug..........
21 
23 
24 public:
25  //typedef map<const StorageSite*, shared_ptr<OneToOneIndexMap> > MappersMap;
26  typedef shared_ptr< StorageSite > StorageSitePtr;
27  typedef shared_ptr< CRConnectivity > CRConnectivityPtr;
28  typedef shared_ptr< Array<int> > ArrayIntPtr;
29  typedef shared_ptr< Array<Mesh::VecD3> > ArrayVecD3Ptr;
30  typedef shared_ptr< Mesh > MeshPtr;
31  typedef map<int, int> IntMap;
32  typedef map<int, vector<int> > VectorMap;
33  typedef pair<int,int> IntPair;
34 
35  enum ETYPE{ TRI = 1, QUAD = 2, TETRA = 3, HEXA = 4 };
36  enum WTYPE{ NOWEIGHTS = 0, WEIGHTS_ONLY_EDGES = 1, WEIGTHS_ONLY_VERTICES = 2,
37  WEIGHTS_BOTH_VERTICES_EDGES = 3};
38  enum NUMFLAG{ C_STYLE = 0, FORTRAN_STYLE = 1 };
39  enum CELLTYPE{ INTERIOR = 1, GHOST_BOUNDARY_CELL = 2, GHOST_INTERFACE_CELL};
40  enum PARTTYPE{ PARMETIS = 1, FIEDLER =2};
41 
42  explicit MeshPartitioner( const MeshList& mesh_list, vector<int> npart, vector<int> eType);
43  ~MeshPartitioner();
44 
45  void partition();
46  void fiedler_order( const string& fname );
47 
48  void mesh();
49  const MeshList& meshList() const { return _meshListLocal; }
50  void extractBoundaryMesh();
51  const Mesh& getBoundaryMesh() const { return *_bMesh; }
52 
53 
54  void debug_print();
55 #if 0
56  void dumpTecplot();
57 #endif
58  void mesh_xdmfplot();
59 
60  // set property methods
61  void setWeightType( int weight_type );
62  void setNumFlag( int num_flag);
63 
64  //clean up memory
65  void cleanup();
66  void isCleanup(bool clean_up) { _cleanup = clean_up; }
67  void isDebug (bool debug ) { _cleanup = false;
68  _debugMode = debug; }
69  //this need to be public since it will be called by python script
70  void DEBUG_compute_elem_dist();
71  void DEBUG_parmetis_mesh();
72  void DEBUG_fiedler_partition();
73  void DEBUG_elem_connectivity();
74  void DEBUG_map_part_elms();
75  void DEBUG_count_elems_part();
76  void DEBUG_exchange_part_elems();
77  void DEBUG_mapBounIDAndCell();
78  void DEBUG_resize_elem();
79  void DEBUG_CRConnectivity_cellParts();
80  void DEBUG_CRConnectivity_faceParts();
81  void DEBUG_interfaces();
82  void DEBUG_faceCells_faceNodes();
83  void DEBUG_non_interior_cells();
84  void DEBUG_preserve_cell_order();
85  void DEBUG_order_faceCells_faceNodes();
86  void DEBUG_coordinates();
87  void DEBUG_exchange_interface_meshes();
88  void DEBUG_mesh();
89  void DEBUG_local_global();
90  void DEBUG_cellcells_global();
91  void DEBUG_globalCellID_procID_map();
92  void DEBUG_gatherCellsLevel1_partID_map();
93  void DEBUG_level1_scatter_gather_cells();
94  void DEBUG_CRConnectivity_cellCells2();
95 
96 private:
97 
98  MeshPartitioner( const MeshPartitioner& part_mesh ); //dont allow copy constructor
99 
100  void init();
101  void compute_elem_dist();
102  void elem_connectivity();
103  void parmetis_mesh();
104  void fiedler_partition();
105  int get_local_nodes(int id);
106  void set_eptr_eind(int id);
107  void map_part_elms();
108  void count_elems_part();
109  void exchange_part_elems();
110  void shift_sum_row();
111  void mesh_setup();
112  int global_offset();
113  void set_local_global();
114  void set_cellcells_global();
115  void cellcells_global_extension();
116  void globalCellID_procID_map();
117  void gatherCellsLevel1_partID_map();
118  void level1_scatter_gather_cells();
119 
120 
121  void CRConnectivity_cellParts();
122  void mapBounIDAndCell(int id);
123  void resize_elem(int id);
124  void CRConnectivity_faceParts();
125  void faceCells_faceNodes();
126 
127  void interfaces();
128  void coordinates();
129  int count_interior_faces( int id );
130  void order_faceCells_faceNodes();
131  void non_interior_cells();
132  void exchange_interface_meshes();
133  void mappers();
134  void create_window( int id );
135  void free_window( );
136  void fence_window();
137  int get_window_displ( int id, int neigh_mesh_id );
138  void construct_mesh( int id );
139  void setMeshColors();
140  void preserve_cell_order();
141  void scatterCellsLevel1();
142 
143 
144 
145  void mesh_xdmf_header();
146  void mesh_file();
147  void mesh_tecplot();
148 
149 
150  void cleanup_follow_exchange_part_elems();
151  void cleanup_follow_faceCells_faceNodes();
152  void cleanup_follow_mappers();
153 
154  void CRConnectivityPrint( const CRConnectivity& conn, int procID, const string& name );
155  void CRConnectivityPrintFile( const CRConnectivity& conn, const string& name );
156 
157 
158 
159  void debug_file_open( const string& fname );
160  void debug_file_close();
161 
163  vector<int> _nPart;
164  vector<int> _totElems;
165  vector<int> _totElemsAndGhosts;
166  vector< Array<int>* > _elemDist; //store dist element number for each Mesh
167  vector< Array<int>* > _globalIndx; //store where partition starts in glbal array
168  vector< int* > _ePtr;
169  vector< int* > _eInd;
170  vector< int* > _eElm;
171  vector< int* > _elmWght;
172  vector< int > _wghtFlag;
173  vector< int > _numFlag;
174  vector< int > _ncon;
175  vector< int > _ncommonNodes;
176  vector< int > _eType;
177  vector< float* > _tpwgts;
178  vector< float* > _ubvec;
179  int _options;
180  int _procID;
181  //output variables
182  vector< int > _edgecut;
183  vector< int* > _part;
184 
185  //
186  vector< multimap<int,int> > _mapPartAndElms;
187  vector< int* > _row;
188  vector< int* > _col;
189  vector< int* > _elem; //just interior (local)
190  vector< set<int> > _elemSet;
191  vector< int* > _elemWithGhosts; //interior+boundary (local)
192 
193 
194  vector<int> _nelems;
195  vector<int> _nelemsWithGhosts;
196  vector<int> _colDim;
197  int _nmesh;
198 
199  vector< StorageSitePtr > _cellSiteGlobal;
200  vector< StorageSitePtr > _cellSite;
201  vector< StorageSitePtr > _nodeSite;
202  vector< StorageSitePtr > _faceSite;
203  vector< StorageSitePtr > _partSite;
204 
205 
206  vector< const CRConnectivity* > _faceCellsGlobal; //global mesh
207  vector< const CRConnectivity* > _faceNodesGlobal; //global mesh
208 
209  vector< CRConnectivityPtr > _faceCells; //belongs to this partition
210  vector< CRConnectivityPtr > _faceNodes; //belongs to this partition
211  vector< CRConnectivityPtr > _cellCells; //belongs to this partition
212  vector< CRConnectivityPtr > _cellNodes; //belongs to this partition
213  vector< CRConnectivityPtr > _faceCellsOrdered;
214  vector< CRConnectivityPtr > _faceNodesOrdered;
215 
216  vector< CRConnectivityPtr > _cellParts;
217  vector< CRConnectivityPtr > _partCells;
218  vector< CRConnectivityPtr > _faceParts;
219  vector< CRConnectivityPtr > _partFaces; //transpose of _faceParts
220  vector< CRConnectivityPtr > _partNodes;
221 
222 
223  vector< set<int> > _boundarySet;
224  vector< multimap<int,int> > _mapBounIDAndCell; //belongs to this partition (global numbering)
225  vector< map<int,string> > _mapBounIDAndBounType; //belongs to this partition
226 
227  vector< ArrayVecD3Ptr > _coord; //belongs to this partition
228  vector< set<int> > _interfaceSet;
229  vector< multimap<int,int> > _interfaceMap; //belongs to this partition (local numbering)
230 
231  vector< set<int> > _nonInteriorCells; //local numbering
232 
233  vector< map<int,int> > _bndryOffsets;
234  vector< map<int,int> > _interfaceOffsets;
235  vector< vector<int> > _cellToOrderedCell;
236  vector< multimap<int,int> > _globalToLocalMappers;
237  vector< map<int,int> > _localToGlobalMappers;
238  map<int,int> _globalToLocal;
240  map<int,int> _cellsLevel1PartID;
242 
243  //variables aglomorated for MPI communications
244  vector< ArrayIntPtr > _interfaceMeshCounts; //ArrayIntPtr[0] = value , 0th mesh has total "value" neigh interfaced meshes
245  vector< ArrayIntPtr > _offsetInterfaceCells; //this start location of interfaces, need at communuctation a lot
246  vector< ArrayIntPtr > _procTotalInterfaces; //store total interfaces for each process
247  vector< ArrayIntPtr > _interfaceMeshIDs; //
248  vector< ArrayIntPtr > _ghostCellsGlobal; //stored in contigous memory (global numbering) local data
249  vector< ArrayIntPtr > _ghostCellsLocal; //local numbering local data
250  vector< int > _windowSize;
251 
252 
253  vector< vector< ArrayIntPtr > > _fromIndices;
254  vector< vector< ArrayIntPtr > > _toIndices;
255  ArrayIntPtr _fiedlerMap; // map original cell number to fiedler numbering
257 
258  MPI::Win _winGlobal;
259  MPI::Win _winLocal;
260  bool _cleanup;
262  ofstream _debugFile;
263  vector< Mesh* > _meshListLocal; //all is for you
264  Mesh* _bMesh; //this is boundary mesh of whole object
265 };
266 
267 #endif
vector< int * > _ePtr
vector< int * > _eInd
vector< StorageSitePtr > _faceSite
vector< map< int, int > > _bndryOffsets
vector< CRConnectivityPtr > _cellCells
vector< multimap< int, int > > _globalToLocalMappers
vector< int > _totElems
vector< float * > _ubvec
vector< ArrayVecD3Ptr > _coord
vector< int > _ncommonNodes
vector< ArrayIntPtr > _interfaceMeshCounts
vector< StorageSitePtr > _nodeSite
vector< CRConnectivityPtr > _partFaces
vector< CRConnectivityPtr > _faceParts
ArrayIntPtr _fiedlerMap
pair< int, int > IntPair
vector< ArrayIntPtr > _interfaceMeshIDs
vector< int * > _elemWithGhosts
vector< set< int > > _elemSet
shared_ptr< StorageSite > StorageSitePtr
vector< int * > _eElm
vector< int * > _elem
Definition: Mesh.h:49
vector< int > _numFlag
vector< int * > _elmWght
vector< ArrayIntPtr > _procTotalInterfaces
vector< int > _nPart
vector< set< int > > _interfaceSet
vector< map< int, int > > _localToGlobalMappers
vector< CRConnectivityPtr > _partCells
vector< int > _wghtFlag
vector< Array< int > * > _globalIndx
shared_ptr< Array< Mesh::VecD3 > > ArrayVecD3Ptr
vector< StorageSitePtr > _cellSite
vector< int * > _part
vector< CRConnectivityPtr > _faceNodes
vector< CRConnectivityPtr > _partNodes
void isDebug(bool debug)
vector< StorageSitePtr > _partSite
vector< int > _eType
vector< StorageSitePtr > _cellSiteGlobal
vector< ArrayIntPtr > _offsetInterfaceCells
map< int, int > _cellToPreservedOrderCell
shared_ptr< CRConnectivity > CRConnectivityPtr
const MeshList & meshList() const
void isCleanup(bool clean_up)
vector< set< int > > _boundarySet
vector< map< int, int > > _interfaceOffsets
shared_ptr< Mesh > MeshPtr
map< int, int > _globalToLocal
vector< Array< int > * > _elemDist
const Mesh & getBoundaryMesh() const
vector< const CRConnectivity * > _faceNodesGlobal
vector< int > _ncon
vector< int * > _col
vector< CRConnectivityPtr > _faceNodesOrdered
vector< set< int > > _nonInteriorCells
vector< int > _nelems
vector< int > _windowSize
const MeshList _meshList
map< int, int > IntMap
vector< CRConnectivityPtr > _faceCellsOrdered
vector< multimap< int, int > > _mapPartAndElms
vector< int * > _row
shared_ptr< Array< int > > ArrayIntPtr
vector< vector< ArrayIntPtr > > _toIndices
vector< map< int, string > > _mapBounIDAndBounType
vector< int > _totElemsAndGhosts
vector< CRConnectivityPtr > _cellNodes
vector< Mesh * > _meshListLocal
vector< multimap< int, int > > _mapBounIDAndCell
map< int, int > _cellsLevel1PartID
vector< vector< int > > _cellToOrderedCell
map< int, int > _gatherCellsLevel1PartIDMap
vector< ArrayIntPtr > _ghostCellsLocal
vector< CRConnectivityPtr > _faceCells
vector< CRConnectivityPtr > _cellParts
vector< multimap< int, int > > _interfaceMap
vector< float * > _tpwgts
map< int, vector< int > > VectorMap
vector< int > _nelemsWithGhosts
vector< Mesh * > MeshList
Definition: Mesh.h:439
vector< int > _colDim
vector< vector< ArrayIntPtr > > _fromIndices
vector< int > _edgecut
vector< const CRConnectivity * > _faceCellsGlobal
vector< ArrayIntPtr > _ghostCellsGlobal