From b2fdc672738cfff81978f4c76f9c6cac02fb693a Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Sat, 19 Jun 2021 11:43:09 +0200
Subject: [PATCH] ENH: improve verbosity controls for topoSetSource

---
 .../topoSetCellSource/topoSetCellSource.C     | 12 ++++++-
 .../topoSetCellSource/topoSetCellSource.H     |  8 +++--
 .../topoSetCellZoneSource.C                   | 12 ++++++-
 .../topoSetCellZoneSource.H                   |  8 +++--
 .../topoSetFaceSource/topoSetFaceSource.C     | 12 ++++++-
 .../topoSetFaceSource/topoSetFaceSource.H     |  8 +++--
 .../topoSetFaceZoneSource.C                   | 12 ++++++-
 .../topoSetFaceZoneSource.H                   |  8 +++--
 .../topoSetPointSource/topoSetPointSource.C   | 12 ++++++-
 .../topoSetPointSource/topoSetPointSource.H   |  8 +++--
 .../topoSetPointZoneSource.C                  | 12 ++++++-
 .../topoSetPointZoneSource.H                  |  8 +++--
 .../sets/topoSetSource/topoSetSource.C        | 36 +++++++++++++++++--
 .../sets/topoSetSource/topoSetSource.H        | 29 ++++++++++-----
 14 files changed, 155 insertions(+), 30 deletions(-)

diff --git a/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.C b/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.C
index 3ffdac89bb5..0206eb6c90b 100644
--- a/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.C
+++ b/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,6 +45,16 @@ Foam::topoSetCellSource::topoSetCellSource(const polyMesh& mesh)
 {}
 
 
+Foam::topoSetCellSource::topoSetCellSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh, dict)
+{}
+
+
 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 Foam::autoPtr<Foam::topoSetCellSource>
diff --git a/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.H b/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.H
index 087b5a115b5..b3251ac2ca8 100644
--- a/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.H
+++ b/src/meshTools/sets/cellSources/topoSetCellSource/topoSetCellSource.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,9 +89,13 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from mesh
         explicit topoSetCellSource(const polyMesh& mesh);
 
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetCellSource(const polyMesh& mesh, const dictionary& dict);
+
+
         //- Clone (disallowed)
         autoPtr<topoSetCellSource> clone() const
         {
diff --git a/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.C b/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.C
index c4123bab6ee..f757459efc5 100644
--- a/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.C
+++ b/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,6 +45,16 @@ Foam::topoSetCellZoneSource::topoSetCellZoneSource(const polyMesh& mesh)
 {}
 
 
+Foam::topoSetCellZoneSource::topoSetCellZoneSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh, dict)
+{}
+
+
 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 Foam::autoPtr<Foam::topoSetCellZoneSource>
diff --git a/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.H b/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.H
index 73784f1a500..61e1080f94d 100644
--- a/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.H
+++ b/src/meshTools/sets/cellZoneSources/topoSetCellZoneSource/topoSetCellZoneSource.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -92,9 +92,13 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from mesh
         explicit topoSetCellZoneSource(const polyMesh& mesh);
 
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetCellZoneSource(const polyMesh& mesh, const dictionary& dict);
+
+
         //- Clone (disallowed)
         autoPtr<topoSetCellZoneSource> clone() const
         {
diff --git a/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.C b/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.C
index f7c9cc19180..206a7aa9e37 100644
--- a/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.C
+++ b/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,6 +45,16 @@ Foam::topoSetFaceSource::topoSetFaceSource(const polyMesh& mesh)
 {}
 
 
+Foam::topoSetFaceSource::topoSetFaceSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh, dict)
+{}
+
+
 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 Foam::autoPtr<Foam::topoSetFaceSource>
diff --git a/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.H b/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.H
index aeed1ffb374..245b639b9f7 100644
--- a/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.H
+++ b/src/meshTools/sets/faceSources/topoSetFaceSource/topoSetFaceSource.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,9 +89,13 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from mesh
         explicit topoSetFaceSource(const polyMesh& mesh);
 
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetFaceSource(const polyMesh& mesh, const dictionary& dict);
+
+
         //- Clone (disallowed)
         autoPtr<topoSetFaceSource> clone() const
         {
diff --git a/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.C b/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.C
index 0ae4dc9befb..d4a31973236 100644
--- a/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.C
+++ b/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,6 +45,16 @@ Foam::topoSetFaceZoneSource::topoSetFaceZoneSource(const polyMesh& mesh)
 {}
 
 
+Foam::topoSetFaceZoneSource::topoSetFaceZoneSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh, dict)
+{}
+
+
 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 Foam::autoPtr<Foam::topoSetFaceZoneSource>
diff --git a/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.H b/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.H
index 5d651eb281b..70bc09c0363 100644
--- a/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.H
+++ b/src/meshTools/sets/faceZoneSources/topoSetFaceZoneSource/topoSetFaceZoneSource.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -92,9 +92,13 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from mesh
         explicit topoSetFaceZoneSource(const polyMesh& mesh);
 
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetFaceZoneSource(const polyMesh& mesh, const dictionary& dict);
+
+
         //- Clone (disallowed)
         autoPtr<topoSetFaceZoneSource> clone() const
         {
diff --git a/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.C b/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.C
index b57fa617cfa..6483209386b 100644
--- a/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.C
+++ b/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,6 +45,16 @@ Foam::topoSetPointSource::topoSetPointSource(const polyMesh& mesh)
 {}
 
 
+Foam::topoSetPointSource::topoSetPointSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh, dict)
+{}
+
+
 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 Foam::autoPtr<Foam::topoSetPointSource>
diff --git a/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.H b/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.H
index aac0aee5d9a..e2b2fdf1c1c 100644
--- a/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.H
+++ b/src/meshTools/sets/pointSources/topoSetPointSource/topoSetPointSource.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,9 +89,13 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from mesh
         explicit topoSetPointSource(const polyMesh& mesh);
 
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetPointSource(const polyMesh& mesh, const dictionary& dict);
+
+
         //- Clone (disallowed)
         autoPtr<topoSetPointSource> clone() const
         {
diff --git a/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.C b/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.C
index e1ded575c78..cbda72836b3 100644
--- a/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.C
+++ b/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,6 +45,16 @@ Foam::topoSetPointZoneSource::topoSetPointZoneSource(const polyMesh& mesh)
 {}
 
 
+Foam::topoSetPointZoneSource::topoSetPointZoneSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh, dict)
+{}
+
+
 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
 
 Foam::autoPtr<Foam::topoSetPointZoneSource>
diff --git a/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.H b/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.H
index ab0ea3d0722..032b900f90c 100644
--- a/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.H
+++ b/src/meshTools/sets/pointZoneSources/topoSetPointZoneSource/topoSetPointZoneSource.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -92,9 +92,13 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from mesh
         explicit topoSetPointZoneSource(const polyMesh& mesh);
 
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetPointZoneSource(const polyMesh& mesh, const dictionary& dict);
+
+
         //- Clone (disallowed)
         autoPtr<topoSetPointZoneSource> clone() const
         {
diff --git a/src/meshTools/sets/topoSetSource/topoSetSource.C b/src/meshTools/sets/topoSetSource/topoSetSource.C
index c6fc41c57d8..f87a8af58cf 100644
--- a/src/meshTools/sets/topoSetSource/topoSetSource.C
+++ b/src/meshTools/sets/topoSetSource/topoSetSource.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2019 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -27,6 +27,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "topoSetSource.H"
+#include "dictionary.H"
 #include "polyMesh.H"
 #include "bitSet.H"
 #include "topoSet.H"
@@ -228,11 +229,40 @@ void Foam::topoSetSource::addOrDelete
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-Foam::topoSetSource::topoSetSource(const polyMesh& mesh)
+Foam::topoSetSource::topoSetSource
+(
+    const polyMesh& mesh,
+    bool verbose
+)
 :
     mesh_(mesh),
-    verbose_(true)
+    verbose_(verbose)
 {}
 
 
+Foam::topoSetSource::topoSetSource
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh)
+{
+    verbose(dict);
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::topoSetSource::verbose(const dictionary& dict)
+{
+    bool flag(verbose_);
+
+    if (dict.readIfPresent("verbose", flag))
+    {
+        verbose_ = flag;
+    }
+}
+
+
 // ************************************************************************* //
diff --git a/src/meshTools/sets/topoSetSource/topoSetSource.H b/src/meshTools/sets/topoSetSource/topoSetSource.H
index e338e1d71d3..c45c9d1b466 100644
--- a/src/meshTools/sets/topoSetSource/topoSetSource.H
+++ b/src/meshTools/sets/topoSetSource/topoSetSource.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -56,6 +56,7 @@ namespace Foam
 {
 
 // Forward Declarations
+class dictionary;
 class polyMesh;
 class bitSet;
 class topoSet;
@@ -151,7 +152,7 @@ protected:
         //- Reference to the mesh
         const polyMesh& mesh_;
 
-        //- Verbosity (default: true)
+        //- Output verbosity (default: true)
         bool verbose_;
 
 
@@ -294,8 +295,12 @@ public:
 
     // Constructors
 
-        //- Construct from components
-        explicit topoSetSource(const polyMesh& mesh);
+        //- Construct from mesh, with preferred verbosity
+        explicit topoSetSource(const polyMesh& mesh, bool verbose = true);
+
+        //- Construct from mesh, use "verbose" entry if present
+        topoSetSource(const polyMesh& mesh, const dictionary& dict);
+
 
         //- Clone (disallowed)
         autoPtr<topoSetSource> clone() const
@@ -331,23 +336,29 @@ public:
     // Member Functions
 
         //- Reference to the mesh
-        const polyMesh& mesh() const
+        const polyMesh& mesh() const noexcept
         {
             return mesh_;
         }
 
-        //- Return the current verbosity
-        bool verbose() const
+        //- Get output verbosity
+        bool verbose() const noexcept
         {
             return verbose_;
         }
 
-        //- Set the current verbosity
-        void verbose(bool on)
+        //- Enable/disable verbose output
+        //  \return old value
+        bool verbose(bool on) noexcept
         {
+            bool old(verbose_);
             verbose_ = on;
+            return old;
         }
 
+        //- Use "verbose" entry (if present) to enable/disable verbose output
+        void verbose(const dictionary& dict);
+
 
     // Member Functions
 
-- 
GitLab