Memosa-FVM  0.2
MeshAssembler.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 #include <iostream>
6 #include <fstream>
7 #include <string>
8 #include <sstream>
9 #include "MeshAssembler.h"
10 #include "CRConnectivity.h"
11 #include "MultiField.h"
12 
13 using namespace std;
14 
15 MeshAssembler:: MeshAssembler( const MeshList& meshList ):_meshList( meshList )
16 {
17 
18  init();
19 }
20 
22 {
23  vector< Mesh* >::iterator it_mesh;
24  for ( it_mesh = _mesh.begin(); it_mesh != _mesh.end(); it_mesh++)
25  delete *it_mesh;
26 }
27 
28 
29 void
31 {
32  int dim = _meshList.at(0)->getDimension();
33  //construct merged Linearsystem
34  _mesh.push_back( new Mesh( dim) );
35 
36 
37  _interfaceNodesSet.resize( _meshList.size() );
39 
40  setCellsSite();
41  setFacesSite();
43  //countInterfaceNodes();
44  setNodesSite();
46  setFaceCells();
48  setFaceNodes();
49  setCoord();
50  setMesh();
52 
53 }
54 
55 //setting storagesite for cells
56 void
58 {
59  int siteCount = 0;
60  int siteSelfCount = 0;
61  for ( unsigned int id = 0; id < _meshList.size(); id++ ){
62  const StorageSite& site = _meshList[id]->getCells();
63  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
64  int nghost = 0;
65  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
66  const Array<int>& fromIndices = *(mpos.second);
67  nghost += fromIndices.getLength();
68  }
69  siteCount += site.getCount() - nghost;
70  siteSelfCount += site.getSelfCount();
71  }
72 
73  _cellSite = StorageSitePtr( new StorageSite(siteSelfCount, siteCount-siteSelfCount) );
74 
75 }
76 
77 //setting storagesite for faces
78 void
80 {
81  int faceCount = 0;
82  for ( unsigned int id = 0; id < _meshList.size(); id++ ){
83  const StorageSite& site = _meshList[id]->getFaces();
84  faceCount += site.getCount();
85  }
86 
87  int sharedFaceCount = 0;
88  for ( unsigned int id = 0; id < _meshList.size(); id++ ){
89  const FaceGroupList & faceGroupList = _meshList[id]->getInterfaceGroups();
90  for ( int n = 0; n < _meshList[id]->getInterfaceGroupCount(); n++ ){
91  const StorageSite& site = faceGroupList[n]->site;
92  sharedFaceCount += site.getCount();
93  }
94  }
95  _faceSite = StorageSitePtr( new StorageSite(faceCount - sharedFaceCount / 2 ) );
96  assert( sharedFaceCount%2 == 0 );
97 
98 }
99 
100 
101 void
103 {
104  //loop over meshes
105  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
106  const Mesh& mesh = *(_meshList.at(n));
107  const CRConnectivity& faceNodes = mesh.getAllFaceNodes();
108  //const CRConnectivity& faceCells = mesh.getAllFaceCells();
109  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
110  //looop over interfaces
111  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
112  int id = faceGroupList[i]->id;
113  set<int>& nodes = _interfaceNodesSet[n][id];
114  //loop over faces to fill nodes
115  const StorageSite& site = faceGroupList[i]->site;
116  int jstart = site.getOffset();
117  int jend = jstart + site.getCount();
118  for ( int face = jstart; face < jend; face++ ){
119  //loop over face surronding nodes
120  for ( int node = 0; node < faceNodes.getCount(face); node++ ){
121  nodes.insert( faceNodes(face,node) );
122 /* cout << " nemsh = " << n << "faceNodes(" << face << "," << node << ") = " << faceNodes(face,node) <<
123  " faceCells(" << face << "," << "0) = " << faceCells(face,0) <<
124  " faceCells(" << face << "," << "1) = " << faceCells(face,1) << endl;*/
125  }
126  }
127  }
128  }
129 
130 }
131 
132 //this method counts interface nodes after merging,
133 //it seems only way to match is using its coordinates
134 void
136 {
137 
138  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
139  const Mesh& mesh = *(_meshList.at(n));
140  const StorageSite& faceSite = mesh.getFaces();
141  const CRConnectivity& cellFaces = mesh.getCellFaces();
142  for ( int i = 0; i < faceSite.getCount(); i++ ){
143  cout << " cellFaces[" << i << " ] = ";
144  for ( int j = 0; j < cellFaces.getCount(i); j++ )
145  cout << " " << cellFaces(i,j);
146  cout << endl;
147  }
148  }
149  //writing mapping
150  for ( unsigned int i = 0; i < _meshList.size(); i++ ){
151  const StorageSite& thisSite = _meshList[i]->getCells();
152  const StorageSite::ScatterMap& scatterMap = thisSite.getScatterMap();
153  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
154  const StorageSite& oSite = *(mpos.first);
155  const Array<int>& fromIndices = *(mpos.second);
156  const Array<int>& toIndices = *(oSite.getGatherMap().find(&thisSite)->second);
157  cout << " fromIndices.getLength() = " << fromIndices.getLength() << endl;
158  cout << " scatterArray " << endl;
159  for ( int n = 0; n < fromIndices.getLength(); n++){
160  cout << " fromIndices[" << n << "] = " << fromIndices[n] << " toIndices[" << n << "] = " << toIndices[n] << endl;
161  }
162  }
163  }
164 
165 }
166 
167 //setting Storage site for nodes
168 void
170 {
171  //count inner nodes for assembly
172  int nodeCount = getInnerNodesCount();
173  int nInterfaceNodes = getInterfaceNodesCount();
174  _nodeSite = StorageSitePtr( new StorageSite(nodeCount + nInterfaceNodes) );
175 
176 }
177 
178 //gettin localToGlobal and globalToLocal for cell
179 void
181 {
182  //count cells
183  int selfCount = 0;
184  for ( unsigned int id = 0; id < _meshList.size(); id++ ){
185  const StorageSite& cellSite = _meshList[id]->getCells();
186  selfCount += cellSite.getSelfCount();
187  }
188  _globalCellToMeshID.resize( selfCount );
189  _globalCellToLocal.resize ( selfCount );
190  //loop over meshes
191  int glblIndx = 0;
192  for ( unsigned int id = 0; id < _meshList.size(); id++ ){
193  const StorageSite& cellSite = _meshList[id]->getCells();
194  _localCellToGlobal[id] = ArrayIntPtr( new Array<int>( cellSite.getCount() ) );
195  Array<int>& localToGlobal = *_localCellToGlobal[id];
196  localToGlobal = -1; //initializer
197  //loop over inner cells
198  for ( int n = 0; n < cellSite.getSelfCount(); n++ ){
199  localToGlobal[n] = glblIndx;
200  _globalCellToMeshID[glblIndx] = id; //belongs to which mesh from global Cell ID
201  _globalCellToLocal [glblIndx] = n; //gives local Cell ID from Global ID but which mesh comes from mapGlobalCellToMeshID
202  glblIndx++;
203  }
204  }
205 
206  //creating cellID MultiField to use sync() operation
207  shared_ptr<MultiField> cellMultiField = shared_ptr<MultiField>( new MultiField() );
208  shared_ptr<Field> cellField = shared_ptr<Field> ( new Field("cellID") );
209 
210  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
211  const StorageSite* site = &_meshList[n]->getCells();
212  MultiField::ArrayIndex ai( cellField.get(), site );
213  shared_ptr<Array<int> > cIndex(new Array<int>(site->getCount()));
214  *cIndex = -1;
215  cellMultiField->addArray(ai,cIndex);
216  }
217 
218  //fill local mesh with global Indx
219  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
220  const StorageSite* site = &_meshList[n]->getCells();
221  MultiField::ArrayIndex ai( cellField.get(), site );
222  Array<int>& localCell = dynamic_cast< Array<int>& >( (*cellMultiField)[ai] );
223  const Array<int>& localToGlobal = *_localCellToGlobal[n];
224  for ( int i = 0; i < site->getSelfCount(); i++ )
225  localCell[i] =localToGlobal[i];
226  }
227  //sync opeartion
228  cellMultiField->sync();
229 
230  //fill local mesh with global Indx after sync
231  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
232  const StorageSite* site = &_meshList[n]->getCells();
233  MultiField::ArrayIndex ai( cellField.get(), site );
234  const Array<int>& localCell = dynamic_cast< const Array<int>& >( (*cellMultiField)[ai] );
235  Array<int>& localToGlobal = *_localCellToGlobal[n];
236  for ( int i = 0; i < site->getCount(); i++ )
237  localToGlobal[i] = localCell[i];
238  }
239 
240 
241 // //above algorithm fill localCellToGlobal for only inner cells but we will do ghost cells for interfaces
242 // for ( unsigned int i = 0; i < _meshList.size(); i++ ){
243 // const StorageSite& thisSite = _meshList[i]->getCells();
244 // const StorageSite::ScatterMap& scatterMap = thisSite.getScatterMap();
245 // foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
246 // const StorageSite& oSite = *(mpos.first);
247 // const Array<int>& fromIndices = *(mpos.second);
248 // const Array<int>& toIndices = *(oSite.getGatherMap().find(&thisSite)->second);
249 // cout << " fromIndices.getLength() = " << fromIndices.getLength() << endl;
250 // cout << " scatterArray " << endl;
251 // for ( int n = 0; n < fromIndices.getLength(); n++){
252 // cout << " fromIndices[" << n << "] = " << fromIndices[n] << " toIndices[" << n << "] = " << toIndices[n] << endl;
253 // }
254 // }
255 // }
256 
257 }
258 
259 //getting CRConnectivity faceCells
260 void
262 {
264  _faceCells->initCount();
265 
266  //addCount
267  const int cellCount = 2;
268  for ( int i = 0; i < _faceSite->getCount(); i++ )
269  _faceCells->addCount(i, cellCount); // face has always two cells
270  //finish count
271  _faceCells->finishCount();
272 
273  //first interior faces
274  int face = 0;
275  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
276  const Mesh& mesh = *(_meshList[n]);
277  const CRConnectivity& faceCells = mesh.getAllFaceCells();
278  const FaceGroup& faceGroup = mesh.getInteriorFaceGroup();
279  const Array<int>& localToGlobal = *_localCellToGlobal[n];
280  for ( int i = 0; i < faceGroup.site.getCount(); i++ ){
281  int cell1 = faceCells(i,0);
282  int cell2 = faceCells(i,1);
283  _faceCells->add( face, localToGlobal[ cell1 ] );
284  _faceCells->add( face, localToGlobal[ cell2 ] );
285  face++;
286  }
287  }
288 
289  //now add interfaces
290  set<int> faceGroupSet; // this set make sure that no duplication in sweep
291  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
292  const Mesh& mesh = *(_meshList[n]);
293  const CRConnectivity& faceCells = mesh.getAllFaceCells();
294  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
295  const Array<int>& localToGlobal = *_localCellToGlobal[n];
296  //loop over interfaces
297  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
298  int faceGroupID = faceGroupList[i]->id;
299  //pass only if it is not in faceGroupSet
300  if ( faceGroupSet.count( faceGroupID) == 0 ){
301  faceGroupSet.insert( faceGroupID );
302  //sweep interfaces for add up operation
303  int ibeg = faceGroupList[i]->site.getOffset();
304  int iend = ibeg + faceGroupList[i]->site.getCount();
305  for ( int i = ibeg; i < iend; i++ ){
306  int cell1 = faceCells(i,0);
307  int cell2 = faceCells(i,1);
308  _faceCells->add( face, localToGlobal[ cell1 ] );
309  _faceCells->add( face, localToGlobal[ cell2 ] );
310  face++;
311  }
312  }
313  }
314  }
315  //now add boundary faces
316  int indx = _cellSite->getSelfCount();
317  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
318  const Mesh& mesh = *(_meshList[n]);
319  const StorageSite& cellSite = mesh.getCells();
320  const CRConnectivity& faceCells = mesh.getAllFaceCells();
321  const FaceGroupList& bounGroupList = mesh.getBoundaryFaceGroups();
322  const Array<int>& localToGlobal = *_localCellToGlobal[n];
323  //loop over interfaces
324  for ( int i = 0; i <mesh.getBoundaryGroupCount(); i++ ){
325  //sweep interfaces for add up operation
326  int ibeg = bounGroupList[i]->site.getOffset();
327  int iend = ibeg + bounGroupList[i]->site.getCount();
328  for ( int i = ibeg; i < iend; i++ ){
329  int cell1 = faceCells(i,0);
330  int cell2 = faceCells(i,1);
331  //cell1
332  if ( cell1 < cellSite.getSelfCount() )
333  _faceCells->add( face, localToGlobal[ cell1 ] );
334  else
335  _faceCells->add( face, localToGlobal[ cell2 ] );
336  //adding boundary cells
337  _faceCells->add( face, indx );
338  indx++;
339  face++;
340  }
341  }
342  }
343 
344  //finishAdd
345  _faceCells->finishAdd();
346 
347 
348 }
349 
350 //getting CRConnectivity faceNodes
351 void
353 {
355  _faceNodes->initCount();
356  //addCount
357  const Mesh& mesh0 = *_meshList[0];
358  const int nodeCount = mesh0.getAllFaceNodes().getRow()[1] - mesh0.getAllFaceNodes().getRow()[0];
359  for ( int i = 0; i < _faceSite->getCount(); i++ )
360  _faceNodes->addCount(i, nodeCount);
361  //finish count
362  _faceNodes->finishCount();
363  //first interior faces
364  int face = 0;
365  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
366  const Mesh& mesh = *(_meshList[n]);
367  const CRConnectivity& faceNodes = mesh.getAllFaceNodes();
368  const FaceGroup& faceGroup = mesh.getInteriorFaceGroup();
369  const StorageSite& faceGroupSite = faceGroup.site;
370  const Array<int>& localToGlobal = *_localNodeToGlobal[n];
371  for ( int i = 0; i < faceGroupSite.getCount(); i++ ){
372  for ( int j = 0; j < faceNodes.getCount(i); j++ ){
373  int nodeID = faceNodes(i,j);
374  _faceNodes->add( face, localToGlobal[nodeID] );
375  }
376  face++;
377  }
378  }
379 
380  //interfaces (mesh)
381  set<int> faceGroupSet;
382  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
383  const Mesh& mesh = *(_meshList[n]);
384  const CRConnectivity& faceNodes = mesh.getAllFaceNodes();
385  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
386  const Array<int>& localToGlobal = *_localNodeToGlobal[n];
387  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
388  int faceGroupID = faceGroupList[i]->id;
389  //pass only if it is not in faceGroupSet
390  if ( faceGroupSet.count( faceGroupID) == 0 ){
391  faceGroupSet.insert( faceGroupID );
392  //sweep interfaces for add up operation
393  int ibeg = faceGroupList[i]->site.getOffset();
394  int iend = ibeg + faceGroupList[i]->site.getCount();
395  for ( int i = ibeg; i < iend; i++ ){
396  for ( int j = 0; j < faceNodes.getCount(i); j++ ){
397  int nodeID = faceNodes(i,j);
398  _faceNodes->add( face, localToGlobal[nodeID] );
399  }
400  face++;
401  }
402  }
403  }
404  }
405  //interior face size stored
406  _interiorFaceSize = face;
407 
408 
409  //now add boundary faces
410  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
411  const Mesh& mesh = *(_meshList[n]);
412  const CRConnectivity& faceNodes = mesh.getAllFaceNodes();
413  const FaceGroupList& bounGroupList = mesh.getBoundaryFaceGroups();
414  const Array<int>& localToGlobal = *_localNodeToGlobal[n];
415  //loop over interfaces
416  for ( int i = 0; i <mesh.getBoundaryGroupCount(); i++ ){
417  //sweep interfaces for add up operation
418  int ibeg = bounGroupList[i]->site.getOffset();
419  int iend = ibeg + bounGroupList[i]->site.getCount();
420  for ( int i = ibeg; i < iend; i++ ){
421  for ( int j = 0; j < faceNodes.getCount(i); j++ ){
422  int nodeID = faceNodes(i,j);
423  _faceNodes->add( face, localToGlobal[nodeID] );
424  }
425  face++;
426  }
427  }
428  }
429 
430  //finishAdd
431  _faceNodes->finishAdd();
432 }
433 
434 //count only inner nodes of all mesh after assembly
435 int
437  int nodeCount = 0;
438  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
439  const Mesh& mesh = *(_meshList.at(n));
440  const CRConnectivity& faceNodes = mesh.getAllFaceNodes();
441  const StorageSite& site = _meshList[n]->getNodes();
442  Array<int> nodeArray( site.getCount() );
443  nodeArray = -1;
444  //looop over interior faces
445  int nface = mesh.getFaces().getCount();
446  for ( int i = 0; i < nface; i++ )
447  //loop over face surronding nodes
448  for ( int node = 0; node < faceNodes.getCount(i); node++ )
449  nodeArray[ faceNodes(i,node) ] = 1;
450 
451  //loop over interface faces to reset
452  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
453  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
454  int id = faceGroupList[i]->id;
455  set<int>& nodes = _interfaceNodesSet[n][id];
456  foreach ( const set<int>::value_type node, nodes )
457  nodeArray[ node] = -1; //reseting again, we want to seperate inner/boundary nodes than interface nodes
458  }
459  //node count
460  for ( int i = 0; i < nodeArray.getLength(); i++ )
461  if ( nodeArray[i] != -1 ) nodeCount++;
462  }
463 
464  return nodeCount;
465 }
466 
467 //count nodes (duplicated) on shared interfaces from each local mesh side
468 int
470 {
471  //loop over meshes
472  int nInterfaceNodes = 0;
473  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
474  const Mesh& mesh = *(_meshList.at(n));
475  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
476  //looop over interfaces
477  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
478  int id = faceGroupList[i]->id;
479  const set<int>& nodes = _interfaceNodesSet[n][id];
480  nInterfaceNodes += nodes.size();
481  }
482  }
483  return nInterfaceNodes;
484 }
485 
486 //count nodes on interfaces (not duplicated)
487 int
489 {
490  //count nodes on shared interfaces (duplicated)
491  int nInterfaceNodes = getInterfaceNodesDuplicatedCount();
492 
493  Array< Mesh::VecD3 > interfaceNodeValues ( nInterfaceNodes );
494  Array< int > globalIndx ( nInterfaceNodes );
495  globalIndx = -1;
496 
497  //filing interfaceNodeValues
498  int indx = 0;
499  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
500  const Mesh& mesh = *(_meshList.at(n));
501  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
502  const Array<Mesh::VecD3>& coord = mesh.getNodeCoordinates();
503  //looop over interfaces
504  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
505  int id = faceGroupList[i]->id;
506  const set<int>& nodes = _interfaceNodesSet[n][id];
507  foreach ( const set<int>::value_type node, nodes ){
508  interfaceNodeValues[indx] = coord[node];
509  indx++;
510  }
511  }
512  }
513 
514  //greedy algorithm to fill interfaceNodeCount
515  indx =0;
516  for ( int i = 0; i < nInterfaceNodes; i++ ){
517  if ( globalIndx[i] == -1 ){
518  globalIndx[i] = indx;
519  double x = interfaceNodeValues[i][0];
520  double y = interfaceNodeValues[i][1];
521  double z = interfaceNodeValues[i][2];
522  for ( int j = i+1; j < nInterfaceNodes; j++ ){
523  if ( globalIndx[j] == -1 ){
524  double xOther = interfaceNodeValues[j][0];
525  double yOther = interfaceNodeValues[j][1];
526  double zOther = interfaceNodeValues[j][2];
527  if ( x == xOther && y == yOther && z == zOther )
528  globalIndx[j] = indx;
529  }
530  }
531  indx++;
532  }
533  }
534 
535 
536  _nInterfaceNodes = indx;
537  //filling localInterfaceNodes to GlobalNodes data structure
538  indx = 0;
539  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
540  const Mesh& mesh = *(_meshList.at(n));
541  const FaceGroupList& faceGroupList = mesh.getInterfaceGroups();
542  //looop over interfaces
543  for ( int i = 0; i < mesh.getInterfaceGroupCount(); i++ ){
544  int id = faceGroupList[i]->id;
545  const set<int>& nodes = _interfaceNodesSet[n][id];
546  foreach ( const set<int>::value_type node, nodes ){
547  _localInterfaceNodesToGlobalMap[n][node] = globalIndx[indx];
548  indx++;
549  }
550  }
551  }
552 
553  return _nInterfaceNodes;
554 }
555 
556 //local Nodes to global Nodes
557 void
559 {
560 
561  int glblIndx = _nInterfaceNodes; // node numbering first from interfaces
562  cout << " glbIndx = " << glblIndx << endl;
563  for ( unsigned int id = 0; id < _meshList.size(); id++ ){
564  const StorageSite& nodeSite = _meshList[id]->getNodes();
565  const StorageSite& faceSite = _meshList[id]->getFaces();
566  const CRConnectivity& faceNodes = _meshList[id]->getAllFaceNodes();
567  _localNodeToGlobal[id] = ArrayIntPtr( new Array<int>( nodeSite.getCount() ) );
568  Array<bool> isVisitedNodes( nodeSite.getCount() );
569  isVisitedNodes = false;
570  Array<int>& localToGlobal = *_localNodeToGlobal[id];
571  localToGlobal = -1; //initializer
572  const map<int,int>& localInterfaceNodesToGlobalMap = _localInterfaceNodesToGlobalMap[id];
573  //loop over faces then connecting nodes
574  for ( int face = 0; face < faceSite.getCount(); face++ ){
575  for ( int n = 0; n < faceNodes.getCount(face); n++ ){
576  int nodeID = faceNodes(face,n);
577  //cout << " nodeID = " << nodeID << " isVisitedNodes = " << isVisitedNodes[nodeID] << endl;
578  if ( !isVisitedNodes[nodeID]){ //if it is not visited, we renumber it
579  if ( localInterfaceNodesToGlobalMap.count( nodeID ) == 0 )
580  localToGlobal[nodeID] = glblIndx++;
581  else
582  localToGlobal[nodeID] = localInterfaceNodesToGlobalMap.find(nodeID)->second;
583  isVisitedNodes[nodeID] = true;
584  }
585  }
586  }
587  }
588 
589 
590 
591 }
592 
593 
594 void
596 {
597  //interior face size stored
598  int face = _interiorFaceSize;
599  //now add boundary faces
600  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
601  const Mesh& mesh = *(_meshList[n]);
602  const FaceGroupList& bounGroupList = mesh.getBoundaryFaceGroups();
603  //loop over interfaces
604  for ( int i = 0; i <mesh.getBoundaryGroupCount(); i++ ){
605  //sweep interfaces for add up operation
606  int size = bounGroupList[i]->site.getCount();
607  int offset = face;
608  int id = bounGroupList[i]->id;
609  string boundaryType = bounGroupList[i]->groupType;
610  //update face for offset
611  face += size;
612  _mesh.at(0)->createBoundaryFaceGroup( size, offset, id, boundaryType );
613  }
614  }
615 
616 }
617 
618 //setting coordinates
619 void
621 {
622  _coord = ArrayVecD3Ptr(new Array<Mesh::VecD3>(_nodeSite->getCount()));
623  for ( unsigned n = 0; n < _meshList.size(); n++ ){
624  const Mesh& mesh = *(_meshList[n]);
625  const StorageSite& nodeSite = mesh.getNodes();
626  const Array<int>& localToGlobal = *_localNodeToGlobal[n];
627  const Array<Mesh::VecD3>& coordLocal = mesh.getNodeCoordinates();
628  //loop over local mesh nodes
629  for ( int i = 0; i < nodeSite.getCount(); i++ ){
630  if ( localToGlobal[i] != -1 ) //so mapping is well defined
631  (*_coord)[ localToGlobal[i] ] = coordLocal[i];
632  }
633  }
634 }
635 
636 //set StorageSites
637 void
639 {
640  StorageSite& faceSite = _mesh.at(0)->getFaces();
641  StorageSite& cellSite = _mesh.at(0)->getCells();
642  StorageSite& nodeSite = _mesh.at(0)->getNodes();
643  faceSite.setCount( _faceSite->getCount() );
644  cellSite.setCount( _cellSite->getSelfCount(), _cellSite->getCount()-_cellSite->getSelfCount() );
645  nodeSite.setCount( _nodeSite->getCount() );
646 }
647 //setting assembled mesh
648 void
650 {
651  //set sites
652  setSites();
653  //interior face group
654  _mesh.at(0)->createInteriorFaceGroup( _interiorFaceSize );
655  //boundary face group
657  //setting coordinates
658  _mesh.at(0)->setCoordinates( _coord );
659  //setting faceNodes CRConnecitivty
660  _mesh.at(0)->setFaceNodes ( _faceNodes );
661  //setting faceCells CRConnectivity
662  _mesh.at(0)->setFaceCells ( _faceCells );
663 
664 }
665 
666 //filling _cellColor array in the merged mesh. This will be used in Parmetis (elmWghts)
667 void
669 {
670  //allocate Mesh::_cellColor
671  _mesh.at(0)->createCellColor();
672 
673  Array<int>& cellColor = _mesh.at(0)->getCellColors();
674  //first interior faces of local meshes
675  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
676  const Mesh& mesh = *(_meshList[n]);
677  const CRConnectivity& faceCells = mesh.getAllFaceCells();
678  const FaceGroup& faceGroup = mesh.getInteriorFaceGroup();
679  const Array<int>& localToGlobal = *_localCellToGlobal[n];
680  for ( int i = 0; i < faceGroup.site.getCount(); i++ ){
681  int cell1 = faceCells(i,0);
682  int cell2 = faceCells(i,1);
683  cellColor[ localToGlobal[ cell1 ] ] = n;
684  cellColor[ localToGlobal[ cell2 ] ] = n;
685  }
686  }
687 
688  //now color only boundary cells
689  int indx = _cellSite->getSelfCount();
690  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
691  const Mesh& mesh = *(_meshList[n]);
692  const FaceGroupList& bounGroupList = mesh.getBoundaryFaceGroups();
693  //loop over interfaces
694  for ( int i = 0; i <mesh.getBoundaryGroupCount(); i++ ){
695  //sweep interfaces for add up operation
696  int ibeg = bounGroupList[i]->site.getOffset();
697  int iend = ibeg + bounGroupList[i]->site.getCount();
698  for ( int i = ibeg; i < iend; i++ ){
699  cellColor[indx] = n;
700  //adding boundary cells
701  indx++;
702  }
703  }
704  }
705  //assigning Mesh::numOfAssembleMesh
706  _mesh[0]->setNumOfAssembleMesh( int(_meshList.size()) );
707 
708 }
709 
710 
711 void
713 {
714  debug_file_open("sites");
715  _debugFile << " cells.getSelfCount() = " << _cellSite->getSelfCount() << " cells.selfCount() = " << _cellSite->getCount() << endl;
716  _debugFile << " faces.getSelfCount() = " << _faceSite->getSelfCount() << " faces.selfCount() = " << _faceSite->getCount() << endl;
717  _debugFile << " nodes.getSelfCount() = " << _nodeSite->getSelfCount() << " nodes.selfCount() = " << _nodeSite->getCount() << endl;
719 }
720 
721 
722 void
724 {
725  debug_file_open("localToGlobal");
726  //mapLocalToGlobal
727  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
728  _debugFile << " mesh = " << n << endl;
729  const Array<int>& localToGlobal = *_localCellToGlobal[n];
730  for ( int i = 0; i < localToGlobal.getLength(); i++ )
731  _debugFile << " localCellToGlobal[" << i << "] = " << localToGlobal[i] << endl;
732  _debugFile << endl;
733  }
735 }
736 
737 void
739 {
740  debug_file_open("globalCellToMeshID");
741  //globalCellToMeshID
742  for ( unsigned int i = 0; i < _globalCellToMeshID.size(); i++ )
743  _debugFile << " globalCellToMeshID[" << i << "] = " << _globalCellToMeshID[i] << endl;
744 
745  _debugFile << endl;
746  //globalCellToLocal
747  for ( unsigned int i = 0; i < _globalCellToLocal.size(); i++ )
748  _debugFile << " globalCellToLocal[" << i << "] = " << _globalCellToLocal[i] << endl;
749 
751 }
752 
753 
754 void
756 {
757  debug_file_open("syncLocalToGlobal");
758  //printing things
759  _debugFile << " localCellToGlobal after sync() opeartion " << endl;
760  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
761  const Array<int>& localToGlobal = *_localCellToGlobal[n];
762  _debugFile << " mesh = " << n << endl;
763  for ( int i = 0; i < localToGlobal.getLength(); i++ )
764  _debugFile << " localToGlobal[" << i << "] = " << localToGlobal[i] << endl;
765  _debugFile << endl;
766  }
768 }
769 
770 
771 void
773 {
774  debug_file_open("faceCells");
775  //faceCells
776  _debugFile << " faceCells Connectivity " << endl;
777  for ( int i = 0; i < _faceSite->getCount(); i++ ) {
778  int ncells = _faceCells->getCount(i);
779  for ( int j = 0; j < ncells; j++ ){
780  _debugFile << " faceCells(" << i << "," << j << ") = " << (*_faceCells)(i,j);
781  }
782  _debugFile << endl;
783  }
785 }
786 
787 void
789 {
790  debug_file_open("localNodeToGlobal");
791  //localNodeToGlobal
792  _debugFile << " localNodeToGlobal " << endl;
793  for ( unsigned int n = 0; n < _meshList.size(); n++ ){
794  const Array<int>& localToGlobal = *_localNodeToGlobal[n];
795  for ( int i = 0; i < localToGlobal.getLength(); i++ )
796  _debugFile << " localToGlobal[" << i << "] = " << localToGlobal[i] << endl;
797  _debugFile << endl;
798  }
800 }
801 
802 void
804 {
805  debug_sites();
809  debug_faceCells();
811 
812 }
813 
814 
815 
816 void
817 MeshAssembler::debug_file_open( const string& fname_ )
818 {
819  string fname = "MESHASSEMBLER_"+fname_+".dat";
820  _debugFile.open( fname.c_str() );
821 }
822 
823 void
825 {
826  _debugFile.close();
827 }
const CRConnectivity & getAllFaceNodes() const
Definition: Mesh.cpp:368
const FaceGroupList & getBoundaryFaceGroups() const
Definition: Mesh.h:187
int getCount(const int i) const
const Array< int > & getRow() const
const FaceGroup & getInteriorFaceGroup() const
Definition: Mesh.h:181
int getBoundaryGroupCount() const
Definition: Mesh.h:184
int getSelfCount() const
Definition: StorageSite.h:40
int getInterfaceNodesDuplicatedCount()
Definition: Mesh.h:28
shared_ptr< Array< Mesh::VecD3 > > ArrayVecD3Ptr
Definition: MeshAssembler.h:25
ofstream _debugFile
Definition: MeshAssembler.h:97
const StorageSite & getNodes() const
Definition: Mesh.h:110
Definition: Field.h:14
Definition: Mesh.h:49
vector< int > _globalCellToLocal
Definition: MeshAssembler.h:86
void debug_globalCellToMeshID_mappers()
void setCount(const int selfCount, const int nGhost=0)
Definition: StorageSite.h:42
shared_ptr< Array< int > > ArrayIntPtr
Definition: MeshAssembler.h:20
int getInterfaceGroupCount() const
Definition: Mesh.h:185
void debug_faceCells()
shared_ptr< StorageSite > StorageSitePtr
Definition: MeshAssembler.h:22
StorageSitePtr _cellSite
Definition: MeshAssembler.h:78
void debug_localNodeToGlobal()
MeshList _mesh
const CRConnectivity & getAllFaceCells() const
Definition: Mesh.cpp:378
const CRConnectivity & getCellFaces() const
Definition: Mesh.cpp:454
void debug_sync_localToGlobal_mappers()
CRConnectivityPtr _faceNodes
Definition: MeshAssembler.h:94
MeshAssembler(const MeshList &meshList)
const Array< VecD3 > & getNodeCoordinates() const
Definition: Mesh.h:218
void setMeshCellColor()
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
void debug_file_open(const string &fname)
vector< FaceGroupPtr > FaceGroupList
Definition: Mesh.h:47
vector< int > _globalCellToMeshID
Definition: MeshAssembler.h:85
CRConnectivityPtr _faceCells
Definition: MeshAssembler.h:93
void countInterfaceNodes()
const StorageSite & getFaces() const
Definition: Mesh.h:108
StorageSitePtr _nodeSite
Definition: MeshAssembler.h:80
void setInterfaceNodes()
const StorageSite & getCells() const
Definition: Mesh.h:109
int getInterfaceNodesCount()
ArrayVecD3Ptr _coord
Definition: MeshAssembler.h:95
map< int, ArrayIntPtr > _localNodeToGlobal
Definition: MeshAssembler.h:89
const MeshList _meshList
Definition: MeshAssembler.h:76
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
void debug_localToGlobal_mappers()
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
Definition: StorageSite.h:23
shared_ptr< CRConnectivity > CRConnectivityPtr
Definition: MeshAssembler.h:23
int getOffset() const
Definition: StorageSite.h:87
void setBoundaryFaceGroup()
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
map< int, ArrayIntPtr > _localCellToGlobal
Definition: MeshAssembler.h:84
int getCount() const
Definition: StorageSite.h:39
vector< map< int, int > > _localInterfaceNodesToGlobalMap
Definition: MeshAssembler.h:88
VecMap _interfaceNodesSet
Definition: MeshAssembler.h:82
const FaceGroupList & getInterfaceGroups() const
Definition: Mesh.h:190
StorageSitePtr _faceSite
Definition: MeshAssembler.h:79
int getInnerNodesCount()
void debug_file_close()
vector< Mesh * > MeshList
Definition: Mesh.h:439
StorageSite site
Definition: Mesh.h:40
int getLength() const
Definition: Array.h:87