From f6cc25f5ebb2a96baf41574a66956733c3957ee0 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 13 Mar 2017 12:01:05 +0000
Subject: [PATCH] ENH: cellSetOption: suppress printing of excess messages.
 Fixes #415.

---
 src/fvOptions/cellSetOption/cellSetOption.C | 56 +++++++++++++++------
 src/fvOptions/cellSetOption/cellSetOption.H |  5 +-
 2 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/src/fvOptions/cellSetOption/cellSetOption.C b/src/fvOptions/cellSetOption/cellSetOption.C
index 56a664432cd..665b98343df 100644
--- a/src/fvOptions/cellSetOption/cellSetOption.C
+++ b/src/fvOptions/cellSetOption/cellSetOption.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,6 +89,32 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict)
 }
 
 
+void Foam::fv::cellSetOption::setVol()
+{
+    scalar VOld = V_;
+
+    // Set volume information
+    V_ = 0.0;
+    forAll(cells_, i)
+    {
+        V_ += mesh_.V()[cells_[i]];
+    }
+    reduce(V_, sumOp<scalar>());
+
+
+    // Convert both volumes to representation using current writeprecision
+    word VOldName(Time::timeName(VOld, IOstream::defaultPrecision()));
+    word VName(Time::timeName(V_, IOstream::defaultPrecision()));
+
+    if (VName != VOldName)
+    {
+        Info<< indent
+            << "- selected " << returnReduce(cells_.size(), sumOp<label>())
+            << " cell(s) with volume " << V_ << endl;
+    }
+}
+
+
 void Foam::fv::cellSetOption::setCellSet()
 {
     switch (selectionMode_)
@@ -164,18 +190,6 @@ void Foam::fv::cellSetOption::setCellSet()
                 << exit(FatalError);
         }
     }
-
-    // Set volume information
-    V_ = 0.0;
-    forAll(cells_, i)
-    {
-        V_ += mesh_.V()[cells_[i]];
-    }
-    reduce(V_, sumOp<scalar>());
-
-    Info<< indent
-        << "- selected " << returnReduce(cells_.size(), sumOp<label>())
-        << " cell(s) with volume " << V_ << endl;
 }
 
 
@@ -203,6 +217,7 @@ Foam::fv::cellSetOption::cellSetOption
     read(dict);
     setSelection(coeffs_);
     setCellSet();
+    setVol();
     Info<< decrIndent;
 }
 
@@ -222,7 +237,20 @@ bool Foam::fv::cellSetOption::isActive()
         // Update the cell set if the mesh is changing
         if (mesh_.changing())
         {
-            setCellSet();
+            if (mesh_.topoChanging())
+            {
+                setCellSet();
+                // Force printing of new set volume
+                V_ = -GREAT;
+            }
+            else if (selectionMode_ == smPoints)
+            {
+                // This is the only geometric selection mode
+                setCellSet();
+            }
+
+            // Report new volume (if changed)
+            setVol();
         }
 
         return true;
diff --git a/src/fvOptions/cellSetOption/cellSetOption.H b/src/fvOptions/cellSetOption/cellSetOption.H
index dd07b2e87f6..050abd5f0a9 100644
--- a/src/fvOptions/cellSetOption/cellSetOption.H
+++ b/src/fvOptions/cellSetOption/cellSetOption.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -126,6 +126,9 @@ protected:
         //- Set the cell set based on the user input selection mode
         void setCellSet();
 
+        //- Recalculate the volume
+        void setVol();
+
 
 public:
 
-- 
GitLab