From 8b826a9b51175f431f52620db5cd437bd3c93481 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 31 Oct 2018 10:36:22 +0000
Subject: [PATCH] ENH: new searchableSurfaceToCell source (#1060)

---
 src/finiteVolume/Make/options                 |   1 +
 src/meshTools/Make/files                      |   1 +
 .../searchableSurfaceToCell.C                 | 187 ++++++++++++++++++
 .../searchableSurfaceToCell.H                 | 122 ++++++++++++
 .../searchableSurfaceToFaceZone.C             |  18 +-
 .../searchableSurfaceToFaceZone.H             |  11 +-
 6 files changed, 338 insertions(+), 2 deletions(-)
 create mode 100644 src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.C
 create mode 100644 src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.H

diff --git a/src/finiteVolume/Make/options b/src/finiteVolume/Make/options
index 4ac4139c42a..d4fc619be07 100644
--- a/src/finiteVolume/Make/options
+++ b/src/finiteVolume/Make/options
@@ -1,4 +1,5 @@
 EXE_INC = \
+    -I$(LIB_SRC)/fileFormats/lnInclude \
     -I$(LIB_SRC)/surfMesh/lnInclude \
     -I$(LIB_SRC)/meshTools/lnInclude
 
diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files
index 8f9880af3b3..d13a5f43e5e 100644
--- a/src/meshTools/Make/files
+++ b/src/meshTools/Make/files
@@ -162,6 +162,7 @@ $(cellSources)/pointToCell/pointToCell.C
 $(cellSources)/regionToCell/regionToCell.C
 $(cellSources)/rotatedBoxToCell/rotatedBoxToCell.C
 $(cellSources)/shapeToCell/shapeToCell.C
+$(cellSources)/searchableSurfaceToCell/searchableSurfaceToCell.C
 $(cellSources)/sphereToCell/sphereToCell.C
 $(cellSources)/surfaceToCell/surfaceToCell.C
 $(cellSources)/targetVolumeToCell/targetVolumeToCell.C
diff --git a/src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.C b/src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.C
new file mode 100644
index 00000000000..5a5e529fdb6
--- /dev/null
+++ b/src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.C
@@ -0,0 +1,187 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "searchableSurfaceToCell.H"
+#include "polyMesh.H"
+#include "Time.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    defineTypeNameAndDebug(searchableSurfaceToCell, 0);
+    addToRunTimeSelectionTable
+    (
+        topoSetSource,
+        searchableSurfaceToCell,
+        word
+    );
+    addToRunTimeSelectionTable
+    (
+        topoSetCellSource,
+        searchableSurfaceToCell,
+        word
+    );
+    addNamedToRunTimeSelectionTable
+    (
+        topoSetSource,
+        searchableSurfaceToCell,
+        word,
+        surface
+    );
+}
+
+
+Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToCell::usage_
+(
+    searchableSurfaceToCell::typeName,
+    "\n    Usage: searchableSurfaceToCell surface\n\n"
+    "    Select cells with centre enclosed by the surface"
+    "\n"
+);
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::searchableSurfaceToCell::combine(topoSet& set, const bool add) const
+{
+    if (!surf_)
+    {
+        return;
+    }
+    const searchableSurface& s = *surf_;
+
+    // Add cells within the enclosing volumes
+
+    const label len = mesh_.nCells();
+
+    List<volumeType> volTypes;
+
+    s.getVolumeType(mesh_.cellCentres(), volTypes);
+
+    for (label celli=0; celli < len; ++celli)
+    {
+        if (volTypes[celli] == volumeType::INSIDE)
+        {
+            addOrDelete(set, celli, add);
+        }
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::searchableSurfaceToCell::searchableSurfaceToCell
+(
+    const word& surfaceType,
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetCellSource(mesh),
+    surf_
+    (
+        searchableSurface::New
+        (
+            surfaceType,
+            IOobject
+            (
+                dict.lookupOrDefault("name", mesh.objectRegistry::db().name()),
+                mesh.time().constant(), // Instance
+                "triSurface",           // Local
+                mesh.time(),            // Registry
+                IOobject::MUST_READ,
+                IOobject::NO_WRITE
+            ),
+            dict
+        )
+    )
+{
+    // Check/warn for non-enclosed
+    if (surf_ && !surf_->hasVolumeType())
+    {
+        WarningInFunction
+            << nl << "The surface '" << surf_->name() << "' of type '"
+            << surf_->type() << "' appears to be unclosed ... ignoring"
+            << nl << endl;
+
+        surf_.clear();
+    }
+}
+
+
+Foam::searchableSurfaceToCell::searchableSurfaceToCell
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    searchableSurfaceToCell
+    (
+        dict.get<word>("surface"),
+        mesh,
+        dict
+    )
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::searchableSurfaceToCell::applyToSet
+(
+    const topoSetSource::setAction action,
+    topoSet& set
+) const
+{
+    if (!surf_ || !surf_->hasVolumeType())
+    {
+        return;
+    }
+
+    if (action == topoSetSource::ADD || action == topoSetSource::NEW)
+    {
+        if (verbose_)
+        {
+            Info<< "    Adding cells enclosed by searchableSurface"
+                << "..." << endl;
+        }
+
+        combine(set, true);
+    }
+    else if (action == topoSetSource::SUBTRACT)
+    {
+        if (verbose_)
+        {
+            Info<< "    Removing cells enclosed by searchableSurface"
+                << "..." << endl;
+        }
+
+        combine(set, false);
+    }
+}
+
+
+// ************************************************************************* //
diff --git a/src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.H b/src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.H
new file mode 100644
index 00000000000..bb436d54e5b
--- /dev/null
+++ b/src/meshTools/sets/cellSources/searchableSurfaceToCell/searchableSurfaceToCell.H
@@ -0,0 +1,122 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::searchableSurfaceToCell
+
+Description
+    A topoSetSource to select cells based on cell centres within a
+    searchableSurface.
+
+    \heading Dictionary parameters
+    \table
+        Property    | Description                           | Required | Default
+        surface     | The searchable surface type           | yes   |
+        name        | Name for the IOobject                 | no    | mesh-name
+    \endtable
+
+SourceFiles
+    searchableSurfaceToCell.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef searchableSurfaceToCell_H
+#define searchableSurfaceToCell_H
+
+#include "topoSetCellSource.H"
+#include "searchableSurface.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                   Class searchableSurfaceToCell Declaration
+\*---------------------------------------------------------------------------*/
+
+class searchableSurfaceToCell
+:
+    public topoSetCellSource
+{
+    // Private Data
+
+        //- Add usage string
+        static addToUsageTable usage_;
+
+        //- The searchableSurface
+        autoPtr<searchableSurface> surf_;
+
+
+    // Private Member Functions
+
+        void combine(topoSet& set, const bool add) const;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("searchableSurfaceToCell");
+
+
+    // Constructors
+
+        //- Construct surface-type from dictionary
+        searchableSurfaceToCell
+        (
+            const word& surfaceType,
+            const polyMesh& mesh,
+            const dictionary& dict
+        );
+
+        //- Construct from dictionary
+        searchableSurfaceToCell
+        (
+            const polyMesh& mesh,
+            const dictionary& dict
+        );
+
+
+    //- Destructor
+    virtual ~searchableSurfaceToCell() = default;
+
+
+    // Member Functions
+
+        virtual void applyToSet
+        (
+            const topoSetSource::setAction action,
+            topoSet& set
+        ) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C
index 23121c3eb7d..71c983befe0 100644
--- a/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C
+++ b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C
@@ -58,6 +58,7 @@ Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFaceZone::usage_
 
 Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
 (
+    const word& surfaceType,
     const polyMesh& mesh,
     const dictionary& dict
 )
@@ -67,7 +68,7 @@ Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
     (
         searchableSurface::New
         (
-            dict.get<word>("surface"),
+            surfaceType,
             IOobject
             (
                 dict.lookupOrDefault("name", mesh.objectRegistry::db().name()),
@@ -83,6 +84,21 @@ Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
 {}
 
 
+Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    searchableSurfaceToFaceZone
+    (
+        dict.get<word>("surface"),
+        mesh,
+        dict
+    )
+{}
+
+
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
 Foam::searchableSurfaceToFaceZone::~searchableSurfaceToFaceZone()
diff --git a/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H
index a5507dd1faf..100c481eef5 100644
--- a/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H
+++ b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H
@@ -75,6 +75,15 @@ public:
 
     // Constructors
 
+        //- Construct surface-type from dictionary
+        searchableSurfaceToFaceZone
+        (
+            const word& surfaceType,
+            const polyMesh& mesh,
+            const dictionary& dict
+        );
+
+
         //- Construct from dictionary
         searchableSurfaceToFaceZone
         (
@@ -89,7 +98,7 @@ public:
 
     // Member Functions
 
-        virtual sourceType setType() const
+        virtual topoSetSource::sourceType setType() const
         {
             return FACEZONESOURCE;
         }
-- 
GitLab