From 0e3f655865f9d2915578af4d63316a114706bf04 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Wed, 25 May 2016 15:40:58 +0100
Subject: [PATCH] functionObjects: Clear the result field from the
 objectRegistry if the argument fields are not available This is needed to
 handle the processing of many time directories, some of which may have the
 required fields and some not.

---
 .../fvMeshFunctionObject.C                    | 25 +++++++
 .../fvMeshFunctionObject.H                    |  3 +
 .../fvMeshFunctionObjectTemplates.C           | 16 ++++-
 .../field/CourantNo/CourantNo.C               | 70 +++++++++----------
 .../field/CourantNo/CourantNo.H               |  8 +--
 .../functionObjects/field/Lambda2/Lambda2.C   | 42 +++++------
 .../functionObjects/field/Lambda2/Lambda2.H   | 11 ++-
 .../functionObjects/field/MachNo/MachNo.C     | 42 +++++------
 .../functionObjects/field/MachNo/MachNo.H     | 11 ++-
 .../functionObjects/field/PecletNo/PecletNo.C | 68 +++++++++---------
 .../functionObjects/field/PecletNo/PecletNo.H |  9 ++-
 .../functionObjects/field/Q/Q.C               | 42 +++++------
 .../functionObjects/field/Q/Q.H               | 11 ++-
 .../field/blendingFactor/blendingFactor.C     | 36 +++++-----
 .../field/blendingFactor/blendingFactor.H     | 10 +--
 .../blendingFactor/blendingFactorTemplates.C  |  2 +-
 .../functionObjects/field/div/div.C           | 32 ++++-----
 .../functionObjects/field/div/div.H           | 11 ++-
 .../functionObjects/field/div/divTemplates.C  |  2 +-
 .../field/enstrophy/enstrophy.C               | 42 +++++------
 .../field/enstrophy/enstrophy.H               | 11 ++-
 .../field/fieldExpression/fieldExpression.C   | 37 +++++++++-
 .../field/fieldExpression/fieldExpression.H   | 10 ++-
 .../functionObjects/field/flowType/flowType.C | 42 +++++------
 .../functionObjects/field/flowType/flowType.H | 11 ++-
 .../functionObjects/field/grad/grad.C         | 32 ++++-----
 .../functionObjects/field/grad/grad.H         | 11 ++-
 .../field/grad/gradTemplates.C                |  2 +-
 .../functionObjects/field/mag/mag.C           | 44 ++++++------
 .../functionObjects/field/mag/mag.H           | 11 ++-
 .../functionObjects/field/mag/magTemplates.C  |  2 +-
 .../functionObjects/field/pressure/pressure.C | 40 ++++++-----
 .../functionObjects/field/pressure/pressure.H |  6 +-
 .../field/vorticity/vorticity.C               | 42 +++++------
 .../field/vorticity/vorticity.H               | 11 ++-
 35 files changed, 435 insertions(+), 370 deletions(-)

diff --git a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C
index 7fbfb027246..57945b0246e 100644
--- a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C
+++ b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C
@@ -66,6 +66,31 @@ bool Foam::functionObjects::fvMeshFunctionObject::writeField
 }
 
 
+bool Foam::functionObjects::fvMeshFunctionObject::clearField
+(
+    const word& fieldName
+)
+{
+    if (foundField<regIOobject>(fieldName))
+    {
+        const regIOobject& resultField = lookupField<regIOobject>(fieldName);
+
+        if (resultField.ownedByRegistry())
+        {
+            return const_cast<regIOobject&>(resultField).checkOut();
+        }
+        else
+        {
+            return false;
+        }
+    }
+    else
+    {
+        return true;
+    }
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
diff --git a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H
index 62315000f7a..78c259f0f73 100644
--- a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H
+++ b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H
@@ -95,6 +95,9 @@ protected:
         //- Write field if present in objectRegistry
         bool writeField(const word& fieldName);
 
+        //- Clear field from the objectRegistry if present
+        bool clearField(const word& fieldName);
+
 
 private:
 
diff --git a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C
index 48b680620e4..b3e07b25137 100644
--- a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C
+++ b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C
@@ -74,10 +74,22 @@ bool Foam::functionObjects::fvMeshFunctionObject::store
      && mesh_.foundObject<FieldType>(fieldName)
     )
     {
-        const_cast<FieldType&>
+        const FieldType& field =
         (
             mesh_.lookupObject<FieldType>(fieldName)
-        ) = tfield;
+        );
+
+        // If there is a result field already registered assign to the new
+        // result field otherwise transfer ownership of the new result field to
+        // the object registry
+        if (&field != &tfield())
+        {
+            const_cast<FieldType&>(field) = tfield;
+        }
+        else
+        {
+            mesh_.objectRegistry::store(tfield.ptr());
+        }
     }
     else
     {
diff --git a/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C b/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C
index 736fdece672..53cd86a6063 100644
--- a/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C
+++ b/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C
@@ -66,41 +66,7 @@ Foam::functionObjects::CourantNo::byRho
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::CourantNo::CourantNo
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "phi", "Co")
-{
-    read(dict);
-}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::CourantNo::~CourantNo()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
-{
-    fieldExpression::read(dict);
-
-    phiName_ = dict.lookupOrDefault<word>("phi", "phi");
-    rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
-
-    return true;
-}
-
-
-bool Foam::functionObjects::CourantNo::execute(const bool postProcess)
+bool Foam::functionObjects::CourantNo::calc()
 {
     if (foundField<surfaceScalarField>(phiName_))
     {
@@ -163,4 +129,38 @@ bool Foam::functionObjects::CourantNo::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::CourantNo::CourantNo
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "phi", "Co")
+{
+    read(dict);
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::CourantNo::~CourantNo()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
+{
+    fieldExpression::read(dict);
+
+    phiName_ = dict.lookupOrDefault<word>("phi", "phi");
+    rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
+
+    return true;
+}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/CourantNo/CourantNo.H b/src/postProcessing/functionObjects/field/CourantNo/CourantNo.H
index d29afdf24dd..346cd2bb7ed 100644
--- a/src/postProcessing/functionObjects/field/CourantNo/CourantNo.H
+++ b/src/postProcessing/functionObjects/field/CourantNo/CourantNo.H
@@ -73,12 +73,15 @@ class CourantNo
 
     // Private Member Functions
 
-        //- Divide Co by rho if required
+        //- Divide the Courant number by rho if required
         tmp<volScalarField::Internal> byRho
         (
             const tmp<volScalarField::Internal>& Co
         ) const;
 
+        //- Calculate the Courant number field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -105,9 +108,6 @@ public:
 
         //- Read the CourantNo data
         virtual bool read(const dictionary&);
-
-        //- Calculate the Courant number
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C b/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C
index e6f8ccfad1d..00231478761 100644
--- a/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C
+++ b/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C
@@ -45,28 +45,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::Lambda2::Lambda2
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "U", "Lambda2")
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::Lambda2::~Lambda2()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-bool Foam::functionObjects::Lambda2::execute(const bool postProcess)
+bool Foam::functionObjects::Lambda2::calc()
 {
     if (foundField<volVectorField>(fieldName_))
     {
@@ -93,4 +74,23 @@ bool Foam::functionObjects::Lambda2::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::Lambda2::Lambda2
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "U", "Lambda2")
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::Lambda2::~Lambda2()
+{}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/Lambda2/Lambda2.H b/src/postProcessing/functionObjects/field/Lambda2/Lambda2.H
index 34cc98d73c0..f94e6cd1d73 100644
--- a/src/postProcessing/functionObjects/field/Lambda2/Lambda2.H
+++ b/src/postProcessing/functionObjects/field/Lambda2/Lambda2.H
@@ -61,6 +61,11 @@ class Lambda2
 :
     public fieldExpression
 {
+    // Private Member Functions
+
+        //- Calculate the Lambda2 field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -81,12 +86,6 @@ public:
 
     //- Destructor
     virtual ~Lambda2();
-
-
-    // Member Functions
-
-        //- Calculate the Lambda2 field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/MachNo/MachNo.C b/src/postProcessing/functionObjects/field/MachNo/MachNo.C
index d252a45b307..1d08a64025a 100644
--- a/src/postProcessing/functionObjects/field/MachNo/MachNo.C
+++ b/src/postProcessing/functionObjects/field/MachNo/MachNo.C
@@ -45,28 +45,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::MachNo::MachNo
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "U", "Ma")
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::MachNo::~MachNo()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-bool Foam::functionObjects::MachNo::execute(const bool postProcess)
+bool Foam::functionObjects::MachNo::calc()
 {
     if
     (
@@ -92,4 +73,23 @@ bool Foam::functionObjects::MachNo::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::MachNo::MachNo
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "U", "Ma")
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::MachNo::~MachNo()
+{}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/MachNo/MachNo.H b/src/postProcessing/functionObjects/field/MachNo/MachNo.H
index 4d744f62194..342647cd908 100644
--- a/src/postProcessing/functionObjects/field/MachNo/MachNo.H
+++ b/src/postProcessing/functionObjects/field/MachNo/MachNo.H
@@ -60,6 +60,11 @@ class MachNo
 :
     public fieldExpression
 {
+    // Private Member Functions
+
+        //- Calculate the Mach number field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -81,12 +86,6 @@ public:
 
     //- Destructor
     virtual ~MachNo();
-
-
-    // Member Functions
-
-        //- Calculate the Mach number field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C b/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C
index 2164947a986..5e11a10ee47 100644
--- a/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C
+++ b/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C
@@ -46,40 +46,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-Foam::functionObjects::PecletNo::PecletNo
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "phi", "Pe")
-{
-    read(dict);
-}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::PecletNo::~PecletNo()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-bool Foam::functionObjects::PecletNo::read(const dictionary& dict)
-{
-    fieldExpression::read(dict);
-
-    phiName_ = dict.lookupOrDefault<word>("phi", "phi");
-
-    return true;
-}
-
-
-bool Foam::functionObjects::PecletNo::execute(const bool postProcess)
+bool Foam::functionObjects::PecletNo::calc()
 {
     if (foundField<surfaceScalarField>(phiName_))
     {
@@ -112,4 +81,37 @@ bool Foam::functionObjects::PecletNo::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::PecletNo::PecletNo
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "phi", "Pe")
+{
+    read(dict);
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::PecletNo::~PecletNo()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+bool Foam::functionObjects::PecletNo::read(const dictionary& dict)
+{
+    fieldExpression::read(dict);
+
+    phiName_ = dict.lookupOrDefault<word>("phi", "phi");
+
+    return true;
+}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/PecletNo/PecletNo.H b/src/postProcessing/functionObjects/field/PecletNo/PecletNo.H
index 7dd7149f76b..3ff90f0cd4e 100644
--- a/src/postProcessing/functionObjects/field/PecletNo/PecletNo.H
+++ b/src/postProcessing/functionObjects/field/PecletNo/PecletNo.H
@@ -66,6 +66,12 @@ class PecletNo
         word phiName_;
 
 
+    // Private Member Functions
+
+        //- Calculate the Peclet number field and return true if successful
+        virtual bool calc();
+
+
 public:
 
     //- Runtime type information
@@ -92,9 +98,6 @@ public:
 
         //- Read the PecletNo data
         virtual bool read(const dictionary&);
-
-        //- Calculate the Peclet number field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/Q/Q.C b/src/postProcessing/functionObjects/field/Q/Q.C
index 52cc9f14893..043550caa66 100644
--- a/src/postProcessing/functionObjects/field/Q/Q.C
+++ b/src/postProcessing/functionObjects/field/Q/Q.C
@@ -45,28 +45,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::Q::Q
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "U", "Q")
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::Q::~Q()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-bool Foam::functionObjects::Q::execute(const bool postProcess)
+bool Foam::functionObjects::Q::calc()
 {
     if (foundField<volVectorField>(fieldName_))
     {
@@ -87,4 +68,23 @@ bool Foam::functionObjects::Q::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::Q::Q
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "U", "Q")
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::Q::~Q()
+{}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/Q/Q.H b/src/postProcessing/functionObjects/field/Q/Q.H
index feca1d1b4cb..1305b02b1f6 100644
--- a/src/postProcessing/functionObjects/field/Q/Q.H
+++ b/src/postProcessing/functionObjects/field/Q/Q.H
@@ -64,6 +64,11 @@ class Q
 :
     public fieldExpression
 {
+    // Private Member Functions
+
+        //- Calculate the Q field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -84,12 +89,6 @@ public:
 
     //- Destructor
     virtual ~Q();
-
-
-    // Member Functions
-
-        //- Calculate the Q field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.C b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.C
index 50a055c0a6b..60cc2d36f79 100644
--- a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.C
+++ b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.C
@@ -38,6 +38,25 @@ namespace functionObjects
 }
 
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::functionObjects::blendingFactor::calc()
+{
+    bool processed = false;
+
+    processed = processed || calcBF<scalar>();
+    processed = processed || calcBF<vector>();
+
+    if (!processed)
+    {
+        WarningInFunction
+            << "Unprocessed field " << fieldName_ << endl;
+    }
+
+    return processed;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::blendingFactor::blendingFactor
@@ -73,21 +92,4 @@ bool Foam::functionObjects::blendingFactor::read(const dictionary& dict)
 }
 
 
-bool Foam::functionObjects::blendingFactor::execute(const bool postProcess)
-{
-    bool processed = false;
-
-    processed = processed || calc<scalar>();
-    processed = processed || calc<vector>();
-
-    if (!processed)
-    {
-        WarningInFunction
-            << "Unprocessed field " << fieldName_ << endl;
-    }
-
-    return processed;
-}
-
-
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.H b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.H
index b7f0363be28..56f0310f7f0 100644
--- a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.H
+++ b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactor.H
@@ -69,9 +69,12 @@ class blendingFactor
 
     // Private Member Functions
 
-        //- Calculate the blending factor
+        //- Calculate the blending factor field
         template<class Type>
-        bool calc();
+        bool calcBF();
+
+        //- Calculate the blending factor field and return true if successful
+        virtual bool calc();
 
 
 public:
@@ -99,9 +102,6 @@ public:
 
         //- Read the blendingFactor data
         virtual bool read(const dictionary&);
-
-        //- Calculate the blending-factor
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C
index 565b77c0d75..6c51490edbb 100644
--- a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C
+++ b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C
@@ -30,7 +30,7 @@ License
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 template<class Type>
-bool Foam::functionObjects::blendingFactor::calc()
+bool Foam::functionObjects::blendingFactor::calcBF()
 {
     typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
 
diff --git a/src/postProcessing/functionObjects/field/div/div.C b/src/postProcessing/functionObjects/field/div/div.C
index c8aefb16932..582e33ef555 100644
--- a/src/postProcessing/functionObjects/field/div/div.C
+++ b/src/postProcessing/functionObjects/field/div/div.C
@@ -40,6 +40,19 @@ namespace functionObjects
 }
 
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::functionObjects::div::calc()
+{
+    bool processed = false;
+
+    processed = processed || calcDiv<surfaceScalarField>();
+    processed = processed || calcDiv<volVectorField>();
+
+    return processed;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::div::div
@@ -59,23 +72,4 @@ Foam::functionObjects::div::~div()
 {}
 
 
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-bool Foam::functionObjects::div::execute(const bool postProcess)
-{
-    bool processed = false;
-
-    processed = processed || calc<surfaceScalarField>();
-    processed = processed || calc<volVectorField>();
-
-    if (!processed)
-    {
-        WarningInFunction
-            << "Unprocessed field " << fieldName_ << endl;
-    }
-
-    return processed;
-}
-
-
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/div/div.H b/src/postProcessing/functionObjects/field/div/div.H
index 1076300b88f..778147454f2 100644
--- a/src/postProcessing/functionObjects/field/div/div.H
+++ b/src/postProcessing/functionObjects/field/div/div.H
@@ -66,7 +66,10 @@ class div
         //- Calculate the divergence of either a
         //  volScalarField or a surfaceScalarField and register the result
         template<class FieldType>
-        bool calc();
+        bool calcDiv();
+
+        //- Calculate the divergence field and return true if successful
+        virtual bool calc();
 
 
 public:
@@ -88,12 +91,6 @@ public:
 
     //- Destructor
     virtual ~div();
-
-
-    // Member Functions
-
-        //- Calculate the divergence field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/div/divTemplates.C b/src/postProcessing/functionObjects/field/div/divTemplates.C
index e791e25b2cf..fb204a45696 100644
--- a/src/postProcessing/functionObjects/field/div/divTemplates.C
+++ b/src/postProcessing/functionObjects/field/div/divTemplates.C
@@ -28,7 +28,7 @@ License
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class FieldType>
-bool Foam::functionObjects::div::calc()
+bool Foam::functionObjects::div::calcDiv()
 {
     if (foundField<FieldType>(fieldName_))
     {
diff --git a/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C b/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C
index 3c28af5147a..9370c668c99 100644
--- a/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C
+++ b/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C
@@ -45,28 +45,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::enstrophy::enstrophy
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "U", "enstrophy")
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::enstrophy::~enstrophy()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-bool Foam::functionObjects::enstrophy::execute(const bool postProcess)
+bool Foam::functionObjects::enstrophy::calc()
 {
     if (foundField<volVectorField>(fieldName_))
     {
@@ -85,4 +66,23 @@ bool Foam::functionObjects::enstrophy::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::enstrophy::enstrophy
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "U", "enstrophy")
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::enstrophy::~enstrophy()
+{}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/enstrophy/enstrophy.H b/src/postProcessing/functionObjects/field/enstrophy/enstrophy.H
index 211102e20a7..ae044e8aacf 100644
--- a/src/postProcessing/functionObjects/field/enstrophy/enstrophy.H
+++ b/src/postProcessing/functionObjects/field/enstrophy/enstrophy.H
@@ -59,6 +59,11 @@ class enstrophy
 :
     public fieldExpression
 {
+    // Private Member Functions
+
+        //- Calculate the enstrophy field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -79,12 +84,6 @@ public:
 
     //- Destructor
     virtual ~enstrophy();
-
-
-    // Member Functions
-
-        //- Calculate the enstrophy field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C b/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C
index f4d5575594e..868e0d78f5d 100644
--- a/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C
+++ b/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C
@@ -36,6 +36,15 @@ namespace functionObjects
 }
 
 
+// * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
+
+bool Foam::functionObjects::fieldExpression::calc()
+{
+    NotImplemented;
+    return false;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::fieldExpression::fieldExpression
@@ -81,9 +90,35 @@ bool Foam::functionObjects::fieldExpression::read(const dictionary& dict)
 }
 
 
+bool Foam::functionObjects::fieldExpression::execute(const bool postProcess)
+{
+    if (!calc())
+    {
+        Warning
+            << "functionObject " << type() << ": Cannot find required field "
+            << fieldName_ << endl;
+
+        // Clear the result field from the objectRegistry if present
+        clear();
+
+        return false;
+    }
+    else
+    {
+        return true;
+    }
+}
+
+
 bool Foam::functionObjects::fieldExpression::write(const bool postProcess)
 {
-    return fvMeshFunctionObject::writeField(resultName_);
+    return writeField(resultName_);
+}
+
+
+bool Foam::functionObjects::fieldExpression::clear()
+{
+    return clearField(resultName_);
 }
 
 
diff --git a/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.H b/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.H
index 3b0e645e230..f6c7eb227fb 100644
--- a/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.H
+++ b/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.H
@@ -69,6 +69,11 @@ protected:
         word resultName_;
 
 
+    // Protected member functions
+
+        virtual bool calc();
+
+
 private:
 
     // Private Member Functions
@@ -109,10 +114,13 @@ public:
         virtual bool read(const dictionary&);
 
         //- Calculate the fieldExpressionergence field
-        virtual bool execute(const bool postProcess = false) = 0;
+        virtual bool execute(const bool postProcess = false);
 
         //- Write the fieldExpressionergence field
         virtual bool write(const bool postProcess = false);
+
+        //- Clear the result field from the objectRegistry
+        virtual bool clear();
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/flowType/flowType.C b/src/postProcessing/functionObjects/field/flowType/flowType.C
index d282617778d..5193f3736c4 100644
--- a/src/postProcessing/functionObjects/field/flowType/flowType.C
+++ b/src/postProcessing/functionObjects/field/flowType/flowType.C
@@ -45,28 +45,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::flowType::flowType
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "U", "flowType")
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::flowType::~flowType()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-bool Foam::functionObjects::flowType::execute(const bool postProcess)
+bool Foam::functionObjects::flowType::calc()
 {
     if (foundField<volVectorField>(fieldName_))
     {
@@ -97,4 +78,23 @@ bool Foam::functionObjects::flowType::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::flowType::flowType
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "U", "flowType")
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::flowType::~flowType()
+{}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/flowType/flowType.H b/src/postProcessing/functionObjects/field/flowType/flowType.H
index f73e82b732a..54205736f40 100644
--- a/src/postProcessing/functionObjects/field/flowType/flowType.H
+++ b/src/postProcessing/functionObjects/field/flowType/flowType.H
@@ -70,6 +70,11 @@ class flowType
 :
     public fieldExpression
 {
+    // Private Member Functions
+
+        //- Calculate the flowType field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -90,12 +95,6 @@ public:
 
     //- Destructor
     virtual ~flowType();
-
-
-    // Member Functions
-
-        //- Calculate the flowType field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/grad/grad.C b/src/postProcessing/functionObjects/field/grad/grad.C
index 1ee5d82f8cc..b265ec80b7c 100644
--- a/src/postProcessing/functionObjects/field/grad/grad.C
+++ b/src/postProcessing/functionObjects/field/grad/grad.C
@@ -38,6 +38,19 @@ namespace functionObjects
 }
 
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::functionObjects::grad::calc()
+{
+    bool processed = false;
+
+    processed = processed || calcGrad<scalar>();
+    processed = processed || calcGrad<vector>();
+
+    return processed;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::grad::grad
@@ -59,23 +72,4 @@ Foam::functionObjects::grad::~grad()
 {}
 
 
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-bool Foam::functionObjects::grad::execute(const bool postProcess)
-{
-    bool processed = false;
-
-    processed = processed || calc<scalar>();
-    processed = processed || calc<vector>();
-
-    if (!processed)
-    {
-        WarningInFunction
-            << "Unprocessed field " << fieldName_ << endl;
-    }
-
-    return true;
-}
-
-
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/grad/grad.H b/src/postProcessing/functionObjects/field/grad/grad.H
index 68bd4450f61..36db751f317 100644
--- a/src/postProcessing/functionObjects/field/grad/grad.H
+++ b/src/postProcessing/functionObjects/field/grad/grad.H
@@ -64,7 +64,10 @@ class grad
 
         //- Calculate the magnitude of the field and register the result
         template<class Type>
-        bool calc();
+        bool calcGrad();
+
+        //- Calculate the gradient field and return true if successful
+        virtual bool calc();
 
 
 public:
@@ -86,12 +89,6 @@ public:
 
     //- Destructor
     virtual ~grad();
-
-
-    // Member Functions
-
-        //- Calculate the gradient field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/grad/gradTemplates.C b/src/postProcessing/functionObjects/field/grad/gradTemplates.C
index 026b1a3c705..1eeae184665 100644
--- a/src/postProcessing/functionObjects/field/grad/gradTemplates.C
+++ b/src/postProcessing/functionObjects/field/grad/gradTemplates.C
@@ -28,7 +28,7 @@ License
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 template<class Type>
-bool Foam::functionObjects::grad::calc()
+bool Foam::functionObjects::grad::calcGrad()
 {
     typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
     typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
diff --git a/src/postProcessing/functionObjects/field/mag/mag.C b/src/postProcessing/functionObjects/field/mag/mag.C
index c2e519d267e..b37a053c580 100644
--- a/src/postProcessing/functionObjects/field/mag/mag.C
+++ b/src/postProcessing/functionObjects/field/mag/mag.C
@@ -38,6 +38,28 @@ namespace functionObjects
 }
 
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::functionObjects::mag::calc()
+{
+    bool processed = false;
+
+    processed = processed || calcMag<scalar>();
+    processed = processed || calcMag<vector>();
+    processed = processed || calcMag<sphericalTensor>();
+    processed = processed || calcMag<symmTensor>();
+    processed = processed || calcMag<tensor>();
+
+    if (!processed)
+    {
+        WarningInFunction
+            << "Unprocessed field " << fieldName_ << endl;
+    }
+
+    return processed;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::mag::mag
@@ -59,26 +81,4 @@ Foam::functionObjects::mag::~mag()
 {}
 
 
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-bool Foam::functionObjects::mag::execute(const bool postProcess)
-{
-    bool processed = false;
-
-    processed = processed || calc<scalar>();
-    processed = processed || calc<vector>();
-    processed = processed || calc<sphericalTensor>();
-    processed = processed || calc<symmTensor>();
-    processed = processed || calc<tensor>();
-
-    if (!processed)
-    {
-        WarningInFunction
-            << "Unprocessed field " << fieldName_ << endl;
-    }
-
-    return processed;
-}
-
-
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/mag/mag.H b/src/postProcessing/functionObjects/field/mag/mag.H
index a77951827e3..f27908762d0 100644
--- a/src/postProcessing/functionObjects/field/mag/mag.H
+++ b/src/postProcessing/functionObjects/field/mag/mag.H
@@ -64,7 +64,10 @@ class mag
 
         //- Calculate the magnitude of the field and register the result
         template<class Type>
-        bool calc();
+        bool calcMag();
+
+        //- Calculate the magnitude of the field and return true if successful
+        virtual bool calc();
 
 
 public:
@@ -86,12 +89,6 @@ public:
 
     //- Destructor
     virtual ~mag();
-
-
-    // Member Functions
-
-        //- Calculate the magnitude field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/mag/magTemplates.C b/src/postProcessing/functionObjects/field/mag/magTemplates.C
index 5b78efb93a6..8cb4debaa68 100644
--- a/src/postProcessing/functionObjects/field/mag/magTemplates.C
+++ b/src/postProcessing/functionObjects/field/mag/magTemplates.C
@@ -29,7 +29,7 @@ License
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
-bool Foam::functionObjects::mag::calc()
+bool Foam::functionObjects::mag::calcMag()
 {
     typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
     typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
diff --git a/src/postProcessing/functionObjects/field/pressure/pressure.C b/src/postProcessing/functionObjects/field/pressure/pressure.C
index da8a3269311..d2f854f1814 100644
--- a/src/postProcessing/functionObjects/field/pressure/pressure.C
+++ b/src/postProcessing/functionObjects/field/pressure/pressure.C
@@ -159,6 +159,27 @@ Foam::functionObjects::pressure::coeff
 }
 
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::functionObjects::pressure::calc()
+{
+    if (foundField<volScalarField>(fieldName_))
+    {
+        const volScalarField& p = lookupField<volScalarField>(fieldName_);
+
+        return store
+        (
+            resultName_,
+            coeff(pRef(pDyn(p, rhoScale(p))))
+        );
+    }
+    else
+    {
+        return false;
+    }
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::functionObjects::pressure::pressure
@@ -238,23 +259,4 @@ bool Foam::functionObjects::pressure::read(const dictionary& dict)
 }
 
 
-bool Foam::functionObjects::pressure::execute(const bool postProcess)
-{
-    if (foundField<volScalarField>(fieldName_))
-    {
-        const volScalarField& p = lookupField<volScalarField>(fieldName_);
-
-        return store
-        (
-            resultName_,
-            coeff(pRef(pDyn(p, rhoScale(p))))
-        );
-    }
-    else
-    {
-        return false;
-    }
-}
-
-
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/pressure/pressure.H b/src/postProcessing/functionObjects/field/pressure/pressure.H
index bd92001723e..4970c5aa585 100644
--- a/src/postProcessing/functionObjects/field/pressure/pressure.H
+++ b/src/postProcessing/functionObjects/field/pressure/pressure.H
@@ -196,6 +196,9 @@ class pressure
         //- Convert to coeff by applying the freestream dynamic pressure scaling
         tmp<volScalarField> coeff(const tmp<volScalarField>& tp) const;
 
+        //- Calculate the derived pressure field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -222,9 +225,6 @@ public:
 
         //- Read the pressure data
         virtual bool read(const dictionary&);
-
-        //- Calculate the selected pressure form
-        virtual bool execute(const bool postProcess = false);
 };
 
 
diff --git a/src/postProcessing/functionObjects/field/vorticity/vorticity.C b/src/postProcessing/functionObjects/field/vorticity/vorticity.C
index 8c2291136f4..b6c462e50f7 100644
--- a/src/postProcessing/functionObjects/field/vorticity/vorticity.C
+++ b/src/postProcessing/functionObjects/field/vorticity/vorticity.C
@@ -45,28 +45,9 @@ namespace functionObjects
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::functionObjects::vorticity::vorticity
-(
-    const word& name,
-    const Time& runTime,
-    const dictionary& dict
-)
-:
-    fieldExpression(name, runTime, dict, "U", "vorticity")
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::vorticity::~vorticity()
-{}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-bool Foam::functionObjects::vorticity::execute(const bool postProcess)
+bool Foam::functionObjects::vorticity::calc()
 {
     if (foundField<volVectorField>(fieldName_))
     {
@@ -85,4 +66,23 @@ bool Foam::functionObjects::vorticity::execute(const bool postProcess)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::vorticity::vorticity
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fieldExpression(name, runTime, dict, "U", "vorticity")
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::functionObjects::vorticity::~vorticity()
+{}
+
+
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/field/vorticity/vorticity.H b/src/postProcessing/functionObjects/field/vorticity/vorticity.H
index 13c1f096f69..44a0b101638 100644
--- a/src/postProcessing/functionObjects/field/vorticity/vorticity.H
+++ b/src/postProcessing/functionObjects/field/vorticity/vorticity.H
@@ -59,6 +59,11 @@ class vorticity
 :
     public fieldExpression
 {
+    // Private Member Functions
+
+        //- Calculate the vorticity field and return true if successful
+        virtual bool calc();
+
 
 public:
 
@@ -79,12 +84,6 @@ public:
 
     //- Destructor
     virtual ~vorticity();
-
-
-    // Member Functions
-
-        //- Calculate the vorticity field
-        virtual bool execute(const bool postProcess = false);
 };
 
 
-- 
GitLab