Commit fd38002d authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Added regionFunctionObject and fvMeshFunctionObject intermediate base-classes

to simplify writing common functionObjects and avoid unnecessary code duplication
parent ee0aff67
......@@ -223,6 +223,7 @@ db/functionObjects/writeFile/writeFile.C
db/functionObjects/writeFiles/writeFiles.C
db/functionObjects/timeControl/timeControl.C
db/functionObjects/timeControl/timeControlFunctionObject.C
db/functionObjects/regionFunctionObject/regionFunctionObject.C
Time = db/Time
$(Time)/TimePaths.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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 "regionFunctionObject.H"
#include "Time.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(regionFunctionObject, 0);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::regionFunctionObject::regionFunctionObject
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
functionObject(name),
time_(runTime),
obr_
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
)
{}
Foam::functionObjects::regionFunctionObject::regionFunctionObject
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
functionObject(name),
time_(obr.time()),
obr_(obr)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::regionFunctionObject::~regionFunctionObject()
{}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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/>.
Class
Foam::functionObjects::regionFunctionObject
Description
Specialization of Foam::functionObject for a region and providing a
reference to the region Foam::objectRegistry.
SeeAlso
Foam::functionObject
SourceFiles
regionFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_regionFunctionObject_H
#define functionObjects_regionFunctionObject_H
#include "functionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class regionFunctionObject Declaration
\*---------------------------------------------------------------------------*/
class regionFunctionObject
:
public functionObject
{
protected:
// Protected member data
//- Reference to the Time
const Time& time_;
//- Reference to the region objectRegistry
const objectRegistry& obr_;
private:
// Private Member Functions
//- Disallow default bitwise copy construct
regionFunctionObject(const regionFunctionObject&);
//- Disallow default bitwise assignment
void operator=(const regionFunctionObject&);
public:
//- Runtime type information
TypeName("regionFunctionObject");
// Constructors
//- Construct from Time and dictionary.
// The region objectRegistry is looked-up runTime with the name
// looked-up from the dictionary (defaults to polyMesh::defaultRegion)
regionFunctionObject
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from the region objectRegistry and dictionary
regionFunctionObject
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~regionFunctionObject();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -100,20 +100,12 @@ Foam::Omanip<int> Foam::functionObjects::writeFile::valueWidth
Foam::functionObjects::writeFile::writeFile
(
const word& name,
const Time& t,
const Time& runTime,
const dictionary& dict,
const word& prefix
)
:
functionObject(name),
time_(t),
obr_
(
time_.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
regionFunctionObject(name, runTime, dict),
prefix_(prefix),
log_(true)
{}
......@@ -127,9 +119,7 @@ Foam::functionObjects::writeFile::writeFile
const word& prefix
)
:
functionObject(name),
time_(obr.time()),
obr_(obr),
regionFunctionObject(name, obr, dict),
prefix_(prefix),
log_(true)
{}
......
......@@ -28,8 +28,8 @@ Description
functionObject base class for writing single files
See Also
Foam::regionFunctionObject
Foam::functionObject
Foam::OutputFilterFunctionObject
SourceFiles
functionObjectFile.C
......@@ -39,7 +39,7 @@ SourceFiles
#ifndef functionObjects_writeFile_H
#define functionObjects_writeFile_H
#include "functionObject.H"
#include "regionFunctionObject.H"
#include "Time.H"
#include "IOmanip.H"
......@@ -56,19 +56,13 @@ namespace functionObjects
class writeFile
:
public functionObject
public regionFunctionObject
{
protected:
// Protected data
//- Reference to the Time
const Time& time_;
//- Reference to the objectRegistry
const objectRegistry& obr_;
//- Prefix
const word prefix_;
......
......@@ -91,6 +91,7 @@ $(faceToCell)/extendedFaceToCellStencil.C
$(faceToCell)/extendedCentredFaceToCellStencil.C
$(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C
fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C
fvPatchFields = fields/fvPatchFields
$(fvPatchFields)/fvPatchField/fvPatchFields.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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 "fvMeshFunctionObject.H"
#include "Time.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fvMeshFunctionObject, 0);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
regionFunctionObject(name, runTime, dict),
mesh_(refCast<const fvMesh>(obr_))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fvMeshFunctionObject::~fvMeshFunctionObject()
{}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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/>.
Class
Foam::functionObjects::fvMeshFunctionObject
Description
Specialization of Foam::functionObject for an Foam::fvMesh, providing a
reference to the Foam::fvMesh.
If the selected region is not an Foam::fvMesh a Foam::FatalError will be
generated.
SeeAlso
Foam::regionFunctionObject
Foam::functionObject
SourceFiles
fvMeshFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fvMeshFunctionObject_H
#define functionObjects_fvMeshFunctionObject_H
#include "regionFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fvMeshFunctionObject Declaration
\*---------------------------------------------------------------------------*/
class fvMeshFunctionObject
:
public regionFunctionObject
{
protected:
// Protected member data
//- Reference to the fvMesh
const fvMesh& mesh_;
private:
// Private Member Functions
//- Disallow default bitwise copy construct
fvMeshFunctionObject(const fvMeshFunctionObject&);
//- Disallow default bitwise assignment
void operator=(const fvMeshFunctionObject&);
public:
//- Runtime type information
TypeName("fvMeshFunctionObject");
// Constructors
//- Construct from Time and dictionary
fvMeshFunctionObject
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~fvMeshFunctionObject();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -47,9 +47,7 @@ Foam::volScalarField& Foam::functionObjects::div::divField
const dimensionSet& dims
)
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
if (!mesh.foundObject<volScalarField>(divName))
if (!mesh_.foundObject<volScalarField>(divName))
{
volScalarField* divFieldPtr
(
......@@ -58,20 +56,20 @@ Foam::volScalarField& Foam::functionObjects::div::divField
IOobject
(
divName,
mesh.time().timeName(),
mesh,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
mesh_,
dimensionedScalar("zero", dims/dimLength, 0.0)
)
);
mesh.objectRegistry::store(divFieldPtr);
mesh_.objectRegistry::store(divFieldPtr);
}
const volScalarField& field = mesh.lookupObject<volScalarField>(divName);
const volScalarField& field = mesh_.lookupObject<volScalarField>(divName);
return const_cast<volScalarField&>(field);
}
......@@ -86,23 +84,8 @@ Foam::functionObjects::div::div
const dictionary& dict
)
:
functionObject(name),
obr_
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
fieldName_("undefined-fieldName"),
resultName_("undefined-resultName")
fvMeshFunctionObject(name, runTime, dict)
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......
......@@ -40,7 +40,7 @@ SourceFiles
#ifndef functionObjects_div_H
#define functionObjects_div_H
#include "functionObject.H"
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -49,7 +49,6 @@ namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dimensionSet;
namespace functionObjects
......@@ -61,13 +60,10 @@ namespace functionObjects
class div
:
public functionObject
public fvMeshFunctionObject
{
// Private data
//- Reference to the objectRegistry
const objectRegistry& obr_;
//- Name of field to process
word fieldName_;
......
......@@ -36,11 +36,9 @@ void Foam::functionObjects::div::calcDiv
bool& processed
)
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
if (mesh.foundObject<FieldType>(fieldName))
if (mesh_.foundObject<FieldType>(fieldName))
{
const FieldType& vf = mesh.lookupObject<FieldType>(fieldName);
const FieldType& vf = mesh_.lookupObject<FieldType>(fieldName);
volScalarField& field = divField(resultName, vf.dimensions());
......
......@@ -48,23 +48,8 @@ Foam::functionObjects::grad::grad
const dictionary& dict
)
:
functionObject(name),
obr_
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
fieldName_("undefined-fieldName"),
resultName_("undefined-resultName")
fvMeshFunctionObject(name, runTime, dict)
{
if (!isA<fvMesh>(obr_))
{