From 273741c0522b942e20fc588493c279946f40b508 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 10 Mar 2021 18:58:15 +0100
Subject: [PATCH] BUG: correct the EnSight point value patch conversion (#2010)

- patch point ordering was affected by the EnSight face sorting
  (tri, quad, nsided). This did not affect other point fields,
  since they use the internal field values.
---
 .../output/ensightOutputVolFieldTemplates.C   | 34 +++++++++++++------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/conversion/ensight/output/ensightOutputVolFieldTemplates.C b/src/conversion/ensight/output/ensightOutputVolFieldTemplates.C
index 01fb014e1f1..d7f07621ca0 100644
--- a/src/conversion/ensight/output/ensightOutputVolFieldTemplates.C
+++ b/src/conversion/ensight/output/ensightOutputVolFieldTemplates.C
@@ -224,14 +224,14 @@ bool Foam::ensightOutput::writePointField
             os.beginPart(part.index());
         }
 
-        labelList uniqueMeshPointLabels;
-        part.uniqueMeshPoints(mesh, uniqueMeshPointLabels, parallel);
+        labelList uniquePointLabels;
+        part.uniqueMeshPoints(mesh, uniquePointLabels, parallel);
 
         ensightOutput::Detail::writeFieldComponents
         (
             os,
             ensightFile::coordinates,
-            UIndirectList<Type>(pf.internalField(), uniqueMeshPointLabels),
+            UIndirectList<Type>(pf.internalField(), uniquePointLabels),
             parallel
         );
     }
@@ -249,30 +249,42 @@ bool Foam::ensightOutput::writePointField
             os.beginPart(part.index());
         }
 
+        labelList uniquePointLabels;
+        part.uniqueMeshPoints(mesh, uniquePointLabels, parallel);
+
         const auto& bfld = pf.boundaryField()[patchId];
 
         // Only valuePointPatchField is actually derived from Field
         const auto* vpp = isA<Field<Type>>(bfld);
         if (vpp)
         {
+            // Require patch local indices, not mesh point labels.
+            // But need to use polyPatch meshPointMap() to recover the
+            // local indices since the ensight output will have jumbled
+            // the face output order
+
+            const polyPatch& pp = mesh.boundaryMesh()[patchId];
+
+            for (label& pointi : uniquePointLabels)
+            {
+                pointi = pp.meshPointMap()[pointi];
+            }
+
             ensightOutput::Detail::writeFieldComponents
             (
                 os,
                 ensightFile::coordinates,
-                *vpp,
+                UIndirectList<Type>(*vpp, uniquePointLabels),
                 parallel
             );
         }
         else
         {
-            labelList uniqueMeshPointLabels;
-            part.uniqueMeshPoints(mesh, uniqueMeshPointLabels, parallel);
-
             ensightOutput::Detail::writeFieldComponents
             (
                 os,
                 ensightFile::coordinates,
-                UIndirectList<Type>(pf.internalField(), uniqueMeshPointLabels),
+                UIndirectList<Type>(pf.internalField(), uniquePointLabels),
                 parallel
             );
         }
@@ -294,14 +306,14 @@ bool Foam::ensightOutput::writePointField
         // uses internalField only
 
         {
-            labelList uniqueMeshPointLabels;
-            part.uniqueMeshPoints(mesh, uniqueMeshPointLabels, parallel);
+            labelList uniquePointLabels;
+            part.uniqueMeshPoints(mesh, uniquePointLabels, parallel);
 
             ensightOutput::Detail::writeFieldComponents
             (
                 os,
                 ensightFile::coordinates,
-                UIndirectList<Type>(pf.internalField(), uniqueMeshPointLabels),
+                UIndirectList<Type>(pf.internalField(), uniquePointLabels),
                 parallel
             );
         }
-- 
GitLab