From 4ff1c7dca4ef470b80e4573860511b356f9aa7ad Mon Sep 17 00:00:00 2001 From: Andrew Heather <a.heather@opencfd.co.uk> Date: Thu, 15 Dec 2016 15:45:02 +0000 Subject: [PATCH] ENH: runTimePostProcessing - added option to clear/remove objects after use --- .../CMakeLists-Common.txt | 1 + .../fieldVisualisationBase.C | 2 - .../fieldVisualisationBase.H | 7 - .../functionObjectBase.C | 112 +++++++++++++++ .../functionObjectBase.H | 130 ++++++++++++++++++ .../functionObjectCloud.C | 43 +++++- .../functionObjectCloud.H | 10 +- .../functionObjectLine.C | 30 ++-- .../functionObjectLine.H | 10 +- .../functionObjectSurface.C | 38 +++-- .../functionObjectSurface.H | 16 +-- .../runTimePostProcessing/geometryBase.H | 4 + .../runTimePostProcessing/geometrySurface.C | 9 ++ .../runTimePostProcessing/geometrySurface.H | 3 + .../runTimePostProcessing.C | 18 +++ .../graphics/runTimePostProcessing/scene.H | 1 + .../graphics/runTimePostProcessing/text.C | 8 +- .../graphics/runTimePostProcessing/text.H | 3 + 18 files changed, 370 insertions(+), 75 deletions(-) create mode 100644 src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.C create mode 100644 src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.H diff --git a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt index bb98b9c158e..3e7a61e625f 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt +++ b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt @@ -48,6 +48,7 @@ set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} file(GLOB SOURCE_FILES fieldVisualisationBase.C + functionObjectBase.C functionObjectCloud.C functionObjectLine.C functionObjectSurface.C diff --git a/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C b/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C index f43b60c172d..084bcc1e99b 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C +++ b/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C @@ -507,12 +507,10 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase ( - const runTimePostProcessing& parent, const dictionary& dict, const HashPtrTable<Function1<vector>, word>& colours ) : - parent_(parent), colours_(colours), fieldName_(dict.lookup("field")), colourBy_(cbColour), diff --git a/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.H b/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.H index 7ddaa2e6873..0ae8c6a6080 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.H +++ b/src/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.H @@ -93,12 +93,6 @@ public: private: - // Private data - - //- Reference to the parent function object - const runTimePostProcessing& parent_; - - // Private Member Functions //- Disallow default bitwise copy construct @@ -185,7 +179,6 @@ public: //- Construct from dictionary fieldVisualisationBase ( - const runTimePostProcessing& parent, const dictionary& dict, const HashPtrTable<Function1<vector>, word>& colours ); diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.C b/src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.C new file mode 100644 index 00000000000..e2c1ebee874 --- /dev/null +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.C @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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 "functionObjectBase.H" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ +namespace runTimePostPro +{ + defineTypeNameAndDebug(functionObjectBase, 0); +} +} +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::runTimePostPro::functionObjectBase::removeFile +( + const word& keyword, + const word& fieldName +) +{ + dictionary dict; + state_.getObjectDict(functionObjectName_, fieldName, dict); + + fileName fName; + if (dict.readIfPresent(keyword, fName)) + { + Foam::rm(fName); + return true; + } + + return false; +} + + +Foam::fileName +Foam::functionObjects::runTimePostPro::functionObjectBase::getFileName +( + const word& keyword, + const word& fieldName +) const +{ + dictionary dict; + state_.getObjectDict(functionObjectName_, fieldName, dict); + + fileName fName(dict.lookupOrDefault(keyword, fileName::null)); + + return fName; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::runTimePostPro::functionObjectBase::functionObjectBase +( + const stateFunctionObject& state, + const dictionary& dict, + const HashPtrTable<Function1<vector>, word>& colours +) +: + fieldVisualisationBase(dict, colours), + state_(state), + functionObjectName_(""), + clearObjects_(dict.lookupOrDefault<bool>("clearObjects", false)) +{ + dict.lookup("functionObject") >> functionObjectName_; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::runTimePostPro::functionObjectBase::~functionObjectBase() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::functionObjects::runTimePostPro::functionObjectBase::clear() +{ + return clearObjects_; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.H b/src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.H new file mode 100644 index 00000000000..09515f32806 --- /dev/null +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectBase.H @@ -0,0 +1,130 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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::functionObjectBase + +Description + Base class for function object visualisation + +SourceFiles + functionObjectBase.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_runTimePostPro_functionObjectBase_H +#define functionObjects_runTimePostPro_functionObjectBase_H + +#include "fieldVisualisationBase.H" +#include "stateFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ +namespace runTimePostPro +{ + +/*---------------------------------------------------------------------------*\ + Class functionObjectBase Declaration +\*---------------------------------------------------------------------------*/ + +class functionObjectBase +: + public fieldVisualisationBase +{ +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + functionObjectBase(const functionObjectBase&); + + //- Disallow default bitwise assignment + void operator=(const functionObjectBase&); + + +protected: + + // Protected data + + //- Reference to the state + const stateFunctionObject& state_; + + //- Function object name + word functionObjectName_; + + //- Flag to indicate that source data should be cleared after use + bool clearObjects_; + + + // Protected Member Functions + + //- Retrieve file used to create the scene object + fileName getFileName(const word& keyword, const word& fieldName) const; + + //- Remove file used to create the scene object + bool removeFile(const word& keyword, const word& fieldName); + + +public: + + //- Run-time type information + TypeName("functionObjectBase"); + + + // Constructors + + //- Construct from dictionary + functionObjectBase + ( + const stateFunctionObject& state, + const dictionary& dict, + const HashPtrTable<Function1<vector>, word>& colours + ); + + + //- Destructor + virtual ~functionObjectBase(); + + + // Member Functions + + //- Clear files used to create the object(s) + virtual bool clear(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace runTimePostPro +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.C b/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.C index a414f269c9e..357997df256 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.C +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.C @@ -62,9 +62,8 @@ Foam::functionObjects::runTimePostPro::functionObjectCloud::functionObjectCloud ) : pointData(parent, dict, colours), - fieldVisualisationBase(parent, dict, colours), + functionObjectBase(parent, dict, colours), cloudName_(dict.lookup("cloud")), - functionObject_(dict.lookup("functionObject")), colourFieldName_(dict.lookup("colourField")), actor_() { @@ -103,18 +102,18 @@ addGeometryToScene if (cloudDict.found("functionObjectCloud")) { const dictionary& foDict = cloudDict.subDict("cloudFunctionObject"); - if (foDict.found(functionObject_)) + if (foDict.found(functionObjectName_)) { - foDict.subDict(functionObject_).readIfPresent("file", fName); + foDict.subDict(functionObjectName_).readIfPresent("file", fName); } } if (fName.empty()) { WarningInFunction - << "Unable to find function object " << functionObject_ + << "Unable to find function object " << functionObjectName_ << " output for field " << fieldName_ - << ". Line will not be processed" + << ". Cloud will not be processed" << endl; return; } @@ -159,4 +158,36 @@ void Foam::functionObjects::runTimePostPro::functionObjectCloud::updateActors } +bool Foam::functionObjects::runTimePostPro::functionObjectCloud::clear() +{ + if (functionObjectBase::clear()) + { + const dictionary& cloudDict = + geometryBase::parent_.mesh().lookupObject<IOdictionary> + ( + cloudName_ & "OutputProperties" + ); + + if (cloudDict.found("functionObjectCloud")) + { + const dictionary& foDict = cloudDict.subDict("functionObjectCloud"); + if (foDict.found(functionObjectName_)) + { + const dictionary& functionDict = + foDict.subDict(functionObjectName_); + + fileName fName; + if (functionDict.readIfPresent("file", fName)) + { + Foam::rm(fName); + return true; + } + } + } + } + + return false; +} + + // ************************************************************************* // diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.H b/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.H index 19348aea06c..35645965bc5 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.H +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectCloud.H @@ -36,7 +36,7 @@ SourceFiles #define functionObjects_runTimePostPro_functionObjectCloud_H #include "pointData.H" -#include "fieldVisualisationBase.H" +#include "functionObjectBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,7 +54,7 @@ namespace runTimePostPro class functionObjectCloud : public pointData, - public fieldVisualisationBase + public functionObjectBase { private: @@ -74,9 +74,6 @@ protected: //- Name of functionObjectCloud word cloudName_; - //- Name of functionObjectCloud function object result to render - word functionObject_; - //- Name of field to colour by word colourFieldName_; @@ -116,6 +113,9 @@ public: //- Update actors virtual void updateActors(const scalar position); + + //- Clear files used to create the object(s) + virtual bool clear(); }; diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.C b/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.C index db5f1619e78..b1a9093f63f 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.C +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.C @@ -61,8 +61,7 @@ Foam::functionObjects::runTimePostPro::functionObjectLine::functionObjectLine ) : pathline(parent, dict, colours), - fieldVisualisationBase(parent, dict, colours), - functionObject_(dict.lookup("functionObject")), + functionObjectBase(parent, dict, colours), actor_() { actor_ = vtkSmartPointer<vtkActor>::New(); @@ -89,23 +88,12 @@ addGeometryToScene return; } - dictionary dict; - if (!geometryBase::parent_.getObjectDict(functionObject_, fieldName_, dict)) - { - WarningInFunction - << "Unable to find function object " << functionObject_ - << " output for field " << fieldName_ - << ". Line will not be processed" - << endl; - return; - } - - fileName fName; - if (!dict.readIfPresent("file", fName)) + fileName fName = getFileName("file", fieldName_); + if (fName.empty()) { WarningInFunction << "Unable to read file name from function object " - << functionObject_ << " for field " << fieldName_ + << functionObjectName_ << " for field " << fieldName_ << ". Line will not be processed" << endl; return; @@ -140,5 +128,15 @@ void Foam::functionObjects::runTimePostPro::functionObjectLine::updateActors actor_->GetProperty()->SetOpacity(opacity(position)); } +bool Foam::functionObjects::runTimePostPro::functionObjectLine::clear() +{ + if (functionObjectBase::clear()) + { + return removeFile("file", fieldName_); + } + + return false; +} + // ************************************************************************* // diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.H b/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.H index 8f896382c85..f16dc25547e 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.H +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectLine.H @@ -36,7 +36,7 @@ SourceFiles #define functionObjects_runTimePostPro_functionObjectLine_H #include "pathline.H" -#include "fieldVisualisationBase.H" +#include "functionObjectBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,7 +54,7 @@ namespace runTimePostPro class functionObjectLine : public pathline, - public fieldVisualisationBase + public functionObjectBase { private: @@ -71,9 +71,6 @@ protected: // Protected data - //- Name of function object result to render - word functionObject_; - //- Actor vtkSmartPointer<vtkActor> actor_; @@ -110,6 +107,9 @@ public: //- Update actors virtual void updateActors(const scalar position); + + //- Clear files used to create the object(s) + virtual bool clear(); }; diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C b/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C index cfa91bf2487..343985afa29 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C @@ -62,14 +62,8 @@ functionObjectSurface ) : geometrySurface(parent, dict, colours, List<fileName>()), - fieldVisualisationBase(parent, dict, colours), - functionObject_("") -{ - if (visible_) - { - dict.lookup("functionObject") >> functionObject_; - } -} + functionObjectBase(parent, dict, colours) +{} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -93,23 +87,12 @@ addGeometryToScene return; } - dictionary dict; - if (!geometryBase::parent_.getObjectDict(functionObject_, fieldName_, dict)) - { - WarningInFunction - << "Unable to find function object " << functionObject_ - << " output for field " << fieldName_ - << ". Surface will not be processed" - << endl; - return; - } - - fileName fName; - if (!dict.readIfPresent("file", fName)) + fileName fName = getFileName("file", fieldName_); + if (fName.empty()) { WarningInFunction << "Unable to read file name from function object " - << functionObject_ << " for field " << fieldName_ + << functionObjectName_ << " for field " << fieldName_ << ". Surface will not be processed" << endl; return; @@ -167,4 +150,15 @@ addGeometryToScene } +bool Foam::functionObjects::runTimePostPro::functionObjectSurface::clear() +{ + if (functionObjectBase::clear()) + { + return removeFile("file", fieldName_); + } + + return false; +} + + // ************************************************************************* // diff --git a/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.H b/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.H index 95e592dbc87..2ae627a6bf4 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.H +++ b/src/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.H @@ -36,7 +36,7 @@ SourceFiles #define functionObjects_runTimePostPro_functionObjectSurface_H #include "geometrySurface.H" -#include "fieldVisualisationBase.H" +#include "functionObjectBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,10 +54,9 @@ namespace runTimePostPro class functionObjectSurface : public geometrySurface, - public fieldVisualisationBase + public functionObjectBase { - private: // Private Member Functions @@ -69,14 +68,6 @@ private: void operator=(const functionObjectSurface&) = delete; -protected: - - // Protected data - - //- Name of function object result to render - word functionObject_; - - public: //- Run-time type information @@ -106,6 +97,9 @@ public: const scalar position, vtkRenderer* renderer ); + + //- Clear files used to create the object(s) + virtual bool clear(); }; diff --git a/src/functionObjects/graphics/runTimePostProcessing/geometryBase.H b/src/functionObjects/graphics/runTimePostProcessing/geometryBase.H index 1163d70a89b..714c5de0df3 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/geometryBase.H +++ b/src/functionObjects/graphics/runTimePostProcessing/geometryBase.H @@ -50,6 +50,7 @@ namespace Foam { namespace functionObjects { + class runTimePostProcessing; namespace runTimePostPro @@ -163,6 +164,9 @@ public: //- Update the actors virtual void updateActors(const scalar position) = 0; + + //- Clear files used to create the object(s) + virtual bool clear() = 0; }; diff --git a/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.C b/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.C index 1ebaa6e5e98..19be822aa7b 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.C +++ b/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.C @@ -211,4 +211,13 @@ void Foam::functionObjects::runTimePostPro::geometrySurface::updateActors } +bool Foam::functionObjects::runTimePostPro::geometrySurface::clear() +{ + // Note: not removing geometry files + // - these are usually static files that are used e.g. for meshing + + return true; +} + + // ************************************************************************* // diff --git a/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.H b/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.H index 674746deb2c..7aaf3af17ab 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.H +++ b/src/functionObjects/graphics/runTimePostProcessing/geometrySurface.H @@ -127,6 +127,9 @@ public: //- Update actors virtual void updateActors(const scalar position); + + //- Clear files used to create the object(s) + virtual bool clear(); }; diff --git a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C index 0b46ab48ff4..fe97eba4b3b 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C +++ b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C @@ -217,6 +217,24 @@ bool Foam::functionObjects::runTimePostProcessing::write() } } + // Clean up + forAll(text_, i) + { + text_[i].clear(); + } + forAll(points_, i) + { + points_[i].clear(); + } + forAll(lines_, i) + { + lines_[i].clear(); + } + forAll(surfaces_, i) + { + surfaces_[i].clear(); + } + // Reset any floating point trapping sigFpe::set(false); diff --git a/src/functionObjects/graphics/runTimePostProcessing/scene.H b/src/functionObjects/graphics/runTimePostProcessing/scene.H index e2f5d87e122..549b430e397 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/scene.H +++ b/src/functionObjects/graphics/runTimePostProcessing/scene.H @@ -81,6 +81,7 @@ namespace functionObjects { namespace runTimePostPro { + /*---------------------------------------------------------------------------*\ Class scene Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/functionObjects/graphics/runTimePostProcessing/text.C b/src/functionObjects/graphics/runTimePostProcessing/text.C index e36d8ca8646..fc395f57179 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/text.C +++ b/src/functionObjects/graphics/runTimePostProcessing/text.C @@ -115,7 +115,13 @@ void Foam::functionObjects::runTimePostPro::text::updateActors const scalar position ) { - // do nothing - all handled by addGeometryToScene + // Do nothing - all handled by addGeometryToScene +} + + +bool Foam::functionObjects::runTimePostPro::text::clear() +{ + return true; } diff --git a/src/functionObjects/graphics/runTimePostProcessing/text.H b/src/functionObjects/graphics/runTimePostProcessing/text.H index f98f36add56..6d492d7b1b9 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/text.H +++ b/src/functionObjects/graphics/runTimePostProcessing/text.H @@ -135,6 +135,9 @@ public: //- Update actors virtual void updateActors(const scalar position); + + //- Clear files used to create the object(s) + virtual bool clear(); }; -- GitLab