ensightMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ensightMesh.H"
27 #include "argList.H"
28 #include "Time.H"
29 #include "fvMesh.H"
30 #include "globalMeshData.H"
32 #include "processorPolyPatch.H"
33 #include "cellModeller.H"
34 #include "IOmanip.H"
35 #include "itoa.H"
36 #include "globalIndex.H"
37 #include "mapDistribute.H"
38 #include "stringListOps.H"
39 
40 #include "ensightBinaryStream.H"
41 #include "ensightAsciiStream.H"
42 
43 #include <fstream>
44 
45 // * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * //
46 
48 {
49  patchPartOffset_ = 2;
50  meshCellSets_.setSize(mesh_.nCells());
51 
52  boundaryFaceSets_.setSize(mesh_.boundary().size());
53  allPatchNames_.clear();
54  patchNames_.clear();
55  nPatchPrims_ = 0;
56  faceZoneFaceSets_.setSize(mesh_.faceZones().size());
57  faceZoneNames_.clear();
58  nFaceZonePrims_ = 0;
59  boundaryFaceToBeIncluded_.clear();
60 
61  if (!noPatches_)
62  {
63  // Patches are output. Check that they're synced.
64  mesh_.boundaryMesh().checkParallelSync(true);
65 
66  allPatchNames_ = mesh_.boundaryMesh().names();
67  if (Pstream::parRun())
68  {
69  allPatchNames_.setSize
70  (
71  mesh_.boundary().size()
72  - mesh_.globalData().processorPatches().size()
73  );
74  }
75 
76  if (patches_)
77  {
78  if (patchPatterns_.empty())
79  {
80  forAll(allPatchNames_, nameI)
81  {
82  patchNames_.insert(allPatchNames_[nameI]);
83  }
84  }
85  else
86  {
87  // Find patch names which match that requested at command-line
88  forAll(allPatchNames_, nameI)
89  {
90  const word& patchName = allPatchNames_[nameI];
91  if (findStrings(patchPatterns_, patchName))
92  {
93  patchNames_.insert(patchName);
94  }
95  }
96  }
97  }
98  }
99 
100  if (patchNames_.size())
101  {
102  // no internalMesh
103  patchPartOffset_ = 1;
104  }
105  else
106  {
107  const cellShapeList& cellShapes = mesh_.cellShapes();
108 
109  const cellModel& tet = *(cellModeller::lookup("tet"));
110  const cellModel& pyr = *(cellModeller::lookup("pyr"));
111  const cellModel& prism = *(cellModeller::lookup("prism"));
112  const cellModel& wedge = *(cellModeller::lookup("wedge"));
113  const cellModel& hex = *(cellModeller::lookup("hex"));
114 
115 
116 
117  // Count the shapes
118  labelList& tets = meshCellSets_.tets;
119  labelList& pyrs = meshCellSets_.pyrs;
120  labelList& prisms = meshCellSets_.prisms;
121  labelList& wedges = meshCellSets_.wedges;
122  labelList& hexes = meshCellSets_.hexes;
123  labelList& polys = meshCellSets_.polys;
124 
125  label nTets = 0;
126  label nPyrs = 0;
127  label nPrisms = 0;
128  label nWedges = 0;
129  label nHexes = 0;
130  label nPolys = 0;
131 
132  forAll(cellShapes, celli)
133  {
134  const cellShape& cellShape = cellShapes[celli];
135  const cellModel& cellModel = cellShape.model();
136 
137  if (cellModel == tet)
138  {
139  tets[nTets++] = celli;
140  }
141  else if (cellModel == pyr)
142  {
143  pyrs[nPyrs++] = celli;
144  }
145  else if (cellModel == prism)
146  {
147  prisms[nPrisms++] = celli;
148  }
149  else if (cellModel == wedge)
150  {
151  wedges[nWedges++] = celli;
152  }
153  else if (cellModel == hex)
154  {
155  hexes[nHexes++] = celli;
156  }
157  else
158  {
159  polys[nPolys++] = celli;
160  }
161  }
162 
163  tets.setSize(nTets);
164  pyrs.setSize(nPyrs);
165  prisms.setSize(nPrisms);
166  wedges.setSize(nWedges);
167  hexes.setSize(nHexes);
168  polys.setSize(nPolys);
169 
170  meshCellSets_.nTets = nTets;
171  reduce(meshCellSets_.nTets, sumOp<label>());
172 
173  meshCellSets_.nPyrs = nPyrs;
174  reduce(meshCellSets_.nPyrs, sumOp<label>());
175 
176  meshCellSets_.nPrisms = nPrisms;
177  reduce(meshCellSets_.nPrisms, sumOp<label>());
178 
179  meshCellSets_.nHexesWedges = nWedges+nHexes;
180  reduce(meshCellSets_.nHexesWedges, sumOp<label>());
181 
182  meshCellSets_.nPolys = nPolys;
183  reduce(meshCellSets_.nPolys, sumOp<label>());
184 
185 
186  // Determine parallel shared points
187  globalPointsPtr_ = mesh_.globalData().mergePoints
188  (
189  pointToGlobal_,
190  uniquePointMap_
191  );
192  }
193 
194  if (!noPatches_)
195  {
196  forAll(mesh_.boundary(), patchi)
197  {
198  if (mesh_.boundary()[patchi].size())
199  {
200  const polyPatch& p = mesh_.boundaryMesh()[patchi];
201 
202  labelList& tris = boundaryFaceSets_[patchi].tris;
203  labelList& quads = boundaryFaceSets_[patchi].quads;
204  labelList& polys = boundaryFaceSets_[patchi].polys;
205 
206  tris.setSize(p.size());
207  quads.setSize(p.size());
208  polys.setSize(p.size());
209 
210  label nTris = 0;
211  label nQuads = 0;
212  label nPolys = 0;
213 
214  forAll(p, facei)
215  {
216  const face& f = p[facei];
217 
218  if (f.size() == 3)
219  {
220  tris[nTris++] = facei;
221  }
222  else if (f.size() == 4)
223  {
224  quads[nQuads++] = facei;
225  }
226  else
227  {
228  polys[nPolys++] = facei;
229  }
230  }
231 
232  tris.setSize(nTris);
233  quads.setSize(nQuads);
234  polys.setSize(nPolys);
235  }
236  }
237  }
238 
239  forAll(allPatchNames_, patchi)
240  {
241  const word& patchName = allPatchNames_[patchi];
242  nFacePrimitives nfp;
243 
244  if (patchNames_.empty() || patchNames_.found(patchName))
245  {
246  if (mesh_.boundary()[patchi].size())
247  {
248  nfp.nTris = boundaryFaceSets_[patchi].tris.size();
249  nfp.nQuads = boundaryFaceSets_[patchi].quads.size();
250  nfp.nPolys = boundaryFaceSets_[patchi].polys.size();
251  }
252  }
253 
254  reduce(nfp.nTris, sumOp<label>());
255  reduce(nfp.nQuads, sumOp<label>());
256  reduce(nfp.nPolys, sumOp<label>());
257 
258  nPatchPrims_.insert(patchName, nfp);
259  }
260 
261  // faceZones
262  if (faceZones_)
263  {
264  wordList faceZoneNamesAll = mesh_.faceZones().names();
265  // Need to sort the list of all face zones since the index may vary
266  // from processor to processor...
267  sort(faceZoneNamesAll);
268 
269  // Find faceZone names which match that requested at command-line
270  forAll(faceZoneNamesAll, nameI)
271  {
272  const word& zoneName = faceZoneNamesAll[nameI];
273  if (findStrings(faceZonePatterns_, zoneName))
274  {
275  faceZoneNames_.insert(zoneName);
276  }
277  }
278 
279  // Build list of boundary faces to be exported
280  boundaryFaceToBeIncluded_.setSize
281  (
282  mesh_.nFaces()
283  - mesh_.nInternalFaces(),
284  1
285  );
286 
287  forAll(mesh_.boundaryMesh(), patchi)
288  {
289  const polyPatch& pp = mesh_.boundaryMesh()[patchi];
290  if
291  (
292  isA<processorPolyPatch>(pp)
293  && !refCast<const processorPolyPatch>(pp).owner()
294  )
295  {
296  label bFacei = pp.start()-mesh_.nInternalFaces();
297  forAll(pp, i)
298  {
299  boundaryFaceToBeIncluded_[bFacei++] = 0;
300  }
301  }
302  }
303 
304  // Count face types in each faceZone
305  forAll(faceZoneNamesAll, zoneI)
306  {
307  const word& zoneName = faceZoneNamesAll[zoneI];
308  const label faceZoneId = mesh_.faceZones().findZoneID(zoneName);
309 
310  const faceZone& fz = mesh_.faceZones()[faceZoneId];
311 
312  if (fz.size())
313  {
314  labelList& tris = faceZoneFaceSets_[faceZoneId].tris;
315  labelList& quads = faceZoneFaceSets_[faceZoneId].quads;
316  labelList& polys = faceZoneFaceSets_[faceZoneId].polys;
317 
318  tris.setSize(fz.size());
319  quads.setSize(fz.size());
320  polys.setSize(fz.size());
321 
322  label nTris = 0;
323  label nQuads = 0;
324  label nPolys = 0;
325 
326  label faceCounter = 0;
327 
328  forAll(fz, i)
329  {
330  label facei = fz[i];
331 
332  // Avoid counting faces on processor boundaries twice
333  if (faceToBeIncluded(facei))
334  {
335  const face& f = mesh_.faces()[facei];
336 
337  if (f.size() == 3)
338  {
339  tris[nTris++] = faceCounter;
340  }
341  else if (f.size() == 4)
342  {
343  quads[nQuads++] = faceCounter;
344  }
345  else
346  {
347  polys[nPolys++] = faceCounter;
348  }
349 
350  ++faceCounter;
351  }
352  }
353 
354  tris.setSize(nTris);
355  quads.setSize(nQuads);
356  polys.setSize(nPolys);
357  }
358  }
359 
360  forAll(faceZoneNamesAll, zoneI)
361  {
362  const word& zoneName = faceZoneNamesAll[zoneI];
363  nFacePrimitives nfp;
364  const label faceZoneId = mesh_.faceZones().findZoneID(zoneName);
365 
366  if (faceZoneNames_.found(zoneName))
367  {
368  if
369  (
370  faceZoneFaceSets_[faceZoneId].tris.size()
371  || faceZoneFaceSets_[faceZoneId].quads.size()
372  || faceZoneFaceSets_[faceZoneId].polys.size()
373  )
374  {
375  nfp.nTris = faceZoneFaceSets_[faceZoneId].tris.size();
376  nfp.nQuads = faceZoneFaceSets_[faceZoneId].quads.size();
377  nfp.nPolys = faceZoneFaceSets_[faceZoneId].polys.size();
378  }
379  }
380 
381  reduce(nfp.nTris, sumOp<label>());
382  reduce(nfp.nQuads, sumOp<label>());
383  reduce(nfp.nPolys, sumOp<label>());
384 
385  nFaceZonePrims_.insert(zoneName, nfp);
386  }
387  }
388 }
389 
390 
391 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
392 
393 Foam::ensightMesh::ensightMesh
394 (
395  const fvMesh& mesh,
396  const bool noPatches,
397 
398  const bool patches,
399  const wordReList& patchPatterns,
400 
401  const bool faceZones,
402  const wordReList& faceZonePatterns,
403 
404  const bool binary
405 )
406 :
407  mesh_(mesh),
408  noPatches_(noPatches),
409  patches_(patches),
410  patchPatterns_(patchPatterns),
411  faceZones_(faceZones),
412  faceZonePatterns_(faceZonePatterns),
413  binary_(binary),
414  meshCellSets_(mesh.nCells())
415 {
416  correct();
417 }
418 
419 
420 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
421 
423 {}
424 
425 
426 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
427 
428 bool Foam::ensightMesh::faceToBeIncluded(const label facei) const
429 {
430  bool res = false;
431 
432  if (mesh_.isInternalFace(facei))
433  {
434  res = true;
435  }
436  else
437  {
438  res = boundaryFaceToBeIncluded_[facei-mesh_.nInternalFaces()];
439  }
440 
441  return res;
442 }
443 
444 
446 {
447  label appI = 0;
448  reduce(appI,maxOp<label>());
449 }
450 
451 
452 Foam::cellShapeList Foam::ensightMesh::map
453 (
454  const cellShapeList& cellShapes,
455  const labelList& prims,
456  const labelList& pointToGlobal
457 ) const
458 {
459  cellShapeList mcsl(prims.size());
460 
461  forAll(prims, i)
462  {
463  mcsl[i] = cellShapes[prims[i]];
464  inplaceRenumber(pointToGlobal, mcsl[i]);
465  }
466 
467  return mcsl;
468 }
469 
470 
471 Foam::cellShapeList Foam::ensightMesh::map
472 (
473  const cellShapeList& cellShapes,
474  const labelList& hexes,
475  const labelList& wedges,
476  const labelList& pointToGlobal
477 ) const
478 {
479  cellShapeList mcsl(hexes.size() + wedges.size());
480 
481  forAll(hexes, i)
482  {
483  mcsl[i] = cellShapes[hexes[i]];
484  inplaceRenumber(pointToGlobal, mcsl[i]);
485  }
486 
487  label offset = hexes.size();
488 
489  const cellModel& hex = *(cellModeller::lookup("hex"));
490  labelList hexLabels(8);
491 
492  forAll(wedges, i)
493  {
494  const cellShape& cellPoints = cellShapes[wedges[i]];
495 
496  hexLabels[0] = cellPoints[0];
497  hexLabels[1] = cellPoints[1];
498  hexLabels[2] = cellPoints[0];
499  hexLabels[3] = cellPoints[2];
500  hexLabels[4] = cellPoints[3];
501  hexLabels[5] = cellPoints[4];
502  hexLabels[6] = cellPoints[6];
503  hexLabels[7] = cellPoints[5];
504 
505  mcsl[i + offset] = cellShape(hex, hexLabels);
506  inplaceRenumber(pointToGlobal, mcsl[i + offset]);
507  }
508 
509  return mcsl;
510 }
511 
512 
513 void Foam::ensightMesh::writePrims
514 (
515  const cellShapeList& cellShapes,
516  ensightStream& ensightGeometryFile
517 ) const
518 {
519  // Create a temp int array
520  if (cellShapes.size())
521  {
522  if (ensightGeometryFile.ascii())
523  {
524  // Workaround for paraview issue : write one cell per line
525 
526  forAll(cellShapes, i)
527  {
528  const cellShape& cellPoints = cellShapes[i];
529 
530  List<int> temp(cellPoints.size());
531 
532  forAll(cellPoints, pointi)
533  {
534  temp[pointi] = cellPoints[pointi] + 1;
535  }
536  ensightGeometryFile.write(temp);
537  }
538  }
539  else
540  {
541  // All the cellShapes have the same number of elements!
542  int numIntElem = cellShapes.size()*cellShapes[0].size();
543  List<int> temp(numIntElem);
544 
545  int n = 0;
546 
547  forAll(cellShapes, i)
548  {
549  const cellShape& cellPoints = cellShapes[i];
550 
551  forAll(cellPoints, pointi)
552  {
553  temp[n] = cellPoints[pointi] + 1;
554  n++;
555  }
556  }
557  ensightGeometryFile.write(temp);
558  }
559  }
560 }
561 
562 
563 void Foam::ensightMesh::writePolysNFaces
564 (
565  const labelList& polys,
566  const cellList& cellFaces,
567  ensightStream& ensightGeometryFile
568 ) const
569 {
570  forAll(polys, i)
571  {
572  ensightGeometryFile.write(cellFaces[polys[i]].size());
573  }
574 }
575 
576 
577 void Foam::ensightMesh::writePolysNPointsPerFace
578 (
579  const labelList& polys,
580  const cellList& cellFaces,
581  const faceList& faces,
582  ensightStream& ensightGeometryFile
583 ) const
584 {
585  forAll(polys, i)
586  {
587  const labelList& cf = cellFaces[polys[i]];
588 
589  forAll(cf, facei)
590  {
591  ensightGeometryFile.write(faces[cf[facei]].size());
592  }
593  }
594 }
595 
596 
597 void Foam::ensightMesh::writePolysPoints
598 (
599  const labelList& polys,
600  const cellList& cellFaces,
601  const faceList& faces,
602  const labelList& faceOwner,
603  ensightStream& ensightGeometryFile
604 ) const
605 {
606  forAll(polys, i)
607  {
608  const labelList& cf = cellFaces[polys[i]];
609 
610  forAll(cf, facei)
611  {
612  const label faceId = cf[facei];
613  const face& f = faces[faceId]; // points of face (in global points)
614  const label np = f.size();
615  bool reverseOrder = false;
616  if (faceId >= faceOwner.size())
617  {
618  // Boundary face.
619  // Nothing should be done for processor boundary.
620  // The current cell always owns them. Given that we
621  // are reverting the
622  // order when the cell is the neighbour to the face,
623  // the orientation of
624  // all the boundaries, no matter if they are "real"
625  // or processorBoundaries, is consistent.
626  }
627  else
628  {
629  if (faceOwner[faceId] != polys[i])
630  {
631  reverseOrder = true;
632  }
633  }
634 
635  // If the face owner is the current cell, write the points
636  // in the standard order.
637  // If the face owner is not the current cell, write the points
638  // in reverse order.
639  // EnSight prefers to have all the faces of an nfaced cell
640  // oriented in the same way.
641  List<int> temp(np);
642  forAll(f, pointi)
643  {
644  if (reverseOrder)
645  {
646  temp[np-1-pointi] = f[pointi] + 1;
647  }
648  else
649  {
650  temp[pointi] = f[pointi] + 1;
651  }
652  }
653  ensightGeometryFile.write(temp);
654  }
655  }
656 }
657 
658 
659 void Foam::ensightMesh::writeAllPolys
660 (
661  const labelList& pointToGlobal,
662  ensightStream& ensightGeometryFile
663 ) const
664 {
665  if (meshCellSets_.nPolys)
666  {
667  const cellList& cellFaces = mesh_.cells();
668  const labelList& faceOwner = mesh_.faceOwner();
669 
670  // Renumber faces to use global point numbers
671  faceList faces(mesh_.faces());
672  forAll(faces, i)
673  {
674  inplaceRenumber(pointToGlobal, faces[i]);
675  }
676 
677  if (Pstream::master())
678  {
679  ensightGeometryFile.write("nfaced");
680  ensightGeometryFile.write(meshCellSets_.nPolys);
681  }
682 
683  // Number of faces for each poly cell
684 
685  if (Pstream::master())
686  {
687  // Master
688  writePolysNFaces
689  (
690  meshCellSets_.polys,
691  cellFaces,
692  ensightGeometryFile
693  );
694  // Slaves
695  for (int slave=1; slave<Pstream::nProcs(); slave++)
696  {
697  IPstream fromSlave(Pstream::scheduled, slave);
698  labelList polys(fromSlave);
699  cellList cellFaces(fromSlave);
700 
701  writePolysNFaces
702  (
703  polys,
704  cellFaces,
705  ensightGeometryFile
706  );
707  }
708  }
709  else
710  {
711  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
712  toMaster<< meshCellSets_.polys << cellFaces;
713  }
714 
715 
716  // Number of points for each face of the above list
717  if (Pstream::master())
718  {
719  // Master
720  writePolysNPointsPerFace
721  (
722  meshCellSets_.polys,
723  cellFaces,
724  faces,
725  ensightGeometryFile
726  );
727  // Slaves
728  for (int slave=1; slave<Pstream::nProcs(); slave++)
729  {
730  IPstream fromSlave(Pstream::scheduled, slave);
731  labelList polys(fromSlave);
732  cellList cellFaces(fromSlave);
733  faceList faces(fromSlave);
734 
735  writePolysNPointsPerFace
736  (
737  polys,
738  cellFaces,
739  faces,
740  ensightGeometryFile
741  );
742  }
743  }
744  else
745  {
746  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
747  toMaster<< meshCellSets_.polys << cellFaces << faces;
748  }
749 
750 
751  // List of points id for each face of the above list
752  if (Pstream::master())
753  {
754  // Master
755  writePolysPoints
756  (
757  meshCellSets_.polys,
758  cellFaces,
759  faces,
760  faceOwner,
761  ensightGeometryFile
762  );
763  // Slaves
764  for (int slave=1; slave<Pstream::nProcs(); slave++)
765  {
766  IPstream fromSlave(Pstream::scheduled, slave);
767  labelList polys(fromSlave);
768  cellList cellFaces(fromSlave);
769  faceList faces(fromSlave);
770  labelList faceOwner(fromSlave);
771 
772  writePolysPoints
773  (
774  polys,
775  cellFaces,
776  faces,
777  faceOwner,
778  ensightGeometryFile
779  );
780  }
781  }
782  else
783  {
784  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
785  toMaster<< meshCellSets_.polys << cellFaces << faces << faceOwner;
786  }
787  }
788 }
789 
790 
791 void Foam::ensightMesh::writeAllPrims
792 (
793  const char* key,
794  const label nPrims,
795  const cellShapeList& cellShapes,
796  ensightStream& ensightGeometryFile
797 ) const
798 {
799  if (nPrims)
800  {
801  if (Pstream::master())
802  {
803  ensightGeometryFile.write(key);
804  ensightGeometryFile.write(nPrims);
805 
806  writePrims(cellShapes, ensightGeometryFile);
807 
808  for (int slave=1; slave<Pstream::nProcs(); slave++)
809  {
810  IPstream fromSlave(Pstream::scheduled, slave);
811  cellShapeList cellShapes(fromSlave);
812 
813  writePrims(cellShapes, ensightGeometryFile);
814  }
815  }
816  else
817  {
818  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
819  toMaster<< cellShapes;
820  }
821  }
822 }
823 
824 
825 void Foam::ensightMesh::writeFacePrims
826 (
827  const faceList& patchFaces,
828  ensightStream& ensightGeometryFile
829 ) const
830 {
831  forAll(patchFaces, i)
832  {
833  const face& patchFace = patchFaces[i];
834 
835  List<int> temp(patchFace.size());
836  forAll(patchFace, pointi)
837  {
838  temp[pointi] = patchFace[pointi] + 1;
839  }
840 
841  ensightGeometryFile.write(temp);
842  }
843 }
844 
845 
846 void Foam::ensightMesh::writeAllFacePrims
847 (
848  const char* key,
849  const labelList& prims,
850  const label nPrims,
851  const faceList& patchFaces,
852  ensightStream& ensightGeometryFile
853 ) const
854 {
855  if (nPrims)
856  {
857  if (Pstream::master())
858  {
859  ensightGeometryFile.write(key);
860  ensightGeometryFile.write(nPrims);
861 
862  writeFacePrims
863  (
864  UIndirectList<face>(patchFaces, prims)(),
865  ensightGeometryFile
866  );
867 
868  for (int slave=1; slave<Pstream::nProcs(); slave++)
869  {
870  IPstream fromSlave(Pstream::scheduled, slave);
871  faceList patchFaces(fromSlave);
872 
873  writeFacePrims(patchFaces, ensightGeometryFile);
874  }
875  }
876  else
877  {
878  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
879  toMaster<< UIndirectList<face>(patchFaces, prims);
880  }
881  }
882 }
883 
884 
885 void Foam::ensightMesh::writeNSidedNPointsPerFace
886 (
887  const faceList& patchFaces,
888  ensightStream& ensightGeometryFile
889 ) const
890 {
891  forAll(patchFaces, i)
892  {
893  ensightGeometryFile.write(patchFaces[i].size());
894  }
895 }
896 
897 
898 void Foam::ensightMesh::writeNSidedPoints
899 (
900  const faceList& patchFaces,
901  ensightStream& ensightGeometryFile
902 ) const
903 {
904  writeFacePrims(patchFaces, ensightGeometryFile);
905 }
906 
907 
908 void Foam::ensightMesh::writeAllNSided
909 (
910  const labelList& prims,
911  const label nPrims,
912  const faceList& patchFaces,
913  ensightStream& ensightGeometryFile
914 ) const
915 {
916  if (nPrims)
917  {
918  if (Pstream::master())
919  {
920  ensightGeometryFile.write("nsided");
921  ensightGeometryFile.write(nPrims);
922  }
923 
924  // Number of points for each face
925  if (Pstream::master())
926  {
927  writeNSidedNPointsPerFace
928  (
929  UIndirectList<face>(patchFaces, prims)(),
930  ensightGeometryFile
931  );
932 
933  for (int slave=1; slave<Pstream::nProcs(); slave++)
934  {
935  IPstream fromSlave(Pstream::scheduled, slave);
936  faceList patchFaces(fromSlave);
937 
938  writeNSidedNPointsPerFace
939  (
940  patchFaces,
941  ensightGeometryFile
942  );
943  }
944  }
945  else
946  {
947  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
948  toMaster<< UIndirectList<face>(patchFaces, prims);
949  }
950 
951  // List of points id for each face
952  if (Pstream::master())
953  {
954  writeNSidedPoints
955  (
956  UIndirectList<face>(patchFaces, prims)(),
957  ensightGeometryFile
958  );
959 
960  for (int slave=1; slave<Pstream::nProcs(); slave++)
961  {
962  IPstream fromSlave(Pstream::scheduled, slave);
963  faceList patchFaces(fromSlave);
964 
965  writeNSidedPoints(patchFaces, ensightGeometryFile);
966  }
967  }
968  else
969  {
970  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
971  toMaster<< UIndirectList<face>(patchFaces, prims);
972  }
973  }
974 }
975 
976 
977 void Foam::ensightMesh::writeAllPoints
978 (
979  const label ensightPartI,
980  const word& ensightPartName,
981  const pointField& uniquePoints,
982  const label nPoints,
983  ensightStream& ensightGeometryFile
984 ) const
985 {
986  barrier();
987 
988  if (Pstream::master())
989  {
990  ensightGeometryFile.writePartHeader(ensightPartI);
991  ensightGeometryFile.write(ensightPartName.c_str());
992  ensightGeometryFile.write("coordinates");
993  ensightGeometryFile.write(nPoints);
994 
995  for (direction d=0; d<vector::nComponents; d++)
996  {
997  ensightGeometryFile.write(uniquePoints.component(d));
998  for (int slave=1; slave<Pstream::nProcs(); slave++)
999  {
1000  IPstream fromSlave(Pstream::scheduled, slave);
1001  scalarField patchPointsComponent(fromSlave);
1002  ensightGeometryFile.write(patchPointsComponent);
1003  }
1004  }
1005  }
1006  else
1007  {
1008  for (direction d=0; d<vector::nComponents; d++)
1009  {
1010  OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1011  toMaster<< uniquePoints.component(d);
1012  }
1013  }
1014 }
1015 
1016 
1018 (
1019  const fileName& postProcPath,
1020  const word& prepend,
1021  const label timeIndex,
1022  const bool meshMoving,
1023  Ostream& ensightCaseFile
1024 ) const
1025 {
1026  const Time& runTime = mesh_.time();
1027  const cellShapeList& cellShapes = mesh_.cellShapes();
1028 
1029 
1030  word timeFile = prepend;
1031 
1032  if (timeIndex == 0)
1033  {
1034  timeFile += "0000.";
1035  }
1036  else if (meshMoving)
1037  {
1038  timeFile += itoa(timeIndex) + '.';
1039  }
1040 
1041  // set the filename of the ensight file
1042  fileName ensightGeometryFileName = timeFile + "mesh";
1043 
1044  ensightStream* ensightGeometryFilePtr = NULL;
1045  if (Pstream::master())
1046  {
1047  if (binary_)
1048  {
1049  ensightGeometryFilePtr = new ensightBinaryStream
1050  (
1051  postProcPath/ensightGeometryFileName,
1052  runTime
1053  );
1054  ensightGeometryFilePtr->write("C binary");
1055  }
1056  else
1057  {
1058  ensightGeometryFilePtr = new ensightAsciiStream
1059  (
1060  postProcPath/ensightGeometryFileName,
1061  runTime
1062  );
1063  }
1064  }
1065 
1066  ensightStream& ensightGeometryFile = *ensightGeometryFilePtr;
1067 
1068  if (Pstream::master())
1069  {
1070  string desc = string("written by OpenFOAM-") + Foam::FOAMversion;
1071 
1072  ensightGeometryFile.write("EnSight Geometry File");
1073  ensightGeometryFile.write(desc.c_str());
1074  ensightGeometryFile.write("node id assign");
1075  ensightGeometryFile.write("element id assign");
1076  }
1077 
1078  if (patchNames_.empty())
1079  {
1080  label nPoints = globalPoints().size();
1081 
1082  const pointField uniquePoints(mesh_.points(), uniquePointMap_);
1083 
1084  writeAllPoints
1085  (
1086  1,
1087  "internalMesh",
1088  uniquePoints,
1089  nPoints,
1090  ensightGeometryFile
1091  );
1092 
1093  writeAllPrims
1094  (
1095  "hexa8",
1096  meshCellSets_.nHexesWedges,
1097  map // Rewrite cellShapes to global numbering
1098  (
1099  cellShapes,
1100  meshCellSets_.hexes,
1101  meshCellSets_.wedges,
1102  pointToGlobal_
1103  ),
1104  ensightGeometryFile
1105  );
1106 
1107  writeAllPrims
1108  (
1109  "penta6",
1110  meshCellSets_.nPrisms,
1111  map(cellShapes, meshCellSets_.prisms, pointToGlobal_),
1112  ensightGeometryFile
1113  );
1114 
1115  writeAllPrims
1116  (
1117  "pyramid5",
1118  meshCellSets_.nPyrs,
1119  map(cellShapes, meshCellSets_.pyrs, pointToGlobal_),
1120  ensightGeometryFile
1121  );
1122 
1123  writeAllPrims
1124  (
1125  "tetra4",
1126  meshCellSets_.nTets,
1127  map(cellShapes, meshCellSets_.tets, pointToGlobal_),
1128  ensightGeometryFile
1129  );
1130 
1131  writeAllPolys
1132  (
1133  pointToGlobal_,
1134  ensightGeometryFile
1135  );
1136  }
1137 
1138 
1139  label ensightPatchi = patchPartOffset_;
1140 
1141  forAll(allPatchNames_, patchi)
1142  {
1143  const word& patchName = allPatchNames_[patchi];
1144 
1145  if (patchNames_.empty() || patchNames_.found(patchName))
1146  {
1147  const nFacePrimitives& nfp = nPatchPrims_[patchName];
1148 
1149  if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1150  {
1151  const polyPatch& p = mesh_.boundaryMesh()[patchi];
1152 
1153  const labelList& tris = boundaryFaceSets_[patchi].tris;
1154  const labelList& quads = boundaryFaceSets_[patchi].quads;
1155  const labelList& polys = boundaryFaceSets_[patchi].polys;
1156 
1157  // Renumber the patch points/faces into unique points
1159  labelList uniqueMeshPointLabels;
1160  autoPtr<globalIndex> globalPointsPtr =
1161  mesh_.globalData().mergePoints
1162  (
1163  p.meshPoints(),
1164  p.meshPointMap(),
1165  pointToGlobal,
1166  uniqueMeshPointLabels
1167  );
1168 
1169  pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels);
1170  // Renumber the patch faces
1171  faceList patchFaces(p.localFaces());
1172  forAll(patchFaces, i)
1173  {
1174  inplaceRenumber(pointToGlobal, patchFaces[i]);
1175  }
1176 
1177  writeAllPoints
1178  (
1179  ensightPatchi++,
1180  patchName,
1181  uniquePoints,
1182  globalPointsPtr().size(),
1183  ensightGeometryFile
1184  );
1185 
1186  writeAllFacePrims
1187  (
1188  "tria3",
1189  tris,
1190  nfp.nTris,
1191  patchFaces,
1192  ensightGeometryFile
1193  );
1194 
1195  writeAllFacePrims
1196  (
1197  "quad4",
1198  quads,
1199  nfp.nQuads,
1200  patchFaces,
1201  ensightGeometryFile
1202  );
1203 
1204  writeAllNSided
1205  (
1206  polys,
1207  nfp.nPolys,
1208  patchFaces,
1209  ensightGeometryFile
1210  );
1211  }
1212  }
1213  }
1214 
1215  // write faceZones, if requested
1216  forAllConstIter(wordHashSet, faceZoneNames_, iter)
1217  {
1218  const word& faceZoneName = iter.key();
1219 
1220  label faceID = mesh_.faceZones().findZoneID(faceZoneName);
1221 
1222  const faceZone& fz = mesh_.faceZones()[faceID];
1223 
1224  const nFacePrimitives& nfp = nFaceZonePrims_[faceZoneName];
1225 
1226  if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1227  {
1228  const labelList& tris = faceZoneFaceSets_[faceID].tris;
1229  const labelList& quads = faceZoneFaceSets_[faceID].quads;
1230  const labelList& polys = faceZoneFaceSets_[faceID].polys;
1231 
1232  // Renumber the faceZone points/faces into unique points
1234  labelList uniqueMeshPointLabels;
1235  autoPtr<globalIndex> globalPointsPtr =
1236  mesh_.globalData().mergePoints
1237  (
1238  fz().meshPoints(),
1239  fz().meshPointMap(),
1240  pointToGlobal,
1241  uniqueMeshPointLabels
1242  );
1243 
1244  pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels);
1245 
1246  // Find the list of master faces belonging to the faceZone,
1247  // in local numbering
1248  faceList faceZoneFaces(fz().localFaces());
1249 
1250  // Count how many master faces belong to the faceZone. Is there
1251  // a better way of doing this?
1252  label nMasterFaces = 0;
1253 
1254  forAll(fz, facei)
1255  {
1256  if (faceToBeIncluded(fz[facei]))
1257  {
1258  ++nMasterFaces;
1259  }
1260  }
1261 
1262  // Create the faceList for the master faces only and fill it.
1263  faceList faceZoneMasterFaces(nMasterFaces);
1264 
1265  label currentFace = 0;
1266 
1267  forAll(fz, facei)
1268  {
1269  if (faceToBeIncluded(fz[facei]))
1270  {
1271  faceZoneMasterFaces[currentFace] = faceZoneFaces[facei];
1272  ++currentFace;
1273  }
1274  }
1275 
1276  // Renumber the faceZone master faces
1277  forAll(faceZoneMasterFaces, i)
1278  {
1279  inplaceRenumber(pointToGlobal, faceZoneMasterFaces[i]);
1280  }
1281 
1282  writeAllPoints
1283  (
1284  ensightPatchi++,
1285  faceZoneName,
1286  uniquePoints,
1287  globalPointsPtr().size(),
1288  ensightGeometryFile
1289  );
1290 
1291  writeAllFacePrims
1292  (
1293  "tria3",
1294  tris,
1295  nfp.nTris,
1296  faceZoneMasterFaces,
1297  ensightGeometryFile
1298  );
1299 
1300  writeAllFacePrims
1301  (
1302  "quad4",
1303  quads,
1304  nfp.nQuads,
1305  faceZoneMasterFaces,
1306  ensightGeometryFile
1307  );
1308 
1309  writeAllNSided
1310  (
1311  polys,
1312  nfp.nPolys,
1313  faceZoneMasterFaces,
1314  ensightGeometryFile
1315  );
1316  }
1317  }
1318 
1319  if (Pstream::master())
1320  {
1321  delete ensightGeometryFilePtr;
1322  }
1323 }
1324 
1325 
1326 // ************************************************************************* //
void write(const fileName &postProcPath, const word &prepend, const label timeIndex, const bool meshMoving, Ostream &ensightCaseFile) const
labelList polys
Definition: cellSets.H:59
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
uint8_t direction
Definition: direction.H:46
static int masterNo()
Process index of the master.
Definition: UPstream.H:405
label faceId(-1)
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
Definition: cellModeller.C:88
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
labelList hexes
Definition: cellSets.H:58
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
wordList names() const
Return a list of patch names.
label nPyrs
Definition: cellSets.H:49
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
word itoa(const label n)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
List< face > faceList
Definition: faceListFwd.H:43
label nPolys
Definition: cellSets.H:52
bool faceToBeIncluded(const label facei) const
When exporting faceZones, check if a given face has to be included.
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:411
const labelList & processorPatches() const
Return list of processor patch labels.
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
~ensightMesh()
Destructor.
Operations on lists of strings.
labelList pyrs
Definition: cellSets.H:55
patches[0]
const char *const FOAMversion
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
const cellList & cells() const
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Combination-Reduction operation for a parallel run. The information from all nodes is collected on th...
label nCells() const
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
labelList tets
Definition: cellSets.H:54
void correct()
Update for new mesh.
void setSize(const label nCells)
Definition: cellSets.H:84
const cellShapeList & cellShapes() const
Return cell shapes.
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:341
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:96
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:43
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:356
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const cellShapeList & cellShapes
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:256
void clear()
Clear all entries from table.
Definition: HashTable.C:464
void sort(UList< T > &)
Definition: UList.C:115
label nHexesWedges
Definition: cellSets.H:51
List< label > labelList
A List of labels.
Definition: labelList.H:56
HashSet wordHashSet
A HashSet with word keys.
Definition: HashSet.H:207
void setSize(const label, const unsigned int &val=0u)
Alias for resize()
Definition: PackedListI.H:822
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
void clear()
Clear the list, i.e. set addressable size to zero.
Definition: PackedListI.H:891
bool empty() const
Return true if the hash table is empty.
Definition: HashTableI.H:72
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1140
Istream and Ostream manipulators taking arguments.
const fvMesh & mesh() const
Definition: ensightMesh.H:281
labelList prisms
Definition: cellSets.H:56
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil)-psi)*pSat, rhoMin);#1"/home/ubuntu/OpenFOAM-4.1/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H"1{alphav=max(min((rho-rholSat)/(rhovSat-rholSat), scalar(1)), scalar(0));alphal=1.0-alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:72
static void barrier()
Helper to cause barrier. Necessary on Quadrics.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
label nTets
Definition: cellSets.H:48
label nFaces() const
List< word > wordList
A List of words.
Definition: fileName.H:54
void setSize(const label)
Reset size of List.
Definition: List.C:295
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:393
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:399
label patchi
label n
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1017
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
const labelList & pointToGlobal() const
From mesh point to global merged point.
Definition: ensightMesh.H:342
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:545
label nInternalFaces() const
labelList wedges
Definition: cellSets.H:57
const globalIndex & globalPoints() const
Global numbering for merged points.
Definition: ensightMesh.H:336
List< cell > cellList
list of cells
Definition: cellList.H:42
label nPrisms
Definition: cellSets.H:50
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29