functionObjects: rewritten to all be derived from 'functionObject'
- Avoids the need for the 'OutputFilterFunctionObject' wrapper
- Time-control for execution and writing is now provided by the
'timeControlFunctionObject' which instantiates the processing
'functionObject' and controls its operation.
- Alternative time-control functionObjects can now be written and
selected at run-time without the need to compile wrapped version of
EVERY existing functionObject which would have been required in the
old structure.
- The separation of 'execute' and 'write' functions is now formalized in the
'functionObject' base-class and all derived classes implement the
two functions.
- Unnecessary implementations of functions with appropriate defaults
in the 'functionObject' base-class have been removed reducing
clutter and simplifying implementation of new functionObjects.
- The 'coded' 'functionObject' has also been updated, simplified and tested.
- Further simplification is now possible by creating some general
intermediate classes derived from 'functionObject'.
This commit is contained in:
@ -29,6 +29,7 @@ License
|
||||
#include "Time.H"
|
||||
#include "OSspecific.H"
|
||||
#include "PstreamReduceOps.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -37,6 +38,13 @@ namespace Foam
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(abort, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
abort,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +76,7 @@ void Foam::functionObjects::abort::removeFile() const
|
||||
|
||||
if (hasAbort && Pstream::master())
|
||||
{
|
||||
// cleanup ABORT file (on master only)
|
||||
// Cleanup ABORT file (on master only)
|
||||
rm(abortFile_);
|
||||
}
|
||||
}
|
||||
@ -79,20 +87,19 @@ void Foam::functionObjects::abort::removeFile() const
|
||||
Foam::functionObjects::abort::abort
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
obr_(obr),
|
||||
functionObject(name),
|
||||
time_(runTime),
|
||||
abortFile_("$FOAM_CASE/" + name),
|
||||
action_(nextWrite)
|
||||
{
|
||||
abortFile_.expand();
|
||||
read(dict);
|
||||
|
||||
// remove any old files from previous runs
|
||||
// Remove any old files from previous runs
|
||||
removeFile();
|
||||
}
|
||||
|
||||
@ -105,7 +112,7 @@ Foam::functionObjects::abort::~abort()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::abort::read(const dictionary& dict)
|
||||
bool Foam::functionObjects::abort::read(const dictionary& dict)
|
||||
{
|
||||
if (dict.found("action"))
|
||||
{
|
||||
@ -120,10 +127,12 @@ void Foam::functionObjects::abort::read(const dictionary& dict)
|
||||
{
|
||||
abortFile_.expand();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::abort::execute()
|
||||
bool Foam::functionObjects::abort::execute(const bool postProcess)
|
||||
{
|
||||
bool hasAbort = isFile(abortFile_);
|
||||
reduce(hasAbort, orOp<bool>());
|
||||
@ -134,10 +143,10 @@ void Foam::functionObjects::abort::execute()
|
||||
{
|
||||
case noWriteNow :
|
||||
{
|
||||
if (obr_.time().stopAt(Time::saNoWriteNow))
|
||||
if (time_.stopAt(Time::saNoWriteNow))
|
||||
{
|
||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||
<< obr_.time().timeIndex()
|
||||
<< time_.timeIndex()
|
||||
<< "): stop without writing data"
|
||||
<< endl;
|
||||
}
|
||||
@ -146,10 +155,10 @@ void Foam::functionObjects::abort::execute()
|
||||
|
||||
case writeNow :
|
||||
{
|
||||
if (obr_.time().stopAt(Time::saWriteNow))
|
||||
if (time_.stopAt(Time::saWriteNow))
|
||||
{
|
||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||
<< obr_.time().timeIndex()
|
||||
<< time_.timeIndex()
|
||||
<< "): stop+write data"
|
||||
<< endl;
|
||||
}
|
||||
@ -158,10 +167,10 @@ void Foam::functionObjects::abort::execute()
|
||||
|
||||
case nextWrite :
|
||||
{
|
||||
if (obr_.time().stopAt(Time::saNextWrite))
|
||||
if (time_.stopAt(Time::saNextWrite))
|
||||
{
|
||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||
<< obr_.time().timeIndex()
|
||||
<< time_.timeIndex()
|
||||
<< "): stop after next data write"
|
||||
<< endl;
|
||||
}
|
||||
@ -169,21 +178,22 @@ void Foam::functionObjects::abort::execute()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::abort::end()
|
||||
bool Foam::functionObjects::abort::write(const bool postProcess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::abort::end()
|
||||
{
|
||||
removeFile();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::abort::timeSet()
|
||||
{}
|
||||
|
||||
|
||||
void Foam::functionObjects::abort::write()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -44,19 +44,13 @@ SourceFiles
|
||||
#ifndef functionObjects_abort_H
|
||||
#define functionObjects_abort_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class objectRegistry;
|
||||
class dictionary;
|
||||
class polyMesh;
|
||||
class mapPolyMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
@ -65,6 +59,8 @@ namespace functionObjects
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class abort
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
public:
|
||||
|
||||
@ -82,10 +78,8 @@ private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Name of the abort file unless otherwise specified
|
||||
word name_;
|
||||
|
||||
const objectRegistry& obr_;
|
||||
//- Reference to the Time
|
||||
const Time& time_;
|
||||
|
||||
//- The fully-qualified name of the abort file
|
||||
fileName abortFile_;
|
||||
@ -117,13 +111,12 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
//- Construct from Time and dictionary
|
||||
abort
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry&,
|
||||
const dictionary&,
|
||||
const bool loadFromFilesUnused = false
|
||||
const Time& runTime,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
|
||||
@ -133,34 +126,17 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return name of the abort file
|
||||
virtual const word& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
//- Read the dictionary settings
|
||||
virtual void read(const dictionary&);
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute, check existence of abort file and take action
|
||||
virtual void execute();
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Execute, check existence of abort file and take action
|
||||
virtual bool write(const bool postProcess = false);
|
||||
|
||||
//- Execute at the final time-loop, used for cleanup
|
||||
virtual void end();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual void timeSet();
|
||||
|
||||
//- Execute, check existence of abort file and take action
|
||||
virtual void write();
|
||||
|
||||
//- Update for changes of mesh - does nothing
|
||||
virtual void updateMesh(const mapPolyMesh&)
|
||||
{}
|
||||
|
||||
//- Update for changes of mesh - does nothing
|
||||
virtual void movePoints(const polyMesh&)
|
||||
{}
|
||||
virtual bool end();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ 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 "abortFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineNamedTemplateTypeNameAndDebug(abortFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
abortFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,54 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ 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/>.
|
||||
|
||||
Typedef
|
||||
Foam::abortFunctionObject
|
||||
|
||||
Description
|
||||
FunctionObject wrapper around abort to allow it to be created via
|
||||
the functions entry within controlDict.
|
||||
|
||||
SourceFiles
|
||||
abortFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef abortFunctionObject_H
|
||||
#define abortFunctionObject_H
|
||||
|
||||
#include "abort.H"
|
||||
#include "OutputFilterFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef OutputFilterFunctionObject<functionObjects::abort>
|
||||
abortFunctionObject;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user