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,7 @@ License
\*---------------------------------------------------------------------------*/
#include "residuals.H"
#include "volFields.H"
#include "dictionary.H"
#include "Time.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -35,6 +33,13 @@ namespace Foam
namespace functionObjects
{
defineTypeNameAndDebug(residuals, 0);
addToRunTimeSelectionTable
(
functionObject,
residuals,
dictionary
);
}
}
@ -44,23 +49,21 @@ namespace functionObjects
Foam::functionObjects::residuals::residuals
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
const Time& runTime,
const dictionary& dict
)
:
functionObjectFiles(obr, name, typeName),
name_(name),
obr_(obr),
writeFiles(name, runTime, dict, name),
fieldSet_()
{
if (!isA<fvMesh>(obr))
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
resetName(typeName);
}
@ -72,9 +75,11 @@ Foam::functionObjects::residuals::~residuals()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::residuals::read(const dictionary& dict)
bool Foam::functionObjects::residuals::read(const dictionary& dict)
{
dict.lookup("fields") >> fieldSet_;
return true;
}
@ -101,21 +106,16 @@ void Foam::functionObjects::residuals::writeFileHeader(const label i)
}
void Foam::functionObjects::residuals::execute()
{}
void Foam::functionObjects::residuals::end()
{}
void Foam::functionObjects::residuals::timeSet()
{}
void Foam::functionObjects::residuals::write()
bool Foam::functionObjects::residuals::execute(const bool postProcess)
{
functionObjectFiles::write();
return true;
}
bool Foam::functionObjects::residuals::write(const bool postProcess)
{
writeFiles::write();
if (Pstream::master())
{
@ -134,6 +134,8 @@ void Foam::functionObjects::residuals::write()
file() << endl;
}
return true;
}

View File

@ -51,7 +51,8 @@ Description
SeeAlso
Foam::functionObject
Foam::OutputFilterFunctionObject
Foam::functionObjects::writeFiles
Foam::functionObjects::timeControl
SourceFiles
residuals.C
@ -61,26 +62,12 @@ SourceFiles
#ifndef functionObjects_residuals_H
#define functionObjects_residuals_H
#include "functionObjectFiles.H"
#include "primitiveFieldsFwd.H"
#include "volFieldsFwd.H"
#include "HashSet.H"
#include "OFstream.H"
#include "Switch.H"
#include "NamedEnum.H"
#include "solverPerformance.H"
#include "writeFiles.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class polyMesh;
class mapPolyMesh;
namespace functionObjects
{
@ -90,23 +77,17 @@ namespace functionObjects
class residuals
:
public functionObjectFiles
public writeFiles
{
protected:
// Protected data
//- Name of this set of residuals
// Also used as the name of the output directory
word name_;
const objectRegistry& obr_;
//- Fields to write residuals
wordList fieldSet_;
// Private Member Functions
// Protected Member Functions
//- Output field header information
template<class Type>
@ -115,6 +96,10 @@ protected:
//- Output file header information
virtual void writeFileHeader(const label i);
//- Calculate the field min/max
template<class Type>
void writeResidual(const word& fieldName);
private:
@ -135,14 +120,12 @@ public:
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
//- Construct from Time and dictionary
residuals
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
const Time& runTime,
const dictionary& dict
);
@ -152,38 +135,14 @@ public:
// Member Functions
//- Return name of the functionObject
virtual const word& name() const
{
return name_;
}
//- Read the controls
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();
//- Calculate the field min/max
template<class Type>
void writeResidual(const word& fieldName);
virtual bool execute(const bool postProcess = false);
//- Write the residuals
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) 2015 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 "residualsFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(residualsFunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
residualsFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

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

View File

@ -25,8 +25,6 @@ License
#include "residuals.H"
#include "volFields.H"
#include "dictionary.H"
#include "Time.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //