From d1caaa052907da3081f1b76a84a5e53688c56e74 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Sat, 15 Dec 2018 18:08:51 +0100
Subject: [PATCH] ENH: build dummy runTimePostProcessing if VTK/ParaView are
 not available

- this allows more use of the runTimePostProcessing functionObject
  that will fail more gracefully if the proper version could not be
  built.

  The dummy functionObject simply emits a message that it is not available.
---
 .../functionObject/functionObject.C           | 55 +++++++++---
 .../functionObject/functionObject.H           | 53 +++++++++---
 .../graphics/runTimePostProcessing/Allwclean  |  6 +-
 .../graphics/runTimePostProcessing/Allwmake   | 43 ++++++----
 .../runTimePostProcessing/dummy/Make/files    |  3 +
 .../runTimePostProcessing/dummy/Make/options  |  2 +
 .../dummy/runTimePostProcessingDummy.C        | 67 +++++++++++++++
 .../dummy/runTimePostProcessingDummy.H        | 85 +++++++++++++++++++
 .../runTimePostProcessing.C                   |  8 +-
 .../runTimePostProcessing.H                   | 22 ++---
 .../RAS/elipsekkLOmega/system/controlDict     |  4 +-
 11 files changed, 284 insertions(+), 64 deletions(-)
 create mode 100644 src/functionObjects/graphics/runTimePostProcessing/dummy/Make/files
 create mode 100644 src/functionObjects/graphics/runTimePostProcessing/dummy/Make/options
 create mode 100644 src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.C
 create mode 100644 src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.H

diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C
index a3a3b42db4a..2c4c866ba59 100644
--- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C
+++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C
@@ -40,6 +40,7 @@ bool Foam::functionObject::postProcess(false);
 
 Foam::word Foam::functionObject::outputPrefix("postProcessing");
 
+
 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
 
 Foam::word Foam::functionObject::scopedName(const word& name) const
@@ -68,10 +69,9 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
 {
     const word functionType(dict.get<word>("type"));
 
-    if (debug)
-    {
-        Info<< "Selecting function " << functionType << endl;
-    }
+    DebugInfo
+        << "Selecting function " << functionType << endl;
+
 
     // Load any additional libraries
     {
@@ -122,12 +122,6 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
 }
 
 
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObject::~functionObject()
-{}
-
-
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 const Foam::word& Foam::functionObject::name() const
@@ -179,4 +173,45 @@ void Foam::functionObject::movePoints(const polyMesh&)
 {}
 
 
+// * * * * * * * * * * * * unavailableFunctionObject * * * * * * * * * * * * //
+
+Foam::functionObject::unavailableFunctionObject::unavailableFunctionObject
+(
+    const word& name
+)
+:
+    functionObject(name)
+{}
+
+
+void Foam::functionObject::unavailableFunctionObject::carp(std::string message)
+{
+    FatalError
+        << "####" << nl
+        << "    " << type() << " not available" << nl
+        << "####" << nl;
+
+    if (message.size())
+    {
+        FatalError
+            << message.c_str() << nl;
+    }
+
+    FatalError
+        << exit(FatalError);
+}
+
+
+bool Foam::functionObject::unavailableFunctionObject::execute()
+{
+    return true;
+}
+
+
+bool Foam::functionObject::unavailableFunctionObject::write()
+{
+    return true;
+}
+
+
 // ************************************************************************* //
diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H
index 6cf20b4d476..1a7b17c0708 100644
--- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H
+++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H
@@ -127,7 +127,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of classes
+// Forward declarations
 class Time;
 class polyMesh;
 class mapPolyMesh;
@@ -144,15 +144,6 @@ class functionObject
         const word name_;
 
 
-    // Private Member Functions
-
-        //- No copy construct
-        functionObject(const functionObject&) = delete;
-
-        //- No copy assignment
-        void operator=(const functionObject&) = delete;
-
-
 protected:
 
     // Protected Member Functions
@@ -163,6 +154,9 @@ protected:
 
 public:
 
+    // Forward declarations
+    class unavailableFunctionObject;
+
     //- Runtime type information
     virtual const word& type() const = 0;
 
@@ -209,13 +203,13 @@ public:
         static autoPtr<functionObject> New
         (
             const word& name,
-            const Time&,
-            const dictionary&
+            const Time& runTime,
+            const dictionary& dict
         );
 
 
     //- Destructor
-    virtual ~functionObject();
+    virtual ~functionObject() = default;
 
 
     // Member Functions
@@ -243,7 +237,7 @@ public:
         virtual bool write() = 0;
 
         //- Called when Time::run() determines that the time-loop exits.
-        //  By default it simply calls execute().
+        //  The base implementation is a no-op.
         virtual bool end();
 
         //- Called at the end of Time::adjustDeltaT() if adjustTime is true
@@ -262,6 +256,37 @@ public:
 };
 
 
+/*---------------------------------------------------------------------------*\
+          Class functionObject::unavailableFunctionObject Declaration
+\*---------------------------------------------------------------------------*/
+
+//- Abstract functionObject to report when a real version is unavailable.
+class functionObject::unavailableFunctionObject
+:
+    public functionObject
+{
+protected:
+
+    //- Construct with name
+    unavailableFunctionObject(const word& name);
+
+    //- Report it is unavailable, emitting a FatalError for try/catch
+    //- in the caller
+    void carp(std::string message = "");
+
+
+public:
+
+    // Member Functions
+
+        //- No nothing
+        virtual bool execute();
+
+        //- No nothing
+        virtual bool write();
+};
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwclean b/src/functionObjects/graphics/runTimePostProcessing/Allwclean
index e3340097cff..140edc4bd16 100755
--- a/src/functionObjects/graphics/runTimePostProcessing/Allwclean
+++ b/src/functionObjects/graphics/runTimePostProcessing/Allwclean
@@ -2,10 +2,12 @@
 cd ${0%/*} || exit 1                            # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions  # Source wmake functions
 
-# Cleanup library
+# This cleanup handles both cmake runTimePostProcessing and the dummy version
+
+# Cleanup library files with .so version endings
 rm -f $FOAM_LIBBIN/librunTimePostProcessing* 2>/dev/null
 
 # Cleanup generated files - remove entire top-level
-removeObjectDir $PWD
+removeObjectDir "$PWD"
 
 #------------------------------------------------------------------------------
diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwmake b/src/functionObjects/graphics/runTimePostProcessing/Allwmake
index a0321c849b1..dc55737109b 100755
--- a/src/functionObjects/graphics/runTimePostProcessing/Allwmake
+++ b/src/functionObjects/graphics/runTimePostProcessing/Allwmake
@@ -6,9 +6,9 @@ cd ${0%/*} || exit 1                            # Run from this directory
 
 echo "======================================================================"
 echo "${PWD##*/} : $PWD"
-echo
 
 unset depend
+
 if [ -d "$VTK_DIR" ]
 then
     depend="VTK_DIR=$VTK_DIR"
@@ -17,25 +17,36 @@ then
     depend="ParaView_DIR=$ParaView_DIR"
 fi
 
-if [ -n "$depend" ]
+# Or force use of dummy only
+# unset depend
+
+if [ "$targetType" = objects ]
+then
+    depend=ignore
+elif [ -n "$depend" ]
 then
-    if [ "$targetType" != objects ]
+    if command -v cmake > /dev/null 2>&1
     then
-        if command -v cmake > /dev/null 2>&1
-        then
-            cmakeVersioned "$depend" $PWD || {
-                echo
-                echo "    WARNING: incomplete build of VTK-based post-processing"
-                echo
-            }
-        else
-            echo "WARNING: skipped - needs cmake"
-        fi
+        cmakeVersioned "$depend" $PWD || {
+            echo
+            echo "    WARNING: incomplete build of VTK-based post-processing"
+            echo
+            depend="dummy"
+        }
+    else
+        echo "==> skip runTimePostProcessing (needs cmake)"
+        depend="dummy"
     fi
 else
-    echo "WARNING: skipped - needs a VTK or a ParaView installation"
-    echo "    - For ParaView  : export the 'ParaView_DIR' variable"
-    echo "    - For VTK       : export the 'VTK_DIR'      variable"
+    echo "WARNING: skip runTimePostProcessing (no VTK or ParaView)"
+    echo "    - ParaView  : export the 'ParaView_DIR' variable"
+    echo "    - VTK       : export the 'VTK_DIR'      variable"
+fi
+
+if [ "${depend:-dummy}" = dummy ]
+then
+    echo "==> dummy runTimePostProcessing"
+    wmakeVersioned "vtk=dummy" $PWD dummy
 fi
 
 echo "======================================================================"
diff --git a/src/functionObjects/graphics/runTimePostProcessing/dummy/Make/files b/src/functionObjects/graphics/runTimePostProcessing/dummy/Make/files
new file mode 100644
index 00000000000..33685ca6e5d
--- /dev/null
+++ b/src/functionObjects/graphics/runTimePostProcessing/dummy/Make/files
@@ -0,0 +1,3 @@
+runTimePostProcessingDummy.C
+
+LIB = $(FOAM_LIBBIN)/librunTimePostProcessing
diff --git a/src/functionObjects/graphics/runTimePostProcessing/dummy/Make/options b/src/functionObjects/graphics/runTimePostProcessing/dummy/Make/options
new file mode 100644
index 00000000000..6b8588463d9
--- /dev/null
+++ b/src/functionObjects/graphics/runTimePostProcessing/dummy/Make/options
@@ -0,0 +1,2 @@
+/* EXE_INC = */
+/* LIB_LIBS = */
diff --git a/src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.C b/src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.C
new file mode 100644
index 00000000000..51f02faa8a2
--- /dev/null
+++ b/src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.C
@@ -0,0 +1,67 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+     \\/     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 "runTimePostProcessingDummy.H"
+#include "dictionary.H"
+#include "Time.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace functionObjects
+{
+    defineTypeNameAndDebug(runTimePostProcessingDummy, 0);
+
+    addToRunTimeSelectionTable
+    (
+        functionObject,
+        runTimePostProcessingDummy,
+        dictionary
+    );
+}
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::functionObjects::runTimePostProcessingDummy::runTimePostProcessingDummy
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    functionObject::unavailableFunctionObject(name)
+{
+    carp
+    (
+        "VTK libraries were not available at compilation time"
+    );
+}
+
+
+// ************************************************************************* //
diff --git a/src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.H b/src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.H
new file mode 100644
index 00000000000..b71e771351f
--- /dev/null
+++ b/src/functionObjects/graphics/runTimePostProcessing/dummy/runTimePostProcessingDummy.H
@@ -0,0 +1,85 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+     \\/     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/>.
+
+Class
+    Foam::functionObjects::runTimePostPro::runTimePostProcessingDummy
+
+Group
+    grpGraphicsFunctionObjects
+
+Description
+    Dummy implementation of runTimePostProcessing to report when
+    the real version is unavailable.
+
+SourceFiles
+    runTimePostProcessingDummy.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef functionObjects_runTimePostProcessingDummy_H
+#define functionObjects_runTimePostProcessingDummy_H
+
+#include "functionObject.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace functionObjects
+{
+
+/*---------------------------------------------------------------------------*\
+                 Class runTimePostProcessingDummy Declaration
+\*---------------------------------------------------------------------------*/
+
+class runTimePostProcessingDummy
+:
+    public functionObject::unavailableFunctionObject
+{
+public:
+
+    //- Runtime type information
+    TypeName("runTimePostProcessing");
+
+    // Constructors
+
+        //- Construct from dictionary
+        runTimePostProcessingDummy
+        (
+            const word& name,
+            const Time& runTime,
+            const dictionary& dict
+        );
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace functionObjects
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C
index 58bab58707b..5aa639a049c 100644
--- a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C
+++ b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -80,12 +80,6 @@ Foam::functionObjects::runTimePostProcessing::runTimePostProcessing
 }
 
 
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::runTimePostProcessing::~runTimePostProcessing()
-{}
-
-
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 bool Foam::functionObjects::runTimePostProcessing::read(const dictionary& dict)
diff --git a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H
index 225ae28954b..8fd76343ba3 100644
--- a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H
+++ b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -119,15 +119,11 @@ private:
         PtrList<runTimePostPro::text> text_;
 
 
-        // Private Member Functions
+    // Private Member Functions
 
-            //- Helper function to read scene objects
-            template<class Type>
-            void readObjects
-            (
-                const dictionary& dict,
-                PtrList<Type>& objects
-            ) const;
+        //- Helper function to read scene objects
+        template<class Type>
+        void readObjects(const dictionary& dict, PtrList<Type>& objects) const;
 
 
 public:
@@ -143,12 +139,12 @@ public:
         (
             const word& name,
             const Time& runTime,
-            const dictionary&dict
+            const dictionary& dict
         );
 
 
     //- Destructor
-    virtual ~runTimePostProcessing();
+    virtual ~runTimePostProcessing() = default;
 
 
     // Member Functions
@@ -158,8 +154,8 @@ public:
             return mesh_;
         }
 
-        //- Read the field min/max data
-        virtual bool read(const dictionary&);
+        //- Read the post-processing controls
+        virtual bool read(const dictionary& dict);
 
         //- Execute, currently does nothing
         virtual bool execute();
diff --git a/tutorials/incompressible/pimpleFoam/RAS/elipsekkLOmega/system/controlDict b/tutorials/incompressible/pimpleFoam/RAS/elipsekkLOmega/system/controlDict
index 6f9d819fbca..ba2cede19cc 100644
--- a/tutorials/incompressible/pimpleFoam/RAS/elipsekkLOmega/system/controlDict
+++ b/tutorials/incompressible/pimpleFoam/RAS/elipsekkLOmega/system/controlDict
@@ -52,8 +52,8 @@ maxCo           0.2;
 
 functions
 {
-//     #include "sampling"
-//     #include "runTimePostProcessing"
+    #include "sampling"
+    #include "runTimePostProcessing"
 }
 
 // ************************************************************************* //
-- 
GitLab