From 19e03f7dd1773ad907abb0e0f1d652b2a0e18c9a Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Mon, 17 Sep 2018 09:00:51 +0200
Subject: [PATCH] ENH: add renumbering support into foamVtuSizing algorithm
 (issue #926)

- allows cell point labels will use global numbering, but only for
  unmerged points. We'd ideally like to avoid point merging per se,
  and instead use VTK point blanking instead (as required).

  This approach allows parallel collation of the output into a single
  piece directly.
---
 src/fileFormats/vtk/part/foamVtuCells.C       |  27 +-
 src/fileFormats/vtk/part/foamVtuCells.H       |  39 +--
 src/fileFormats/vtk/part/foamVtuSizing.C      | 267 ++++++++++++++++--
 src/fileFormats/vtk/part/foamVtuSizing.H      | 106 +++++--
 src/fileFormats/vtk/part/foamVtuSizingI.H     |   2 +-
 .../vtk/part/foamVtuSizingTemplates.C         |  78 +++--
 6 files changed, 428 insertions(+), 91 deletions(-)

diff --git a/src/fileFormats/vtk/part/foamVtuCells.C b/src/fileFormats/vtk/part/foamVtuCells.C
index ca134c23c73..f23278f4a52 100644
--- a/src/fileFormats/vtk/part/foamVtuCells.C
+++ b/src/fileFormats/vtk/part/foamVtuCells.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -62,13 +62,13 @@ Foam::vtk::vtuCells::vtuCells
 
 Foam::vtk::vtuCells::vtuCells
 (
-    const vtk::outputOptions outOpts,
+    const vtk::outputOptions opts,
     const bool decompose
 )
 :
     vtuCells
     (
-        (outOpts.legacy() ? contentType::LEGACY : contentType::XML),
+        (opts.legacy() ? contentType::LEGACY : contentType::XML),
         decompose
     )
 {}
@@ -77,22 +77,16 @@ Foam::vtk::vtuCells::vtuCells
 Foam::vtk::vtuCells::vtuCells
 (
     const polyMesh& mesh,
-    const vtk::outputOptions outOpts,
+    const vtk::outputOptions opts,
     const bool decompose
 )
 :
-    vtuCells(outOpts, decompose)
+    vtuCells(opts, decompose)
 {
     reset(mesh);
 }
 
 
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::vtk::vtuCells::~vtuCells()
-{}
-
-
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void Foam::vtk::vtuCells::clear()
@@ -108,9 +102,9 @@ void Foam::vtk::vtuCells::clear()
 }
 
 
-void Foam::vtk::vtuCells::reset(const polyMesh& mesh)
+void Foam::vtk::vtuCells::repopulate(const polyMesh& mesh)
 {
-    vtuSizing::reset(mesh, decomposeRequest_);
+    // vtuSizing::reset() called prior to this method
 
     cellTypes_.setSize(nFieldCells());
     vertLabels_.setSize(sizeOf(output_, slotType::CELLS));
@@ -157,6 +151,13 @@ void Foam::vtk::vtuCells::reset(const polyMesh& mesh)
 }
 
 
+void Foam::vtk::vtuCells::reset(const polyMesh& mesh)
+{
+    vtuSizing::reset(mesh, decomposeRequest_);
+    repopulate(mesh);
+}
+
+
 void Foam::vtk::vtuCells::reset
 (
     const polyMesh& mesh,
diff --git a/src/fileFormats/vtk/part/foamVtuCells.H b/src/fileFormats/vtk/part/foamVtuCells.H
index 67381ed60e7..97cb36398ac 100644
--- a/src/fileFormats/vtk/part/foamVtuCells.H
+++ b/src/fileFormats/vtk/part/foamVtuCells.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2011-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -58,13 +58,13 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of classes
+// Forward declarations
 class polyMesh;
 
 namespace vtk
 {
-// Forward declaration of classes
-    class outputOptions;
+// Forward declarations
+class outputOptions;
 
 /*---------------------------------------------------------------------------*\
                      Class Foam::vtk::vtuCells Declaration
@@ -76,7 +76,7 @@ class vtuCells
 {
     // Private Member Data
 
-      // Requested output types
+    // Requested output types
 
         //- Output content type
         contentType output_;
@@ -84,7 +84,8 @@ class vtuCells
         //- Bookkeeping for polyhedral cell decomposition
         bool decomposeRequest_;
 
-      // Storage of output
+
+    // Storage of output
 
         //- Cell types (including added cells) in vtk numbering
         //  Range is 1-255
@@ -108,6 +109,10 @@ class vtuCells
 
     // Private Member Functions
 
+        //- Create the geometry using the previously requested output and
+        //  decomposition types.
+        void repopulate(const polyMesh& mesh);
+
         //- No copy construct
         vtuCells(const vtuCells&) = delete;
 
@@ -128,7 +133,7 @@ public:
         );
 
         //- Construct from components and create the output information
-        //  immediately
+        //- immediately
         vtuCells
         (
             const polyMesh& mesh,
@@ -140,27 +145,27 @@ public:
         //  Optionally with polyhedral decomposition.
         vtuCells
         (
-            const vtk::outputOptions outOpts,
+            const vtk::outputOptions opts,
             const bool decompose = false
         );
 
-        //- Construct from components and create the output information
-        //  immediately
+        //- Construct from components, and create the output information
+        //- immediately
         vtuCells
         (
             const polyMesh& mesh,
-            const vtk::outputOptions outOpts,
+            const vtk::outputOptions opts,
             const bool decompose = false
         );
 
 
     //- Destructor
-    ~vtuCells();
+    ~vtuCells() = default;
 
 
     // Member Functions
 
-      // Access
+    // Access
 
         //- The output content type
         inline enum contentType content() const;
@@ -175,17 +180,17 @@ public:
         inline label size() const;
 
 
-      // Edit
+    // Edit
 
         //- Reset all sizes to zero.
         void clear();
 
         //- Create the geometry using the previously requested output and
-        //  decomposition types.
+        //- decomposition types.
         void reset(const polyMesh& mesh);
 
         //- Respecify requested output and decomposition type prior to
-        //  creating the geometry
+        //- creating the geometry
         void reset
         (
             const polyMesh& mesh,
@@ -200,7 +205,7 @@ public:
         void renumberPoints(const labelUList& mapping);
 
 
-      // Storage Access
+    // Storage Access
 
         //- Values for "types" (XML) and "CELL_TYPES" (legacy)
         inline const List<uint8_t>& cellTypes() const;
diff --git a/src/fileFormats/vtk/part/foamVtuSizing.C b/src/fileFormats/vtk/part/foamVtuSizing.C
index 417d19e854d..47084495515 100644
--- a/src/fileFormats/vtk/part/foamVtuSizing.C
+++ b/src/fileFormats/vtk/part/foamVtuSizing.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -42,6 +42,12 @@ void Foam::vtk::vtuSizing::presizeMaps(foamVtkMeshMaps& maps) const
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
+Foam::vtk::vtuSizing::vtuSizing()
+{
+    clear();
+}
+
+
 Foam::vtk::vtuSizing::vtuSizing
 (
     const polyMesh& mesh,
@@ -53,13 +59,24 @@ Foam::vtk::vtuSizing::vtuSizing
 }
 
 
-Foam::vtk::vtuSizing::vtuSizing()
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::vtk::vtuSizing::clear()
 {
-    clear();
-}
+    decompose_   = false;
+    nCells_      = 0;
+    nPoints_     = 0;
+    nVertLabels_ = 0;
+
+    nFaceLabels_ = 0;
+    nCellsPoly_  = 0;
+    nVertPoly_   = 0;
 
+    nAddCells_   = 0;
+    nAddPoints_  = 0;
+    nAddVerts_   = 0;
+}
 
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void Foam::vtk::vtuSizing::reset
 (
@@ -90,7 +107,9 @@ void Foam::vtk::vtuSizing::reset
     nFaceLabels_ = 0;
     nVertPoly_   = 0;
 
-    forAll(shapes, celli)
+    const label len = mesh.nCells();
+
+    for (label celli=0; celli < len; ++celli)
     {
         const cellShape& shape = shapes[celli];
         const cellModel& model = shape.model();
@@ -177,7 +196,7 @@ void Foam::vtk::vtuSizing::reset
         }
     }
 
-    // decompose requested and needed
+    // Requested and actually required
     decompose_ = (decompose && nCellsPoly_);
 }
 
@@ -262,6 +281,8 @@ Foam::label Foam::vtk::vtuSizing::sizeOf
 }
 
 
+// * * * * * * * * * * * * * *  Populate Lists * * * * * * * * * * * * * * * //
+
 void Foam::vtk::vtuSizing::populateLegacy
 (
     const polyMesh& mesh,
@@ -491,30 +512,235 @@ void Foam::vtk::vtuSizing::populateInternal
 }
 
 
-void Foam::vtk::vtuSizing::clear()
+// * * * * * * * * * * * * * * Renumber vertices * * * * * * * * * * * * * * //
+
+Foam::labelList Foam::vtk::vtuSizing::copyVertLabelsLegacy
+(
+    const labelUList& vertLabels,
+    const label globalPointOffset
+)
 {
-    decompose_   = false;
-    nCells_      = 0;
-    nPoints_     = 0;
-    nVertLabels_ = 0;
+    if (!globalPointOffset)
+    {
+        return vertLabels;
+    }
 
-    nFaceLabels_ = 0;
-    nCellsPoly_  = 0;
-    nVertPoly_   = 0;
+    labelList output(vertLabels);
+    renumberVertLabelsLegacy(output, globalPointOffset);
 
-    nAddCells_   = 0;
-    nAddPoints_  = 0;
-    nAddVerts_   = 0;
+    return output;
+}
+
+
+void Foam::vtk::vtuSizing::renumberVertLabelsLegacy
+(
+    labelUList& vertLabels,
+    const label globalPointOffset
+)
+{
+    if (!globalPointOffset)
+    {
+        return;
+    }
+
+    // LEGACY vertLabels = "cells" contains
+    // - connectivity
+    // [nLabels, vertex labels...]
+    // - face-stream
+    // [nLabels nFaces, nFace0Pts, id1,id2,..., nFace1Pts, id1,id2,...]
+
+    // Note the simplest volume cell is a tet (4 points, 4 faces)
+    // As a poly-face stream this would have
+    // 2 for nLabels, nFaces
+    // 4 labels (size + ids) per face * 4 == 16 labels
+    //
+    // Therefore anything with 18 labels or more must be a poly
+
+    auto iter = vertLabels.begin();
+    auto last = vertLabels.end();
+
+    while (iter < last)
+    {
+        label nLabels = *iter;  // nLabels (for this cell)
+        ++iter;
+
+        if (nLabels < 18)
+        {
+            // Normal primitive type
+
+            while (nLabels--)
+            {
+                *iter += globalPointOffset;
+                ++iter;
+            }
+        }
+        else
+        {
+            // Polyhedral face-stream (explained above)
+
+            label nFaces = *iter;
+            ++iter;
+
+            while (nFaces--)
+            {
+                nLabels = *iter;  // nLabels (for this face)
+                ++iter;
+
+                while (nLabels--)
+                {
+                    *iter += globalPointOffset;
+                    ++iter;
+                }
+            }
+        }
+    }
 }
 
 
+Foam::labelList Foam::vtk::vtuSizing::copyVertLabelsXml
+(
+    const labelUList& vertLabels,
+    const label globalPointOffset
+)
+{
+    if (!globalPointOffset)
+    {
+        return vertLabels;
+    }
+
+    labelList output(vertLabels);
+    renumberVertLabelsXml(output, globalPointOffset);
+
+    return output;
+}
+
+
+void Foam::vtk::vtuSizing::renumberVertLabelsXml
+(
+    labelUList& vertLabels,
+    const label globalPointOffset
+)
+{
+    if (!globalPointOffset)
+    {
+        return;
+    }
+
+    // XML vertLabels = "connectivity" contains
+    // [cell1-verts, cell2-verts, ...]
+
+    for (label& vertId : vertLabels)
+    {
+        vertId += globalPointOffset;
+    }
+}
+
+
+Foam::labelList Foam::vtk::vtuSizing::copyFaceLabelsXml
+(
+    const labelUList& faceLabels,
+    const label globalPointOffset
+)
+{
+    if (!globalPointOffset)
+    {
+        return faceLabels;
+    }
+
+    labelList output(faceLabels);
+    renumberFaceLabelsXml(output, globalPointOffset);
+
+    return output;
+}
+
+
+void Foam::vtk::vtuSizing::renumberFaceLabelsXml
+(
+    labelUList& faceLabels,
+    const label globalPointOffset
+)
+{
+    if (!globalPointOffset)
+    {
+        return;
+    }
+
+    // XML face-stream
+    // [nFaces, nFace0Pts, id1,id2,..., nFace1Pts, id1,id2,...]
+
+    auto iter = faceLabels.begin();
+    auto last = faceLabels.end();
+
+    while (iter < last)
+    {
+        label nFaces = *iter;
+        ++iter;
+
+        while (nFaces--)
+        {
+            label nLabels = *iter;
+            ++iter;
+
+            while (nLabels--)
+            {
+                *iter += globalPointOffset;
+                ++iter;
+            }
+        }
+    }
+}
+
+
+Foam::labelList Foam::vtk::vtuSizing::copyFaceOffsetsXml
+(
+    const labelUList& faceOffsets,
+    const label prevOffset
+)
+{
+    if (!prevOffset)
+    {
+        return faceOffsets;
+    }
+
+    labelList output(faceOffsets);
+    renumberFaceOffsetsXml(output, prevOffset);
+
+    return output;
+}
+
+
+void Foam::vtk::vtuSizing::renumberFaceOffsetsXml
+(
+    labelUList& faceOffsets,
+    const label prevOffset
+)
+{
+    if (!prevOffset)
+    {
+        return;
+    }
+
+    // offsets
+    // [-1, off1, off2, ... -1, ..]
+
+    for (label& val : faceOffsets)
+    {
+        if (val != -1)
+        {
+            val += prevOffset;
+        }
+    }
+}
+
+
+// * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
+
 void Foam::vtk::vtuSizing::info(Ostream& os) const
 {
     os  << "nFieldCells:" << nFieldCells();
     if (nAddCells_)
     {
-        os  << " (" << nCells_
-            << "+" << nAddCells_ << ")";
+        os  << " (" << nCells_ << "+" << nAddCells_ << ")";
     }
     else
     {
@@ -549,6 +775,7 @@ bool Foam::vtk::vtuSizing::operator==(const vtuSizing& rhs) const
     return
     (
         decompose()   == rhs.decompose()
+        // required?  && pointOffset() == rhs.pointOffset()
      && nCells()      == rhs.nCells()
      && nPoints()     == rhs.nPoints()
      && nVertLabels() == rhs.nVertLabels()
diff --git a/src/fileFormats/vtk/part/foamVtuSizing.H b/src/fileFormats/vtk/part/foamVtuSizing.H
index be2f6e405a4..8b892d1e329 100644
--- a/src/fileFormats/vtk/part/foamVtuSizing.H
+++ b/src/fileFormats/vtk/part/foamVtuSizing.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -76,6 +76,13 @@ Description
     The VTK storage concept for "connectivity" and "faces" somewhat resemble
     a CompactListList.
 
+Note
+    It is possible to specify a global point offset (via the globalIndex)
+    so that the cell point labels will use global numbering.
+    There is no support for point renumbering with merged mesh points,
+    since it likely more efficient to use VTK point-blanking to mark duplicate
+    points instead of merging points ourselves.
+
 SourceFiles
     foamVtuSizing.C
     foamVtuSizingI.H
@@ -94,7 +101,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of classes
+// Forward declarations
 class polyMesh;
 
 namespace vtk
@@ -144,7 +151,7 @@ private:
         //- Number of vertex labels to represent the mesh
         label nVertLabels_;
 
-      // Polyhedrals
+    // Polyhedrals
 
         //- Number of polyhedral face labels for the mesh
         label nFaceLabels_;
@@ -155,7 +162,7 @@ private:
         //- Number of vertex labels used by polyhedrals
         label nVertPoly_;
 
-      // Decomposed polyhedrals
+    // Decomposed polyhedrals
 
         //- Number of additional (decomposed) cells for the mesh
         label nAddCells_;
@@ -172,7 +179,7 @@ private:
         //- set-size for cellMap and additionalIds
         void presizeMaps(foamVtkMeshMaps& maps) const;
 
-        //- Populate lists for internal VTK representation
+        //- Populate lists. For (legacy | xml | internal) VTK representations
         template<class LabelType, class LabelType2>
         static void populateArrays
         (
@@ -188,7 +195,6 @@ private:
             UList<LabelType2>& addPointsIds
         );
 
-        // Allow default bitwise copy/assignment
 
 public:
 
@@ -197,9 +203,13 @@ public:
         //- Construct null.
         vtuSizing();
 
-        //- Construct sizes by analyzing the mesh,
-        //  optionally with polyhedral decomposition.
-        vtuSizing(const polyMesh& mesh, const bool decompose=false);
+        //- Construct sizing by analyzing the mesh.
+        //  No polyhedral decomposition.
+        explicit vtuSizing(const polyMesh& mesh);
+
+        //- Construct sizing by analyzing the mesh.
+        //  Optionally with polyhedral decomposition.
+        vtuSizing(const polyMesh& mesh, const bool decompose);
 
 
     //- Destructor
@@ -208,19 +218,19 @@ public:
 
     // Member Functions
 
-      // Edit
+    // Edit
 
-        //- Construct sizes by analyzing the mesh,
-        //  optionally with polyhedral decomposition.
+        //- Reset sizing by analyzing the mesh.
+        //  Optionally with polyhedral decomposition.
         void reset(const polyMesh& mesh, const bool decompose=false);
 
         //- Reset all sizes to zero.
         void clear();
 
 
-      // Access
+    // Access
 
-        //- Query the decompose flag
+        //- Query the decompose flag (normally off)
         inline bool decompose() const;
 
         //- Number of cells for the mesh
@@ -258,7 +268,7 @@ public:
         inline label nFieldPoints() const;
 
 
-      // Derived sizes
+    // Derived sizes
 
         //- Return the required size for the storage slot
         label sizeOf
@@ -281,7 +291,7 @@ public:
         inline label sizeInternal(const enum slotType slot) const;
 
 
-      // Utility routines
+    // Routines for populating the output lists
 
         //- Populate lists for Legacy output
         void populateLegacy
@@ -380,13 +390,73 @@ public:
         ) const;
 
 
-      // Write
+    // Routines for renumber vertices with a global point offset
+    // Legacy and xml only, internal version less likely to be needed
+
+        //- Copy vertex labels with a global point offset - legacy format
+        static labelList copyVertLabelsLegacy
+        (
+            const labelUList& connectivity,
+            const label globalPointOffset
+        );
+
+        //- Copy vertex labels with a global point offset - XML format
+        static labelList copyVertLabelsXml
+        (
+            const labelUList& connectivity,
+            const label globalPointOffset
+        );
+
+        //- Copy faces stream labels with a global point offset - XML format
+        static labelList copyFaceLabelsXml
+        (
+            const labelUList& faceLabels,
+            const label globalPointOffset
+        );
+
+        //- Copy face offsets with an offset from previous - XML format
+        static labelList copyFaceOffsetsXml
+        (
+            const labelUList& faceOffsets,
+            const label prevOffset
+        );
+
+        //- Renumber vertex labels by global point offset - legacy format
+        static void renumberVertLabelsLegacy
+        (
+            labelUList& connectivity,
+            const label globalPointOffset
+        );
+
+        //- Renumber vertex labels by global point offset - XML format
+        static void renumberVertLabelsXml
+        (
+            labelUList& connectivity,
+            const label globalPointOffset
+        );
+
+        //- Renumber faces stream labels by global point offset - XML format
+        static void renumberFaceLabelsXml
+        (
+            labelUList& faceLabels,
+            const label globalPointOffset
+        );
+
+        //- Renumber face offsets with an offset from previous - XML format
+        static void renumberFaceOffsetsXml
+        (
+            labelUList& faceOffsets,
+            const label prevOffset
+        );
+
+
+    // Write
 
         //- Report some information
         void info(Ostream& os) const;
 
 
-      // Member Operators
+    // Member Operators
 
         //- Test equality
         bool operator==(const vtuSizing& rhs) const;
diff --git a/src/fileFormats/vtk/part/foamVtuSizingI.H b/src/fileFormats/vtk/part/foamVtuSizingI.H
index 6777ce7e7a9..a00bf8ac483 100644
--- a/src/fileFormats/vtk/part/foamVtuSizingI.H
+++ b/src/fileFormats/vtk/part/foamVtuSizingI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
diff --git a/src/fileFormats/vtk/part/foamVtuSizingTemplates.C b/src/fileFormats/vtk/part/foamVtuSizingTemplates.C
index 40df139d2c7..f5253f04b37 100644
--- a/src/fileFormats/vtk/part/foamVtuSizingTemplates.C
+++ b/src/fileFormats/vtk/part/foamVtuSizingTemplates.C
@@ -263,7 +263,9 @@ void Foam::vtk::vtuSizing::populateArrays
     // the per-cell vertLabels entries, and the faceOffset contains the *size*
     // associated with the per-cell faceLabels.
 
-    forAll(shapes, celli)
+    const label len = shapes.size();
+
+    for (label celli=0; celli < len; ++celli)
     {
         const cellShape& shape = shapes[celli];
         const cellModel& model = shape.model();
@@ -282,9 +284,9 @@ void Foam::vtk::vtuSizing::populateArrays
                 vertLabels[nVertLabels++] = shape.size();
             }
 
-            forAll(shape, i)
+            for (const label cpi : shape)
             {
-                vertLabels[nVertLabels++] = shape[i];
+                vertLabels[nVertLabels++] = cpi;
             }
         }
         else if (model == pyr)
@@ -299,9 +301,9 @@ void Foam::vtk::vtuSizing::populateArrays
                 vertLabels[nVertLabels++] = shape.size();
             }
 
-            forAll(shape, i)
+            for (const label cpi : shape)
             {
-                vertLabels[nVertLabels++] = shape[i];
+                vertLabels[nVertLabels++] = cpi;
             }
         }
         else if (model == hex)
@@ -316,9 +318,9 @@ void Foam::vtk::vtuSizing::populateArrays
                 vertLabels[nVertLabels++] = shape.size();
             }
 
-            forAll(shape, i)
+            for (const label cpi : shape)
             {
-                vertLabels[nVertLabels++] = shape[i];
+                vertLabels[nVertLabels++] = cpi;
             }
         }
         else if (model == prism)
@@ -403,10 +405,11 @@ void Foam::vtk::vtuSizing::populateArrays
             bool first = true;
 
             const labelList& cFaces = mesh.cells()[celli];
-            forAll(cFaces, cFaceI)
+
+            for (const label facei : cFaces)
             {
-                const face& f = mesh.faces()[cFaces[cFaceI]];
-                const bool isOwner = (owner[cFaces[cFaceI]] == celli);
+                const face& f = mesh.faces()[facei];
+                const bool isOwner = (owner[facei] == celli);
 
                 // Count triangles/quads in decomposition
                 label nTria = 0, nQuad = 0;
@@ -418,10 +421,10 @@ void Foam::vtk::vtuSizing::populateArrays
                 nTria = 0, nQuad = 0;
                 f.trianglesQuads(mesh.points(), nTria, nQuad, faces3, faces4);
 
-                forAll(faces4, fci)
+                for (const face& quad : faces4)
                 {
                     // Quad becomes a pyramid
-                    const face& quad = faces4[fci];
+
                     const label nShapePoints = 5;  // pyr (5 vertices)
 
                     label celLoc, vrtLoc;
@@ -466,13 +469,14 @@ void Foam::vtk::vtuSizing::populateArrays
                         vertLabels[vrtLoc++] = quad[3];
                     }
 
-                    vertLabels[vrtLoc++] = newVertexLabel; // apex
+                    // The apex
+                    vertLabels[vrtLoc++] = newVertexLabel;
                 }
 
-                forAll(faces3, fci)
+                for (const face& tria : faces3)
                 {
                     // Triangle becomes a tetrahedral
-                    const face& tria = faces3[fci];
+
                     const label nShapePoints = 4;  // tet (4 vertices)
 
                     label celLoc, vrtLoc;
@@ -516,7 +520,9 @@ void Foam::vtk::vtuSizing::populateArrays
                         vertLabels[vrtLoc++] = tria[1];
                         vertLabels[vrtLoc++] = tria[2];
                     }
-                    vertLabels[vrtLoc++] = newVertexLabel; // apex
+
+                    // The apex
+                    vertLabels[vrtLoc++] = newVertexLabel;
                 }
             }
         }
@@ -540,14 +546,14 @@ void Foam::vtk::vtuSizing::populateArrays
 
             faceOutput[faceIndexer++] = cFaces.size();
 
-            forAll(cFaces, cFaceI)
+            for (const label facei : cFaces)
             {
-                const face& f = mesh.faces()[cFaces[cFaceI]];
-                const bool isOwner = (owner[cFaces[cFaceI]] == celli);
+                const face& f = mesh.faces()[facei];
+                const bool isOwner = (owner[facei] == celli);
 
                 hashUniqId.insert(f);
 
-                // number of labels for this face
+                // The number of labels for this face
                 faceOutput[faceIndexer++] = f.size();
 
                 if (isOwner)
@@ -586,9 +592,9 @@ void Foam::vtk::vtuSizing::populateArrays
                 }
 
                 const labelList uniq = hashUniqId.sortedToc();
-                forAll(uniq, i)
+                for (const label fpi : uniq)
                 {
-                    vertLabels[nVertLabels++] = uniq[i];
+                    vertLabels[nVertLabels++] = fpi;
                 }
             }
         }
@@ -662,4 +668,32 @@ void Foam::vtk::vtuSizing::populateArrays
 }
 
 
+//unused template<class LabelType, class LabelType2>
+//unused void Foam::vtk::vtuSizing::renumberVertLabelsInternalImpl
+//unused (
+//unused     UList<uint8_t>& cellTypes,
+//unused     UList<LabelType>& vertLabels,
+//unused     const LabelType2 globalPointOffset
+//unused )
+//unused {
+//unused     // INTERNAL vertLabels = "connectivity" contain
+//unused     // [nLabels, vertex labels...]
+//unused
+//unused     auto iter = vertLabels.begin();
+//unused     const auto last = vertLabels.end();
+//unused
+//unused     while (iter < last)
+//unused     {
+//unused         LabelType nLabels = *iter;
+//unused         ++iter;
+//unused
+//unused         while (nLabels--)
+//unused         {
+//unused             *iter += globalPointOffset;
+//unused             ++iter;
+//unused         }
+//unused     }
+//unused }
+
+
 // ************************************************************************* //
-- 
GitLab