From 4ea1f8f98ac57a1f7c73927560759bcfca82597e Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 30 Apr 2010 12:36:49 +0200
Subject: [PATCH] ENH: enable vtkPolyhedron support when detected

---
 .../PV3FoamReader/vtkPV3FoamReader.cxx        |  4 +-
 .../PV3FoamReader/vtkPV3FoamReader.h          | 18 ++---
 .../PV3FoamReader/vtkPV3Foam/Make/options     | 12 ++-
 .../vtkPV3Foam/vtkOpenFOAMPoints.H            |  2 +-
 .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C     | 14 ++--
 .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H     | 10 +--
 .../vtkPV3Foam/vtkPV3FoamAddToSelection.H     |  2 +-
 .../vtkPV3Foam/vtkPV3FoamFields.C             | 12 ++-
 .../PV3FoamReader/vtkPV3Foam/vtkPV3FoamMesh.C |  2 +-
 .../vtkPV3Foam/vtkPV3FoamMeshLagrangian.C     |  2 +-
 .../vtkPV3Foam/vtkPV3FoamMeshPatch.C          |  4 +-
 .../vtkPV3Foam/vtkPV3FoamMeshSet.C            |  4 +-
 .../vtkPV3Foam/vtkPV3FoamMeshVolume.C         | 79 +++++++++++--------
 .../vtkPV3Foam/vtkPV3FoamMeshZone.C           |  4 +-
 .../vtkPV3Foam/vtkPV3FoamPointFields.H        |  2 +-
 .../vtkPV3Foam/vtkPV3FoamUpdateInfo.C         |  2 +-
 .../vtkPV3Foam/vtkPV3FoamUtils.C              |  2 +-
 .../vtkPV3Foam/vtkPV3FoamVolFields.H          |  2 +-
 .../vtkPV3blockMeshReader.cxx                 |  4 +-
 .../vtkPV3blockMesh/vtkPV3blockMesh.C         |  6 +-
 .../vtkPV3blockMesh/vtkPV3blockMesh.H         |  8 +-
 .../vtkPV3blockMesh/vtkPV3blockMeshConvert.C  |  4 +-
 .../PV3Readers/vtkPV3Readers/vtkPV3Readers.C  |  2 +-
 .../graphics/ensightFoamReader/libuserd.C     |  2 +-
 .../fieldview9Reader/fieldview9Reader.C       |  4 +-
 .../fieldview9Reader/readerDatabase.H         |  2 +-
 26 files changed, 121 insertions(+), 88 deletions(-)

diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx
index d964ad78d35..5198de5eb11 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx
@@ -39,7 +39,7 @@ License
 #include "vtkStreamingDemandDrivenPipeline.h"
 #include "vtkStringArray.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "vtkPV3Foam.H"
 
 #undef EXPERIMENTAL_TIME_CACHING
@@ -413,7 +413,7 @@ int vtkPV3FoamReader::RequestData
 
 #endif
 
-    // Do any cleanup on the Foam side
+    // Do any cleanup on the OpenFOAM side
     foamData_->CleanUp();
 
     return 1;
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h
index d1dc2f72090..dc91b2e2776 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h
@@ -47,7 +47,7 @@ SourceFiles
 class vtkDataArraySelection;
 class vtkCallbackCommand;
 
-// Foam forward declarations
+// OpenFOAM forward declarations
 namespace Foam
 {
     class vtkPV3Foam;
@@ -78,16 +78,16 @@ public:
     vtkGetStringMacro(FileName);
 
     // Description:
-    // FOAM mesh caching control
+    // OpenFOAM mesh caching control
     vtkSetMacro(CacheMesh, int);
     vtkGetMacro(CacheMesh, int);
 
     // Description:
-    // FOAM refresh times/fields
+    // OpenFOAM refresh times/fields
     virtual void SetRefresh(int);
 
     // Description:
-    // FOAM Skip/include the 0/ time directory
+    // OpenFOAM skip/include the 0/ time directory
     vtkSetMacro(SkipZeroTime, int);
     vtkGetMacro(SkipZeroTime, int);
 
@@ -97,27 +97,27 @@ public:
     vtkGetMacro(UpdateGUI, int);
 
     // Description:
-    // FOAM extrapolate internal values onto the patches
+    // OpenFOAM extrapolate internal values onto the patches
     vtkSetMacro(ExtrapolatePatches, int);
     vtkGetMacro(ExtrapolatePatches, int);
 
     // Description:
-    // FOAM use vtkPolyhedron instead of decomposing polyhedra
+    // OpenFOAM use vtkPolyhedron instead of decomposing polyhedra
     vtkSetMacro(UseVTKPolyhedron, int);
     vtkGetMacro(UseVTKPolyhedron, int);
 
     // Description:
-    // FOAM read sets control
+    // OpenFOAM read sets control
     virtual void SetIncludeSets(int);
     vtkGetMacro(IncludeSets, int);
 
     // Description:
-    // FOAM read zones control
+    // OpenFOAM read zones control
     virtual void SetIncludeZones(int);
     vtkGetMacro(IncludeZones, int);
 
     // Description:
-    // FOAM display patch names control
+    // OpenFOAM display patch names control
     virtual void SetShowPatchNames(int);
     vtkGetMacro(ShowPatchNames, int);
 
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/Make/options b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/Make/options
index 48e0c4a9a3c..b10a420add9 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/Make/options
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/Make/options
@@ -1,10 +1,18 @@
+/* Note: enable vtkPolyhedron when available */
+
+PARAVIEW_INC=$(ParaView_DIR)/include/paraview-$(ParaView_MAJOR)
+
 EXE_INC = \
     -I$(LIB_SRC)/meshTools/lnInclude \
     -I$(LIB_SRC)/finiteVolume/lnInclude \
     -I$(LIB_SRC)/lagrangian/basic/lnInclude \
-    -I$(ParaView_DIR)/include/paraview-$(ParaView_MAJOR) \
     -I../../vtkPV3Readers/lnInclude \
-    -I../PV3FoamReader
+    -I../PV3FoamReader \
+    -I$(PARAVIEW_INC) \
+    $(shell \
+        test -f $(PARAVIEW_INC)/vtkPolyhedron.h && \
+        echo "-DHAS_VTK_POLYHEDRON" || echo "-UHAS_VTK_POLYHEDRON" \
+    )
 
 LIB_LIBS = \
     -lvtkPV3Readers \
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMPoints.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMPoints.H
index f518ecfaf3f..d6489ec11e2 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMPoints.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMPoints.H
@@ -56,7 +56,7 @@ inline void vtkSetOpenFOAMPoint
 }
 
 
-// Convert Foam mesh vertices to VTK
+// Convert OpenFOAM mesh vertices to VTK
 inline vtkPoints* vtkSetOpenFOAMPoints(const Foam::pointField& points)
 {
     vtkPoints *vtkpoints = vtkPoints::New();
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C
index c94572f729a..1a01cb65640 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C
@@ -26,7 +26,7 @@ License
 #include "vtkPV3Foam.H"
 #include "vtkPV3FoamReader.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "fvMesh.H"
 #include "Time.H"
 #include "patchZones.H"
@@ -426,12 +426,12 @@ void Foam::vtkPV3Foam::updateFoamMesh()
         meshPtr_ = NULL;
     }
 
-    // Check to see if the FOAM mesh has been created
+    // Check to see if the OpenFOAM mesh has been created
     if (!meshPtr_)
     {
         if (debug)
         {
-            Info<< "Creating Foam mesh for region " << meshRegion_
+            Info<< "Creating OpenFOAM mesh for region " << meshRegion_
                 << " at time=" << dbPtr_().timeName()
                 << endl;
 
@@ -454,7 +454,7 @@ void Foam::vtkPV3Foam::updateFoamMesh()
     {
         if (debug)
         {
-            Info<< "Using existing Foam mesh" << endl;
+            Info<< "Using existing OpenFOAM mesh" << endl;
         }
     }
 
@@ -488,7 +488,7 @@ void Foam::vtkPV3Foam::Update
 
     reader_->UpdateProgress(0.15);
 
-    // Update the Foam mesh
+    // Update the OpenFOAM mesh
     updateFoamMesh();
     reader_->UpdateProgress(0.4);
 
@@ -527,6 +527,10 @@ void Foam::vtkPV3Foam::Update
     convertVolFields(output);
     convertPointFields(output);
     convertLagrangianFields(lagrangianOutput);
+    if (debug)
+    {
+        Info<< "done reader part" << endl;
+    }
     reader_->UpdateProgress(0.95);
 
     meshChanged_ = fieldsChanged_ = false;
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H
index 7b874029d61..62e7d42ed1a 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H
@@ -89,7 +89,7 @@ class vtkIndent;
 namespace Foam
 {
 
-// Foam class forward declarations
+// OpenFOAM class forward declarations
 class argList;
 class Time;
 class fvMesh;
@@ -249,10 +249,10 @@ class vtkPV3Foam
         //- Access to the controlling vtkPV3FoamReader
         vtkPV3FoamReader* reader_;
 
-        //- Foam time control
+        //- OpenFOAM time control
         autoPtr<Time> dbPtr_;
 
-        //- Foam mesh
+        //- OpenFOAM mesh
         fvMesh* meshPtr_;
 
         //- The mesh region
@@ -384,7 +384,7 @@ class vtkPV3Foam
 
         // Update helper functions
 
-            //- Foam mesh
+            //- OpenFOAM mesh
             void updateFoamMesh();
 
             //- Reduce memory footprint after conversion
@@ -496,7 +496,7 @@ class vtkPV3Foam
         );
 
 
-        // Convert Foam fields
+        // Convert OpenFOAM fields
 
             //- Volume fields - all types
             template<class Type>
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddToSelection.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddToSelection.H
index 451d08b65dc..6858a2ea73e 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddToSelection.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddToSelection.H
@@ -26,7 +26,7 @@ License
 #ifndef vtkPV3FoamAddToSelection_H
 #define vtkPV3FoamAddToSelection_H
 
-// FOAM includes
+// OpenFOAM includes
 #include "IOobjectList.H"
 #include "SortableList.H"
 
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C
index 3ede5b2f710..25e9582d6a2 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "IOobjectList.H"
 #include "vtkPV3FoamReader.h"
 
@@ -94,7 +94,7 @@ void Foam::vtkPV3Foam::convertVolFields
     if (debug)
     {
         Info<< "<beg> Foam::vtkPV3Foam::convertVolFields" << nl
-            << "converting Foam volume fields" << endl;
+            << "converting OpenFOAM volume fields" << endl;
         forAllConstIter(IOobjectList, objects, iter)
         {
             Info<< "  " << iter()->name()
@@ -163,6 +163,10 @@ void Foam::vtkPV3Foam::convertPointFields
 
     if (selectedFields.empty())
     {
+        if (debug)
+        {
+            Info<< "no point fields selected" << endl;
+        }
         return;
     }
 
@@ -179,7 +183,7 @@ void Foam::vtkPV3Foam::convertPointFields
     if (debug)
     {
         Info<< "<beg> Foam::vtkPV3Foam::convertPointFields" << nl
-            << "converting Foam volume fields" << endl;
+            << "converting OpenFOAM volume fields -> point fields" << endl;
         forAllConstIter(IOobjectList, objects, iter)
         {
             Info<< "  " << iter()->name()
@@ -274,7 +278,7 @@ void Foam::vtkPV3Foam::convertLagrangianFields
 
         if (debug)
         {
-            Info<< "converting Foam lagrangian fields" << nl;
+            Info<< "converting OpenFOAM lagrangian fields" << nl;
             forAllConstIter(IOobjectList, objects, iter)
             {
                 Info<< "  " << iter()->name()
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMesh.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMesh.C
index 5442d468cf4..f68a207df11 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMesh.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMesh.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "cellSet.H"
 #include "faceSet.H"
 #include "pointSet.H"
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C
index 9822282393d..2f0f4a2f4f3 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "Cloud.H"
 #include "fvMesh.H"
 #include "IOobjectList.H"
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshPatch.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshPatch.C
index e9da7f40705..ea0ba18f47c 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshPatch.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshPatch.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "polyPatch.H"
 #include "primitivePatch.H"
 #include "vtkOpenFOAMPoints.H"
@@ -47,7 +47,7 @@ vtkPolyData* Foam::vtkPV3Foam::patchVTKMesh(const polyPatch& p)
         printMemory();
     }
 
-    // Convert Foam mesh vertices to VTK
+    // Convert OpenFOAM mesh vertices to VTK
     const Foam::pointField& points = p.localPoints();
 
     vtkPoints* vtkpoints = vtkPoints::New();
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshSet.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshSet.C
index 3e9893b3778..7960c07dca1 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshSet.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshSet.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "faceSet.H"
 #include "pointSet.H"
 #include "vtkOpenFOAMPoints.H"
@@ -65,7 +65,7 @@ vtkPolyData* Foam::vtkPV3Foam::faceSetVTKMesh
 
     // The balance of this routine should be identical to patchVTKMesh
 
-    // Convert Foam mesh vertices to VTK
+    // Convert OpenFOAM mesh vertices to VTK
     const pointField& points = p.localPoints();
 
     vtkPoints* vtkpoints = vtkPoints::New();
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshVolume.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshVolume.C
index 96884fae249..02c0484a5d4 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshVolume.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshVolume.C
@@ -26,7 +26,7 @@ License
 #include "vtkPV3Foam.H"
 #include "vtkPV3FoamReader.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "fvMesh.H"
 #include "cellModeller.H"
 #include "vtkOpenFOAMPoints.H"
@@ -74,15 +74,15 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
     labelList& superCells = decompInfo.superCells();
     labelList& addPointCellLabels = decompInfo.addPointCellLabels();
 
-    if (debug)
-    {
-        Info<< "... scanning" << endl;
-    }
-
     // Scan for cells which need to be decomposed and count additional points
     // and cells
     if (!reader_->GetUseVTKPolyhedron())
     {
+        if (debug)
+        {
+            Info<< "... scanning for polyhedra" << endl;
+        }
+
         forAll(cellShapes, cellI)
         {
             const cellModel& model = cellShapes[cellI].model();
@@ -138,7 +138,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
         Info<< "... converting points" << endl;
     }
 
-    // Convert Foam mesh vertices to VTK
+    // Convert OpenFOAM mesh vertices to VTK
     vtkPoints* vtkpoints = vtkPoints::New();
     vtkpoints->Allocate(mesh.nPoints() + nAddPoints);
 
@@ -164,6 +164,17 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
     // data types - max 'order' = hex = 8 points
     vtkIdType nodeIds[8];
 
+    // hash to establish unique node ids for a polyhedral cell
+    HashSet<vtkIdType, Hash<label> > hashUniqId(2*256);
+
+    // unique node ids for a polyhedral cell
+    DynamicList<vtkIdType> uniqueNodeIds(256);
+
+    // face-stream for a polyhedral cell
+    // [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...]
+    DynamicList<vtkIdType> faceStream(256);
+
+
     forAll(cellShapes, cellI)
     {
         const cellShape& cellShape = cellShapes[cellI];
@@ -272,7 +283,6 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
             const labelList& cFaces = mesh.cells()[cellI];
 
             vtkIdType nFaces = cFaces.size();
-            vtkIdType nodeCount = 0;
             vtkIdType nLabels = nFaces;
 
             // count size for face stream
@@ -282,46 +292,51 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
                 nLabels += f.size();
             }
 
-            // unique node ids - approximately equal to the number of point ids
-            DynamicList<vtkIdType> uniqueNodeIds(nLabels-nFaces);
+            // hash to establish unique node ids for a polyhedral cell
+            hashUniqId.clear();
 
-            // zero-based index into uniqueNodeIds
-            DynamicList<vtkIdType> faceLabels(nLabels);
+            // unique node ids - approximately equal to the number of point ids
+            uniqueNodeIds.clear();
+            uniqueNodeIds.reserve(nLabels-nFaces);
 
-            // localized point id within the cell
-            Map<label> mapLocalId(2*nLabels);
+            // build face-stream
+            // [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...]
+            // point Ids are global
+            faceStream.clear();
+            faceStream.reserve(nLabels + nFaces);
 
-            // establish the unique point ids,
-            // record the local mapping ids,
-            // create new face list
             forAll(cFaces, cFaceI)
             {
                 const face& f = mesh.faces()[cFaces[cFaceI]];
+                const bool isOwner = (owner[cFaces[cFaceI]] == cellI);
                 const label nFacePoints = f.size();
 
                 // number of labels for this face
-                faceLabels.append(nFacePoints);
+                faceStream.append(nFacePoints);
 
-                forAll(f, fp)
+                if (isOwner)
                 {
-                    const label nodeId = f[fp];
-
-                    if (mapLocalId.insert(nodeId, nodeCount))
+                    forAll(f, fp)
                     {
-                        // insertion was successful (node Id was unique)
-                        uniqueNodeIds.append(nodeId);
-                        // map orig vertex id -> localized point label
-                        faceLabels.append(nodeCount);
-                        ++nodeCount;
+                        hashUniqId.insert(f[fp]);
+                        faceStream.append(f[fp]);
                     }
-                    else
+                }
+                else
+                {
+                    // fairly immaterial if we reverse the list
+                    // or use face::reverseFace()
+                    forAllReverse(f, fp)
                     {
-                        // map orig vertex id -> localized point label
-                        faceLabels.append(mapLocalId[nodeId]);
+                        hashUniqId.insert(f[fp]);
+                        faceStream.append(f[fp]);
                     }
                 }
             }
 
+            uniqueNodeIds.append(hashUniqId.sortedToc());
+            vtkIdType nodeCount = uniqueNodeIds.size();
+
 #ifdef HAS_VTK_POLYHEDRON
             vtkmesh->InsertNextCell
             (
@@ -329,9 +344,11 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
                 nodeCount,
                 uniqueNodeIds.data(),
                 nFaces,
-                faceLabels.data()
+                faceStream.data()
             );
 #else
+            // this is a horrible substitute
+            // but avoids crashes when there is no vtkPolyhedron support
             vtkmesh->InsertNextCell
             (
                 VTK_CONVEX_POINT_SET,
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshZone.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshZone.C
index c4bb977fb75..0f47f53d7e3 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshZone.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshZone.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "vtkOpenFOAMPoints.H"
 
 // VTK includes
@@ -62,7 +62,7 @@ vtkPolyData* Foam::vtkPV3Foam::faceZoneVTKMesh
 
     // The balance of this routine should be identical to patchVTKMesh
 
-    // Convert Foam mesh vertices to VTK
+    // Convert OpenFOAM mesh vertices to VTK
     const pointField& points = p.localPoints();
 
     vtkPoints* vtkpoints = vtkPoints::New();
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamPointFields.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamPointFields.H
index 0ca9092af98..a243d81a7cc 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamPointFields.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamPointFields.H
@@ -29,7 +29,7 @@ InClass
 #ifndef vtkPV3FoamPointFields_H
 #define vtkPV3FoamPointFields_H
 
-// Foam includes
+// OpenFOAM includes
 #include "interpolatePointToCell.H"
 
 #include "vtkOpenFOAMTupleRemap.H"
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C
index 8f610a283f7..dcc1b962bb0 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C
@@ -25,7 +25,7 @@ License
 
 #include "vtkPV3Foam.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "cellSet.H"
 #include "faceSet.H"
 #include "pointSet.H"
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUtils.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUtils.C
index 01d87a4f14b..878baa244a5 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUtils.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUtils.C
@@ -29,7 +29,7 @@ Description
 #include "vtkPV3Foam.H"
 #include "vtkPV3FoamReader.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "fvMesh.H"
 #include "Time.H"
 #include "IFstream.H"
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H
index f4a328916d6..cad7ffb0114 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H
@@ -29,7 +29,7 @@ InClass
 #ifndef vtkPV3FoamVolFields_H
 #define vtkPV3FoamVolFields_H
 
-// Foam includes
+// OpenFOAM includes
 #include "emptyFvPatchField.H"
 #include "wallPolyPatch.H"
 #include "faceSet.H"
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/PV3blockMeshReader/vtkPV3blockMeshReader.cxx b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/PV3blockMeshReader/vtkPV3blockMeshReader.cxx
index d65680ce7a2..5deee083ae2 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/PV3blockMeshReader/vtkPV3blockMeshReader.cxx
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/PV3blockMeshReader/vtkPV3blockMeshReader.cxx
@@ -39,7 +39,7 @@ License
 #include "vtkStreamingDemandDrivenPipeline.h"
 #include "vtkStringArray.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "vtkPV3blockMesh.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@@ -226,7 +226,7 @@ int vtkPV3blockMeshReader::RequestData
     foamData_->Update(output);
     updatePointNumbersView(ShowPointNumbers);
 
-    // Do any cleanup on the Foam side
+    // Do any cleanup on the OpenFOAM side
     foamData_->CleanUp();
 
     return 1;
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.C
index 4460ce2ab16..a7483a210c0 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.C
@@ -26,7 +26,7 @@ License
 #include "vtkPV3blockMesh.H"
 #include "vtkPV3blockMeshReader.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "blockMesh.H"
 #include "Time.H"
 #include "patchZones.H"
@@ -298,7 +298,7 @@ void Foam::vtkPV3blockMesh::updateFoamMesh()
         Info<< "<beg> Foam::vtkPV3blockMesh::updateFoamMesh" << endl;
     }
 
-    // Check to see if the FOAM mesh has been created
+    // Check to see if the OpenFOAM mesh has been created
     if (!meshPtr_)
     {
         if (debug)
@@ -347,7 +347,7 @@ void Foam::vtkPV3blockMesh::Update
 
     reader_->UpdateProgress(0.2);
 
-    // Update the Foam mesh
+    // Update the OpenFOAM mesh
     updateFoamMesh();
     reader_->UpdateProgress(0.5);
 
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.H
index aac26fdd359..2efb067cd72 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMesh.H
@@ -71,7 +71,7 @@ class vtkIndent;
 namespace Foam
 {
 
-// Foam class forward declarations
+// OpenFOAM class forward declarations
 class argList;
 class Time;
 class blockMesh;
@@ -167,10 +167,10 @@ class vtkPV3blockMesh
         //- Access to the controlling vtkPV3blockMeshReader
         vtkPV3blockMeshReader* reader_;
 
-        //- Foam time control
+        //- OpenFOAM time control
         autoPtr<Time> dbPtr_;
 
-        //- Foam mesh
+        //- OpenFOAM mesh
         blockMesh* meshPtr_;
 
         //- Selected geometrical parts
@@ -242,7 +242,7 @@ class vtkPV3blockMesh
 
         // Update helper functions
 
-            //- Foam mesh
+            //- OpenFOAM mesh
             void updateFoamMesh();
 
         // Mesh conversion functions
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMeshConvert.C b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMeshConvert.C
index 71e277d5345..dd038d13ad9 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMeshConvert.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3blockMeshReader/vtkPV3blockMesh/vtkPV3blockMeshConvert.C
@@ -26,7 +26,7 @@ License
 #include "vtkPV3blockMesh.H"
 #include "vtkPV3blockMeshReader.h"
 
-// Foam includes
+// OpenFOAM includes
 #include "blockMesh.H"
 #include "Time.H"
 
@@ -81,7 +81,7 @@ void Foam::vtkPV3blockMesh::convertMeshBlocks
 
         vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
 
-        // Convert Foam mesh vertices to VTK
+        // Convert OpenFOAM mesh vertices to VTK
         vtkPoints *vtkpoints = vtkPoints::New();
         vtkpoints->Allocate( blockDef.nPoints() );
         const labelList& blockLabels = blockDef.blockShape();
diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/vtkPV3Readers/vtkPV3Readers.C b/applications/utilities/postProcessing/graphics/PV3Readers/vtkPV3Readers/vtkPV3Readers.C
index 4dcb2aee93a..a1c9bc09362 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/vtkPV3Readers/vtkPV3Readers.C
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/vtkPV3Readers/vtkPV3Readers.C
@@ -28,7 +28,7 @@ Description
 
 #include "vtkPV3Readers.H"
 
-// Foam includes
+// OpenFOAM includes
 #include "IFstream.H"
 
 // VTK includes
diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/libuserd.C b/applications/utilities/postProcessing/graphics/ensightFoamReader/libuserd.C
index e8e44ac74f7..f81925bb728 100644
--- a/applications/utilities/postProcessing/graphics/ensightFoamReader/libuserd.C
+++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/libuserd.C
@@ -73,7 +73,7 @@ extern "C"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // slightly changed with 2.0 from 1.0
-// (to handle complex variables -  not used by FOAM anyway)
+// (to handle complex variables - not used by OpenFOAM anyway)
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #include "USERD_get_constant_val.H"
diff --git a/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C b/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C
index a2bebe924c7..230ffd79e04 100644
--- a/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C
+++ b/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C
@@ -117,7 +117,7 @@ void register_functions()
 
 
 //
-// Storage for all Foam state (mainly database & mesh)
+// Storage for all OpenFOAM state (mainly database & mesh)
 //
 static readerDatabase db_;
 
@@ -521,7 +521,7 @@ void user_query_file_function
             (
                 "Could not find system/ and constant/ directory in\n"
               + rootAndCase
-              + "\nPlease select a Foam case directory."
+              + "\nPlease select an OpenFOAM case directory."
             );
 
             *iret = 1;
diff --git a/applications/utilities/postProcessing/graphics/fieldview9Reader/readerDatabase.H b/applications/utilities/postProcessing/graphics/fieldview9Reader/readerDatabase.H
index 211c78b39e7..14fc9d4ced1 100644
--- a/applications/utilities/postProcessing/graphics/fieldview9Reader/readerDatabase.H
+++ b/applications/utilities/postProcessing/graphics/fieldview9Reader/readerDatabase.H
@@ -25,7 +25,7 @@ Class
     Foam::readerDatabase
 
 Description
-    Singleton caching Foam database and mesh and various. Used in Fv reader
+    Singleton caching OpenFOAM database and mesh and various. Used in Fv reader
     to keep track of data inbetween callbacks.
 
 SourceFiles
-- 
GitLab