From 40b3f8b62c529072feae6a9ab6bc10cd1b08e144 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Thu, 11 Aug 2016 16:25:27 +0100
Subject: [PATCH] functionObjects::volFieldValue: Updated to use the new
 volRegion functionObject

---
 .../fieldValues/volFieldValue/volFieldValue.C | 120 +-----------------
 .../fieldValues/volFieldValue/volFieldValue.H | 107 ++++------------
 .../volFieldValue/volFieldValueI.H            |  44 -------
 .../volFieldValue/volFieldValueTemplates.C    |  17 ++-
 4 files changed, 45 insertions(+), 243 deletions(-)
 delete mode 100644 src/functionObjects/field/fieldValues/volFieldValue/volFieldValueI.H

diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C
index 9e490ba2a1a..6389143a45f 100644
--- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C
+++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C
@@ -43,14 +43,6 @@ namespace fieldValues
 }
 }
 
-template<>
-const char*
-Foam::NamedEnum
-<
-    Foam::functionObjects::fieldValues::volFieldValue::regionTypes,
-    2
->::names[] = {"cellZone", "all"};
-
 template<>
 const char*
 Foam::NamedEnum
@@ -72,12 +64,6 @@ Foam::NamedEnum
     "CoV"
 };
 
-const Foam::NamedEnum
-<
-    Foam::functionObjects::fieldValues::volFieldValue::regionTypes,
-    2
-> Foam::functionObjects::fieldValues::volFieldValue::regionTypeNames_;
-
 const Foam::NamedEnum
 <
     Foam::functionObjects::fieldValues::volFieldValue::operationType,
@@ -85,59 +71,6 @@ const Foam::NamedEnum
 > Foam::functionObjects::fieldValues::volFieldValue::operationTypeNames_;
 
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-void Foam::functionObjects::fieldValues::volFieldValue::setCellZoneCells()
-{
-    switch (regionType_)
-    {
-        case stCellZone:
-        {
-            dict().lookup("name") >> regionName_;
-
-            label zoneId = mesh_.cellZones().findZoneID(regionName_);
-
-            if (zoneId < 0)
-            {
-                FatalErrorInFunction
-                    << "Unknown cell zone name: " << regionName_
-                    << ". Valid cell zones are: " << mesh_.cellZones().names()
-                    << nl << exit(FatalError);
-            }
-
-            cellId_ = mesh_.cellZones()[zoneId];
-            nCells_ = returnReduce(cellId_.size(), sumOp<label>());
-            break;
-        }
-
-        case stAll:
-        {
-            cellId_ = identity(mesh_.nCells());
-            nCells_ = returnReduce(cellId_.size(), sumOp<label>());
-            break;
-        }
-
-        default:
-        {
-            FatalErrorInFunction
-               << "Unknown region type. Valid region types are:"
-                << regionTypeNames_ << nl << exit(FatalError);
-        }
-    }
-
-    if (debug)
-    {
-        Pout<< "Selected region size = " << cellId_.size() << endl;
-    }
-}
-
-
-Foam::scalar Foam::functionObjects::fieldValues::volFieldValue::volume() const
-{
-    return gSum(filterField(mesh_.V()));
-}
-
-
 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
 
 void Foam::functionObjects::fieldValues::volFieldValue::initialise
@@ -145,24 +78,6 @@ void Foam::functionObjects::fieldValues::volFieldValue::initialise
     const dictionary& dict
 )
 {
-    setCellZoneCells();
-
-    if (nCells_ == 0)
-    {
-        FatalErrorInFunction
-            << type() << " " << name() << ": "
-            << regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
-            << "    Region has no cells" << exit(FatalError);
-    }
-
-    volume_ = volume();
-
-    Info<< type() << " " << name() << ":"
-        << regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
-        << "    total cells  = " << nCells_ << nl
-        << "    total volume = " << volume_
-        << nl << endl;
-
     if (dict.readIfPresent("weightField", weightFieldName_))
     {
         Info<< "    weight field = " << weightFieldName_;
@@ -177,18 +92,9 @@ void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
     const label i
 )
 {
-    writeCommented(file(), "Region type : ");
-    file() << regionTypeNames_[regionType_] << " " << regionName_ << endl;
-    writeCommented(file(), "Cells  : ");
-    file() << nCells_ << endl;
-    writeCommented(file(), "Volume : ");
-    file() << volume_ << endl;
+    volRegion::writeFileHeader(*this, file());
 
     writeCommented(file(), "Time");
-    if (writeVolume_)
-    {
-        file() << tab << "Volume";
-    }
 
     forAll(fields_, i)
     {
@@ -211,12 +117,9 @@ Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
 )
 :
     fieldValue(name, runTime, dict, typeName),
-    regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
+    volRegion(fieldValue::mesh_, dict),
     operation_(operationTypeNames_.read(dict.lookup("operation"))),
-    nCells_(0),
-    cellId_(),
-    weightFieldName_("none"),
-    writeVolume_(dict.lookupOrDefault("writeVolume", false))
+    weightFieldName_("none")
 {
     read(dict);
 }
@@ -230,12 +133,9 @@ Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
 )
 :
     fieldValue(name, obr, dict, typeName),
-    regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
+    volRegion(fieldValue::mesh_, dict),
     operation_(operationTypeNames_.read(dict.lookup("operation"))),
-    nCells_(0),
-    cellId_(),
-    weightFieldName_("none"),
-    writeVolume_(dict.lookupOrDefault("writeVolume", false))
+    weightFieldName_("none")
 {
     read(dict);
 }
@@ -272,16 +172,6 @@ bool Foam::functionObjects::fieldValues::volFieldValue::write()
         writeTime(file());
     }
 
-    if (writeVolume_)
-    {
-        volume_ = volume();
-        if (Pstream::master())
-        {
-            file() << tab << volume_;
-        }
-        Log << "    total volume = " << volume_ << endl;
-    }
-
     forAll(fields_, i)
     {
         const word& fieldName = fields_[i];
diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H
index af66f72a84e..d8d94b50709 100644
--- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H
+++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H
@@ -28,12 +28,10 @@ Group
     grpFieldFunctionObjects
 
 Description
-    Provides a 'cell region' variant of the fieldValues function object.
-
-    Given a list of user-specified fields and a selection of mesh cells, a
-    number of operations can be performed, such as sums, averages and
-    integrations.
+    Provides a 'volRegion' specialization of the fieldValue function object.
 
+    Given a list of user-specified fields and a 'volRegion', a number of
+    operations can be performed, such as sums, averages and integrations.
 
     Example of function object specification:
     \verbatim
@@ -62,16 +60,15 @@ Description
 
 Usage
     \table
-        Property     | Description             | Required    | Default value
-        type         | Type name: volFieldValue   | yes         |
-        log          | Write data to standard output | no    | no
-        writeFields  | Write the region field values  | yes     |
-        writeVolume  | Write the volume of the volFieldValue | no |
-        regionType   | cell regionType: see below  | yes         |
-        name         | name of cell regionType if required  | no |
-        operation    | operation to perform    | yes         |
-        weightField  | name of field to apply weighting | no |
-        fields       | list of fields to operate on | yes    |
+        Property     | Description              | Required    | Default value
+        type         | Type name: volFieldValue            | yes   |
+        log          | Write data to standard output       | no    | no
+        writeFields  | Write the region field values       | yes   |
+        regionType   | volRegion type: see below           | yes   |
+        name         | Name of volRegion if required       | no    |
+        operation    | Operation to perform                | yes   |
+        weightField  | Name of field to apply weighting    | no    |
+        fields       | List of fields to operate on        | yes   |
     \endtable
 
     Where \c regionType is defined by
@@ -82,21 +79,22 @@ Usage
 
     The \c operation is one of:
     \plaintable
-       none          | no operation
-       sum           | sum
-       sumMag        | sum of component magnitudes
-       average       | ensemble average
-       weightedAverage | weighted average
-       volAverage    | volume weighted average
-       weightedVolAverage | weighted volume average
-       volIntegrate  | volume integral
-       min           | minimum
-       max           | maximum
-       CoV           | coefficient of variation: standard deviation/mean
+       none               | No operation
+       sum                | Sum
+       sumMag             | Sum of component magnitudes
+       average            | Ensemble average
+       weightedAverage    | Weighted average
+       volAverage         | Volume weighted average
+       weightedVolAverage | Weighted volume average
+       volIntegrate       | Volume integral
+       min                | Minimum
+       max                | Maximum
+       CoV                | Coefficient of variation: standard deviation/mean
     \endplaintable
 
 See also
-    Foam::fieldValues
+    Foam::functionObjects::fieldValues::fieldValue
+    Foam::functionObjects::volRegion
     Foam::functionObject
 
 SourceFiles
@@ -108,7 +106,7 @@ SourceFiles
 #define functionObjects_volFieldValue_H
 
 #include "fieldValue.H"
-#include "NamedEnum.H"
+#include "volRegion.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -125,24 +123,14 @@ namespace fieldValues
 
 class volFieldValue
 :
-    public fieldValue
+    public fieldValue,
+    public volRegion
 {
 
 public:
 
     // Public data types
 
-        //- region type enumeration
-        enum regionTypes
-        {
-            stCellZone,
-            stAll
-        };
-
-        //- region type names
-        static const NamedEnum<regionTypes, 2> regionTypeNames_;
-
-
         //- Operation type enumeration
         enum operationType
         {
@@ -163,45 +151,16 @@ public:
         static const NamedEnum<operationType, 11> operationTypeNames_;
 
 
-private:
-
-    // Private Member Functions
-
-        //- Set cells to evaluate based on a cell zone
-        void setCellZoneCells();
-
-        //- Set cells to evaluate based on a patch
-        void setPatchCells();
-
-        //- Calculate and return volume of the volFieldValue: sum(V)
-        scalar volume() const;
-
-
 protected:
 
     // Protected data
 
-        //- region type
-        regionTypes regionType_;
-
         //- Operation to apply to values
         operationType operation_;
 
-        //- Global number of cells
-        label nCells_;
-
-        //- Local list of cell IDs
-        labelList cellId_;
-
         //- Weight field name - only used for opWeightedAverage mode
         word weightFieldName_;
 
-        //- Volume of the volFieldValue
-        scalar volume_;
-
-        //- Optionally write the volume of the volFieldValue
-        bool writeVolume_;
-
 
     // Protected Member Functions
 
@@ -264,12 +223,6 @@ public:
 
     // Public Member Functions
 
-        //- Return the region type
-        inline const regionTypes& regionType() const;
-
-        //- Return the local list of cell IDs
-        inline const labelList& cellId() const;
-
         //- Templated helper function to output field values
         template<class Type>
         bool writeValues(const word& fieldName);
@@ -294,10 +247,6 @@ public:
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-#include "volFieldValueI.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 #ifdef NoRepository
     #include "volFieldValueTemplates.C"
 #endif
diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueI.H b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueI.H
deleted file mode 100644
index 076e3e232a8..00000000000
--- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueI.H
+++ /dev/null
@@ -1,44 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     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 "volFieldValue.H"
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-inline const Foam::functionObjects::fieldValues::volFieldValue::regionTypes&
-Foam::functionObjects::fieldValues::volFieldValue::regionType() const
-{
-    return regionType_;
-}
-
-
-inline const Foam::labelList&
-Foam::functionObjects::fieldValues::volFieldValue::cellId() const
-{
-    return cellId_;
-}
-
-
-// ************************************************************************* //
diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C
index e54c7b6bda3..00681d3f5b2 100644
--- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C
+++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C
@@ -165,7 +165,7 @@ bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
     if (ok)
     {
         Field<Type> values(setFieldValues<Type>(fieldName));
-        scalarField V(filterField(mesh_.V()));
+        scalarField V(filterField(fieldValue::mesh_.V()));
         scalarField weightField(values.size(), 1.0);
 
         if (weightFieldName_ != "none")
@@ -191,8 +191,8 @@ bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
                 (
                     IOobject
                     (
-                        fieldName + "_" + regionTypeNames_[regionType_] + "-"
-                            + regionName_,
+                        fieldName + '_' + regionTypeNames_[regionType_]
+                      + '-' + volRegion::regionName_,
                         obr_.time().timeName(),
                         obr_,
                         IOobject::NO_READ,
@@ -206,7 +206,7 @@ bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
             file()<< tab << result;
 
             Log << "    " << operationTypeNames_[operation_]
-                << "(" << regionName_ << ") of " << fieldName
+                << "(" << volRegion::regionName_ << ") of " << fieldName
                 <<  " = " << result << endl;
         }
     }
@@ -222,7 +222,14 @@ Foam::functionObjects::fieldValues::volFieldValue::filterField
     const Field<Type>& field
 ) const
 {
-    return tmp<Field<Type>>(new Field<Type>(field, cellId_));
+    if (isNull(cellIDs()))
+    {
+        return field;
+    }
+    else
+    {
+        return tmp<Field<Type>>(new Field<Type>(field, cellIDs()));
+    }
 }
 
 
-- 
GitLab