Commit 0bc29794 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: runTimePostProcessing - added option to clear/remove objects after use

parent 493438c9
...@@ -48,6 +48,7 @@ set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} ...@@ -48,6 +48,7 @@ set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN}
file(GLOB SOURCE_FILES file(GLOB SOURCE_FILES
fieldVisualisationBase.C fieldVisualisationBase.C
functionObjectBase.C
functionObjectCloud.C functionObjectCloud.C
functionObjectLine.C functionObjectLine.C
functionObjectSurface.C functionObjectSurface.C
......
...@@ -507,12 +507,10 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs ...@@ -507,12 +507,10 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs
Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase
( (
const runTimePostProcessing& parent,
const dictionary& dict, const dictionary& dict,
const HashPtrTable<Function1<vector>, word>& colours const HashPtrTable<Function1<vector>, word>& colours
) )
: :
parent_(parent),
colours_(colours), colours_(colours),
fieldName_(dict.lookup("field")), fieldName_(dict.lookup("field")),
colourBy_(cbColour), colourBy_(cbColour),
......
...@@ -93,12 +93,6 @@ public: ...@@ -93,12 +93,6 @@ public:
private: private:
// Private data
//- Reference to the parent function object
const runTimePostProcessing& parent_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
...@@ -185,7 +179,6 @@ public: ...@@ -185,7 +179,6 @@ public:
//- Construct from dictionary //- Construct from dictionary
fieldVisualisationBase fieldVisualisationBase
( (
const runTimePostProcessing& parent,
const dictionary& dict, const dictionary& dict,
const HashPtrTable<Function1<vector>, word>& colours const HashPtrTable<Function1<vector>, word>& colours
); );
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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_;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //
...@@ -62,9 +62,8 @@ Foam::functionObjects::runTimePostPro::functionObjectCloud::functionObjectCloud ...@@ -62,9 +62,8 @@ Foam::functionObjects::runTimePostPro::functionObjectCloud::functionObjectCloud
) )
: :
pointData(parent, dict, colours), pointData(parent, dict, colours),
fieldVisualisationBase(parent, dict, colours), functionObjectBase(parent, dict, colours),
cloudName_(dict.lookup("cloud")), cloudName_(dict.lookup("cloud")),
functionObject_(dict.lookup("functionObject")),
colourFieldName_(dict.lookup("colourField")), colourFieldName_(dict.lookup("colourField")),
actor_() actor_()
{ {
...@@ -103,18 +102,18 @@ addGeometryToScene ...@@ -103,18 +102,18 @@ addGeometryToScene
if (cloudDict.found("functionObjectCloud")) if (cloudDict.found("functionObjectCloud"))
{ {
const dictionary& foDict = cloudDict.subDict("cloudFunctionObject"); 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()) if (fName.empty())
{ {
WarningInFunction WarningInFunction
<< "Unable to find function object " << functionObject_ << "Unable to find function object " << functionObjectName_
<< " output for field " << fieldName_ << " output for field " << fieldName_
<< ". Line will not be processed" << ". Cloud will not be processed"
<< endl; << endl;
return; return;
} }
...@@ -159,4 +158,36 @@ void Foam::functionObjects::runTimePostPro::functionObjectCloud::updateActors ...@@ -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;
}
// ************************************************************************* // // ************************************************************************* //
...@@ -36,7 +36,7 @@ SourceFiles ...@@ -36,7 +36,7 @@ SourceFiles
#define functionObjects_runTimePostPro_functionObjectCloud_H #define functionObjects_runTimePostPro_functionObjectCloud_H
#include "pointData.H" #include "pointData.H"
#include "fieldVisualisationBase.H" #include "functionObjectBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -54,7 +54,7 @@ namespace runTimePostPro ...@@ -54,7 +54,7 @@ namespace runTimePostPro
class functionObjectCloud class functionObjectCloud
: :
public pointData, public pointData,
public fieldVisualisationBase public functionObjectBase
{ {
private: private:
...@@ -74,9 +74,6 @@ protected: ...@@ -74,9 +74,6 @@ protected:
//- Name of functionObjectCloud //- Name of functionObjectCloud
word cloudName_; word cloudName_;
//- Name of functionObjectCloud function object result to render
word functionObject_;
//- Name of field to colour by //- Name of field to colour by
word colourFieldName_; word colourFieldName_;
...@@ -116,6 +113,9 @@ public: ...@@ -116,6 +113,9 @@ public:
//- Update actors //- Update actors
virtual void updateActors(const scalar position); virtual void updateActors(const scalar position);
//- Clear files used to create the object(s)
virtual bool clear();
}; };
......
...@@ -61,8 +61,7 @@ Foam::functionObjects::runTimePostPro::functionObjectLine::functionObjectLine ...@@ -61,8 +61,7 @@ Foam::functionObjects::runTimePostPro::functionObjectLine::functionObjectLine
) )
: :
pathline(parent, dict, colours), pathline(parent, dict, colours),
fieldVisualisationBase(parent, dict, colours), functionObjectBase(parent, dict, colours),
functionObject_(dict.lookup("functionObject")),
actor_() actor_()
{ {
actor_ = vtkSmartPointer<vtkActor>::New(); actor_ = vtkSmartPointer<vtkActor>::New();
...@@ -89,23 +88,12 @@ addGeometryToScene ...@@ -89,23 +88,12 @@ addGeometryToScene
return; return;
} }
dictionary dict; fileName fName = getFileName("file", fieldName_);
if (!geometryBase::parent_.getObjectDict(functionObject_, fieldName_, dict)) if (fName.empty())
{
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))
{ {
WarningInFunction WarningInFunction
<< "Unable to read file name from function object " << "Unable to read file name from function object "
<< functionObject_ << " for field " << fieldName_ << functionObjectName_ << " for field " << fieldName_
<< ". Line will not be processed" << ". Line will not be processed"
<< endl; << endl;
return; return;
...@@ -140,5 +128,15 @@ void Foam::functionObjects::runTimePostPro::functionObjectLine::updateActors ...@@ -140,5 +128,15 @@ void Foam::functionObjects::runTimePostPro::functionObjectLine::updateActors
actor_->GetProperty()->SetOpacity(opacity(position)); actor_->GetProperty()->SetOpacity(opacity(position));
} }
bool Foam::functionObjects::runTimePostPro::functionObjectLine::clear()
{
if (functionObjectBase::clear())
{
return removeFile("file", fieldName_);
}
return false;
}
// ************************************************************************* // // ************************************************************************* //
...@@ -36,7 +36,7 @@ SourceFiles ...@@ -36,7 +36,7 @@ SourceFiles
#define functionObjects_runTimePostPro_functionObjectLine_H #define functionObjects_runTimePostPro_functionObjectLine_H
#include "pathline.H" #include "pathline.H"
#include "fieldVisualisationBase.H" #include "functionObjectBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -54,7 +54,7 @@ namespace runTimePostPro ...@@ -54,7 +54,7 @@ namespace runTimePostPro
class functionObjectLine class functionObjectLine
: :
public pathline, public pathline,
public fieldVisualisationBase public functionObjectBase
{ {
private: private:
...@@ -71,9 +71,6 @@ protected: ...@@ -71,9 +71,6 @@ protected:
// Protected data // Protected data
//- Name of function object result to render
word functionObject_;
//- Actor //- Actor
vtkSmartPointer<vtkActor> actor_; vtkSmartPointer<vtkActor> actor_;
...@@ -110,6 +107,9 @@ public: ...@@ -110,6 +107,9 @@ public:
//- Update actors //- Update actors
virtual void updateActors(const scalar position); virtual void updateActors(const scalar position);
//- Clear files used to create the object(s)
virtual bool clear();
}; };
......
...@@ -62,14 +62,8 @@ functionObjectSurface ...@@ -62,14 +62,8 @@ functionObjectSurface
) )
: :
geometrySurface(parent, dict, colours, List<fileName>()), geometrySurface(parent, dict, colours, List<fileName>()),
fieldVisualisationBase(parent, dict, colours), functionObjectBase(parent, dict, colours)
functionObject_("") {}
{
if (visible_)
{
dict.lookup("functionObject") >> functionObject_;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
...@@ -93,23 +87,12 @@ addGeometryToScene ...@@ -93,23 +87,12 @@ addGeometryToScene
return; return;
} }
dictionary dict; fileName fName = getFileName("file", fieldName_);
if (!geometryBase::parent_.getObjectDict(functionObject_, fieldName_, dict)) if (fName.empty())
{
WarningInFunction
<< "Unable to find function object " << functionObject_
<< " output for field " << fieldName_
<< ". Surface will not be processed"
<< endl;
return;