From 14eaf2ddf16073e246376130ac56cfcc9eb7e765 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Mon, 16 Apr 2018 13:54:06 +0200
Subject: [PATCH] ENH: initial support for overset blanking (volume mesh only)

- uses the cellCellStencil information to blank holes and the
  interpolated cells.

- needs more detailed attention for handling cases when three or more
  meshes are overlapping.
---
 src/catalyst/CMakeLists-Common.txt            |  2 +
 src/catalyst/volMesh/foamVtkFvMeshAdaptor.C   |  1 +
 src/catalyst/volMesh/foamVtkFvMeshAdaptor.H   |  4 +
 .../volMesh/foamVtkFvMeshAdaptorGeom.C        | 81 +++++++++++++++++++
 4 files changed, 88 insertions(+)

diff --git a/src/catalyst/CMakeLists-Common.txt b/src/catalyst/CMakeLists-Common.txt
index acbfc7c..dc47eb6 100644
--- a/src/catalyst/CMakeLists-Common.txt
+++ b/src/catalyst/CMakeLists-Common.txt
@@ -9,6 +9,7 @@ include_directories(
     $ENV{WM_PROJECT_DIR}/src/conversion/lnInclude
     $ENV{WM_PROJECT_DIR}/src/meshTools/lnInclude
     $ENV{WM_PROJECT_DIR}/src/lagrangian/basic/lnInclude
+    $ENV{WM_PROJECT_DIR}/src/overset/lnInclude
     ${CMAKE_CURRENT_SOURCE_DIR}
     ${CMAKE_CURRENT_BINARY_DIR}
 )
@@ -67,6 +68,7 @@ set(OPENFOAM_LIBRARIES
     Pstream
     meshTools
     lagrangian
+    overset
 )
 
 add_library(
diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptor.C b/src/catalyst/volMesh/foamVtkFvMeshAdaptor.C
index beb45d8..180bacd 100644
--- a/src/catalyst/volMesh/foamVtkFvMeshAdaptor.C
+++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptor.C
@@ -206,6 +206,7 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields)
 
     convertGeometryInternal();
     convertGeometryPatches();
+    applyGhosting();
     convertVolFields(selectFields);
     meshState_ = polyMesh::UNCHANGED;
 }
diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H b/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H
index 4b8460d..ab21352 100644
--- a/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H
+++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptor.H
@@ -183,6 +183,10 @@ private:
         //  There will be several for groups, but only one for regular patches.
         void convertGeometryPatches();
 
+        //- Ghost cells to affect the visibility of the geometry.
+        //  Currently only used for overset.
+        void applyGhosting();
+
 
     // Field Conversion
 
diff --git a/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C b/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C
index e84652b..e74d6e9 100644
--- a/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C
+++ b/src/catalyst/volMesh/foamVtkFvMeshAdaptorGeom.C
@@ -24,6 +24,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "foamVtkFvMeshAdaptor.H"
+#include "cellCellStencilObject.H"
 
 // VTK includes
 #include <vtkMultiBlockDataSet.h>
@@ -155,4 +156,84 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryPatches()
 }
 
 
+// These need to be rebuild here, since the component mesh may just have point
+// motion without topology changes.
+void Foam::vtk::fvMeshAdaptor::applyGhosting()
+{
+    if (!usingVolume())
+    {
+        return;
+    }
+
+    const auto* stencilPtr =
+        mesh_.lookupObjectPtr<cellCellStencilObject>
+        (
+            cellCellStencilObject::typeName
+        );
+
+    if (!stencilPtr)
+    {
+        return;
+    }
+
+    const auto& longName = internalName;
+
+    auto iter = cachedVtu_.find(longName);
+    if (!iter.found() || !iter.object().dataset)
+    {
+        // Should not happen, but for safety require a vtk geometry
+        return;
+    }
+    foamVtuData& vtuData = iter.object();
+    auto dataset = vtuData.dataset;
+
+    const auto& stencil = *stencilPtr;
+    const labelUList& cellMap = vtuData.cellMap();
+
+    auto vtkgcell = dataset->GetCellGhostArray();
+    if (!vtkgcell)
+    {
+        vtkgcell = dataset->AllocateCellGhostArray();
+    }
+
+    // auto vtkgpoint = dataset->GetPointGhostArray();
+    // if (!vtkgpoint)
+    // {
+    //     vtkgpoint = dataset->AllocatePointGhostArray();
+    // }
+
+    UList<uint8_t> gcell =
+        vtk::Tools::asUList(vtkgcell, cellMap.size());
+
+    vtkgcell->FillValue(0); // Initialize to zero
+
+    const labelUList& types = stencil.cellTypes();
+
+    forAll(cellMap, i)
+    {
+        const label cellType = types[cellMap[i]];
+
+        if (cellType == cellCellStencil::INTERPOLATED)
+        {
+            gcell[i] |=
+            (
+                vtkDataSetAttributes::DUPLICATECELL
+            );
+        }
+        else if (cellType == cellCellStencil::HOLE)
+        {
+            // Need duplicate (not just HIDDENCELL) for it to be properly
+            // recognized
+            gcell[i] |=
+            (
+                vtkDataSetAttributes::DUPLICATECELL
+              | vtkDataSetAttributes::HIDDENCELL
+            );
+        }
+    }
+
+    dataset->GetCellData()->AddArray(vtkgcell);
+}
+
+
 // ************************************************************************* //
-- 
GitLab