Memosa-FVM  0.2
FluentReader.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 "misc.h"
6 #include "FluentReader.h"
7 #include "CRConnectivity.h"
8 #include "StorageSite.h"
9 #include "OneToOneIndexMap.h"
10 #include "Mesh.h"
11 #include "OneToOneIndexMap.h"
12 
13 #include "Cell.h"
14 
15 enum
16  {
21  };
22 
23 enum
24  {
25  PERIODIC = 12,
27  };
28 
29 
30 FluentReader::FluentReader(const string& fileName) :
31  SchemeReader(fileName),
32  _dimension(0),
33  _numCells(0),
34  _numFaces(0),
35  _numNodes(0),
36  _numBoundaryFaces(0),
37  _cells(0),
38  _faces(0),
39  _nodes(0),
40  _faceNodes(),
41  _faceCells(),
42  _cellFaces(),
43  _cellNodes(),
44  _nodeCells(),
45  _faceZones(),
46  _cellZones(),
47  _coords(0),
48  _rpVarStringLength(0)
49 {}
50 
52 {}
53 
55  const int iBeg,
56  const int iEnd,
57  const bool isBinary, const bool isDP)
58 {
60 
61  const int count = iEnd-iBeg+1;
62  const int nread = _dimension*count;
63  if (isDP)
64  {
65  double *buff;
66  if (_dimension == 3)
67  buff = (double*) a.getData() + (iBeg-1)*_dimension;
68  else
69  buff = new double[nread];
70 
71  if (isBinary)
72  {
73  if (nread != (int)fread(buff,sizeof(double),nread,_fp))
74  cerr << "error reading dp binary nodes" << endl;
75  }
76  else
77  {
78  double *bp = buff;
79  for(int i=0; i<nread; i++)
80  if (fscanf(_fp,"%le",bp++) != 1)
81  cerr << "error reading dp formatted nodes" << endl;
82  }
83 
84  if (_dimension == 2)
85  {
86  double *bp = buff;
87  for(int i=iBeg; i<=iEnd; i++)
88  {
89  a[i-1][0] = *bp++;
90  a[i-1][1] = *bp++;
91  }
92 
93  delete [] buff;
94  }
95  }
96  else
97  {
98  float *buff = new float[nread];
99  if (isBinary)
100  {
101  if (nread != (int)fread(buff,sizeof(float),nread,_fp))
102  cerr << "error reading sp binary nodes" << endl;
103  }
104  else
105  {
106  float *bp = buff;
107  for(int i=0; i<nread; i++)
108  if (fscanf(_fp,"%e",bp++) != 1)
109  cerr << "error reading sp formatted nodes" << endl;
110  }
111 
112  float *bp = buff;
113  for(int i=iBeg; i<=iEnd; i++)
114  for(int d=0; d<_dimension; d++)
115  a[i-1][d] = *bp++;
116 
117  delete [] buff;
118  }
119 }
120 
121 void
122 FluentReader::readNodes(const int pass, const bool isBinary,
123  const bool isDP, const int sectionID)
124 {
125  int threadId, iBeg, iEnd, type, dummy;
126  readHeader(threadId,iBeg,iEnd,type,dummy);
127  if (pass == READ_SIZES)
128  {
129  if (threadId == 0)
130  {
131  _numNodes=iEnd;
132  }
133  else
134  {
135  moveToListOpen();
136  }
137  if (isBinary)
138  closeSectionBinary(sectionID);
139  else
140  closeSection();
141  }
142  else if (pass == READ_COUNTS)
143  {
144  if (threadId != 0)
145  {
146  moveToListOpen();
147  }
148  if (isBinary)
149  closeSectionBinary(sectionID);
150  else
151  closeSection();
152  }
153  else if (pass == READ_MESH)
154  {
155  if (threadId != 0)
156  {
157  readVectorData(_coords,iBeg,iEnd,isBinary,isDP);
158  }
159  if (isBinary)
160  closeSectionBinary(sectionID);
161  else
162  closeSection();
163  }
164 
165  return;
166 }
167 
168 void
169 FluentReader::readCells(const int pass, const bool isBinary,
170  const int sectionID)
171 {
172  int threadId, iBeg, iEnd, type, dummy;
173  readHeader(threadId,iBeg,iEnd,type,dummy);
174  if (pass == READ_SIZES)
175  {
176  if (threadId == 0)
177  {
178  _numCells=iEnd;
179  }
180  else if ((type == 1) || (type == 17))
181  {
182  FluentCellZone *cz = new FluentCellZone();
183  cz->ID=threadId;
184  cz->iBeg=iBeg-1;
185  cz->iEnd=iEnd-1;
186  cz->threadType=type;
187  _cellZones[threadId]=cz;
188  }
189  else if (type == 32)
190  {
191  _numCells -= (iEnd-iBeg+1);
192  }
193  else
194  {
195  throw CException("cell thread type not handled");
196  }
197  }
198  if (isBinary)
199  closeSectionBinary(sectionID);
200  else
201  closeSection();
202 }
203 
204 
205 void
206 FluentReader::readFaces(const int pass, const bool isBinary,
207  const int sectionID)
208 {
209  int threadId, iBeg, iEnd, type, shape;
210  readHeader(threadId,iBeg,iEnd,type,shape);
211 
212  // cerr << " thread id " << threadId << endl;
213  if (pass == READ_SIZES)
214  {
215  if (threadId == 0)
216  {
217  _numFaces=iEnd;
218  }
219  else
220  {
221  if ((type != 0) && (type != 31))
222  {
223  FluentFaceZone *fz = new FluentFaceZone();
224  fz->ID=threadId;
225  fz->iBeg=iBeg-1;
226  fz->iEnd=iEnd-1;
227  fz->threadType=type;
228  fz->partnerId = -1;
229  _faceZones[threadId]=fz;
230 
231 
232  moveToListOpen();
233  for(int f=iBeg; f<=iEnd; f++)
234  {
235  int numNodes = shape;
236  if (shape == 0 || shape == 5)
237  numNodes = readInt(isBinary);
238 
239  skipInt(numNodes,isBinary);
240  int c0 = readInt(isBinary);
241  int c1 = readInt(isBinary);
242 
243  if (c0 == 0 || c1 == 0)
245  }
246  }
247  else
248  {
249  _numFaces -= (iEnd-iBeg+1);
250  }
251  }
252  if (isBinary)
253  closeSectionBinary(sectionID);
254  else
255  closeSection();
256  }
257  else if (pass == READ_COUNTS)
258  {
259  if (threadId != 0)
260  moveToListOpen();
261 
262  if ((threadId != 0) && (type != 0) && (type != 31))
263  {
264  CRConnectivity& faceNodes = *_faceNodes;
265  CRConnectivity& faceCells = *_faceCells;
266  if (shape < 0) shape = _dimension;
267 
268  for(int f=iBeg; f<=iEnd; f++)
269  {
270  int numNodes = shape;
271  if (shape == 0 || shape == 5)
272  numNodes = readInt(isBinary);
273 
274  faceNodes.addCount(f-1,numNodes);
275 
276  skipInt(numNodes+2,isBinary);
277  //int c0 = readInt(isBinary);
278  //int c1 = readInt(isBinary);
279 
280  // if (c0 == 0 || c1 == 0)
281  // faceCells.addCount(f-1,1);
282  //else
283  faceCells.addCount(f-1,2);
284  }
285  }
286 
287  if (isBinary)
288  closeSectionBinary(sectionID);
289  else
290  closeSection();
291 
292  // if (threadId != 0)
293  // moveToListClose();
294  }
295  else if (pass == READ_MESH)
296  {
297  if (threadId != 0)
298  moveToListOpen();
299 
300  if ((threadId != 0) && (type != 0) && (type != 31))
301  {
302  CRConnectivity& faceNodes = *_faceNodes;
303  CRConnectivity& faceCells = *_faceCells;
304  if (shape < 0) shape = _dimension;
305 
306  const int maxNodes = 100;
307  int fnodes[maxNodes];
308  for(int f=iBeg; f<=iEnd; f++)
309  {
310  int numNodes = shape;
311  if (shape == 0 || shape == 5)
312  numNodes = readInt(isBinary);
313 
314  // msvc doesn't like this
315  //int fnodes[numNodes];
316  bool reverseNodes = _dimension == 3;
317 
318  for(int i=0; i<numNodes; i++)
319  fnodes[i] = readInt(isBinary)-1;
320 
321  int c0 = readInt(isBinary);
322  int c1 = readInt(isBinary);
323 
324  // handle boundary mesh where both c0 and c1 are zero
325  if ((c0 == 0) && (c1 == 0))
326  {
327  faceCells.add(f-1,-1);
328  faceCells.add(f-1,-1);
329  }
330  else
331  {
332  if (c0 == 0) reverseNodes = !reverseNodes;
333 
334  if (c0 != 0)
335  faceCells.add(f-1,c0-1);
336  if (c1 != 0)
337  faceCells.add(f-1,c1-1);
338 
339  if (c0 ==0 || c1==0)
340  {
341  faceCells.add(f-1,_numCells+_numBoundaryFaces);
343  }
344  }
345 
346  if (reverseNodes)
347  for(int i=0; i<numNodes; i++)
348  faceNodes.add(f-1,fnodes[numNodes-i-1]);
349  else
350  for(int i=0; i<numNodes; i++)
351  faceNodes.add(f-1,fnodes[i]);
352 
353  }
354  }
355 
356  // if (threadId != 0)
357  // moveToListClose();
358  if (isBinary)
359  closeSectionBinary(sectionID);
360  else
361  closeSection();
362 
363  }
364 
365 #if 0
366  if (isBinary)
367  closeSectionBinary(sectionID);
368  else
369  closeSection();
370 #endif
371  return;
372 }
373 
374 void
375 FluentReader::readFacePairs(const int pass, const bool isBinary,
376  const int sectionID)
377 {
378  int iBeg, iEnd, leftID, rightID, dummy;
379  readHeader(iBeg,iEnd,leftID,rightID,dummy);
380 
381  // cerr << " thread id " << threadId << endl;
382  if (pass == READ_SIZES)
383  {
384  const int count = iEnd-iBeg+1;
385  Array<int>* leftFaces = new Array<int>(count);
386  Array<int>* rightFaces = new Array<int>(count);
387 
388 
389  moveToListOpen();
390  for(int n=0; n<count; n++)
391  {
392  int leftF = readInt(isBinary);
393  int rightF = readInt(isBinary);
394 
395  (*leftFaces)[n]=leftF-1;
396  (*rightFaces)[n]=rightF-1;
397  }
398  if (isBinary)
399  closeSectionBinary(sectionID);
400  else
401  closeSection();
402  FluentFacePairs *fp = new FluentFacePairs(count,leftID,rightID,
403  shared_ptr<Array<int> >(leftFaces),
404  shared_ptr<Array<int> >(rightFaces));
405 
406  _facePairs[leftID] = shared_ptr<FluentFacePairs>(fp);
407  _faceZones[leftID]->partnerId = rightID;
408  _faceZones[rightID]->partnerId = leftID;
409 
410 
411  }
412  else if ((pass == READ_COUNTS) || (pass == READ_MESH))
413  {
414  moveToListOpen();
415  if (isBinary)
416  closeSectionBinary(sectionID);
417  else
418  closeSection();
419  }
420 
421 }
422 
423 void FluentReader::read(const int pass)
424 {
425  int id;
426  while ((id = getNextSection()) != EOF)
427  {
428  bool isBinary = (id > 1000);
429  bool isDP = (id > 3000);
430 
431  // cerr << "reading section " << id << endl;
432 
433  switch (id %1000)
434  {
435  case 0:
436  case 1:
437  moveToListClose();
438  break;
439 
440  case 2:
441  if (pass == READ_SIZES)
442  {
443  fscanf(_fp,"%d",&_dimension);
444  }
445  else
446  moveToListClose();
447  break;
448 
449  case 37:
450  if (pass == READ_SIZES)
451  {
453  }
454  else if (pass == READ_COUNTS)
455  {
456  char* rpVarString = new char[_rpVarStringLength];
457  readList(rpVarString);
458  _rpVars=string(rpVarString,_rpVarStringLength);
459  delete [] rpVarString;
460  }
461  else
462  {
463  closeSection();
464  }
465  break;
466 
467  case 39:
468  case 45:
469 
470  {
471  int zoneId;
472  char zoneName[256], zoneType[80];
473  moveToListOpen();
474  fscanf(_fp,"%d%s",&zoneId,zoneType);
475 
476  // need to read zoneName this way because it may or may not
477  // be followed by an int
478  {
479  int n=0;
480  char c;
481  while ((c = getc(_fp)) != EOF)
482  {
483  if (isspace(c))
484  {
485  if (n>0)
486  {
487  moveToListClose();
488  break;
489  }
490  }
491  else if (c == ')')
492  break;
493  else
494  {
495  if (c == '-') c='_';
496  zoneName[n++]=c;
497  }
498  }
499  zoneName[n]='\0';
500  }
501 
502  if (pass == READ_SIZES)
503  {
504  if (_cellZones.find(zoneId) != _cellZones.end())
505  {
506  FluentCellZone *z = _cellZones[zoneId];
507  z->zoneName=string(zoneName,strlen(zoneName));
508  z->zoneType=string(zoneType,strlen(zoneType));
509  }
510  else if (_faceZones.find(zoneId) != _faceZones.end())
511  {
512  FluentFaceZone *z = _faceZones[zoneId];
513  z->zoneName=string(zoneName,strlen(zoneName));
514  z->zoneType=string(zoneType,strlen(zoneType));
515  }
516 
518  }
519  else if (pass == READ_COUNTS)
520  {
521  char* zoneVarString = new char[_zoneVarStringLength[zoneId]];
522  readList(zoneVarString);
523  if (_cellZones.find(zoneId) != _cellZones.end())
524  {
525  FluentCellZone *z = _cellZones[zoneId];
526  z->zoneVars =
527  string(zoneVarString,_zoneVarStringLength[zoneId]);
528  }
529  else if (_faceZones.find(zoneId) != _faceZones.end())
530  {
531  FluentFaceZone *z = _faceZones[zoneId];
532  z->zoneVars =
533  string(zoneVarString,_zoneVarStringLength[zoneId]);
534  }
535  delete [] zoneVarString;
536  }
537  else
538  {
539  closeSection();
540  }
541  break;
542  }
543 
544  case 10:
545  readNodes(pass,isBinary,isDP,id);
546  break;
547 
548  case 12:
549  readCells(pass,isBinary,id);
550  break;
551 
552  case 13:
553  readFaces(pass,isBinary,id);
554  break;
555 
556  case 18:
557  readFacePairs(pass,isBinary,id);
558  break;
559 
560  default:
561  if (isBinary)
562  closeSectionBinary(id);
563  else
564  closeSection();
565  break;
566  }
567  }
568 }
569 
570 
571 void
573 {
574  // first pass to find the sizes of cell zones etc
575  read(READ_SIZES);
576 
580 
581  _faceNodes = shared_ptr<CRConnectivity>(new CRConnectivity(_faces,_nodes));
582  _faceCells = shared_ptr<CRConnectivity>(new CRConnectivity(_faces,_cells));
583 
584  _faceNodes->initCount();
585  _faceCells->initCount();
586 
587  // rewind and read to determine counts for connectivities
588  resetFilePtr();
589  read(READ_COUNTS);
590 
591  _faceCells->finishCount();
592  _faceNodes->finishCount();
593 
594  _coords.resize(_numNodes);
595  _coords.zero();
596 
597  _numBoundaryFaces = 0;
598 
599  // finally rewind once again and read in all the info
600 
601  resetFilePtr();
602  read(READ_MESH);
603 
604  _faceNodes->finishAdd();
605  _faceCells->finishAdd();
606 
607  buildZones();
608 }
609 
610 int
611 FluentReader::getCellZoneID(const int c) const
612 {
613  foreach(const CellZonesMap::value_type& pos, _cellZones)
614  {
615  const FluentCellZone& cz = *(pos.second);
616  if (c >= cz.iBeg && c <= cz.iEnd)
617  return cz.ID;
618  }
619  if (c < _numCells + _numBoundaryFaces)
620  return 0;
621  throw CException("getCellZoneID: invalid cell id");
622 }
623 
624 const CRConnectivity&
626 {
627  if (!_cellFaces)
628  {
629  _cellFaces = _faceCells->getTranspose();
630  }
631  return *_cellFaces;
632 }
633 
634 const CRConnectivity&
636 {
637  if (!_cellNodes)
638  {
639  const CRConnectivity& cellFaces = getCellFaces();
640  _cellNodes = cellFaces.multiply(*_faceNodes,false);
641  }
642  return *_cellNodes;
643 }
644 
645 const CRConnectivity&
647 {
648  if (!_nodeCells)
649  {
650  const CRConnectivity& cellNodes = getCellNodes();
651  _nodeCells = cellNodes.getTranspose();
652  }
653  return *_nodeCells;
654 }
655 
656 void
658 {
659  const CRConnectivity& faceCells = *_faceCells;
660  // determine the left and right cell zones of each face zone
661  foreach(FaceZonesMap::value_type& pos, _faceZones)
662  {
663  FluentFaceZone& fz = *(pos.second);
664 
665  if (fz.threadType == PERIODIC_SHADOW)
666  fz.zoneType = "shadow";
667 
668  const int c0 = faceCells(fz.iBeg,0);
669 
670  // handle boundary mesh that doesn't have any cells
671  if (c0 == -1)
672  continue;
673 
674  fz.leftCellZoneId = getCellZoneID(c0);
676 
677  const int c1 = faceCells(fz.iBeg,1);
679 
680  if (fz.rightCellZoneId == fz.leftCellZoneId)
681  {
682  lcz->interiorZoneIds.push_back(fz.ID);
683  }
684  else if (fz.rightCellZoneId > 0)
685  {
686  lcz->interfaceZoneIds.push_back(fz.ID);
688  rcz->interfaceZoneIds.push_back(fz.ID);
689  }
690  else
691  lcz->boundaryZoneIds.push_back(fz.ID);
692  }
693 }
694 
695 Mesh*
696 FluentReader::createMesh(const int cellZoneID,
697  Array<int>& globalToLocalCellMap)
698 {
699  const CRConnectivity& faceCells = *_faceCells;
700 
701  const Array<int>& fcRow = faceCells.getRow();
702  const Array<int>& fcCol = faceCells.getCol();
703 
704  Mesh *mesh = new Mesh(_dimension);
705  mesh->setCellZoneID(cellZoneID);
706  FluentCellZone& cz = *(_cellZones[cellZoneID]);
707 
708 
709  vector<int> allFaceList;
710 
711  // determine interior faces
712  int faceOffset = 0;
713  foreach(int fzId, cz.interiorZoneIds)
714  {
715  const FluentFaceZone& fz = *(_faceZones[fzId]);
716  for(int i=fz.iBeg; i<=fz.iEnd; i++) allFaceList.push_back(i);
717  }
718 
719  faceOffset = allFaceList.size();
720  mesh->createInteriorFaceGroup(faceOffset);
721 
722  vector<int> interfaceFaceList;
723  foreach(int fzId, cz.interfaceZoneIds)
724  {
725  const FluentFaceZone& fz = *(_faceZones[fzId]);
726  for(int i=fz.iBeg; i<=fz.iEnd; i++)
727  {
728  allFaceList.push_back(i);
729  interfaceFaceList.push_back(i);
730  }
731 
732  const int thisFZCount = fz.iEnd-fz.iBeg+1;
733  mesh->createInterfaceGroup(thisFZCount,faceOffset,fzId);
734  faceOffset += thisFZCount;
735  }
736 
737  vector<int> boundaryCells;
738  foreach(int fzId, cz.boundaryZoneIds)
739  {
740  const FluentFaceZone& fz = *_faceZones[fzId];
741  for(int i=fz.iBeg; i<=fz.iEnd; i++) allFaceList.push_back(i);
742 
743  const int thisFZCount = fz.iEnd-fz.iBeg+1;
744 
745  if ((fz.zoneType == "interface") || (fz.partnerId != -1))
746  mesh->createInterfaceGroup(thisFZCount,faceOffset,fzId);
747  else
748  mesh->createBoundaryFaceGroup(thisFZCount,faceOffset,fzId,fz.zoneType);
749 
750  faceOffset += thisFZCount;
751 
752  for(int j=fcRow[fz.iBeg]; j<fcRow[fz.iEnd+1]; j++)
753  if (fcCol[j] >= _numCells)
754  boundaryCells.push_back(fcCol[j]);
755  }
756 
757  mesh->getFaces().setCount(allFaceList.size());
758 
759  Array<int> allFaceArray(allFaceList.size());
760  for(unsigned int i=0; i<allFaceList.size(); i++) allFaceArray[i] = allFaceList[i];
761 
762  shared_ptr<CRConnectivity> mFaceCells(_faceCells->getSubset(mesh->getFaces(),
763  allFaceArray));
764  shared_ptr<CRConnectivity> mFaceNodes(_faceNodes->getSubset(mesh->getFaces(),
765  allFaceArray));
766 
767 
768  int numMeshCells = cz.iEnd-cz.iBeg+1;
769 
770 
771  vector<int> interfaceCellList;
772 
773  const int interfaceFaceCount = interfaceFaceList.size();
774  if (interfaceFaceCount > 0)
775  {
776  // need to create an Array from the vector<int> since CRConnectivity
777  // methods expect Array
778  Array<int> ifFacesArray(interfaceFaceCount);
779 
780  for(int i=0; i<interfaceFaceCount; i++)
781  ifFacesArray[i] = interfaceFaceList[i];
782 
783  StorageSite ifFacesSite(interfaceFaceCount,0);
784  StorageSite ifNodesSite(0,0);
785  StorageSite ifCellsSite(0,0);
786 
787  shared_ptr<CRConnectivity>
788  ifFaceNodes(_faceNodes->getLocalizedSubset(ifFacesSite,
789  ifNodesSite,
790  ifFacesArray));
791 
792  const Array<int>& interfaceNodes = ifFaceNodes->getLocalToGlobalMap();
793 
794 
795  shared_ptr<CRConnectivity>
796  ifNodeCells(getNodeCells().getLocalizedSubset(ifNodesSite,
797  ifCellsSite,
798  interfaceNodes));
799 
800  const Array<int>& interfaceAllCells = ifNodeCells->getLocalToGlobalMap();
801 
802  for(int i=0; i<interfaceAllCells.getLength(); i++)
803  {
804  const int c = interfaceAllCells[i];
805  if ((c < cz.iBeg || c >cz.iEnd) &&
806  (c < _numCells))
807  interfaceCellList.push_back(c);
808  }
809  }
810 
811  const int numGhostCells = interfaceCellList.size();
812  const int numBoundaryCells = boundaryCells.size();
813 
814  const int nTotalCells = numMeshCells+numGhostCells+numBoundaryCells;
815  Array<int> allCellList(nTotalCells);
816  Array<int> interiorCellList(numMeshCells);
817 
818  int nc=0;
819  for(int i=cz.iBeg; i<=cz.iEnd; i++)
820  {
821  allCellList[nc]=i;
822  interiorCellList[nc]=i;
823 
824  globalToLocalCellMap[i]=nc++;
825  }
826 
827  foreach(int i, interfaceCellList)
828  {
829  allCellList[nc]=i;
830  globalToLocalCellMap[i]=nc++;
831  }
832 
833  foreach(int i, boundaryCells)
834  {
835  allCellList[nc]=i;
836  globalToLocalCellMap[i]=nc++;
837  }
838 
839  mesh->getCells().setCount(numMeshCells, numGhostCells+numBoundaryCells);
840 
841  StorageSite tempNodesSite(0,0);
842 
843  shared_ptr<CRConnectivity>
844  czAllCellNodes(getCellNodes().getLocalizedSubset(mesh->getCells(),
845  tempNodesSite,
846  interiorCellList));
847  shared_ptr<Array<Vec3> > coords =
848  _coords.getSubset(czAllCellNodes->getLocalToGlobalMap());
849 
850  mesh->setCoordinates(coords);
851 
852  StorageSite& nodes = mesh->getNodes();
853  nodes.setCount(coords->getLength());
854 
855  mFaceNodes->localize(czAllCellNodes->getGlobalToLocalMap(),nodes);
856  mesh->setFaceNodes(mFaceNodes);
857 
858  mFaceCells->localize(globalToLocalCellMap,mesh->getCells());
859  mesh->setFaceCells(mFaceCells);
860 
861  cz.mesh = mesh;
862  cz.globalToLocalNodeMap = czAllCellNodes->getGlobalToLocalMapPtr();
863 
864  foreach(const CellZonesMap::value_type& pos, _cellZones)
865  {
866  const FluentCellZone& ocz = *(pos.second);
867  if (&ocz != &cz)
868  {
869  shared_ptr<OneToOneIndexMap> im(getGhostCellMap(ocz,allCellList));
870  if (im != 0)
871  cz.ghostCellMaps[ocz.ID] = im;
872  }
873  }
874 
875 
876  int nPeriodic = 0;
877  Mesh::PeriodicFacePairs& periodicFacePairs = mesh->getPeriodicFacePairs();
878 
879 
880  foreach(int fzId, cz.boundaryZoneIds)
881  {
882  const FluentFaceZone& fz = *_faceZones[fzId];
883  if (fz.zoneType == "periodic")
884  {
885  FacePairsMap::const_iterator pos = _facePairs.find(fzId);
886  if (pos != _facePairs.end())
887  {
888  const FluentFacePairs& facePairs = *pos->second;
889  const FluentFaceZone& shadowFz = *_faceZones[facePairs.rightID];
890 
891  const Array<int>& pFaces = *facePairs.leftFaces;
892  const Array<int>& shadowFaces = *facePairs.rightFaces;
893 
894  nPeriodic += facePairs.count;
895 
896  const FaceGroup& myFG = mesh->getFaceGroup(fzId);
897  const FaceGroup& myShadowFG = mesh->getFaceGroup(facePairs.rightID);
898 
899 
900  const int myOffset = myFG.site.getOffset();
901  const int myShadowOffset = myShadowFG.site.getOffset();
902 
903  for(int i=0; i<facePairs.count; i++)
904  {
905  // compute face index in our Mesh by first
906  // subtracting the fluent face zone offset and then
907  // adding our face group offset
908 
909  const int lf = pFaces[i] - fz.iBeg + myOffset;
910  const int rf = shadowFaces[i] - shadowFz.iBeg + myShadowOffset;
911 
912  periodicFacePairs[lf] = rf;
913  }
914  }
915  }
916  }
917 
918 
919  if (nPeriodic > 0)
920  {
921  shared_ptr<Array<int> >fromPtr(new Array<int>(nPeriodic*2));
922  shared_ptr<Array<int> >toPtr(new Array<int>(nPeriodic*2));
923 
924  Array<int>& from = *fromPtr;
925  Array<int>& to = *toPtr;
926 
927  const CRConnectivity& faceCells = mesh->getAllFaceCells();
928 
929  StorageSite& cells = mesh->getCells();
930 
931  nPeriodic = 0;
932  for(Mesh::PeriodicFacePairs::const_iterator pos = periodicFacePairs.begin();
933  pos!=periodicFacePairs.end();
934  ++pos)
935  {
936  const int lf = pos->first;
937  const int rf = pos->second;
938  from[nPeriodic] = faceCells(lf,0);
939  from[nPeriodic+1] = faceCells(rf,0);
940  to[nPeriodic] = faceCells(lf,1);
941  to[nPeriodic+1] = faceCells(rf,1);
942 
943  nPeriodic += 2;
944  }
945 
946  cells.getGatherMap()[&cells] = toPtr;
947  cells.getScatterMap()[&cells] = fromPtr;
948  }
949 
950  return mesh;
951 }
952 
953 MeshList
955 {
956 
957  Array<int> globalToLocalCellMap(_numCells+_numBoundaryFaces);
958  globalToLocalCellMap = -1;
959 
960  MeshList meshes;
961 
962  map<int, Mesh*> meshMap;
963  foreach(const CellZonesMap::value_type& pos, _cellZones)
964  {
965  const FluentCellZone& cz = *(pos.second);
966  Mesh* mesh = createMesh(cz.ID, globalToLocalCellMap);
967  meshes.push_back(mesh);
968  meshMap[cz.ID] = mesh;
969  }
970 
971  foreach(const CellZonesMap::value_type& pos, _cellZones)
972  {
973  const FluentCellZone& cz = *(pos.second);
974  Mesh *mesh = cz.mesh;
975  StorageSite& thisSite = mesh->getCells();
976 
977  //StorageSite& thisNodes = mesh->getNodes();
978 
979  foreach(const GhostCellMapsMap::value_type& pos2, cz.ghostCellMaps)
980  {
981  const FluentCellZone& ocz = *_cellZones[pos2.first];
982  shared_ptr<OneToOneIndexMap> mappers = pos2.second;
983  Mesh *omesh = ocz.mesh;
984  StorageSite& oSite = omesh->getCells();
985  thisSite.getGatherMap()[&oSite] = mappers->_toIndices;
986  oSite.getScatterMap()[&thisSite] = mappers->_fromIndices;
987  }
988 
989 #if 0
990  foreach(const CellZonesMap::value_type& pos2, _cellZones)
991  {
992 
993  const FluentCellZone& ocz = *(pos2.second);
994  Mesh *omesh = ocz.mesh;
995  if (omesh != mesh)
996  {
997  StorageSite& oNodes = omesh->getNodes();
998 
999  shared_ptr<OneToOneIndexMap> nodeMap = getCommonNodeMap(cz,ocz);
1000  if (nodeMap)
1001  {
1002  thisNodes.getCommonMap()[&oNodes] = nodeMap->_toIndices;
1003  }
1004  }
1005  }
1006 #endif
1007 
1008  }
1009 
1010  foreach(const FacePairsMap::value_type& pos, _facePairs)
1011  {
1012  const FluentFacePairs& facePairs = *(pos.second);
1013  const FluentFaceZone& leftFZ = *_faceZones[facePairs.leftID];
1014  const FluentFaceZone& rightFZ = *_faceZones[facePairs.rightID];
1015 
1016  const FluentCellZone& leftCZ = *_cellZones[leftFZ.leftCellZoneId];
1017  const FluentCellZone& rightCZ = *_cellZones[rightFZ.leftCellZoneId];
1018 
1019  const Array<int>& leftFaces = *facePairs.leftFaces;
1020  const Array<int>& rightFaces = *facePairs.rightFaces;
1021 
1022  const CRConnectivity& faceCells = *_faceCells;
1023 
1024  Mesh* leftMesh = meshMap[leftFZ.leftCellZoneId];
1025  Mesh* rightMesh = meshMap[rightFZ.leftCellZoneId];
1026 
1027  StorageSite& lCells = leftMesh->getCells();
1028  StorageSite& rCells = rightMesh->getCells();
1029 
1030  const int count = facePairs.count;
1031 
1032  shared_ptr<Array<int> > lScatter(new Array<int>(count));
1033  shared_ptr<Array<int> > rScatter(new Array<int>(count));
1034  shared_ptr<Array<int> > lGather(new Array<int>(count));
1035  shared_ptr<Array<int> > rGather(new Array<int>(count));
1036 
1037 
1038  for(int f=0; f<count; f++)
1039  {
1040  const int lf = leftFaces[f];
1041  const int rf = rightFaces[f];
1042 
1043  (*lScatter)[f] = globalToLocalCellMap[faceCells(lf,0)];
1044  (*rScatter)[f] = globalToLocalCellMap[faceCells(rf,0)];
1045  (*lGather)[f] = globalToLocalCellMap[faceCells(lf,1)];
1046  (*rGather)[f] = globalToLocalCellMap[faceCells(rf,1)];
1047 
1048  }
1049 
1050  lCells.getGatherMap()[&rCells] = lGather;
1051  lCells.getScatterMap()[&rCells] = lScatter;
1052 
1053  rCells.getGatherMap()[&lCells] = rGather;
1054  rCells.getScatterMap()[&lCells] = rScatter;
1055  }
1056 
1057 
1058  return meshes;
1059 }
1060 
1061 shared_ptr<OneToOneIndexMap>
1063 {
1064  const int iBeg = cz.iBeg;
1065  const int iEnd = cz.iEnd;
1066 
1067  int thisZoneCells=0;
1068  for(int ii=0; ii<indices.getLength(); ii++)
1069  {
1070  const int c = indices[ii];
1071  if (c >= iBeg && c<=iEnd) thisZoneCells++;
1072  }
1073 
1074  if (thisZoneCells == 0) return shared_ptr<OneToOneIndexMap>();
1075 
1076  shared_ptr<Array<int> >fromPtr(new Array<int>(thisZoneCells));
1077  shared_ptr<Array<int> >toPtr(new Array<int>(thisZoneCells));
1078 
1079  Array<int>& from = *fromPtr;
1080  Array<int>& to = *toPtr;
1081 
1082  thisZoneCells = 0;
1083  for(int ii=0; ii<indices.getLength(); ii++)
1084  {
1085  const int c = indices[ii];
1086  if (c >= iBeg && c<=iEnd)
1087  {
1088  to[thisZoneCells] = ii;
1089  from[thisZoneCells] = c-iBeg;
1090  thisZoneCells++;
1091  }
1092  }
1093 
1094  shared_ptr<OneToOneIndexMap> imap(new OneToOneIndexMap(fromPtr,toPtr));
1095  return imap;
1096 }
1097 
1098 shared_ptr<OneToOneIndexMap>
1100 {
1101  const Array<int>& gToLocal0 = *(cz0.globalToLocalNodeMap);
1102  const Array<int>& gToLocal1 = *(cz1.globalToLocalNodeMap);
1103 
1104  int nCommon=0;
1105 
1106  const int nNodes = gToLocal0.getLength();
1107 
1108  for(int n=0; n<nNodes; n++)
1109  {
1110  const int l0 = gToLocal0[n];
1111  const int l1 = gToLocal1[n];
1112  if ((l0 != -1) && (l1 != -1))
1113  nCommon++;
1114  }
1115 
1116 
1117  if (nCommon == 0) return shared_ptr<OneToOneIndexMap>();
1118 
1119  shared_ptr<Array<int> >fromPtr(new Array<int>(nCommon));
1120  shared_ptr<Array<int> >toPtr(new Array<int>(nCommon));
1121 
1122  Array<int>& from = *fromPtr;
1123  Array<int>& to = *toPtr;
1124 
1125  nCommon = 0;
1126  for(int n=0; n<nNodes; n++)
1127  {
1128  const int l0 = gToLocal0[n];
1129  const int l1 = gToLocal1[n];
1130  if ((l0 != -1) && (l1 != -1))
1131  {
1132  to[nCommon] = l0;
1133  from[nCommon] = l1;
1134  nCommon++;
1135  }
1136  }
1137 
1138  shared_ptr<OneToOneIndexMap> imap(new OneToOneIndexMap(fromPtr,toPtr));
1139  return imap;
1140 }
const CRConnectivity & getCellFaces()
string zoneVars
Definition: FluentReader.h:29
const Array< int > & getCol() const
FacePairsMap _facePairs
Definition: FluentReader.h:117
void readNodes(const int pass, const bool isBinary, const bool isDP, const int id)
const Array< int > & getRow() const
shared_ptr< CRConnectivity > _nodeCells
Definition: FluentReader.h:113
void read(const int pass)
void setFaceNodes(shared_ptr< CRConnectivity > faceNodes)
Definition: Mesh.cpp:646
void readVectorData(Array< Vec3 > &a, const int iBeg, const int iEnd, const bool isBinary, const bool isDP)
int threadType
Definition: FluentReader.h:26
int getCellZoneID(const int c) const
StorageSite _nodes
Definition: FluentReader.h:107
Definition: Mesh.h:28
PeriodicFacePairs & getPeriodicFacePairs()
Definition: Mesh.h:337
vector< int > interfaceZoneIds
Definition: FluentReader.h:42
virtual ~FluentReader()
const CRConnectivity & getNodeCells()
const StorageSite & getNodes() const
Definition: Mesh.h:110
void resetFilePtr()
Definition: Reader.cpp:27
void readFacePairs(const int pass, const bool isBinary, const int id)
const StorageSite & createInteriorFaceGroup(const int size)
Definition: Mesh.cpp:259
GhostCellMapsMap ghostCellMaps
Definition: FluentReader.h:45
FaceZonesMap _faceZones
Definition: FluentReader.h:115
void setCoordinates(shared_ptr< Array< VecD3 > > x)
Definition: Mesh.h:204
const FaceGroup & getFaceGroup(const int fgId) const
Definition: Mesh.cpp:1570
CellZonesMap _cellZones
Definition: FluentReader.h:116
Definition: Mesh.h:49
int readInt(const bool isBinary)
vector< int > boundaryZoneIds
Definition: FluentReader.h:40
shared_ptr< Array< int > > rightFaces
Definition: FluentReader.h:65
void setFaceCells(shared_ptr< CRConnectivity > faceCells)
Definition: Mesh.cpp:654
void setCount(const int selfCount, const int nGhost=0)
Definition: StorageSite.h:42
Mesh * createMesh(const int cellZoneID, Array< int > &)
map< int, int > PeriodicFacePairs
Definition: Mesh.h:67
const StorageSite & createBoundaryFaceGroup(const int size, const int offset, const int id, const string &boundaryType)
Definition: Mesh.cpp:278
FILE * _fp
Definition: Reader.h:26
string zoneType
Definition: FluentReader.h:28
map< int, int > _zoneVarStringLength
Definition: FluentReader.h:122
shared_ptr< OneToOneIndexMap > getCommonNodeMap(const FluentCellZone &cz0, const FluentCellZone &cz1)
const CRConnectivity & getAllFaceCells() const
Definition: Mesh.cpp:378
void readCells(const int pass, const bool isBinary, const int id)
void closeSection()
const CRConnectivity & getCellNodes()
StorageSite _faces
Definition: FluentReader.h:106
const StorageSite & createInterfaceGroup(const int size, const int offset, const int id)
Definition: Mesh.cpp:268
virtual void * getData() const
Definition: Array.h:275
void readFaces(const int pass, const bool isBinary, const int id)
const int leftID
Definition: FluentReader.h:62
MeshList getMeshList()
shared_ptr< CRConnectivity > _cellNodes
Definition: FluentReader.h:112
void setCellZoneID(const int id)
Definition: Mesh.h:320
Array< Vec3 > _coords
Definition: FluentReader.h:119
const StorageSite & getFaces() const
Definition: Mesh.h:108
string zoneName
Definition: FluentReader.h:27
const StorageSite & getCells() const
Definition: Mesh.h:109
int readListLength()
void moveToListClose()
int getNextSection()
int moveToListOpen()
FluentReader(const string &fileName)
shared_ptr< CRConnectivity > _cellFaces
Definition: FluentReader.h:111
shared_ptr< Array< int > > globalToLocalNodeMap
Definition: FluentReader.h:46
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
const int count
Definition: FluentReader.h:61
shared_ptr< CRConnectivity > _faceCells
Definition: FluentReader.h:110
Definition: Array.h:14
int getOffset() const
Definition: StorageSite.h:87
shared_ptr< CRConnectivity > multiply(const CRConnectivity &b, const bool implicitDiagonal) const
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
shared_ptr< CRConnectivity > getTranspose() const
StorageSite _cells
Definition: FluentReader.h:105
int add(const int index, const int val)
const int rightID
Definition: FluentReader.h:63
vector< int > interiorZoneIds
Definition: FluentReader.h:41
shared_ptr< OneToOneIndexMap > getGhostCellMap(const FluentCellZone &cz, const Array< int > &indices)
void readHeader(int &i1, int &i2, int &i3, int &i4, int &i5)
int _rpVarStringLength
Definition: FluentReader.h:120
shared_ptr< CRConnectivity > _faceNodes
Definition: FluentReader.h:109
void skipInt(const int n, const bool isBinary)
int closeSectionBinary(const int currentId)
void addCount(const int index, const int count)
void readList(char *buffer)
string _rpVars
Definition: FluentReader.h:121
int _numBoundaryFaces
Definition: FluentReader.h:103
vector< Mesh * > MeshList
Definition: Mesh.h:439
shared_ptr< Array< int > > leftFaces
Definition: FluentReader.h:64
StorageSite site
Definition: Mesh.h:40
int getLength() const
Definition: Array.h:87