ensightMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
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::commsTypes::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
712  (
715  );
716  toMaster<< meshCellSets_.polys << cellFaces;
717  }
718 
719 
720  // Number of points for each face of the above list
721  if (Pstream::master())
722  {
723  // Master
724  writePolysNPointsPerFace
725  (
726  meshCellSets_.polys,
727  cellFaces,
728  faces,
729  ensightGeometryFile
730  );
731  // Slaves
732  for (int slave=1; slave<Pstream::nProcs(); slave++)
733  {
734  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
735  labelList polys(fromSlave);
736  cellList cellFaces(fromSlave);
737  faceList faces(fromSlave);
738 
739  writePolysNPointsPerFace
740  (
741  polys,
742  cellFaces,
743  faces,
744  ensightGeometryFile
745  );
746  }
747  }
748  else
749  {
750  OPstream toMaster
751  (
754  );
755  toMaster<< meshCellSets_.polys << cellFaces << faces;
756  }
757 
758 
759  // List of points id for each face of the above list
760  if (Pstream::master())
761  {
762  // Master
763  writePolysPoints
764  (
765  meshCellSets_.polys,
766  cellFaces,
767  faces,
768  faceOwner,
769  ensightGeometryFile
770  );
771  // Slaves
772  for (int slave=1; slave<Pstream::nProcs(); slave++)
773  {
774  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
775  labelList polys(fromSlave);
776  cellList cellFaces(fromSlave);
777  faceList faces(fromSlave);
778  labelList faceOwner(fromSlave);
779 
780  writePolysPoints
781  (
782  polys,
783  cellFaces,
784  faces,
785  faceOwner,
786  ensightGeometryFile
787  );
788  }
789  }
790  else
791  {
792  OPstream toMaster
793  (
796  );
797  toMaster<< meshCellSets_.polys << cellFaces << faces << faceOwner;
798  }
799  }
800 }
801 
802 
803 void Foam::ensightMesh::writeAllPrims
804 (
805  const char* key,
806  const label nPrims,
807  const cellShapeList& cellShapes,
808  ensightStream& ensightGeometryFile
809 ) const
810 {
811  if (nPrims)
812  {
813  if (Pstream::master())
814  {
815  ensightGeometryFile.write(key);
816  ensightGeometryFile.write(nPrims);
817 
818  writePrims(cellShapes, ensightGeometryFile);
819 
820  for (int slave=1; slave<Pstream::nProcs(); slave++)
821  {
822  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
823  cellShapeList cellShapes(fromSlave);
824 
825  writePrims(cellShapes, ensightGeometryFile);
826  }
827  }
828  else
829  {
830  OPstream toMaster
831  (
834  );
835  toMaster<< cellShapes;
836  }
837  }
838 }
839 
840 
841 void Foam::ensightMesh::writeFacePrims
842 (
843  const faceList& patchFaces,
844  ensightStream& ensightGeometryFile
845 ) const
846 {
847  forAll(patchFaces, i)
848  {
849  const face& patchFace = patchFaces[i];
850 
851  List<int> temp(patchFace.size());
852  forAll(patchFace, pointi)
853  {
854  temp[pointi] = patchFace[pointi] + 1;
855  }
856 
857  ensightGeometryFile.write(temp);
858  }
859 }
860 
861 
862 void Foam::ensightMesh::writeAllFacePrims
863 (
864  const char* key,
865  const labelList& prims,
866  const label nPrims,
867  const faceList& patchFaces,
868  ensightStream& ensightGeometryFile
869 ) const
870 {
871  if (nPrims)
872  {
873  if (Pstream::master())
874  {
875  ensightGeometryFile.write(key);
876  ensightGeometryFile.write(nPrims);
877 
878  writeFacePrims
879  (
880  UIndirectList<face>(patchFaces, prims)(),
881  ensightGeometryFile
882  );
883 
884  for (int slave=1; slave<Pstream::nProcs(); slave++)
885  {
886  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
887  faceList patchFaces(fromSlave);
888 
889  writeFacePrims(patchFaces, ensightGeometryFile);
890  }
891  }
892  else
893  {
894  OPstream toMaster
895  (
898  );
899  toMaster<< UIndirectList<face>(patchFaces, prims);
900  }
901  }
902 }
903 
904 
905 void Foam::ensightMesh::writeNSidedNPointsPerFace
906 (
907  const faceList& patchFaces,
908  ensightStream& ensightGeometryFile
909 ) const
910 {
911  forAll(patchFaces, i)
912  {
913  ensightGeometryFile.write(patchFaces[i].size());
914  }
915 }
916 
917 
918 void Foam::ensightMesh::writeNSidedPoints
919 (
920  const faceList& patchFaces,
921  ensightStream& ensightGeometryFile
922 ) const
923 {
924  writeFacePrims(patchFaces, ensightGeometryFile);
925 }
926 
927 
928 void Foam::ensightMesh::writeAllNSided
929 (
930  const labelList& prims,
931  const label nPrims,
932  const faceList& patchFaces,
933  ensightStream& ensightGeometryFile
934 ) const
935 {
936  if (nPrims)
937  {
938  if (Pstream::master())
939  {
940  ensightGeometryFile.write("nsided");
941  ensightGeometryFile.write(nPrims);
942  }
943 
944  // Number of points for each face
945  if (Pstream::master())
946  {
947  writeNSidedNPointsPerFace
948  (
949  UIndirectList<face>(patchFaces, prims)(),
950  ensightGeometryFile
951  );
952 
953  for (int slave=1; slave<Pstream::nProcs(); slave++)
954  {
955  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
956  faceList patchFaces(fromSlave);
957 
958  writeNSidedNPointsPerFace
959  (
960  patchFaces,
961  ensightGeometryFile
962  );
963  }
964  }
965  else
966  {
967  OPstream toMaster
968  (
971  );
972  toMaster<< UIndirectList<face>(patchFaces, prims);
973  }
974 
975  // List of points id for each face
976  if (Pstream::master())
977  {
978  writeNSidedPoints
979  (
980  UIndirectList<face>(patchFaces, prims)(),
981  ensightGeometryFile
982  );
983 
984  for (int slave=1; slave<Pstream::nProcs(); slave++)
985  {
986  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
987  faceList patchFaces(fromSlave);
988 
989  writeNSidedPoints(patchFaces, ensightGeometryFile);
990  }
991  }
992  else
993  {
994  OPstream toMaster
995  (
998  );
999  toMaster<< UIndirectList<face>(patchFaces, prims);
1000  }
1001  }
1002 }
1003 
1004 
1005 void Foam::ensightMesh::writeAllPoints
1006 (
1007  const label ensightPartI,
1008  const word& ensightPartName,
1009  const pointField& uniquePoints,
1010  const label nPoints,
1011  ensightStream& ensightGeometryFile
1012 ) const
1013 {
1014  barrier();
1015 
1016  if (Pstream::master())
1017  {
1018  ensightGeometryFile.writePartHeader(ensightPartI);
1019  ensightGeometryFile.write(ensightPartName.c_str());
1020  ensightGeometryFile.write("coordinates");
1021  ensightGeometryFile.write(nPoints);
1022 
1023  for (direction d=0; d<vector::nComponents; d++)
1024  {
1025  ensightGeometryFile.write(uniquePoints.component(d));
1026  for (int slave=1; slave<Pstream::nProcs(); slave++)
1027  {
1028  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
1029  scalarField patchPointsComponent(fromSlave);
1030  ensightGeometryFile.write(patchPointsComponent);
1031  }
1032  }
1033  }
1034  else
1035  {
1036  for (direction d=0; d<vector::nComponents; d++)
1037  {
1038  OPstream toMaster
1039  (
1042  );
1043  toMaster<< uniquePoints.component(d);
1044  }
1045  }
1046 }
1047 
1048 
1050 (
1051  const fileName& postProcPath,
1052  const word& prepend,
1053  const label timeIndex,
1054  const bool meshMoving,
1055  Ostream& ensightCaseFile
1056 ) const
1057 {
1058  const Time& runTime = mesh_.time();
1059  const cellShapeList& cellShapes = mesh_.cellShapes();
1060 
1061 
1062  word timeFile = prepend;
1063 
1064  if (timeIndex == 0)
1065  {
1066  timeFile += "0000.";
1067  }
1068  else if (meshMoving)
1069  {
1070  timeFile += itoa(timeIndex) + '.';
1071  }
1072 
1073  // set the filename of the ensight file
1074  fileName ensightGeometryFileName = timeFile + "mesh";
1075 
1076  ensightStream* ensightGeometryFilePtr = nullptr;
1077  if (Pstream::master())
1078  {
1079  if (binary_)
1080  {
1081  ensightGeometryFilePtr = new ensightBinaryStream
1082  (
1083  postProcPath/ensightGeometryFileName,
1084  runTime
1085  );
1086  ensightGeometryFilePtr->write("C binary");
1087  }
1088  else
1089  {
1090  ensightGeometryFilePtr = new ensightAsciiStream
1091  (
1092  postProcPath/ensightGeometryFileName,
1093  runTime
1094  );
1095  }
1096  }
1097 
1098  ensightStream& ensightGeometryFile = *ensightGeometryFilePtr;
1099 
1100  if (Pstream::master())
1101  {
1102  string desc = string("written by OpenFOAM-") + Foam::FOAMversion;
1103 
1104  ensightGeometryFile.write("EnSight Geometry File");
1105  ensightGeometryFile.write(desc.c_str());
1106  ensightGeometryFile.write("node id assign");
1107  ensightGeometryFile.write("element id assign");
1108  }
1109 
1110  if (patchNames_.empty())
1111  {
1112  label nPoints = globalPoints().size();
1113 
1114  const pointField uniquePoints(mesh_.points(), uniquePointMap_);
1115 
1116  writeAllPoints
1117  (
1118  1,
1119  "internalMesh",
1120  uniquePoints,
1121  nPoints,
1122  ensightGeometryFile
1123  );
1124 
1125  writeAllPrims
1126  (
1127  "hexa8",
1128  meshCellSets_.nHexesWedges,
1129  map // Rewrite cellShapes to global numbering
1130  (
1131  cellShapes,
1132  meshCellSets_.hexes,
1133  meshCellSets_.wedges,
1134  pointToGlobal_
1135  ),
1136  ensightGeometryFile
1137  );
1138 
1139  writeAllPrims
1140  (
1141  "penta6",
1142  meshCellSets_.nPrisms,
1143  map(cellShapes, meshCellSets_.prisms, pointToGlobal_),
1144  ensightGeometryFile
1145  );
1146 
1147  writeAllPrims
1148  (
1149  "pyramid5",
1150  meshCellSets_.nPyrs,
1151  map(cellShapes, meshCellSets_.pyrs, pointToGlobal_),
1152  ensightGeometryFile
1153  );
1154 
1155  writeAllPrims
1156  (
1157  "tetra4",
1158  meshCellSets_.nTets,
1159  map(cellShapes, meshCellSets_.tets, pointToGlobal_),
1160  ensightGeometryFile
1161  );
1162 
1163  writeAllPolys
1164  (
1165  pointToGlobal_,
1166  ensightGeometryFile
1167  );
1168  }
1169 
1170 
1171  label ensightPatchi = patchPartOffset_;
1172 
1173  forAll(allPatchNames_, patchi)
1174  {
1175  const word& patchName = allPatchNames_[patchi];
1176 
1177  if (patchNames_.empty() || patchNames_.found(patchName))
1178  {
1179  const nFacePrimitives& nfp = nPatchPrims_[patchName];
1180 
1181  if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1182  {
1183  const polyPatch& p = mesh_.boundaryMesh()[patchi];
1184 
1185  const labelList& tris = boundaryFaceSets_[patchi].tris;
1186  const labelList& quads = boundaryFaceSets_[patchi].quads;
1187  const labelList& polys = boundaryFaceSets_[patchi].polys;
1188 
1189  // Renumber the patch points/faces into unique points
1191  labelList uniqueMeshPointLabels;
1192  autoPtr<globalIndex> globalPointsPtr =
1193  mesh_.globalData().mergePoints
1194  (
1195  p.meshPoints(),
1196  p.meshPointMap(),
1197  pointToGlobal,
1198  uniqueMeshPointLabels
1199  );
1200 
1201  pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels);
1202  // Renumber the patch faces
1203  faceList patchFaces(p.localFaces());
1204  forAll(patchFaces, i)
1205  {
1206  inplaceRenumber(pointToGlobal, patchFaces[i]);
1207  }
1208 
1209  writeAllPoints
1210  (
1211  ensightPatchi++,
1212  patchName,
1213  uniquePoints,
1214  globalPointsPtr().size(),
1215  ensightGeometryFile
1216  );
1217 
1218  writeAllFacePrims
1219  (
1220  "tria3",
1221  tris,
1222  nfp.nTris,
1223  patchFaces,
1224  ensightGeometryFile
1225  );
1226 
1227  writeAllFacePrims
1228  (
1229  "quad4",
1230  quads,
1231  nfp.nQuads,
1232  patchFaces,
1233  ensightGeometryFile
1234  );
1235 
1236  writeAllNSided
1237  (
1238  polys,
1239  nfp.nPolys,
1240  patchFaces,
1241  ensightGeometryFile
1242  );
1243  }
1244  }
1245  }
1246 
1247  // write faceZones, if requested
1248  forAllConstIter(wordHashSet, faceZoneNames_, iter)
1249  {
1250  const word& faceZoneName = iter.key();
1251 
1252  label faceID = mesh_.faceZones().findZoneID(faceZoneName);
1253 
1254  const faceZone& fz = mesh_.faceZones()[faceID];
1255 
1256  const nFacePrimitives& nfp = nFaceZonePrims_[faceZoneName];
1257 
1258  if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1259  {
1260  const labelList& tris = faceZoneFaceSets_[faceID].tris;
1261  const labelList& quads = faceZoneFaceSets_[faceID].quads;
1262  const labelList& polys = faceZoneFaceSets_[faceID].polys;
1263 
1264  // Renumber the faceZone points/faces into unique points
1266  labelList uniqueMeshPointLabels;
1267  autoPtr<globalIndex> globalPointsPtr =
1268  mesh_.globalData().mergePoints
1269  (
1270  fz().meshPoints(),
1271  fz().meshPointMap(),
1272  pointToGlobal,
1273  uniqueMeshPointLabels
1274  );
1275 
1276  pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels);
1277 
1278  // Find the list of master faces belonging to the faceZone,
1279  // in local numbering
1280  faceList faceZoneFaces(fz().localFaces());
1281 
1282  // Count how many master faces belong to the faceZone. Is there
1283  // a better way of doing this?
1284  label nMasterFaces = 0;
1285 
1286  forAll(fz, facei)
1287  {
1288  if (faceToBeIncluded(fz[facei]))
1289  {
1290  ++nMasterFaces;
1291  }
1292  }
1293 
1294  // Create the faceList for the master faces only and fill it.
1295  faceList faceZoneMasterFaces(nMasterFaces);
1296 
1297  label currentFace = 0;
1298 
1299  forAll(fz, facei)
1300  {
1301  if (faceToBeIncluded(fz[facei]))
1302  {
1303  faceZoneMasterFaces[currentFace] = faceZoneFaces[facei];
1304  ++currentFace;
1305  }
1306  }
1307 
1308  // Renumber the faceZone master faces
1309  forAll(faceZoneMasterFaces, i)
1310  {
1311  inplaceRenumber(pointToGlobal, faceZoneMasterFaces[i]);
1312  }
1313 
1314  writeAllPoints
1315  (
1316  ensightPatchi++,
1317  faceZoneName,
1318  uniquePoints,
1319  globalPointsPtr().size(),
1320  ensightGeometryFile
1321  );
1322 
1323  writeAllFacePrims
1324  (
1325  "tria3",
1326  tris,
1327  nfp.nTris,
1328  faceZoneMasterFaces,
1329  ensightGeometryFile
1330  );
1331 
1332  writeAllFacePrims
1333  (
1334  "quad4",
1335  quads,
1336  nfp.nQuads,
1337  faceZoneMasterFaces,
1338  ensightGeometryFile
1339  );
1340 
1341  writeAllNSided
1342  (
1343  polys,
1344  nfp.nPolys,
1345  faceZoneMasterFaces,
1346  ensightGeometryFile
1347  );
1348  }
1349  }
1350 
1351  if (Pstream::master())
1352  {
1353  delete ensightGeometryFilePtr;
1354  }
1355 }
1356 
1357 
1358 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
labelList polys
Definition: cellSets.H:59
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: MeshZones.C:341
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const labelList & processorPatches() const
Return list of processor patch labels.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
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
static int masterNo()
Process index of the master.
Definition: UPstream.H:417
label faceId(-1)
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Definition: cellModeller.C:100
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
labelList hexes
Definition: cellSets.H:58
label nPyrs
Definition: cellSets.H:49
label nInternalFaces() const
word itoa(const label n)
label nFaces() const
uint8_t direction
Definition: direction.H:45
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const cellShapeList & cellShapes() const
Return cell shapes.
bool empty() const
Return true if the hash table is empty.
Definition: HashTableI.H:72
List< face > faceList
Definition: faceListFwd.H:43
label nPolys
Definition: cellSets.H:52
label nCells() const
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
const cellList & cells() const
~ensightMesh()
Destructor.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
Operations on lists of strings.
labelList pyrs
Definition: cellSets.H:55
patches[0]
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
const char *const FOAMversion
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
Combination-Reduction operation for a parallel run. The information from all nodes is collected on th...
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
ensightMesh(const fvMesh &mesh, const bool noPatches, const bool patches, const wordReList &patchPatterns, const bool faceZones, const wordReList &faceZonePatterns, const bool binary)
Construct from fvMesh.
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1131
wordList names() const
Return a list of zone names.
Definition: MeshZones.C:256
labelList tets
Definition: cellSets.H:54
void correct()
Update for new mesh.
void setSize(const label nCells)
Definition: cellSets.H:84
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
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
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(rho0+psi *p, rhoMin);# 1 "/home/ubuntu/OpenFOAM-9/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:68
const cellShapeList & cellShapes
void clear()
Clear all entries from table.
Definition: HashTable.C:468
void sort(UList< T > &)
Definition: UList.C:115
wordList names() const
Return a list of patch names.
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1169
const fvMesh & mesh() const
Definition: ensightMesh.H:278
label nHexesWedges
Definition: cellSets.H:51
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1394
List< label > labelList
A List of labels.
Definition: labelList.H:56
HashSet wordHashSet
A HashSet with word keys.
Definition: HashSet.H:208
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1156
void setSize(const label, const unsigned int &val=0u)
Alias for resize()
Definition: PackedListI.H:820
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:889
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Istream and Ostream manipulators taking arguments.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
labelList prisms
Definition: cellSets.H:56
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 size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
List< word > wordList
A List of words.
Definition: fileName.H:54
void setSize(const label)
Reset size of List.
Definition: List.C:281
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
label patchi
const meshFaceZones & faceZones() const
Return face zones.
Definition: polyMesh.H:476
label n
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
const labelList & pointToGlobal() const
From mesh point to global merged point.
Definition: ensightMesh.H:339
const globalIndex & globalPoints() const
Global numbering for merged points.
Definition: ensightMesh.H:333
bool faceToBeIncluded(const label facei) const
When exporting faceZones, check if a given face has to be included.
labelList wedges
Definition: cellSets.H:57
List< cell > cellList
list of cells
Definition: cellList.H:42
label nPrisms
Definition: cellSets.H:50
void write(const fileName &postProcPath, const word &prepend, const label timeIndex, const bool meshMoving, Ostream &ensightCaseFile) const
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:540