From 40e899d995cd9f23f1ffeddddd5a8bd39e6225e5 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 19 Feb 2021 14:35:28 +0100
Subject: [PATCH] BUG: openfoam reader ignores point patch value fields (fixes
 #18125)

- pointPatches may or may not have a "value" type.
  Use the patch value field where possible and the internal field
  otherwise. Previously always used the internal field.
---
 IO/Geometry/vtkOpenFOAMReader.cxx | 61 ++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 5 deletions(-)

diff --git a/IO/Geometry/vtkOpenFOAMReader.cxx b/IO/Geometry/vtkOpenFOAMReader.cxx
index 67adf239fc1..fb2138c944d 100644
--- a/IO/Geometry/vtkOpenFOAMReader.cxx
+++ b/IO/Geometry/vtkOpenFOAMReader.cxx
@@ -9318,16 +9318,67 @@ void vtkOpenFOAMReaderPrivate::GetPointFieldAtTimeStep(const std::string& varNam
   {
     if (patches.isActive(patch.index_))
     {
-      vtkNew<vtkFloatArray> vData;
       vtkDataArray* bpMap = this->BoundaryPointMap->operator[](activeBoundaryIndex);
       const vtkIdType nPoints = bpMap->GetNumberOfTuples();
       const bool meshPoints64Bit = ::Is64BitArray(bpMap);
 
-      vData->SetNumberOfComponents(nComponents);
-      vData->SetNumberOfTuples(nPoints);
-      for (vtkIdType pointi = 0; pointi < nPoints; ++pointi)
+      vtkSmartPointer<vtkFloatArray> vData;
+      std::string bcType;
+
+      if (bfieldEntries != nullptr)
       {
-        vData->SetTuple(pointi, GetLabelValue(bpMap, pointi, meshPoints64Bit), iData);
+        const vtkFoamEntry* bfieldEntry = bfieldEntries->Dictionary().Lookup(patch.name_, true);
+        if (bfieldEntry == nullptr)
+        {
+          // badEntry - but be silent about it
+        }
+        else if (bfieldEntry->FirstValue().GetType() != vtkFoamToken::DICTIONARY)
+        {
+          // badEntry - but be silent about it
+        }
+        else
+        {
+          const vtkFoamDict& patchDict = bfieldEntry->Dictionary();
+
+          // Look for "value" entry
+          vtkFoamEntry* vEntry = patchDict.Lookup("value");
+          if (vEntry == nullptr)
+          {
+            // For alternative fallback
+            const vtkFoamEntry* eptr = patchDict.Lookup("type");
+            if (eptr != nullptr)
+            {
+              bcType = eptr->ToString();
+            }
+          }
+          else
+          {
+            vData = this->FillField(*vEntry, nPoints, io, fieldDataType);
+            // silent about bad entry
+          }
+        }
+      }
+
+      if (vData == nullptr)
+      {
+        // No "value" entry
+        // Default to patch-internal values as boundary values
+        vData = vtkSmartPointer<vtkFloatArray>::New();
+        vData->SetNumberOfComponents(nComponents);
+        vData->SetNumberOfTuples(nPoints);
+
+        // Ad hoc handling of some known bcs without a "value"
+        if (bcType == "noSlip")
+        {
+          vData->FillValue(0);
+        }
+        else
+        {
+          for (vtkIdType pointi = 0; pointi < nPoints; ++pointi)
+          {
+            vData->SetTuple(pointi, GetLabelValue(bpMap, pointi, meshPoints64Bit), iData);
+          }
+        }
       }
 
       auto* bm = vtkPolyData::SafeDownCast(boundaryMesh->GetBlock(activeBoundaryIndex));
-- 
GitLab