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}
file(GLOB SOURCE_FILES
fieldVisualisationBase.C
functionObjectBase.C
functionObjectCloud.C
functionObjectLine.C
functionObjectSurface.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),
......
......@@ -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
);
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
)
:
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;
}
// ************************************************************************* //
......@@ -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();
};
......
......@@ -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;
}
// ************************************************************************* //
......@@ -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();
};
......
......@@ -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;
}
// ************************************************************************* //
......@@ -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();
};
......
......@@ -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;
};
......
......@@ -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;
}