From f431a328d2c859ee1dc1fabe25f6bc97f5bd65d9 Mon Sep 17 00:00:00 2001
From: Andrew Heather <a.heather@opencfd.co.uk>
Date: Thu, 1 Jun 2017 17:26:12 +0100
Subject: [PATCH] ENH: volRegion and volFieldValue - updated output name if
 operating on all cells

---
 .../functionObjects/volRegion/volRegion.C     |  1 +
 .../volFieldValue/volFieldValueTemplates.C    | 19 ++++++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/finiteVolume/functionObjects/volRegion/volRegion.C b/src/finiteVolume/functionObjects/volRegion/volRegion.C
index 3a0dcede22b..b650a4785ed 100644
--- a/src/finiteVolume/functionObjects/volRegion/volRegion.C
+++ b/src/finiteVolume/functionObjects/volRegion/volRegion.C
@@ -83,6 +83,7 @@ Foam::functionObjects::volRegion::volRegion
       ? regionTypeNames_.read(dict.lookup("regionType"))
       : vrtAll
     ),
+    regionName_(polyMesh::defaultRegion),
     regionID_(-1)
 {
     read(dict);
diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C
index e53b2665b8a..c5a30db0009 100644
--- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C
+++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C
@@ -217,12 +217,17 @@ bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
 
             if (Pstream::master())
             {
+                word outName = fieldName + '_' + regionTypeNames_[regionType_];
+                if (this->volRegion::regionName_ != polyMesh::defaultRegion)
+                {
+                    outName = outName + '-' + this->volRegion::regionName_;
+                }
+
                 IOField<Type>
                 (
                     IOobject
                     (
-                        fieldName + '_' + regionTypeNames_[regionType_]
-                      + '-' + volRegion::regionName_,
+                        outName,
                         obr_.time().timeName(),
                         obr_,
                         IOobject::NO_READ,
@@ -241,13 +246,17 @@ bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
         file()<< tab << result;
 
         Log << "    " << operationTypeNames_[operation_]
-            << "(" << volRegion::regionName_ << ") of " << fieldName
+            << "(" << this->volRegion::regionName_ << ") of " << fieldName
             <<  " = " << result << endl;
 
         // Write state/results information
         const word& opName = operationTypeNames_[operation_];
-        word resultName =
-            opName + '(' + volRegion::regionName_ + ',' + fieldName + ')';
+        word outName = fieldName;
+        if (this->volRegion::regionName_ != polyMesh::defaultRegion)
+        {
+            outName = this->volRegion::regionName_ + ',' + outName;
+        }
+        word resultName = opName + '(' + outName + ')';
         this->setResult(resultName, result);
     }
 
-- 
GitLab