diff --git a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt index bb98b9c158e793c38dc4c7257847a800275bc44b..3e7a61e625fa3cdb4a8ae4d34da60e396cf3b4e3 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 f43b60c172d4d4fb0826f1ef1001ad8a4e6bc166..084bcc1e99b20ed9e36f3d6e045a6d506f281112 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 7ddaa2e68730fb8c56b404d701439fa8bfb15af5..0ae8c6a608075c16eb359e1c18ef1d8a9864cbe1 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 0000000000000000000000000000000000000000..e2c1ebee874e0b36364aa78899f37820efabc13e --- /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 0000000000000000000000000000000000000000..09515f328062010348d31dc959644e8f9e28de7a --- /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 a414f269c9ec130feb6e505b2d32cd142ad00850..357997df256a3c4ccf33d3f00c7df966c3bd8324 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 19348aea06c26932a9555a0481c4631272218d4f..35645965bc5e79d9d8fced134f3d72d8ff8ede83 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 db5f1619e7849a4b636f9c6b4e3b97b95e1ea7dc..b1a9093f63f26029e742fc70d73f686fe540a42f 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 8f896382c8562067803635c1e65da30fbfae4124..f16dc25547e74e490a3347b9fcce250d77e7de3f 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 cfa91bf2487fa5480a3fee8645b5020304c6249f..343985afa296001dd71043b983fd45a6f82aae65 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 95e592dbc876b67b3d546ffa858713b82912a112..2ae627a6bf4221372977a42a463e568c8a7318f1 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 1163d70a89b3cca0c1219e4744a8afb8e9704dc8..714c5de0df3ed41f8b158b247aae05e337d574d9 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 1ebaa6e5e9886c9d18e34d098d89bca8638b02fb..19be822aa7bc4b2fc657a1029a062c40a1da68a7 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 674746deb2ceb7fc69c2a27ab783e3ee4511d8fa..7aaf3af17ab9686a08ecfb73eea6961dd9b5164e 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 0b46ab48ff40dd8fc5dfa790d4c62b84f7595299..fe97eba4b3b1f707b1e64f3d19cacb493578b30c 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 e2f5d87e1226d88ec02a8ca140b289eee98178df..549b430e397f76cf5af6de9b6b382736fdda6150 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 e36d8ca8646caf9e9ed1bed9bb30e5d7378f1525..fc395f571793f03739a1648e41daf172f86ec9d6 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 f98f36add56c481fd48e73a2fe21d3bf7e8f8ddc..6d492d7b1b98e43bc892135ae6d7fac18d993756 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(); };