Memosa-FVM  0.2
MeshDismantler.cpp
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 
6 #ifdef FVM_PARALLEL
7 #include <mpi.h>
8 #endif
9 
10 #include <iostream>
11 #include <fstream>
12 #include <string>
13 #include <sstream>
14 #include <utility>
15 #include "MeshDismantler.h"
16 #include "CRConnectivity.h"
17 #include "MultiField.h"
18 
19 
20 
21 
22 using namespace std;
23 
24 MeshDismantler::MeshDismantler( const MeshList& meshList ):_mesh( *meshList.at(0) ), _procID(0)
25 {
26  //assert condition for meshList size
27  assert( meshList.size() == 1 );
28  init();
29 }
30 
32 {
33  vector< Mesh* >::iterator it_mesh;
34  for ( it_mesh = _meshList.begin(); it_mesh != _meshList.end(); it_mesh++)
35  delete *it_mesh;
36 }
37 
38 
39 void
41 {
42 
44 #ifdef FVM_PARALLEL
45  _procID = MPI::COMM_WORLD.Get_rank();
46  _nPart = MPI::COMM_WORLD.Get_size();
47 #endif
48  //number of meshes
50  //giving mesh ids
51  int dim = _mesh.getDimension();
52  //construct meshes
53  for ( int n = 0; n < _nmesh; n++ )
54  _meshList.push_back( new Mesh( dim) );
55 
56 
57  setCellsSite();
58  setFacesSite();
59  setNodesSite();
60  setSites();
62  setFaceCells();
64  setFaceNodes();
65  setCoord();
66  setMesh();
67  setMappers();
69 
70  for ( int n = 0; n < _nmesh; n++ ){
71  const StorageSite& cellSite = _meshList.at(n)->getCells();
72  const StorageSite& faceSite = _meshList.at(n)->getFaces();
73  _meshList.at(n)->eraseConnectivity(cellSite, cellSite);
74  _meshList.at(n)->eraseConnectivity(cellSite, faceSite);
75  //uniquie
76  _meshList.at(n)->uniqueFaceCells();
77  }
78 
79 
81 
82 
83 }
84 
85 //setting storagesite for cells
86 void
88 {
89  vector<int> siteGhostCount(_nmesh,0);
90  vector<int> siteSelfCount (_nmesh,0);
91  //inner cell sweeep
92  const StorageSite& cellSite = _mesh.getCells();
93  const Array<int>& color = _mesh.getCellColors();
94  for ( int n = 0; n < cellSite.getSelfCount(); n++ )
95  siteSelfCount[ color[n] ]++;
96 
97 
98  //ghostcells on partition border and boundary cells sweep
99  for ( int n = cellSite.getSelfCount(); n < cellSite.getCount(); n++ )
100  siteGhostCount[ color[n] ]++;
101 
102  //now find newly emerged ghost cells between meshes
103  //loop over inner faces, if they have two different cell colors, add one ghost cell for each side;
104  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
105  const StorageSite& faceSite = _mesh.getInteriorFaceGroup().site;
106  for ( int n = 0; n < faceSite.getCount(); n++ ){
107  int cell1 = faceCells(n,0);
108  int cell2 = faceCells(n,1);
109  //check if they are different colors, if so, it is mesh boundary, increment ghostCount for both meshes
110  if ( color[ cell1 ] != color[ cell2 ] ){
111  siteGhostCount[ color[cell1] ]++;
112  siteGhostCount[ color[cell2] ]++;
113  }
114  }
115  //forming cellSites
116  for ( int id = 0; id < _nmesh; id++ )
117  _cellSite.push_back( StorageSitePtr( new StorageSite(siteSelfCount[id], siteGhostCount[id] ) ) );
118 
119  //we will first identify newly emerged cellcell2 cells
120  vector< set<int> > gatherCells(_nmesh);
121  for ( int n = 0; n < faceSite.getCount(); n++ ){
122  int cell1 = faceCells(n,0);
123  int cell2 = faceCells(n,1);
124  //check if they are different colors, if so, it is mesh boundary, increment ghostCount for both meshes
125  if ( color[ cell1 ] != color[ cell2 ] ){
126  gatherCells[ color[cell1] ].insert(cell2);
127  gatherCells[ color[cell2] ].insert(cell1);
128  }
129  }
130  //now loop over gather cells and check its global cellCells connectivity
131  const multimap<int,int>& cellCellsGlobal = _mesh.getCellCellsGlobal();
132  const map<int,int>& globalToLocal = _mesh.getGlobalToLocal();
133  for ( int id = 0; id < _nmesh; id++ ){
134  const set<int>& cells = gatherCells[id];
135  set<int> cells2; //storing cellCells2 cells
136  int countLevel1 = _cellSite[id]->getCount();
137  //loop over gather cells
138  foreach(const set<int>::value_type& mpos, cells){
139  int cellID = mpos;
140  multimap<int,int>::const_iterator it;
141  for ( it = cellCellsGlobal.equal_range(cellID).first; it != cellCellsGlobal.equal_range(cellID).second; it++ ){
142  const int localID = globalToLocal.find(it->second)->second;
143  //if it is not gathercells, we accep it, and color[localID] make sure that it doesn't pick inner cells
144  //and cells2 make sure that this is not counted twice
145  if ( cells.count(localID) == 0 && color[localID] != id && cells2.count(localID) == 0){
146  countLevel1++;
147  cells2.insert(localID);
148  }
149  }
150  }
151  //update countLevel1
152  // _cellSite[id]->setCountLevel1(countLevel1);
153  }
154 
155 
156 }
157 
158 //setting storagesite for faces
159 void
161 {
162  //loop over all faces, if cells connected to a face has the same color, just add that face to corresponding mesh.
163  // if has different colors, that face is counted to add both sharing meshes
164  vector<int> faceCount(_nmesh,0);
165  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
166  const StorageSite& faceSite = _mesh.getFaces();
167  const Array<int>& color = _mesh.getCellColors();
168  for ( int n = 0; n < faceSite.getCount(); n++ ){
169  int cell1 = faceCells(n,0);
170  int cell2 = faceCells(n,1);
171  //check if they are different colors, if so, it is mesh boundary, increment ghostCount for both meshes
172  if ( color[ cell1 ] != color[ cell2 ] ){
173  faceCount[ color[cell1] ]++;
174  faceCount[ color[cell2] ]++;
175  } else {
176  faceCount[ color[cell2] ]++; // or cell1, cell1 == cell2 in here
177  }
178  }
179  //forming faceSites
180  for( int id = 0; id < _nmesh; id++ )
181  _faceSite.push_back( StorageSitePtr( new StorageSite(faceCount[id]) ) );
182 
183 
184 }
185 
186 //setting Storage site for nodes
187 void
189 {
190  //get nodeCells and look at colors of the cells and incremet nodeCount for each mesh
191  //count inner nodes for assembly
192  vector<int> nodeCount(_nmesh,0);
193  const StorageSite& nodeSite = _mesh.getNodes();
194  //storing glblNOdeIDs for each mesh
195  vector< vector<int> > globalNodeIDs(_nmesh);
196  for ( int id = 0; id < _nmesh; id++ )
197  globalNodeIDs[id].resize(nodeSite.getCount(),-1);
198 
199 
200  const StorageSite& cellSite = _mesh.getCells();
201  const CRConnectivity& cellNodes = _mesh.getCellNodes();
202  const Array<int>& color = _mesh.getCellColors();
203  //loop over only inner cells nodes
204  for ( int n = 0; n < cellSite.getSelfCount(); n++ ) {
205  int nnodes = cellNodes.getCount(n);
206  int colorID = color[n];
207  for ( int i = 0; i < nnodes; i++ ){
208  int glblNodeID = cellNodes(n,i);
209  //if it is not visited (=-1)
210  if ( globalNodeIDs[colorID][glblNodeID] == -1 ) {
211  globalNodeIDs[colorID][glblNodeID] = 1; //(=1) means visited
212  nodeCount[colorID]++;
213  }
214  }
215  }
216  //pushin in vector field
217  for ( int id = 0; id < _nmesh; id++ )
218  _nodeSite.push_back( StorageSitePtr( new StorageSite(nodeCount[id]) ) );
219 
220 }
221 
222 //gettin localToGlobal and globalToLocal for cell
223 void
225 {
226  //lets create copy cellToGlobal for only inner cells
227  for ( int id = 0; id < _nmesh; id++ ){
228  const StorageSite& cellSite = *_cellSite.at(id);
229  _localCellToGlobal.push_back( ArrayIntPtr( new Array<int>( cellSite.getSelfCount() ) ) );
230  Array<int>& localToGlobal = *_localCellToGlobal[id];
231  localToGlobal = -1; //initializer
232  }
233  //global to local map ( only inner cells)
234  int cellSelfCount = _mesh.getCells().getSelfCount();
235  const Array<int>& color = _mesh.getCellColors();
236  _globalCellToLocal.resize ( cellSelfCount, -1);
237  _globalCellToMeshID.resize( cellSelfCount, -1);
238  vector<int> localCellCount(_nmesh,0);
239  for ( int i = 0; i < cellSelfCount; i++ ){
240  _globalCellToMeshID[i] = color[ i ] ;
241  _globalCellToLocal[i] = localCellCount[ color[i] ]++;
242  }
243 
244 }
245 
246 //getting CRConnectivity faceCells
247 void
249 {
250  vector<int> localCellID(_nmesh,0); //track local mesh cell ids
251  vector<int> localFaceID(_nmesh,0); //track local mesh face ids
252 
253  faceCellsInit( localCellID );
254  faceCellsAddInteriorFaces ( localFaceID );
255  faceCellsAddBoundaryInterfaces ( localFaceID, localCellID );
256  faceCellsAddMeshInterfaces ( localFaceID, localCellID );
257  faceCellsAddPartitionInterfaces( localFaceID, localCellID );
259 
260 }
261 //faceCount
262 void
263 MeshDismantler::faceCellsInit( vector<int>& localCellID )
264 {
265  //initalize local cellID
266  for ( int id = 0; id < _nmesh; id++ )
267  localCellID[id] = _cellSite[id]->getSelfCount();
268 
269  //init count and finishCount;
270  for ( int id = 0; id < _nmesh; id++ ){
271  const StorageSite& faceSite = _meshList.at(id)->getFaces();
272  const StorageSite& cellSite = _meshList.at(id)->getCells();
273  _faceCells.push_back( CRConnectivityPtr( new CRConnectivity( faceSite, cellSite ) ) );
274  _faceCells.at(id)->initCount();
275 
276  //addCount, each face share only two cells
277  const int cellCount = 2;
278  for ( int i = 0; i < faceSite.getCount(); i++ )
279  _faceCells.at(id)->addCount(i, cellCount); // face has always two cells
280  //finish count
281  _faceCells.at(id)->finishCount();
282  }
283 }
284 //interor face adding
285 void
287 {
288  //first add interior faces
289  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
290  const FaceGroup& interiorFaceGroup = _mesh.getInteriorFaceGroup();
291  const StorageSite& interiorFaceSite = interiorFaceGroup.site;
292  for ( int i = 0; i < interiorFaceSite.getCount(); i++ ){
293  int cell1 = faceCells(i,0);
294  int cell2 = faceCells(i,1);
295  int meshID1 = _globalCellToMeshID[cell1];
296  int meshID2 = _globalCellToMeshID[cell2];
297  if ( meshID1 == meshID2 ){ //it means this face interior face
298  _faceCells.at( meshID1 )->add( faceID[meshID1], _globalCellToLocal[cell1] );
299  _faceCells.at( meshID2 )->add( faceID[meshID2], _globalCellToLocal[cell2] );
300  faceID[meshID1]++;
301  }
302  }
303 }
304 //partiion face adding
305 void
306 MeshDismantler::faceCellsAddPartitionInterfaces( vector<int>& faceID, vector<int>& localCellID )
307 {
308  //add partition interfaces
309  int cellSelfCount = _mesh.getCells().getSelfCount();
310  int interfaceCount = _mesh.getInterfaceGroupCount();
311  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
312  const FaceGroupList& interfaceGroupList = _mesh.getInterfaceGroups();
313  //loop over partition faces (
314  for ( int i = 0; i < interfaceCount; i++ ){
315  const StorageSite& interiorFaceSite = interfaceGroupList[i]->site;
316  int offset = interiorFaceSite.getOffset(); //where to begin face
317  int nBeg = offset;
318  int nEnd = nBeg + interiorFaceSite.getCount();
319 
320  //filling faceOffset and ID
321  for ( int id = 0; id < _nmesh; id++ ){
322  _interfaceOffset[id].push_back( faceID[id] );
323  _interfaceID [id].push_back( -interfaceGroupList[i]->id );
324  }
325 
326  for ( int n = nBeg; n < nEnd; n++ ){
327  int cell1 = faceCells(n,0);
328  int cell2 = faceCells(n,1);
329  //if inner cells take it first, second one ghost cell
330  if ( cell1 < cellSelfCount ){
331  int meshID = _globalCellToMeshID[ cell1 ];
332  _faceCells.at( meshID )->add( faceID[meshID], _globalCellToLocal[cell1] );
333  _faceCells.at( meshID )->add( faceID[meshID], localCellID[meshID] );
334  _globalToLocalFaces[meshID][n] = faceID[meshID];
335  localCellID[meshID]++;
336  faceID[meshID]++;
337  } else {
338  int meshID = _globalCellToMeshID[ cell2 ];
339  _faceCells.at( meshID )->add( faceID[meshID], _globalCellToLocal[cell2] );
340  _faceCells.at( meshID )->add( faceID[meshID], localCellID[meshID] );
341  _globalToLocalFaces[meshID][n] = faceID[meshID];
342  localCellID[meshID]++;
343  faceID[meshID]++;
344  }
345  }
346 
347  //filling sizes ( if this interface doesn't involve a mesh, following size will be zero for that mesh
348  for ( int id = 0; id < _nmesh; id++ )
349  _interfaceSize[id].push_back( faceID[id] - _interfaceOffset[id][i] );
350 
351  }
352 
353 }
354 //mesh interface adding
355 void
356 MeshDismantler::faceCellsAddMeshInterfaces(vector<int>& faceID, vector<int>& localCellID )
357 {
358  //loop over interfaces to see color difference
359  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
360  const FaceGroup& interiorFaceGroup = _mesh.getInteriorFaceGroup();
361  const StorageSite& interiorFaceSite = interiorFaceGroup.site;
362 
363  vector<int> countMeshInterface(_nmesh,0);
364  for ( int i = 0; i < interiorFaceSite.getCount(); i++ ){
365  int cell1 = faceCells(i,0);
366  int cell2 = faceCells(i,1);
367  int meshID1 = _globalCellToMeshID[cell1];
368  int meshID2 = _globalCellToMeshID[cell2];
369  if ( meshID1 != meshID2 ){ //it means this face is mesh interface
370  countMeshInterface[meshID1]++;
371  countMeshInterface[meshID2]++;
372  }
373  }
374 
375  //allocate memory
376  _faceIdentifierList.resize( _nmesh );
377  //only sweep interior face to find mesh interface
378  for ( int i = 0; i < interiorFaceSite.getCount(); i++ ){
379  int cell1 = faceCells(i,0);
380  int cell2 = faceCells(i,1);
381  int meshID1 = _globalCellToMeshID[cell1];
382  int meshID2 = _globalCellToMeshID[cell2];
383  if ( meshID1 != meshID2 ){ //it means this face is mesh interface
384  _faceIdentifierList[meshID1].insert( pair<int,int>(meshID2,i) );
385  _faceIdentifierList[meshID2].insert( pair<int,int>(meshID1,i) );
386  }
387  }
388 
389  //loop over meshes
390  for ( int id = 0 ; id < _nmesh ; id++ ){
391  const multimap<int,int>& faceIdentifier = _faceIdentifierList[id];
392  //loop over all meshinterfaces
393  for ( int key = 0; key < _nmesh; key++ ){
394  //filling faceOffset, ID and sizes
395  int nface = faceIdentifier.count(key);
396  if ( nface > 0 ){
397  _interfaceOffset[id].push_back( faceID[id] );
398  _interfaceID [id].push_back( key );
399  _interfaceSize [id].push_back( nface );
400  }
401 
402  multimap<int,int>::const_iterator it;
403  for ( it = faceIdentifier.equal_range(key).first; it != faceIdentifier.equal_range(key).second; it++ ){
404  int glblFaceID = it->second;
405  int cell1 = faceCells(glblFaceID,0);
406  int cell2 = faceCells(glblFaceID,1);
407  int meshID1 = _globalCellToMeshID[cell1];
408 // int meshID2 = _globalCellToMeshID[cell2];
409  if ( id == meshID1 ){
410  _faceCells.at(id)->add( faceID[id], _globalCellToLocal[cell1] );
411  _faceCells.at(id)->add( faceID[id], localCellID[id]);
412  _globalToLocalFaces[id][glblFaceID] = faceID[id];
413  localCellID[id]++;
414  faceID[id]++;
415  } else {
416  _faceCells.at(id)->add( faceID[id], _globalCellToLocal[cell2] );
417  _faceCells.at(id)->add( faceID[id], localCellID[id] );
418  _globalToLocalFaces[id][glblFaceID] = faceID[id];
419  localCellID[id]++;
420  faceID[id]++;
421  }
422  }
423  }
424  }
425 
426 }
427 //boundary interface adding
428 void
429 MeshDismantler::faceCellsAddBoundaryInterfaces( vector<int>& faceID, vector<int>& localCellID )
430 {
431  _globalToLocalFaces.resize( _nmesh );
432  int cellSelfCount = _mesh.getCells().getSelfCount();
433  int boundaryCount = _mesh.getBoundaryGroupCount();
434  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
435  const FaceGroupList& boundaryGroupList = _mesh.getBoundaryFaceGroups();
436  //loop over partition faces (
437  for ( int i = 0; i < boundaryCount; i++ ){
438  const StorageSite& boundaryFaceSite = boundaryGroupList[i]->site;
439  int offset = boundaryFaceSite.getOffset(); //where to begin face
440  int nBeg = offset;
441  int nEnd = nBeg + boundaryFaceSite.getCount();
442  //filling faceOffset and ID and Type
443  const int bounID = boundaryGroupList[i]->id;
444  const string& bType = boundaryGroupList[i]->groupType;
445  for ( int id = 0; id < _nmesh; id++ ){
446  _boundaryOffset[id].push_back( faceID[id] );
447  _boundaryID [id].push_back( bounID );
448  _boundaryType [id].push_back( bType );
449  }
450  for ( int n = nBeg; n < nEnd; n++ ){
451  int cell1 = faceCells(n,0);
452  int cell2 = faceCells(n,1);
453  //if inner cells take it first, second one ghost cell
454  if ( cell1 < cellSelfCount ){
455  int meshID = _globalCellToMeshID[ cell1 ];
456  _faceCells.at( meshID )->add( faceID[meshID], _globalCellToLocal[cell1] );
457  _faceCells.at( meshID )->add( faceID[meshID], localCellID[meshID]++ );
458  faceID[meshID]++;
459  } else {
460  int meshID = _globalCellToMeshID[ cell2 ];
461  _faceCells.at( meshID )->add( faceID[meshID], _globalCellToLocal[cell2] );
462  _faceCells.at( meshID )->add( faceID[meshID], localCellID[meshID]++ );
463  faceID[meshID]++;
464  }
465  }
466  //filling sizes
467  for ( int id = 0; id < _nmesh; id++ )
468  _boundarySize[id].push_back( faceID[id] - _boundaryOffset[id][i] );
469 
470  }
471 
472 }
473 //finishAdd call
474 void
476 {
477  //init count and finishCount;
478  for ( int id = 0; id < _nmesh; id++ )
479  _faceCells.at(id)->finishAdd();
480 }
481 
482 
483 //getting CRConnectivity faceNodes
484 void
486 {
487  vector<int> faceID(_nmesh,0); //track local mesh face ids
488  faceNodesInit();
489  faceNodesAddInteriorFaces ( faceID );
491  faceNodesAddMeshInterfaces ( faceID );
494 }
495 
496 //faceNodes finish count
497 void
499 {
500  //init count and finishCount;
501  for ( int id = 0; id < _nmesh; id++ ){
502  const StorageSite& faceSite = _meshList.at(id)->getFaces();
503  const StorageSite& nodeSite = _meshList.at(id)->getNodes();
504  _faceNodes.push_back( CRConnectivityPtr( new CRConnectivity( faceSite, nodeSite ) ) );
505  _faceNodes.at(id)->initCount();
506  }
507 
508 
509  //first add interior faces addCounts
510  vector<int> faceIndx(_nmesh,0);
511  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
512  const CRConnectivity& faceNodes = _mesh.getAllFaceNodes();
513  const FaceGroup& interiorFaceGroup = _mesh.getInteriorFaceGroup();
514  const StorageSite& interiorFaceSite = interiorFaceGroup.site;
515  for ( int n = 0; n < interiorFaceSite.getCount(); n++ ){
516  int cell1 = faceCells(n,0);
517  int cell2 = faceCells(n,1);
518  int meshID1 = _globalCellToMeshID[cell1];
519  int meshID2 = _globalCellToMeshID[cell2];
520  if ( meshID1 == meshID2 ){ //it means this face interior face
521  const int nodeCount = faceNodes.getCount(n);
522  _faceNodes.at( meshID1 )->addCount( faceIndx[meshID1]++, nodeCount );
523  }
524  }
525 
526  //add partition interfaces to addCount
527  const int interfaceCount = _mesh.getInterfaceGroupCount();
528  const FaceGroupList& interfaceGroupList = _mesh.getInterfaceGroups();
529  //loop over partition faces (
530  for ( int i = 0; i < interfaceCount; i++ ){
531  const StorageSite& interiorFaceSite = interfaceGroupList[i]->site;
532  int offset = interiorFaceSite.getOffset(); //where to begin face
533  int nBeg = offset;
534  int nEnd = nBeg + interiorFaceSite.getCount();
535  //loop over faces
536  for ( int n = nBeg; n < nEnd; n++ ){
537  //loop over nodes
538  const int cell1 = faceCells(n,0);
539  const int meshID = _globalCellToMeshID[ cell1 ];
540  const int nodeCount = faceNodes.getCount(n);
541  _faceNodes.at( meshID )->addCount( faceIndx[meshID]++, nodeCount );
542  }
543  }
544 
545  //loop over mesh interfaces to addCounts
546  //all interior face to search mesh interface
547  for ( int n = 0; n < interiorFaceSite.getCount(); n++ ){
548  int cell1 = faceCells(n,0);
549  int cell2 = faceCells(n,1);
550  int meshID1 = _globalCellToMeshID[cell1];
551  int meshID2 = _globalCellToMeshID[cell2];
552  if ( meshID1 != meshID2 ){ //it means this face is mesh interface
553  //face in meshID1
554  const int nodeCount = faceCells.getCount(n);
555  _faceNodes.at ( meshID1 )->addCount( faceIndx[meshID1]++, nodeCount );
556  //face in meshID2
557  _faceNodes.at ( meshID2 )->addCount( faceIndx[meshID2]++, nodeCount );
558  }
559  }
560 
561  //loop over boundary faces to addCount
562  const int boundaryCount = _mesh.getBoundaryGroupCount();
563  const FaceGroupList& boundaryGroupList = _mesh.getBoundaryFaceGroups();
564  //loop boundary faces to addCount
565  for ( int i = 0; i < boundaryCount; i++ ){
566  const StorageSite& boundaryFaceSite = boundaryGroupList[i]->site;
567  const int offset = boundaryFaceSite.getOffset(); //where to begin face
568  const int nBeg = offset;
569  const int nEnd = nBeg + boundaryFaceSite.getCount();
570  for ( int n = nBeg; n < nEnd; n++ ){
571  const int cell1 = faceCells(n,0);
572  const int meshID = _globalCellToMeshID[ cell1 ];
573  const int nodeCount = faceNodes.getCount(n);
574  _faceNodes.at( meshID )->addCount( faceIndx[meshID]++, nodeCount );
575  }
576  }
577 
578 
579  //finish count
580  for ( int id = 0; id < _nmesh; id++ )
581  _faceNodes.at(id)->finishCount();
582 
583 }
584 //faceNodes add for interior faces
585 void
587 {
588  //first add interior faces
589  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
590  const CRConnectivity& faceNodes = _mesh.getAllFaceNodes();
591  const FaceGroup& interiorFaceGroup = _mesh.getInteriorFaceGroup();
592  const StorageSite& interiorFaceSite = interiorFaceGroup.site;
593  for ( int n = 0; n < interiorFaceSite.getCount(); n++ ){
594  int cell1 = faceCells(n,0);
595  int cell2 = faceCells(n,1);
596  int meshID1 = _globalCellToMeshID[cell1];
597  int meshID2 = _globalCellToMeshID[cell2];
598  if ( meshID1 == meshID2 ){ //it means this face interior face
599  const int nodeCount = faceCells.getCount(n);
600  for ( int i = 0; i < nodeCount; i++ ){
601  int glbNodeID = faceNodes(n,i);
602  int lclNodeID = _globalToLocalNodes[glbNodeID][meshID1]; //gives local id
603  _faceNodes.at( meshID1 )->add( faceID[meshID1], lclNodeID );
604  }
605  faceID[meshID1]++;
606  }
607  }
608 }
609 //faceNodes add for partition faces
610 void
612 {
613  //add partition interfaces
614  int interfaceCount = _mesh.getInterfaceGroupCount();
615  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
616  const CRConnectivity& faceNodes = _mesh.getAllFaceNodes();
617  const FaceGroupList& interfaceGroupList = _mesh.getInterfaceGroups();
618  //loop over partition faces (
619  for ( int i = 0; i < interfaceCount; i++ ){
620  const StorageSite& interiorFaceSite = interfaceGroupList[i]->site;
621  int offset = interiorFaceSite.getOffset(); //where to begin face
622  int nBeg = offset;
623  int nEnd = nBeg + interiorFaceSite.getCount();
624  //loop over faces
625  for ( int n = nBeg; n < nEnd; n++ ){
626  //loop over nodes
627  int cell1 = faceCells(n,0);
628  int meshID = _globalCellToMeshID[ cell1 ];
629  const int nodeCount = faceCells.getCount(n);
630  for ( int j = 0; j < nodeCount; j++ ){
631  int glbNodeID = faceNodes(n,j);
632  int lclNodeID = _globalToLocalNodes[glbNodeID][meshID]; //gives local id
633  _faceNodes.at( meshID )->add( faceID[meshID], lclNodeID );
634  }
635  faceID[meshID]++;
636  }
637  }
638 
639 }
640 
641 void
643 {
644  //loop over interfaces to see color difference
645  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
646  const CRConnectivity& faceNodes = _mesh.getAllFaceNodes();
647  const FaceGroup& interiorFaceGroup = _mesh.getInteriorFaceGroup();
648  const StorageSite& interiorFaceSite = interiorFaceGroup.site;
649  //all interior face to search mesh interface
650  for ( int n = 0; n < interiorFaceSite.getCount(); n++ ){
651  int cell1 = faceCells(n,0);
652  int cell2 = faceCells(n,1);
653  int meshID1 = _globalCellToMeshID[cell1];
654  int meshID2 = _globalCellToMeshID[cell2];
655  if ( meshID1 != meshID2 ){ //it means this face is mesh interface
656  const int nodeCount = faceCells.getCount(n);
657  //face in meshID1
658  for ( int i = 0; i < nodeCount; i++ ){
659  int glblNodeID = faceNodes(n,i);
660  int lclNodeID = _globalToLocalNodes[glblNodeID][meshID1]; //gives local id
661  _faceNodes.at ( meshID1 )->add( faceID[meshID1], lclNodeID );
662  }
663  //face in meshID2 (consistent with global faceNodes connectivity)
664  for ( int i = nodeCount-1; i >= 0; i-- ){
665  int glblNodeID = faceNodes(n,i);
666  int lclNodeID = _globalToLocalNodes[glblNodeID][meshID2]; //gives local id
667  _faceNodes.at ( meshID2 )->add( faceID[meshID2], lclNodeID );
668  }
669  faceID[meshID1]++;
670  faceID[meshID2]++;
671  }
672  }
673 }
674 
675 
676 void
678 {
679  int boundaryCount = _mesh.getBoundaryGroupCount();
680  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
681  const CRConnectivity& faceNodes = _mesh.getAllFaceNodes();
682  const FaceGroupList& boundaryGroupList = _mesh.getBoundaryFaceGroups();
683  //loop over partition faces (
684  for ( int i = 0; i < boundaryCount; i++ ){
685  const StorageSite& boundaryFaceSite = boundaryGroupList[i]->site;
686  int offset = boundaryFaceSite.getOffset(); //where to begin face
687  int nBeg = offset;
688  int nEnd = nBeg + boundaryFaceSite.getCount();
689  for ( int n = nBeg; n < nEnd; n++ ){
690  int cell1 = faceCells(n,0);
691  int meshID = _globalCellToMeshID[ cell1 ];
692  const int nodeCount = faceCells.getCount(n);
693  for ( int j = 0; j < nodeCount; j++ ){
694  int glbNodeID = faceNodes(n,j);
695  int lclNodeID = _globalToLocalNodes[glbNodeID][meshID]; //gives local id
696  _faceNodes.at( meshID )->add( faceID[meshID], lclNodeID );
697  }
698  faceID[meshID]++;
699  }
700  }
701 }
702 
703 void
705 {
706  //init count and finishCount;
707  for ( int id = 0; id < _nmesh; id++ )
708  _faceNodes.at(id)->finishAdd();
709 }
710 
711 
712 //local Nodes to global Nodes
713 void
715 {
716  //count inner nodes for assembly
717  vector<int> nodeCount(_nmesh,0);
718  const StorageSite& nodeSite = _mesh.getNodes();
719  //allocate globalToLocaNodes
720  _globalToLocalNodes.resize( nodeSite.getCount() );
721  //allocating glblNOdeIDs for each mesh
722  vector< vector<int> > globalNodeIDs(_nmesh);
723  for ( int id = 0; id < _nmesh; id++ )
724  globalNodeIDs[id].resize(nodeSite.getCount(),-1);
725 
726  const StorageSite& cellSite = _mesh.getCells();
727  const CRConnectivity& cellNodes = _mesh.getCellNodes();
728  const Array<int>& color = _mesh.getCellColors();
729  //loop over only inner cells nodes
730  for ( int n = 0; n < cellSite.getSelfCount(); n++ ) {
731  int nnodes = cellNodes.getCount(n);
732  int colorID = color[n];
733  for ( int i = 0; i < nnodes; i++ ){
734  int glblNodeID = cellNodes(n,i);
735  //if it is not visited (=-1)
736  if ( globalNodeIDs[colorID][glblNodeID] == -1 ) {
737  map<int,int>& nodeMap = _globalToLocalNodes[glblNodeID];
738  nodeMap[colorID] = nodeCount[colorID];
739  globalNodeIDs[colorID][glblNodeID] = 1;
740  nodeCount[colorID]++;
741  }
742  }
743  }
744 
745 }
746 
747 
748 
749 //setting coordinates
750 void
752 {
753  //allocation memory for coord
754  for ( int id = 0; id < _nmesh; id++ )
755  _coord.push_back( ArrayVecD3Ptr(new Array<Mesh::VecD3>(_nodeSite.at(id)->getCount())) );
756 
757  const StorageSite& nodeSiteGlbl = _mesh.getNodes();
758  const Array<Mesh::VecD3>& coordGlbl = _mesh.getNodeCoordinates();
759  for ( int i = 0; i < nodeSiteGlbl.getCount(); i++ ){
760  const map<int,int>& colorIDToLocalNode = _globalToLocalNodes[i];
761  foreach(const IntMap::value_type& mpos, colorIDToLocalNode){
762  int colorID = mpos.first;
763  int localNodeID = mpos.second;
764  (*_coord[colorID])[localNodeID] = coordGlbl[i];
765  }
766  }
767 }
768 
769 //setting assembled mesh
770 void
772 {
773  //interior face group
775  //boundary face group
777  //interface group
779  //setting coordinates
780  createCoords();
781  //setting faceNodes CRConnecitivty
782  createFaceNodes();
783  //setting faceCells CRConnectivity
784  createFaceCells();
785 
786 }
787 
788 //set StorageSites
789 void
791 {
792  for ( int id = 0; id < _nmesh; id++ ){
793  StorageSite& faceSite = _meshList.at(id)->getFaces();
794  StorageSite& cellSite = _meshList.at(id)->getCells();
795  StorageSite& nodeSite = _meshList.at(id)->getNodes();
796  //setCounts
797  faceSite.setCount( _faceSite.at(id)->getCount() );
798  int nGhost = _cellSite.at(id)->getCount()-_cellSite.at(id)->getSelfCount();
799  cellSite.setCount( _cellSite.at(id)->getSelfCount(), nGhost );
800  cellSite.setCountLevel1( _cellSite.at(id)->getCountLevel1() );
801  nodeSite.setCount( _nodeSite.at(id)->getCount() );
802  }
803 }
804 //interior face
805 void
807 {
808  for ( int id = 0; id < _nmesh; id++ ){
809  int nInteriorFace = 0;
810  const CRConnectivity& faceCells = *_faceCells.at(id);
811  const StorageSite& faceSite = *_faceSite.at(id);
812  const int cellSelfCount = _cellSite.at(id)->getSelfCount();
813  for ( int i = 0; i < faceSite.getCount(); i++ ){
814  int cell1 = faceCells(i,0);
815  int cell2 = faceCells(i,1);
816  if ( (cell1 < cellSelfCount) && (cell2 < cellSelfCount) )
817  nInteriorFace++;
818  }
819  _meshList.at(id)->createInteriorFaceGroup( nInteriorFace );
820  }
821 
822 }
823 //interface group
824 void
826 {
827  for ( int id = 0; id < _nmesh; id++ ){
828  for ( unsigned int i = 0; i < _interfaceOffset[id].size(); i++ ){
829  const int size = _interfaceSize[id][i];
830  const int offset = _interfaceOffset[id][i];
831  const int interfaceID = _interfaceID[id][i];
832  if ( size > 0 )
833  _meshList.at(id)->createInterfaceGroup( size, offset, interfaceID);
834  }
835  }
836 }
837 //boundary face group
838 void
840 {
841  for ( int id = 0; id < _nmesh; id++ ){
842  for ( unsigned int i = 0; i < _boundaryOffset[id].size(); i++ ){
843  const int size = _boundarySize[id][i];
844  const int offset = _boundaryOffset[id][i];
845  const int boundaryID = _boundaryID[id][i];
846  const string& bType = _boundaryType[id][i];
847  if ( size > 0 )
848  _meshList.at(id)->createBoundaryFaceGroup( size, offset, boundaryID, bType );
849  }
850  }
851 }
852 //setting coords
853 void
855 {
856  for ( int id = 0 ; id < _nmesh; id++ )
857  _meshList.at(id)->setCoordinates( _coord.at(id) );
858 }
859 //set faceNodes for meshList
860 void
862 {
863  for ( int id = 0; id < _nmesh; id++ )
864  _meshList.at(id)->setFaceNodes( _faceNodes.at(id) );
865 }
866 //set faceCells for meshList
867 void
869 {
870  for ( int id = 0; id < _nmesh; id++ )
871  _meshList.at(id)->setFaceCells( _faceCells.at(id) );
872 }
873 //fill scatter and gather maps
874 void
876 {
879 
880 }
881 
882 //partition interface mappers
883 void
885 {
886  //mappers
887  const StorageSite::ScatterMap& scatterMap = _mesh.getCells().getScatterMap();
888  const StorageSite::GatherMap& gatherMap = _mesh.getCells().getGatherMap ();
889  //interfaceList
890  const FaceGroupList& faceGroupList = _mesh.getInterfaceGroups();
891  //interfacecount
892  int interfaceGroupCount = _mesh.getInterfaceGroupCount();
893  //loop over interfaces (only partition interfaces)
894  for ( int i = 0; i < interfaceGroupCount; i++ ) {
895  //get key for f
896  int interfaceID = -faceGroupList[i]->id;
897  //mappers in Storagesite is held by the same storage site, so this site
898  //can be used to in scatterMap and gatherMap
899  const StorageSite& interfaceSite = faceGroupList[i]->site;
900  //from intrface ID and meshID (since this is from meshID), we can get that specific storagesite
901  const int meshID0 = 0;
902  Mesh::PartIDMeshIDPair pairID = make_pair<int,int>( interfaceID, meshID0 );
903  const StorageSite* ghostSite = _mesh.getGhostCellSiteScatter( pairID );
904  //get mapper arrays
905  const Array<int>& scatterArray = *scatterMap.find(ghostSite)->second;
906  const Array<int>& gatherArray = *gatherMap.find(ghostSite)->second;
907  EntryVecMap scatterArrayMap;
908  EntryVecMap gatherArrayMap;
909  getGatherArrays ( gatherArray , gatherArrayMap , interfaceSite );
910  getScatterArrays( scatterArray, scatterArrayMap, interfaceSite );
911 
912  //get scatterArrayMap
913  foreach ( const EntryVecMap::value_type& pos, scatterArrayMap ){
914  const pair<int,int>& entry = pos.first;
915  const int meshID = entry.first;
916  const int otherMeshID = entry.second;
917  const int size = int(pos.second.size());
918  //reference ot mappers to fill in
919  StorageSite::ScatterMap& scatterMapLocal = _meshList.at(meshID)->getCells().getScatterMap();
920  StorageSite::GatherMap& gatherMapLocal = _meshList.at(meshID)->getCells().getGatherMap();
921  //storagesite (used for both scatter and gathersites), pass parent (getCells())
922  shared_ptr<StorageSite> siteScatterLocal( new StorageSite(size) );
923 
924  //copy scatterArray to Array<int>
925  int scatterSize = int(scatterArrayMap[entry].size());
926  ArrayIntPtr scatterArrayLocal( new Array<int>( scatterSize ) );
927  for ( int i = 0; i < scatterSize; i++ )
928  (*scatterArrayLocal)[i] = scatterArrayMap[entry][i];
929  //copy gatherArray to Array<int>
930  int gatherSize = int(gatherArrayMap[entry].size());
931  ArrayIntPtr gatherArrayLocal( new Array<int>( gatherSize ) );
932  for ( int i = 0; i < gatherSize; i++ )
933  (*gatherArrayLocal)[i] = gatherArrayMap[entry][i];
934 
935  //setting scatterID and gatherID
936  siteScatterLocal->setScatterProcID( ghostSite->getScatterProcID() );
937  siteScatterLocal->setGatherProcID ( ghostSite->getGatherProcID() );
938  //setting tag (shifting 16 bits to left)
939  int packed_info = (std::max(meshID,otherMeshID) << 16 ) | ( std::min(meshID,otherMeshID) );
940  siteScatterLocal->setTag( packed_info );
941 
942  Mesh::PartIDMeshIDPair pairID = make_pair<int,int>( ghostSite->getGatherProcID(), otherMeshID);
943  _meshList.at(meshID)->createGhostCellSiteScatter( pairID, siteScatterLocal );
944  _meshList.at(meshID)->createGhostCellSiteGather ( pairID, siteScatterLocal );
945  scatterMapLocal[ siteScatterLocal.get() ] = scatterArrayLocal;
946  gatherMapLocal [ siteScatterLocal.get() ] = gatherArrayLocal;
947  }
948  }
949 
950 
951 }
952 
953 
954 void
955 MeshDismantler::getScatterArrays( const Array<int>& scatterArray, EntryVecMap& scatterArrayLocal, const StorageSite& site )
956 {
957  // get counts for each mesh
958  EntryMap sizeScatter;
959  int offset = site.getOffset(); //where to begin face
960  int iBeg = offset;
961  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
962  const Array<int>& color = _mesh.getCellColors();
963  const Array<int>& colorOther = _mesh.getCellColorsOther();
964  //loop over partition faces
965  for ( int i = 0; i < scatterArray.getLength(); i++ ){
966  const int faceIndx = iBeg+i;
967  //check gather cellColor
968  const int cell1 = faceCells(faceIndx,1); //outside cell
969  const int thisMeshID = color[ scatterArray[i] ];
970  const int otherMeshID = colorOther[ cell1 ];
971  EntryIndex eIndex = make_pair<int,int>(thisMeshID, otherMeshID);
972  //sizeScatter[eIndex]++;
973  const int cellID = _globalCellToLocal [ scatterArray[i] ];
974 
975  scatterArrayLocal[eIndex].push_back(cellID);
976  }
977 
978 }
979 
980 
981 void
982 MeshDismantler::getGatherArrays(const Array<int>& gatherArray, EntryVecMap& gatherArrayLocal, const StorageSite& site )
983 {
984  // get counts for each mesh
985  EntryMap sizeScatter;
986  int offset = site.getOffset(); //where to begin face
987  int iBeg = offset;
988  const CRConnectivity& faceCells = _mesh.getAllFaceCells();
989  const Array<int>& color = _mesh.getCellColors();
990  const Array<int>& colorOther = _mesh.getCellColorsOther();
991  //loop over partition faces
992  for ( int i = 0; i < gatherArray.getLength(); i++ ){
993  const int faceIndx = iBeg+i;
994  //check gather cellColor
995  const int cell0 = faceCells(faceIndx,0); //outside cell
996  const int thisMeshID = color[ cell0 ];
997  const int otherMeshID = colorOther[ gatherArray[i] ];
998  EntryIndex eIndex = make_pair<int,int>(thisMeshID, otherMeshID);
999  const int glblFaceID = (*_cellFaces)(gatherArray[i],0);
1000  const int localFaceID = _globalToLocalFaces[thisMeshID][glblFaceID];
1001  const int cellID = (*_faceCells[thisMeshID])(localFaceID,1); // 0 inner , 1 ghost cells
1002  gatherArrayLocal[eIndex].push_back(cellID);
1003  }
1004 
1005 }
1006 
1007 
1008 //mesh interfaces
1009 void
1011 {
1012  //loop over meshes
1013  for ( int id = 0 ; id < _nmesh ; id++ ){
1014  const multimap<int,int>& faceIdentifier = _faceIdentifierList[id];
1015  StorageSite::GatherMap & gatherMapLocal = _meshList.at(id)->getCells().getGatherMap();
1016  const StorageSite* thisSite = &_meshList.at(id)->getCells();
1017  //loop over all meshinterfaces (key = all other meshes)
1018  for ( int key = 0; key < _nmesh; key++ ){
1019  //filling scatter (on this mesh) and gather Array (on other mesh)
1020  int nface = faceIdentifier.count(key);
1021  if ( nface > 0 ){
1022  StorageSite::ScatterMap& scatterMapLocal = _meshList.at(key)->getCells().getScatterMap();
1023  const StorageSite* otherSite = &_meshList.at(key)->getCells();
1024  ArrayIntPtr scatterArrayLocal( new Array<int>( nface ) ); //for other side mesh
1025  ArrayIntPtr gatherArrayLocal ( new Array<int>( nface ) ); //for this side mesh
1026  multimap<int,int>::const_iterator it;
1027  int indx = 0;
1028  for ( it = faceIdentifier.equal_range(key).first; it != faceIdentifier.equal_range(key).second; it++ ){
1029  //fill this mesh gather
1030  const int glblFaceID = it->second;
1031  int localFaceID = _globalToLocalFaces[id][glblFaceID];
1032  const int gatherCellID = (*_faceCells[id])(localFaceID,1);
1033  (*gatherArrayLocal)[indx] = gatherCellID;
1034  //now other mesh to fill scatter arrays
1035  localFaceID = _globalToLocalFaces[key][glblFaceID];
1036  const int scatterCellID = (*_faceCells[key])(localFaceID,0);
1037  (*scatterArrayLocal)[indx] = scatterCellID;
1038  indx++;
1039  }
1040  gatherMapLocal.insert ( make_pair(otherSite, gatherArrayLocal ) ); //gather this side mesh, so we key with other site StorageSite*
1041  scatterMapLocal.insert( make_pair(thisSite , scatterArrayLocal) ); //scatter other side mesh, so we key with this site StorageSite*
1042  }
1043  }
1044  }
1045 
1046 
1047 }
1048 
1049 //filling mesh localToGlobal and globalToLocal
1050 void
1052 {
1053  const int nmesh = int( _meshList.size() );
1054  //creating cellID MultiField to use sync() operation
1055  shared_ptr<MultiField> cellMultiField = shared_ptr<MultiField>( new MultiField() );
1056  shared_ptr<Field> cellField = shared_ptr<Field> ( new Field("globalcellID") );
1057 
1058  for ( int id = 0; id < nmesh; id++ ){
1059  const StorageSite* site = &_meshList[id]->getCells();
1060  MultiField::ArrayIndex ai( cellField.get(), site );
1061  shared_ptr<Array<int> > cIndex(new Array<int>(site->getCountLevel1()));
1062  *cIndex = -1;
1063  cellMultiField->addArray(ai,cIndex);
1064  }
1065 
1066  //global numbering
1067  const int globalOffset = global_offset();
1068  int offset = globalOffset;
1069  for ( int id = 0; id < nmesh; id++ ){
1070  const Mesh& mesh = *_meshList.at(id);
1071  const StorageSite* site = &_meshList[id]->getCells();
1072  MultiField::ArrayIndex ai( cellField.get(), site );
1073  Array<int>& localCell = dynamic_cast< Array<int>& >( (*cellMultiField)[ai] );
1074  //global numbering inner cells
1075  const int selfCount = site->getSelfCount();
1076  for ( int i = 0; i < selfCount; i++ )
1077  localCell[i] = offset + i;
1078  //update offset
1079  offset += selfCount;
1080  //loop over boundaries and global number boundary cells
1081  const FaceGroupList& bounGroupList = mesh.getBoundaryFaceGroups();
1082  const CRConnectivity& faceCells = mesh.getAllFaceCells();
1083  for ( int i = 0; i < mesh.getBoundaryGroupCount(); i++ ){
1084  const int ibeg = bounGroupList[i]->site.getOffset();
1085  const int iend = ibeg + bounGroupList[i]->site.getCount();
1086  int indx=0;
1087  for ( int ii = ibeg; ii < iend; ii++ ){
1088  localCell[ faceCells(ii,1)] = offset + indx;
1089  indx++;
1090  }
1091  //update offset
1092  offset += iend-ibeg;
1093  }
1094 
1095  }
1096 
1097  //sync opeartion
1098  cellMultiField->sync();
1099 
1100  //create localToGlobal array and assign it in Mesh
1101  for ( int id = 0; id < nmesh; id++ ){
1102  Mesh& mesh = *_meshList.at(id);
1103  mesh.createLocalGlobalArray();
1104  const StorageSite* site = &_meshList[id]->getCells();
1105  MultiField::ArrayIndex ai( cellField.get(), site );
1106  const Array<int>& localCell = dynamic_cast< const Array<int>& >( (*cellMultiField)[ai] );
1107  Array<int>& localToGlobal = mesh.getLocalToGlobal();
1108  for ( int i = 0; i < localCell.getLength(); i++ ){
1109  localToGlobal[i] = localCell[i];
1110  assert( localCell[i] != -1 );
1111  }
1112 
1113  //copying GlobalToLocal
1114  map<int,int>& globalToLocal = mesh.getGlobalToLocal();
1115  for ( int i = 0; i < localCell.getLength(); i++ ){
1116  globalToLocal[ localToGlobal[i] ] = i;
1117  }
1118  }
1119 
1120 }
1121 
1122 
1123 
1124 //get offset value for global numbering for each partition
1125 int
1127 {
1128  const int nmesh = int( _meshList.size() );
1129  int count = 0;
1130  //get offsets for
1131  for ( int id = 0; id < nmesh; id++ ){
1132  const Mesh& mesh = *_meshList.at(id);
1133  const StorageSite& cellSite = mesh.getCells();
1134  const FaceGroupList& bounGroupList = mesh.getBoundaryFaceGroups();
1135  int bounCount = 0;
1136  for ( int i = 0; i < mesh.getBoundaryGroupCount(); i++ )
1137  bounCount += bounGroupList[i]->site.getCount();
1138  const int selfCount = cellSite.getSelfCount();
1139  count += selfCount + bounCount;
1140  }
1141 
1142 
1143  //allocation holding each partiton offset
1144  int *counts = new int[ _nPart ];
1145  //MPI calls allgather to know offsets
1146 #ifdef FVM_PARALLEL
1147  MPI::COMM_WORLD.Allgather( &count, 1, MPI::INT, counts, 1, MPI::INT);
1148 #endif
1149 
1150  //compute offsets for each partition
1151  int offset = 0;
1152  for ( int i = 0; i < _procID; i++ )
1153  offset += counts[i];
1154 
1155  //delete allocation counts
1156  delete [] counts;
1157  return offset;
1158 
1159 }
1160 
1161 
1162 
1163 void
1165 {
1166  //create sendCounts
1167  for (int n=0; n<_nmesh; n++ ){
1168  Mesh& mesh = *_meshList[n];
1170  //partitioner interfaces
1171  mesh.syncCounts();
1172  }
1173 
1174  for (int n=0; n<_nmesh; n++ ){
1175  Mesh& mesh = *_meshList[n];
1176  //mesh interfaces
1178  }
1179 
1180 
1181  //create indices
1182  for (int n=0; n<_nmesh; n++ ){
1183  Mesh& mesh = *_meshList[n];
1185  //partitioner interfaces
1186  mesh.syncIndices();
1187  }
1188 
1189  for (int n=0; n<_nmesh; n++ ){
1190  Mesh& mesh = *_meshList[n];
1191  //mesh interfaces
1193  }
1194 
1195  //creaet cellCellsGhostExt
1196  for (int n=0; n<_nmesh; n++ ){
1197  Mesh& mesh = *_meshList[n];
1198  //mesh interfaces
1199  mesh.createCellCellsGhostExt();
1200  }
1201 }
1202 
1203 void
1205 {
1206  debug_cell_site();
1207  debug_face_site();
1208  debug_node_site();
1210  debug_face_cells();
1212  debug_face_nodes();
1215 }
1216 
1217 
1218 void
1220 {
1221  debug_file_open("cellSite");
1222  for ( int id = 0; id < _nmesh; id++ )
1223  _debugFile <<"meshid = " << id << " selfCount = " << _cellSite.at(id)->getSelfCount() << " count = " << _cellSite.at(id)->getCount() <<
1224  " countLevel1 = " << _cellSite.at(id)->getCountLevel1() <<endl;
1225  debug_file_close();
1226 }
1227 
1228 void
1230 {
1231  debug_file_open("faceSite");
1232  for ( int id = 0; id < _nmesh; id++ )
1233  _debugFile <<"meshid = " << id << " count = " << _faceSite.at(id)->getCount() << endl;
1234  debug_file_close();
1235 }
1236 
1237 void
1239 {
1240  debug_file_open("nodeSite");
1241  for ( int id = 0; id < _nmesh; id++ )
1242  _debugFile <<"meshid = " << id << " count = " << _nodeSite.at(id)->getCount() << endl;
1243  debug_file_close();
1244 }
1245 
1246 void
1248 {
1249  debug_file_open("cellsMapper");
1250  for ( unsigned int i = 0; i < _globalCellToMeshID.size(); i++ )
1251  _debugFile << "glblID = " << i << " meshID = " << _globalCellToMeshID[i] << endl;
1252  _debugFile << endl;
1253  for ( unsigned int i = 0; i < _globalCellToLocal.size(); i++ )
1254  _debugFile << "glblID = " << i << " localID = " << _globalCellToLocal[i] << endl;
1255  debug_file_close();
1256 
1257 }
1258 
1259 void
1261 {
1262  debug_file_open("nodesMapper");
1263  for ( unsigned i = 0; i < _globalToLocalNodes.size(); i++ ){
1264  const map<int,int>& nodeMap = _globalToLocalNodes[i];
1265  foreach(const IntMap::value_type& mpos, nodeMap){
1266  int colorID = mpos.first;
1267  int localNodeID = mpos.second;
1268  _debugFile << "glblNodeID = " << i << " meshID = " << colorID << " localNodeID = " << localNodeID << endl;
1269  }
1270  }
1271  debug_file_close();
1272 }
1273 
1274 void
1276 {
1277  debug_file_open("faceCells");
1278  for ( int id = 0; id < _nmesh; id++ ){
1279  const StorageSite & faceSite = *_faceSite.at(id);
1280  const CRConnectivity& faceCells = *_faceCells.at(id);
1281  _debugFile << " meshID : " << id << endl;
1282  for ( int n = 0; n < faceSite.getCount(); n++ ){
1283  _debugFile << "faceCells(" << n << " ) = ";
1284  for ( int i = 0; i < faceCells.getCount(n); i++ ){
1285  _debugFile << faceCells(n,i) << " ";
1286  }
1287  _debugFile << endl;
1288  }
1289  }
1290  debug_file_close();
1291 
1292 }
1293 
1294 void
1296 {
1297  debug_file_open("faceNodes");
1298  for ( int id = 0; id < _nmesh; id++ ){
1299  const StorageSite & faceSite = *_faceSite.at(id);
1300  const CRConnectivity& faceNodes = *_faceNodes.at(id);
1301  _debugFile << " meshID : " << id << endl;
1302  for ( int n = 0; n < faceSite.getCount(); n++ ){
1303  _debugFile << "faceNodes(" << n << " ) = ";
1304  for ( int i = 0; i < faceNodes.getCount(n); i++ ){
1305  _debugFile << faceNodes(n,i) << " ";
1306  }
1307  _debugFile << endl;
1308  }
1309  }
1310  debug_file_close();
1311 }
1312 
1313 void
1315 {
1316  debug_file_open("scatterMappers");
1317  //creating mappers between cell storage site to mesh id
1318  map< const StorageSite*, int > siteMeshMapper; //key = storage site, value = mesh ID of cellSite
1319  for ( int id = 0; id < _nmesh; id++ )
1320  siteMeshMapper[&_meshList.at(id)->getCells()] = id;
1321 
1322  //first make sure consistent order for scatterMap since map order with key which is pointer
1323  //first mesh interface (increasing order) then partition interface (increasing order)
1324  vector< const StorageSite* > scatterSiteVec;
1325  map <int, int> packIDToMeshID;
1326  vector< int > scatterSiteVecID;
1327  IntStorageSiteMap orderedMeshInterface;
1328  for ( int id = 0; id < _nmesh; id++ ){
1329  const StorageSite::ScatterMap& scatterMap = _meshList.at(id)->getCells().getScatterMap();
1330  foreach ( const StorageSite::ScatterMap::value_type& pos, scatterMap ){
1331  const StorageSite& scatterSite = *pos.first;
1332  if ( scatterSite.getGatherProcID() == -1 ){ //this means mesh interface
1333  int neighMeshID = siteMeshMapper[ pos.first ];
1334  const int packed_info = ( (id << 16) | neighMeshID );
1335  orderedMeshInterface.insert( make_pair<int, const StorageSite*>(packed_info, pos.first) );
1336  packIDToMeshID.insert( make_pair<int,int>(packed_info,id) );
1337  }
1338  }
1339  }
1340 
1341  //fill scatterSiteVec, map data structure already ordered them
1342  foreach ( const IntStorageSiteMap::value_type& pos, orderedMeshInterface ){
1343  scatterSiteVec.push_back( pos.second );
1344  const int meshID = packIDToMeshID[pos.first];
1345  scatterSiteVecID.push_back( meshID );
1346  }
1347  //clear for usage in partition interface
1348  packIDToMeshID.clear();
1349  //order partition interface (map will reorder)
1350  IntStorageSiteMap orderedPartInterface;
1351  for ( int id = 0; id < _nmesh; id++ ){
1352  const StorageSite::ScatterMap& scatterMap = _meshList.at(id)->getCells().getScatterMap();
1353  foreach ( const StorageSite::ScatterMap::value_type& pos, scatterMap ){
1354  const StorageSite& scatterSite = *pos.first;
1355  if ( scatterSite.getGatherProcID() != -1 ){ //this means partition face
1356  const int neighID = scatterSite.getGatherProcID();
1357  const int tag = scatterSite.getTag();
1358  const int packed_info = ( (id << 31) | (neighID << 24) | tag );
1359  orderedPartInterface.insert( make_pair<int, const StorageSite*>(packed_info, pos.first) );
1360  packIDToMeshID.insert( make_pair<int,int>(packed_info,id) );
1361  }
1362  }
1363  }
1364 
1365  //fill scatterSiteVec, map data structure already
1366  foreach ( const IntStorageSiteMap::value_type& pos, orderedPartInterface ){
1367  scatterSiteVec.push_back( pos.second );
1368  const int meshID = packIDToMeshID[pos.first];
1369  scatterSiteVecID.push_back( meshID );
1370  }
1371 
1372  int indx = 0;
1373  foreach( const vector<const StorageSite*>::value_type& pos, scatterSiteVec){
1374  if ( pos->getGatherProcID() != -1 ){ //this means partition face
1375  const int id = scatterSiteVecID[indx++];
1376  const StorageSite::ScatterMap& scatterMap = _meshList.at(id)->getCells().getScatterMap();
1377  const Array<int>& scatterArray = *(scatterMap.find(pos)->second);
1378  const int neighID = pos->getGatherProcID();
1379  _debugFile << " meshID = " << id << " procID = " << _procID << " neighProcID = " << neighID << " Tag = " << pos->getTag() << " : " << endl;
1380  for ( int i = 0; i < scatterArray.getLength(); i++ ){
1381  _debugFile << " scatterArray[" << i << "] = " << scatterArray[i] << endl;
1382  }
1383  } else { //this means mesh interface
1384  const int id = scatterSiteVecID[indx++];
1385  const StorageSite::ScatterMap& scatterMap = _meshList.at(id)->getCells().getScatterMap();
1386  const Array<int>& scatterArray = *(scatterMap.find(pos)->second);
1387  int neighMeshID = siteMeshMapper[pos];
1388  _debugFile << " meshID = " << id << " otherside MeshID = " << neighMeshID << " : " << endl;
1389  for ( int i = 0; i < scatterArray.getLength(); i++ ){
1390  _debugFile << " scatterArray[" << i << "] = " << scatterArray[i] << endl;
1391  }
1392  }
1393  }
1394  debug_file_close();
1395 }
1396 void
1397 
1399 {
1400 
1401  debug_file_open("gatherMappers");
1402  //creating mappers between cell storage site to mesh id
1403  map< const StorageSite*, int > siteMeshMapper; //key = storage site, value = mesh ID of cellSite
1404  for ( int id = 0; id < _nmesh; id++ )
1405  siteMeshMapper[&_meshList.at(id)->getCells()] = id;
1406 
1407  //first make sure consistent order for gatherMap since map order with key which is pointer
1408  //first mesh interface (increasing order) then partition interface (increasing order)
1409  vector< const StorageSite* > gatherSiteVec;
1410  map <int, int> packIDToMeshID;
1411  vector< int > gatherSiteVecID;
1412  IntStorageSiteMap orderedMeshInterface;
1413  for ( int id = 0; id < _nmesh; id++ ){
1414  const StorageSite::GatherMap& gatherMap = _meshList.at(id)->getCells().getGatherMap();
1415  foreach ( const StorageSite::GatherMap::value_type& pos, gatherMap ){
1416  const StorageSite& gatherSite = *pos.first;
1417  if ( gatherSite.getGatherProcID() == -1 ){ //this means mesh interface
1418  int neighMeshID = siteMeshMapper[ pos.first ];
1419  const int packed_info = ( (id << 16) | neighMeshID );
1420  orderedMeshInterface.insert( make_pair<int, const StorageSite*>(packed_info, pos.first) );
1421  packIDToMeshID.insert( make_pair<int,int>(packed_info,id) );
1422  }
1423  }
1424  }
1425 
1426  //fill gatherSiteVec, map data structure already ordered them
1427  foreach ( const IntStorageSiteMap::value_type& pos, orderedMeshInterface ){
1428  gatherSiteVec.push_back( pos.second );
1429  const int meshID = packIDToMeshID[pos.first];
1430  gatherSiteVecID.push_back( meshID );
1431  }
1432  //clear for usage in partition interface
1433  packIDToMeshID.clear();
1434  //order partition interface (map will reorder)
1435  IntStorageSiteMap orderedPartInterface;
1436  for ( int id = 0; id < _nmesh; id++ ){
1437  const StorageSite::GatherMap& gatherMap = _meshList.at(id)->getCells().getGatherMap();
1438  foreach ( const StorageSite::GatherMap::value_type& pos, gatherMap ){
1439  const StorageSite& gatherSite = *pos.first;
1440  if ( gatherSite.getGatherProcID() != -1 ){ //this means partition face
1441  const int neighID = gatherSite.getGatherProcID();
1442  const int tag = gatherSite.getTag();
1443  const int packed_info = ( (id << 31) | (neighID << 24) | tag );
1444  orderedPartInterface.insert( make_pair<int, const StorageSite*>(packed_info, pos.first) );
1445  packIDToMeshID.insert( make_pair<int,int>(packed_info,id) );
1446  }
1447  }
1448  }
1449 
1450  //fill scatterSiteVec, map data structure already
1451  foreach ( const IntStorageSiteMap::value_type& pos, orderedPartInterface ){
1452  gatherSiteVec.push_back( pos.second );
1453  const int meshID = packIDToMeshID[pos.first];
1454  gatherSiteVecID.push_back( meshID );
1455  }
1456 
1457  int indx = 0;
1458  foreach( const vector<const StorageSite*>::value_type& pos, gatherSiteVec){
1459  if ( pos->getGatherProcID() != -1 ){ //this means partition face
1460  const int id = gatherSiteVecID[indx++];
1461  const StorageSite::GatherMap& gatherMap = _meshList.at(id)->getCells().getGatherMap();
1462  const Array<int>& gatherArray = *(gatherMap.find(pos)->second);
1463  const int neighID = pos->getGatherProcID();
1464  _debugFile << " meshID = " << id << " procID = " << _procID << " neighProcID = " << neighID << " Tag = " << pos->getTag() << " : " << endl;
1465  for ( int i = 0; i < gatherArray.getLength(); i++ ){
1466  _debugFile << " gatherArray[" << i << "] = " << gatherArray[i] << endl;
1467  }
1468  } else { //this means mesh interface
1469  const int id = gatherSiteVecID[indx++];
1470  const StorageSite::GatherMap& gatherMap = _meshList.at(id)->getCells().getGatherMap();
1471  const Array<int>& gatherArray = *(gatherMap.find(pos)->second);
1472  int neighMeshID = siteMeshMapper[pos];
1473  _debugFile << " meshID = " << id << " otherside MeshID = " << neighMeshID << " : " << endl;
1474  for ( int i = 0; i < gatherArray.getLength(); i++ ){
1475  _debugFile << " gatherArray[" << i << "] = " << gatherArray[i] << endl;
1476  }
1477  }
1478  }
1479  debug_file_close();
1480 }
1481 
1482 
1483 void
1484 MeshDismantler::debug_file_open( const string& fname_ )
1485 {
1486  stringstream ss;
1487  ss << _procID;
1488 
1489  string fname = "MESHDISMANTLER_"+fname_+"_proc"+ss.str()+".dat";
1490  _debugFile.open( fname.c_str() );
1491 }
1492 
1493 void
1495 {
1496  _debugFile.close();
1497 }
int getNumOfAssembleMesh() const
Definition: Mesh.h:251
const CRConnectivity & getAllFaceNodes() const
Definition: Mesh.cpp:368
const FaceGroupList & getBoundaryFaceGroups() const
Definition: Mesh.h:187
int getCount(const int i) const
const FaceGroup & getInteriorFaceGroup() const
Definition: Mesh.h:181
vector< ArrayIntPtr > _localCellToGlobal
int getBoundaryGroupCount() const
Definition: Mesh.h:184
void createInterFaceGroup()
int getSelfCount() const
Definition: StorageSite.h:40
ofstream _debugFile
shared_ptr< StorageSite > StorageSitePtr
void debug_file_open(const string &fname)
CRConnectivityPtr _cellFaces
Definition: Mesh.h:28
map< int, vector< int > > _interfaceOffset
const StorageSite & getNodes() const
Definition: Mesh.h:110
map< int, vector< string > > _boundaryType
Definition: Field.h:14
multiMap & getCellCellsGlobal()
Definition: Mesh.h:247
void faceCellsAddPartitionInterfaces(vector< int > &faceID, vector< int > &localCellID)
void faceNodesAddBoundaryInterfaces(vector< int > &faceID)
Definition: Mesh.h:49
map< EntryIndex, vector< int > > EntryVecMap
MeshDismantler(const MeshList &meshList)
double max(double x, double y)
Definition: Octree.cpp:18
map< int, vector< int > > _boundaryID
void setCount(const int selfCount, const int nGhost=0)
Definition: StorageSite.h:42
vector< CRConnectivityPtr > _faceNodes
map< int, int > & getGlobalToLocal()
Definition: Mesh.h:243
map< int, vector< int > > _boundaryOffset
int getInterfaceGroupCount() const
Definition: Mesh.h:185
vector< ArrayVecD3Ptr > _coord
shared_ptr< Array< Mesh::VecD3 > > ArrayVecD3Ptr
void recvScatterGatherCountsBufferLocal()
Definition: Mesh.cpp:2050
vector< int > _globalCellToMeshID
const StorageSite * getGhostCellSiteScatter(const PartIDMeshIDPair &id) const
Definition: Mesh.h:113
Array< int > & getCellColors()
Definition: Mesh.h:228
const CRConnectivity & getAllFaceCells() const
Definition: Mesh.cpp:378
map< EntryIndex, int > EntryMap
void getGatherArrays(const Array< int > &gatherArray, EntryVecMap &gatherArrayLocal, const StorageSite &site)
void faceCellsInit(vector< int > &localCellID)
void faceCellsAddInteriorFaces(vector< int > &faceID)
void faceNodesAddPartitionInterfaces(vector< int > &faceID)
void syncCounts()
Definition: Mesh.cpp:2072
const Array< VecD3 > & getNodeCoordinates() const
Definition: Mesh.h:218
pair< int, int > EntryIndex
Array< int > & getLocalToGlobal()
Definition: Mesh.h:240
Array< int > & getCellColorsOther()
Definition: Mesh.h:231
int getTag() const
Definition: StorageSite.h:84
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
void faceNodesAddMeshInterfaces(vector< int > &faceID)
int getGatherProcID() const
Definition: StorageSite.h:83
vector< int > _globalCellToLocal
void createScatterGatherIndicesBuffer()
Definition: Mesh.cpp:2124
void faceCellsAddMeshInterfaces(vector< int > &faceID, vector< int > &localCellID)
vector< FaceGroupPtr > FaceGroupList
Definition: Mesh.h:47
map< int, vector< int > > _interfaceID
vector< StorageSitePtr > _cellSite
pair< int, int > PartIDMeshIDPair
Definition: Mesh.h:62
const StorageSite & getFaces() const
Definition: Mesh.h:108
void recvScatterGatherIndicesBufferLocal()
Definition: Mesh.cpp:2172
shared_ptr< Array< int > > ArrayIntPtr
const StorageSite & getCells() const
Definition: Mesh.h:109
vector< StorageSitePtr > _nodeSite
void createInteriorFaceGroup()
void createLocalGlobalArray()
Definition: Mesh.cpp:738
void partitionInterfaceMappers()
vector< map< int, int > > _globalToLocalFaces
shared_ptr< CRConnectivity > CRConnectivityPtr
int getCountLevel1() const
Definition: StorageSite.h:72
vector< map< int, int > > _globalToLocalNodes
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
Definition: StorageSite.h:23
void debug_scatter_mappers()
map< int, const StorageSite * > IntStorageSiteMap
void faceNodesAddInteriorFaces(vector< int > &faceID)
int getOffset() const
Definition: StorageSite.h:87
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
MeshList _meshList
shared_ptr< CRConnectivity > getTranspose() const
void createScatterGatherCountsBuffer()
Definition: Mesh.cpp:2011
int getCount() const
Definition: StorageSite.h:39
vector< CRConnectivityPtr > _faceCells
vector< StorageSitePtr > _faceSite
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
Definition: StorageSite.h:24
void faceCellsAddBoundaryInterfaces(vector< int > &faceID, vector< int > &localCellID)
const FaceGroupList & getInterfaceGroups() const
Definition: Mesh.h:190
void getScatterArrays(const Array< int > &scatterArray, EntryVecMap &scatterArrayLocal, const StorageSite &site)
double min(double x, double y)
Definition: Octree.cpp:23
void createCellCellsGhostExt()
Definition: Mesh.cpp:1999
int getDimension() const
Definition: Mesh.h:105
void setCountLevel1(const int countLevel1)
Definition: StorageSite.h:69
const Mesh & _mesh
const CRConnectivity & getCellNodes() const
Definition: Mesh.cpp:426
vector< multimap< int, int > > _faceIdentifierList
void syncIndices()
Definition: Mesh.cpp:2191
void createBoundaryFaceGroup()
vector< Mesh * > MeshList
Definition: Mesh.h:439
map< int, vector< int > > _boundarySize
map< int, vector< int > > _interfaceSize
StorageSite site
Definition: Mesh.h:40
int getLength() const
Definition: Array.h:87