From a4aa16b509b9b5f4580f19fc314a1d046aa7921b Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 19 Feb 2024 11:35:51 +0000
Subject: [PATCH] ENH: pointMesh: support for subsetMesh

---
 .../mesh/manipulation/subsetMesh/subsetMesh.C | 24 +++++++++++++++----
 .../decomposePar/domainDecomposition.C        |  9 ++++---
 .../mesh/blockMesh/sphere7/system/controlDict |  1 +
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C
index 1a195e36006..1b195acc032 100644
--- a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C
+++ b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2023 OpenCFD Ltd.
+    Copyright (C) 2016-2024 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -220,7 +220,7 @@ PtrList<FieldType> subsetFields
     const pointMesh& pMesh
 )
 {
-    const fvMesh& baseMesh = subsetter.baseMesh();
+    //const fvMesh& baseMesh = subsetter.baseMesh();
 
     const UPtrList<const IOobject> fieldObjects
     (
@@ -247,8 +247,8 @@ PtrList<FieldType> subsetFields
             IOobject
             (
                 io.name(),
-                baseMesh.time().timeName(),
-                baseMesh,
+                pMesh.thisDb().time().timeName(),
+                pMesh.thisDb(),
                 IOobjectOption::MUST_READ,
                 IOobjectOption::NO_WRITE,
                 IOobjectOption::NO_REGISTER
@@ -382,6 +382,8 @@ int main(int argc, char *argv[])
     #include "createTime.H"
 
     #include "createNamedMesh.H"
+    // Make sure pointMesh gets constructed/read as well
+    (void)pointMesh::New(mesh, IOobject::READ_IF_PRESENT);
 
     // arg[1] = word (cellSet) or wordRes (cellZone)
     // const word selectionName = args[1];
@@ -583,7 +585,7 @@ int main(int argc, char *argv[])
     // Read point fields and subset
     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-    const pointMesh& pMesh = pointMesh::New(mesh);
+    const pointMesh& pMesh = pointMesh::New(mesh, IOobject::READ_IF_PRESENT);
 
     #undef  createSubsetFields
     #define createSubsetFields(FieldType, Variable)             \
@@ -663,6 +665,18 @@ int main(int argc, char *argv[])
     subsetter.subMesh().write();
     processorMeshes::removeFiles(subsetter.subMesh());
 
+    auto* subPointMeshPtr =
+        subsetter.subMesh().thisDb().findObject<pointMesh>
+        (
+            pointMesh::typeName
+        );
+    if (subPointMeshPtr)
+    {
+        pointMesh& subPointMesh = const_cast<pointMesh&>(*subPointMeshPtr);
+        subPointMesh.setInstance(subsetter.subMesh().facesInstance());
+        subPointMesh.write();
+    }
+
 
     // Volume fields
     for (const auto& fld : vScalarFlds)     { fld.write(); }
diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C
index c5b8766ec01..6459c4580f0 100644
--- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C
+++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C
@@ -747,12 +747,11 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
         procMesh.write();
 
         // Add pointMesh if it was available
-        if (thisDb().foundObject<pointMesh>(pointMesh::typeName))
+        const auto* pMeshPtr =
+            thisDb().cfindObject<pointMesh>(pointMesh::typeName);
+        if (pMeshPtr)
         {
-            const auto& pMesh = thisDb().lookupObject<pointMesh>
-            (
-                pointMesh::typeName
-            );
+            const auto& pMesh = *pMeshPtr;
             const auto& pMeshBoundary = pMesh.boundary();
 
 
diff --git a/tutorials/mesh/blockMesh/sphere7/system/controlDict b/tutorials/mesh/blockMesh/sphere7/system/controlDict
index 56f7504ebcb..d13ae38f64a 100644
--- a/tutorials/mesh/blockMesh/sphere7/system/controlDict
+++ b/tutorials/mesh/blockMesh/sphere7/system/controlDict
@@ -17,6 +17,7 @@ FoamFile
 DebugSwitches
 {
     pointBoundaryMesh   1;
+    fvMeshSubset        1;
 }
 
 application     blockMesh;
-- 
GitLab