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.
This commit is contained in:
Mark Olesen 2018-12-15 18:08:51 +01:00
parent dd2c7c4894
commit d1caaa0529
11 changed files with 284 additions and 64 deletions

View File

@ -40,6 +40,7 @@ bool Foam::functionObject::postProcess(false);
Foam::word Foam::functionObject::outputPrefix("postProcessing"); Foam::word Foam::functionObject::outputPrefix("postProcessing");
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::word Foam::functionObject::scopedName(const word& name) const 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")); const word functionType(dict.get<word>("type"));
if (debug) DebugInfo
{ << "Selecting function " << functionType << endl;
Info<< "Selecting function " << functionType << endl;
}
// Load any additional libraries // Load any additional libraries
{ {
@ -122,12 +122,6 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObject::~functionObject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::word& Foam::functionObject::name() const 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -127,7 +127,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class Time; class Time;
class polyMesh; class polyMesh;
class mapPolyMesh; class mapPolyMesh;
@ -144,15 +144,6 @@ class functionObject
const word name_; const word name_;
// Private Member Functions
//- No copy construct
functionObject(const functionObject&) = delete;
//- No copy assignment
void operator=(const functionObject&) = delete;
protected: protected:
// Protected Member Functions // Protected Member Functions
@ -163,6 +154,9 @@ protected:
public: public:
// Forward declarations
class unavailableFunctionObject;
//- Runtime type information //- Runtime type information
virtual const word& type() const = 0; virtual const word& type() const = 0;
@ -209,13 +203,13 @@ public:
static autoPtr<functionObject> New static autoPtr<functionObject> New
( (
const word& name, const word& name,
const Time&, const Time& runTime,
const dictionary& const dictionary& dict
); );
//- Destructor //- Destructor
virtual ~functionObject(); virtual ~functionObject() = default;
// Member Functions // Member Functions
@ -243,7 +237,7 @@ public:
virtual bool write() = 0; virtual bool write() = 0;
//- Called when Time::run() determines that the time-loop exits. //- 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(); virtual bool end();
//- Called at the end of Time::adjustDeltaT() if adjustTime is true //- 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 } // End namespace Foam

View File

@ -2,10 +2,12 @@
cd ${0%/*} || exit 1 # Run from this directory cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Source wmake functions . $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 rm -f $FOAM_LIBBIN/librunTimePostProcessing* 2>/dev/null
# Cleanup generated files - remove entire top-level # Cleanup generated files - remove entire top-level
removeObjectDir $PWD removeObjectDir "$PWD"
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -6,9 +6,9 @@ cd ${0%/*} || exit 1 # Run from this directory
echo "======================================================================" echo "======================================================================"
echo "${PWD##*/} : $PWD" echo "${PWD##*/} : $PWD"
echo
unset depend unset depend
if [ -d "$VTK_DIR" ] if [ -d "$VTK_DIR" ]
then then
depend="VTK_DIR=$VTK_DIR" depend="VTK_DIR=$VTK_DIR"
@ -17,25 +17,36 @@ then
depend="ParaView_DIR=$ParaView_DIR" depend="ParaView_DIR=$ParaView_DIR"
fi fi
if [ -n "$depend" ] # Or force use of dummy only
# unset depend
if [ "$targetType" = objects ]
then then
if [ "$targetType" != objects ] depend=ignore
elif [ -n "$depend" ]
then
if command -v cmake > /dev/null 2>&1
then then
if command -v cmake > /dev/null 2>&1 cmakeVersioned "$depend" $PWD || {
then echo
cmakeVersioned "$depend" $PWD || { echo " WARNING: incomplete build of VTK-based post-processing"
echo echo
echo " WARNING: incomplete build of VTK-based post-processing" depend="dummy"
echo }
} else
else echo "==> skip runTimePostProcessing (needs cmake)"
echo "WARNING: skipped - needs cmake" depend="dummy"
fi
fi fi
else else
echo "WARNING: skipped - needs a VTK or a ParaView installation" echo "WARNING: skip runTimePostProcessing (no VTK or ParaView)"
echo " - For ParaView : export the 'ParaView_DIR' variable" echo " - ParaView : export the 'ParaView_DIR' variable"
echo " - For VTK : export the 'VTK_DIR' variable" echo " - VTK : export the 'VTK_DIR' variable"
fi
if [ "${depend:-dummy}" = dummy ]
then
echo "==> dummy runTimePostProcessing"
wmakeVersioned "vtk=dummy" $PWD dummy
fi fi
echo "======================================================================" echo "======================================================================"

View File

@ -0,0 +1,3 @@
runTimePostProcessingDummy.C
LIB = $(FOAM_LIBBIN)/librunTimePostProcessing

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* LIB_LIBS = */

View File

@ -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"
);
}
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -80,12 +80,6 @@ Foam::functionObjects::runTimePostProcessing::runTimePostProcessing
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::runTimePostProcessing::~runTimePostProcessing()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::runTimePostProcessing::read(const dictionary& dict) bool Foam::functionObjects::runTimePostProcessing::read(const dictionary& dict)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -119,15 +119,11 @@ private:
PtrList<runTimePostPro::text> text_; PtrList<runTimePostPro::text> text_;
// Private Member Functions // Private Member Functions
//- Helper function to read scene objects //- Helper function to read scene objects
template<class Type> template<class Type>
void readObjects void readObjects(const dictionary& dict, PtrList<Type>& objects) const;
(
const dictionary& dict,
PtrList<Type>& objects
) const;
public: public:
@ -143,12 +139,12 @@ public:
( (
const word& name, const word& name,
const Time& runTime, const Time& runTime,
const dictionary&dict const dictionary& dict
); );
//- Destructor //- Destructor
virtual ~runTimePostProcessing(); virtual ~runTimePostProcessing() = default;
// Member Functions // Member Functions
@ -158,8 +154,8 @@ public:
return mesh_; return mesh_;
} }
//- Read the field min/max data //- Read the post-processing controls
virtual bool read(const dictionary&); virtual bool read(const dictionary& dict);
//- Execute, currently does nothing //- Execute, currently does nothing
virtual bool execute(); virtual bool execute();

View File

@ -52,8 +52,8 @@ maxCo 0.2;
functions functions
{ {
// #include "sampling" #include "sampling"
// #include "runTimePostProcessing" #include "runTimePostProcessing"
} }
// ************************************************************************* // // ************************************************************************* //