Commit eb5a9821 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide extra log feedback when catalyst function objects end.

- Note that stopping the catalyst function object via a `timeEnd` value
  does not actually call the corresponding end() method.

  See: Development/OpenFOAM-plus#791

ENH: support mkdir as dictionary keyword

- this is a convenient means of creating an output directory from within
  the function object without corresponding python or shell script.

  Some pipelines (image generation) balk if the output directory does
  not exist. Others (vtm writer etc) will create their own.
parent 4ade42e0
......@@ -48,6 +48,29 @@ namespace functionObjects
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::catalystFaMesh::readBasics(const dictionary& dict)
{
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
fileName outputDir;
if (dict.readIfPresent("mkdir", outputDir))
{
outputDir.expand();
outputDir.clean();
Foam::mkDir(outputDir);
}
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
return true;
}
void Foam::functionObjects::catalystFaMesh::updateState
(
polyMesh::readUpdateState state
......@@ -106,11 +129,7 @@ bool Foam::functionObjects::catalystFaMesh::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
readBasics(dict);
// All possible meshes
meshes_ = mesh_.lookupClass<faMesh>();
......@@ -143,9 +162,7 @@ bool Foam::functionObjects::catalystFaMesh::read(const dictionary& dict)
meshes_.filterKeys(wordRes(selectAreas_));
dict.lookup("fields") >> selectFields_;
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
Info<< type() << " " << name() << ":" << nl
<<" areas " << flatOutput(selectAreas_) << nl
......@@ -153,9 +170,9 @@ bool Foam::functionObjects::catalystFaMesh::read(const dictionary& dict)
<<" fields " << flatOutput(selectFields_) << nl
<<" scripts " << scripts_ << nl;
// Run-time modification of pipeline
if (adaptor_.valid())
{
// Run-time modification of pipeline
adaptor_().reset(scripts_);
}
......@@ -276,6 +293,19 @@ bool Foam::functionObjects::catalystFaMesh::write()
}
bool Foam::functionObjects::catalystFaMesh::end()
{
// Only here for extra feedback
if (log && adaptor_.valid())
{
Info<< type() << ": Disconnecting ParaView Catalyst..." << nl;
}
adaptor_.clear();
return true;
}
void Foam::functionObjects::catalystFaMesh::updateMesh(const mapPolyMesh&)
{
updateState(polyMesh::TOPO_CHANGE);
......
......@@ -51,6 +51,7 @@ Usage
Property | Description | Required | Default
type | catalyst::area | yes |
log | report extra information | no | false
mkdir | initial directory to create | no |
region | | no | region0
regions | wordRe list of regions | no |
fields | wordRe list of fields | yes |
......@@ -127,8 +128,13 @@ protected:
// Protected Member Functions
//- Common boilerplate settings
bool readBasics(const dictionary& dict);
//- On movement
void updateState(polyMesh::readUpdateState state);
//- No copy construct
catalystFaMesh(const catalystFaMesh&) = delete;
......@@ -167,6 +173,9 @@ public:
//- Write - does nothing
virtual bool write();
//- On end - provide feedback about disconnecting from catatyst.
virtual bool end();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh& mpm);
......
......@@ -99,6 +99,7 @@ Foam::label Foam::catalystCoprocess::expand
string& s = scripts[scripti];
stringOps::inplaceExpand(s, dict, true, true);
fileName::clean(s); // Remove trailing, repeated slashes etc.
if (isFile(s))
{
......
......@@ -46,6 +46,31 @@ namespace functionObjects
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::catalystCloud::readBasics(const dictionary& dict)
{
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
fileName outputDir;
if (dict.readIfPresent("mkdir", outputDir))
{
outputDir.expand();
outputDir.clean();
Foam::mkDir(outputDir);
}
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::catalystCloud::catalystCloud
......@@ -76,11 +101,7 @@ bool Foam::functionObjects::catalystCloud::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
readBasics(dict);
selectClouds_.clear();
dict.readIfPresent("clouds", selectClouds_);
......@@ -95,18 +116,15 @@ bool Foam::functionObjects::catalystCloud::read(const dictionary& dict)
selectFields_.clear();
dict.readIfPresent("fields", selectFields_);
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
Info<< type() << " " << name() << ":" << nl
<<" clouds " << flatOutput(selectClouds_) << nl
<<" fields " << flatOutput(selectFields_) << nl
<<" scripts " << scripts_ << nl;
// Run-time modification of pipeline
if (adaptor_.valid())
{
// Run-time modification of pipeline
adaptor_().reset(scripts_);
}
......@@ -205,4 +223,17 @@ bool Foam::functionObjects::catalystCloud::write()
}
bool Foam::functionObjects::catalystCloud::end()
{
// Only here for extra feedback
if (log && adaptor_.valid())
{
Info<< type() << ": Disconnecting ParaView Catalyst..." << nl;
}
adaptor_.clear();
return true;
}
// ************************************************************************* //
......@@ -52,6 +52,7 @@ Usage
Property | Description | Required | Default value
type | catalyst::cloud | yes |
log | report extra information | no | false
mkdir | initial directory to create | no |
cloud | | no | defaultCloud
clouds | wordRe list of clouds | no |
region | | no | region0
......@@ -120,7 +121,11 @@ protected:
autoPtr<catalystCoprocess> adaptor_;
// Private Member Functions
// Protected Member Functions
//- Common boilerplate settings
bool readBasics(const dictionary& dict);
//- No copy construct
catalystCloud(const catalystCloud&) = delete;
......@@ -160,6 +165,8 @@ public:
//- Write - does nothing
virtual bool write();
//- On end - provide feedback about disconnecting from catatyst.
virtual bool end();
};
......
......@@ -46,6 +46,29 @@ namespace functionObjects
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::catalystFvMesh::readBasics(const dictionary& dict)
{
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
fileName outputDir;
if (dict.readIfPresent("mkdir", outputDir))
{
outputDir.expand();
outputDir.clean();
Foam::mkDir(outputDir);
}
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
return true;
}
void Foam::functionObjects::catalystFvMesh::updateState
(
polyMesh::readUpdateState state
......@@ -105,12 +128,25 @@ bool Foam::functionObjects::catalystFvMesh::read(const dictionary& dict)
{
functionObject::read(dict);
// Common settings
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
fileName outputDir;
if (dict.readIfPresent("mkdir", outputDir))
{
outputDir.expand();
outputDir.clean();
Foam::mkDir(outputDir);
}
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
// All possible meshes
meshes_ = time_.lookupClass<fvMesh>();
......@@ -128,9 +164,7 @@ bool Foam::functionObjects::catalystFvMesh::read(const dictionary& dict)
meshes_.filterKeys(wordRes(selectRegions_));
dict.lookup("fields") >> selectFields_;
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
Info<< type() << " " << name() << ":" << nl
<<" regions " << flatOutput(selectRegions_) << nl
......@@ -138,9 +172,9 @@ bool Foam::functionObjects::catalystFvMesh::read(const dictionary& dict)
<<" fields " << flatOutput(selectFields_) << nl
<<" scripts " << scripts_ << nl;
// Run-time modification of pipeline
if (adaptor_.valid())
{
// Run-time modification of pipeline
adaptor_().reset(scripts_);
}
......@@ -343,6 +377,19 @@ bool Foam::functionObjects::catalystFvMesh::write()
}
bool Foam::functionObjects::catalystFvMesh::end()
{
// Only here for extra feedback
if (log && adaptor_.valid())
{
Info<< type() << ": Disconnecting ParaView Catalyst..." << nl;
}
adaptor_.clear();
return true;
}
void Foam::functionObjects::catalystFvMesh::updateMesh(const mapPolyMesh&)
{
updateState(polyMesh::TOPO_CHANGE);
......
......@@ -52,6 +52,7 @@ Usage
Property | Description | Required | Default
type | catalyst | yes |
log | report extra information | no | false
mkdir | initial directory to create | no |
region | | no | region0
regions | wordRe list of regions | no |
fields | wordRe list of fields | yes |
......@@ -131,8 +132,13 @@ protected:
// Protected Member Functions
//- Common boilerplate settings
bool readBasics(const dictionary& dict);
//- On movement
void updateState(polyMesh::readUpdateState state);
//- No copy construct
catalystFvMesh(const catalystFvMesh&) = delete;
......@@ -171,6 +177,9 @@ public:
//- Write - does nothing
virtual bool write();
//- On end - provide feedback about disconnecting from catatyst.
virtual bool end();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh& mpm);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment