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

@ -38,6 +38,7 @@ namespace fieldValues
{
defineTypeNameAndDebug(cellSource, 0);
addToRunTimeSelectionTable(fieldValue, cellSource, dictionary);
addToRunTimeSelectionTable(functionObject, cellSource, dictionary);
}
}
}
@ -149,14 +150,14 @@ void Foam::functionObjects::fieldValues::cellSource::initialise
if (nCells_ == 0)
{
FatalErrorInFunction
<< type() << " " << name_ << ": "
<< type() << " " << name() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Source has no cells" << exit(FatalError);
}
volume_ = volume();
Info<< type() << " " << name_ << ":"
Info<< type() << " " << name() << ":"
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " total cells = " << nCells_ << nl
<< " total volume = " << volume_
@ -205,12 +206,11 @@ void Foam::functionObjects::fieldValues::cellSource::writeFileHeader
Foam::functionObjects::fieldValues::cellSource::cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName, loadFromFiles),
fieldValue(name, runTime, dict, typeName),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
nCells_(0),
@ -218,7 +218,32 @@ Foam::functionObjects::fieldValues::cellSource::cellSource
weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{
if (!isA<fvMesh>(obr))
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
Foam::functionObjects::fieldValues::cellSource::cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
nCells_(0),
cellId_(),
weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
@ -236,7 +261,7 @@ Foam::functionObjects::fieldValues::cellSource::~cellSource()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::cellSource::read
bool Foam::functionObjects::fieldValues::cellSource::read
(
const dictionary& dict
)
@ -245,10 +270,15 @@ void Foam::functionObjects::fieldValues::cellSource::read
// No additional info to read
initialise(dict);
return true;
}
void Foam::functionObjects::fieldValues::cellSource::write()
bool Foam::functionObjects::fieldValues::cellSource::write
(
const bool postProcess
)
{
fieldValue::write();
@ -293,6 +323,8 @@ void Foam::functionObjects::fieldValues::cellSource::write()
}
if (log_) Info<< endl;
return true;
}

View File

@ -95,7 +95,6 @@ Description
SeeAlso
Foam::fieldValues
Foam::functionObject
Foam::OutputFilterFunctionObject
SourceFiles
cellSource.C
@ -105,10 +104,8 @@ SourceFiles
#ifndef functionObjects_cellSource_H
#define functionObjects_cellSource_H
#include "NamedEnum.H"
#include "fieldValue.H"
#include "labelList.H"
#include "volFieldsFwd.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -241,13 +238,20 @@ public:
// Constructors
//- Construct from components
//- Construct from name, Time and dictionary
cellSource
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles = false
const dictionary& dict
);
@ -257,30 +261,25 @@ public:
// Public Member Functions
// Access
//- Return the source type
inline const sourceType& source() const;
//- Return the source type
inline const sourceType& source() const;
//- Return the local list of cell IDs
inline const labelList& cellId() const;
//- Return the local list of cell IDs
inline const labelList& cellId() const;
//- Templated helper function to output field values
template<class Type>
bool writeValues(const word& fieldName);
//- Filter a field according to cellIds
template<class Type>
tmp<Field<Type>> filterField(const Field<Type>& field) const;
// Function object functions
//- Read from dictionary
virtual bool read(const dictionary&);
//- Read from dictionary
virtual void read(const dictionary&);
//- Calculate and write
virtual void write();
//- Templated helper function to output field values
template<class Type>
bool writeValues(const word& fieldName);
//- Filter a field according to cellIds
template<class Type>
tmp<Field<Type>> filterField(const Field<Type>& field) const;
//- Calculate and write
virtual bool write(const bool postProcess = false);
};

View File

@ -1,46 +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 "cellSourceFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug
(
cellSourceFunctionObject,
0
);
addToRunTimeSelectionTable
(
functionObject,
cellSourceFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -1,56 +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::cellSourceFunctionObject
Description
FunctionObject wrapper around cellSource to allow it to be
created via the functions entry within controlDict.
SourceFiles
cellSourceFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef cellSourceFunctionObject_H
#define cellSourceFunctionObject_H
#include "cellSource.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject
<
functionObjects::fieldValues::cellSource
> cellSourceFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //