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:
Henry Weller
2016-05-15 16:40:01 +01:00
parent 1441f8cab0
commit 91aba2db2e
230 changed files with 2731 additions and 8756 deletions

View File

@ -24,9 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "writeDictionary.H"
#include "dictionary.H"
#include "Time.H"
#include "HashSet.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -35,6 +35,13 @@ namespace Foam
namespace functionObjects
{
defineTypeNameAndDebug(writeDictionary, 0);
addToRunTimeSelectionTable
(
functionObject,
writeDictionary,
dictionary
);
}
}
@ -66,7 +73,7 @@ bool Foam::functionObjects::writeDictionary::tryDirectory
{
if (firstDict)
{
Info<< type() << " " << name_ << " output:" << nl << endl;
Info<< type() << " " << name() << " output:" << nl << endl;
IOobject::writeDivider(Info);
Info<< endl;
@ -92,13 +99,18 @@ bool Foam::functionObjects::writeDictionary::tryDirectory
Foam::functionObjects::writeDictionary::writeDictionary
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
const Time& runTime,
const dictionary& dict
)
:
name_(name),
obr_(obr),
functionObject(name),
obr_
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
dictNames_(),
digests_()
{
@ -115,7 +127,7 @@ Foam::functionObjects::writeDictionary::~writeDictionary()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::writeDictionary::read(const dictionary& dict)
bool Foam::functionObjects::writeDictionary::read(const dictionary& dict)
{
wordList dictNames(dict.lookup("dictNames"));
HashSet<word> uniqueNames(dictNames);
@ -123,7 +135,7 @@ void Foam::functionObjects::writeDictionary::read(const dictionary& dict)
digests_.setSize(dictNames_.size(), SHA1Digest());
Info<< type() << " " << name_ << ": monitoring dictionaries:" << nl;
Info<< type() << " " << name() << ": monitoring dictionaries:" << nl;
if (dictNames_.size())
{
forAll(dictNames_, i)
@ -136,10 +148,12 @@ void Foam::functionObjects::writeDictionary::read(const dictionary& dict)
Info<< " none" << nl;
}
Info<< endl;
return true;
}
void Foam::functionObjects::writeDictionary::execute()
bool Foam::functionObjects::writeDictionary::execute(const bool postProcess)
{
bool firstDict = true;
forAll(dictNames_, i)
@ -153,7 +167,7 @@ void Foam::functionObjects::writeDictionary::execute()
{
if (firstDict)
{
Info<< type() << " " << name_ << " output:" << nl << endl;
Info<< type() << " " << name() << " output:" << nl << endl;
IOobject::writeDivider(Info);
Info<< endl;
@ -192,21 +206,15 @@ void Foam::functionObjects::writeDictionary::execute()
}
}
}
return true;
}
void Foam::functionObjects::writeDictionary::end()
bool Foam::functionObjects::writeDictionary::write(const bool postProcess)
{
execute();
return true;
}
void Foam::functionObjects::writeDictionary::timeSet()
{}
void Foam::functionObjects::writeDictionary::write()
{}
// ************************************************************************* //

View File

@ -38,8 +38,8 @@ SourceFiles
#ifndef functionObjects_writeDictionary_H
#define functionObjects_writeDictionary_H
#include "functionObject.H"
#include "wordList.H"
#include "runTimeSelectionTables.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,9 +49,6 @@ namespace Foam
// Forward declaration of classes
class objectRegistry;
class dictionary;
class polyMesh;
class mapPolyMesh;
namespace functionObjects
{
@ -61,14 +58,11 @@ namespace functionObjects
\*---------------------------------------------------------------------------*/
class writeDictionary
:
public functionObject
{
protected:
// Private data
//- Name of this set of writeDictionary
word name_;
//- Reference to the database
const objectRegistry& obr_;
@ -109,14 +103,12 @@ public:
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
//- Construct from Time and dictionary
writeDictionary
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
const Time& runTime,
const dictionary& dict
);
@ -126,34 +118,14 @@ public:
// Member Functions
//- Return name of the writeDictionary
virtual const word& name() const
{
return name_;
}
//- Read the writeDictionary data
virtual void read(const dictionary&);
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
virtual bool execute(const bool postProcess = false);
//- Write the writeDictionary
virtual void write();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh
virtual void movePoints(const polyMesh&)
{}
virtual bool write(const bool postProcess = false);
};

View File

@ -1,42 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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 "writeDictionaryFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(writeDictionaryFunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
writeDictionaryFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -1,54 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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::writeDictionaryFunctionObject
Description
FunctionObject wrapper around writeDictionary to allow them to be
created via the functions entry within controlDict.
SourceFiles
writeDictionaryFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef writeDictionaryFunctionObject_H
#define writeDictionaryFunctionObject_H
#include "writeDictionary.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<functionObjects::writeDictionary>
writeDictionaryFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //