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

@ -25,8 +25,8 @@ License
#include "fieldAverage.H"
#include "volFields.H"
#include "Time.H"
#include "fieldAverageItem.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -35,6 +35,7 @@ namespace Foam
namespace functionObjects
{
defineTypeNameAndDebug(fieldAverage, 0);
addToRunTimeSelectionTable(functionObject, fieldAverage, dictionary);
}
}
@ -68,7 +69,7 @@ void Foam::functionObjects::fieldAverage::initialize()
{
resetFields();
Info<< type() << " " << name_ << ":" << nl;
Info<< type() << " " << name() << ":" << nl;
// Add mean fields to the field lists
forAll(faItems_, fieldi)
@ -136,7 +137,7 @@ void Foam::functionObjects::fieldAverage::calcAverages()
periodIndex_++;
}
Info<< type() << " " << name_ << " output:" << nl;
Info<< type() << " " << name() << " output:" << nl;
Info<< " Calculating averages" << nl;
@ -259,13 +260,18 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
Foam::functionObjects::fieldAverage::fieldAverage
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
const Time& t,
const dictionary& dict
)
:
name_(name),
obr_(obr),
functionObject(name),
obr_
(
t.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
prevTimeIndex_(-1),
restartOnRestart_(false),
restartOnOutput_(false),
@ -277,7 +283,7 @@ Foam::functionObjects::fieldAverage::fieldAverage
totalTime_(),
periodIndex_(1)
{
if (!isA<fvMesh>(obr))
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
@ -295,11 +301,11 @@ Foam::functionObjects::fieldAverage::~fieldAverage()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::fieldAverage::read(const dictionary& dict)
bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)
{
initialised_ = false;
Info<< type() << " " << name_ << ":" << nl;
Info<< type() << " " << name() << ":" << nl;
dict.readIfPresent("restartOnRestart", restartOnRestart_);
dict.readIfPresent("restartOnOutput", restartOnOutput_);
@ -314,28 +320,21 @@ void Foam::functionObjects::fieldAverage::read(const dictionary& dict)
readAveragingProperties();
Info<< endl;
return true;
}
void Foam::functionObjects::fieldAverage::execute()
bool Foam::functionObjects::fieldAverage::execute(const bool postProcess)
{
calcAverages();
Info<< endl;
return true;
}
void Foam::functionObjects::fieldAverage::end()
{
calcAverages();
Info<< endl;
}
void Foam::functionObjects::fieldAverage::timeSet()
{}
void Foam::functionObjects::fieldAverage::write()
bool Foam::functionObjects::fieldAverage::write(const bool postProcess)
{
writeAverages();
writeAveragingProperties();
@ -346,15 +345,9 @@ void Foam::functionObjects::fieldAverage::write()
}
Info<< endl;
return true;
}
void Foam::functionObjects::fieldAverage::updateMesh(const mapPolyMesh&)
{}
void Foam::functionObjects::fieldAverage::movePoints(const polyMesh&)
{}
// ************************************************************************* //

View File

@ -110,7 +110,6 @@ Note
SeeAlso
Foam::functionObject
Foam::OutputFilterFunctionObject
SourceFiles
fieldAverage.C
@ -122,7 +121,7 @@ SourceFiles
#ifndef functionObjects_fieldAverage_H
#define functionObjects_fieldAverage_H
#include "volFieldsFwd.H"
#include "functionObject.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -132,11 +131,6 @@ namespace Foam
// Forward declaration of classes
class objectRegistry;
class dictionary;
template<class Type>
class List;
class polyMesh;
class mapPolyMesh;
namespace functionObjects
{
@ -149,15 +143,14 @@ class fieldAverageItem;
\*---------------------------------------------------------------------------*/
class fieldAverage
:
public functionObject
{
protected:
// Protected data
//- Name of this set of field averages.
word name_;
//- Database this class is registered to
//- Reference to the objectRegistry
const objectRegistry& obr_;
//- Time at last call, prevents repeated averaging
@ -291,14 +284,12 @@ public:
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
//- Construct from Time and dictionary
fieldAverage
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
const Time& t,
const dictionary&
);
@ -308,32 +299,14 @@ public:
// Member Functions
//- Return name of the set of field averages
virtual const word& name() const
{
return name_;
}
//- Read the field average data
virtual void read(const dictionary&);
virtual bool read(const dictionary&);
//- Execute the averaging
virtual void execute();
//- Calculate the field averages
virtual bool execute(const bool postProcess = false);
//- Execute the averaging 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();
//- Calculate the field average data and write
virtual void write();
//- Update mesh
virtual void updateMesh(const mapPolyMesh&);
//- Move points
virtual void movePoints(const polyMesh&);
//- Write the field averages
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) 2011 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 "fieldAverageFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(fieldAverageFunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
fieldAverageFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -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::fieldAverageFunctionObject
Description
FunctionObject wrapper around fieldAverage to allow them to be created
via the functions entry within controlDict.
SourceFiles
fieldAverageFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef fieldAverageFunctionObject_H
#define fieldAverageFunctionObject_H
#include "fieldAverage.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<functionObjects::fieldAverage>
fieldAverageFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //