Commit 6a529f2f authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects::volRegion: General base-class to handle vol (cell) region processing

Renamed the original volRegion -> volFieldValue to clarify the purpose
of this class to process vol fields on a volRegion.
parent 3621de79
......@@ -6,7 +6,7 @@
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
type volRegion;
type volFieldValue;
libs ("libfieldFunctionObjects.so");
writeControl timeStep;
......
......@@ -91,7 +91,8 @@ $(faceToCell)/extendedFaceToCellStencil.C
$(faceToCell)/extendedCentredFaceToCellStencil.C
$(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C
fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C
functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C
functionObjects/volRegion/volRegion.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 "volRegion.H"
#include "volMesh.H"
#include "globalMeshData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(volRegion, 0);
}
}
template<>
const char*
Foam::NamedEnum
<
Foam::functionObjects::volRegion::regionTypes,
2
>::names[] = {"cellZone", "all"};
const Foam::NamedEnum
<
Foam::functionObjects::volRegion::regionTypes,
2
> Foam::functionObjects::volRegion::regionTypeNames_;
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::volRegion::writeFileHeader
(
const writeFile& wf,
Ostream& file
)
{
wf.writeCommented(file, "Region : ");
file << regionTypeNames_[regionType_] << " " << regionName_ << endl;
wf.writeHeaderValue(file, "Cells", nCells());
wf.writeHeaderValue(file, "Volume", V());
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::volRegion::volRegion
(
const fvMesh& mesh,
const dictionary& dict
)
:
mesh_(mesh),
regionType_
(
dict.found("regionType")
? regionTypeNames_.read(dict.lookup("regionType"))
: vrtAll
),
regionID_(-1)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::volRegion::~volRegion()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::volRegion::read
(
const dictionary& dict
)
{
switch (regionType_)
{
case vrtCellZone:
{
dict.lookup("name") >> regionName_;
regionID_ = mesh_.cellZones().findZoneID(regionName_);
if (regionID_ < 0)
{
FatalIOErrorInFunction(dict)
<< "Unknown cell zone name: " << regionName_
<< ". Valid cell zones are: " << mesh_.cellZones().names()
<< exit(FatalIOError);
}
if (nCells() == 0)
{
FatalIOErrorInFunction(dict)
<< regionTypeNames_[regionType_]
<< "(" << regionName_ << "):" << nl
<< " Region has no cells"
<< exit(FatalIOError);
}
break;
}
case vrtAll:
{
break;
}
default:
{
FatalIOErrorInFunction(dict)
<< "Unknown region type. Valid region types are:"
<< regionTypeNames_
<< exit(FatalIOError);
}
}
return true;
}
const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
{
if (regionType_ == vrtAll)
{
return labelList::null();
}
else
{
return mesh_.cellZones()[regionID_];
}
}
Foam::label Foam::functionObjects::volRegion::nCells() const
{
if (regionType_ == vrtAll)
{
return mesh_.globalData().nTotalCells();
}
else
{
return returnReduce(cellIDs().size(), sumOp<label>());
}
}
Foam::scalar Foam::functionObjects::volRegion::V() const
{
if (regionType_ == vrtAll)
{
return gSum(mesh_.V());
}
else
{
return gSum(scalarField(mesh_.V(), cellIDs()));
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::volRegion
Group
grpFieldFunctionObjects
Description
Volume (cell) region selection class.
Examples of function object specification:
\verbatim
volRegion0
{
.
.
regionType cellZone;
name c0;
.
.
}
volRegionAll
{
.
.
regionType all;
.
.
}
\endverbatim
Usage
\table
Property | Description | Required | Default value
regionType | cellZone or all | no | all
name | Name of cellZone if required | no |
\endtable
See also
Foam::functionObject
SourceFiles
volRegion.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_volRegion_H
#define functionObjects_volRegion_H
#include "writeFile.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class volRegion Declaration
\*---------------------------------------------------------------------------*/
class volRegion
{
// Private member data
const fvMesh& mesh_;
public:
// Public data types
//- Region type enumeration
enum regionTypes
{
vrtCellZone,
vrtAll
};
//- Region type names
static const NamedEnum<regionTypes, 2> regionTypeNames_;
protected:
// Protected data
//- Region type
regionTypes regionType_;
//- Region name (patch, zone, etc.)
word regionName_;
//- Region ID (patch ID, zone ID, etc.)
label regionID_;
// Protected Member Functions
//- Output file header information
void writeFileHeader(const writeFile& wf, Ostream& file);
public:
//- Run-time type information
TypeName("volRegion");
// Constructors
//- Construct from fvMesh and dictionary
volRegion
(
const fvMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~volRegion();
// Public Member Functions
//- Read from dictionary
bool read(const dictionary&);
//- Return the region type
inline const regionTypes& regionType() const;
//- Return the local list of cell IDs
const labelList& cellIDs() const;
//- Return the number of cells in the region
label nCells() const;
//- Return total volume of the region
scalar V() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "volRegionI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -23,22 +23,12 @@ License
\*---------------------------------------------------------------------------*/
#include "volRegion.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::functionObjects::fieldValues::volRegion::regionTypes&
Foam::functionObjects::fieldValues::volRegion::regionType() const
inline const Foam::functionObjects::volRegion::regionTypes&
Foam::functionObjects::volRegion::regionType() const
{
return regionType_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::volRegion::cellId() const
{
return cellId_;
}
// ************************************************************************* //
......@@ -8,8 +8,8 @@ fieldMinMax/fieldMinMax.C
fieldValues/fieldValue/fieldValue.C
fieldValues/fieldValue/fieldValueNew.C
fieldValues/fieldValueDelta/fieldValueDelta.C
fieldValues/volRegion/volRegion.C
fieldValues/surfaceRegion/surfaceRegion.C
fieldValues/volFieldValue/volFieldValue.C
fieldValues/surfaceFieldValue/surfaceFieldValue.C
nearWallFields/nearWallFields.C
nearWallFields/findCellParticle.C
......
......@@ -178,7 +178,7 @@ public:
//- Execute
virtual bool execute();
//- Write to screen/file
//- Write
virtual bool write();
};
......
......@@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "surfaceRegion.H"
#include "surfaceFieldValue.H"
#include "fvMesh.H"
#include "cyclicPolyPatch.H"
#include "emptyPolyPatch.H"
......@@ -42,9 +42,9 @@ namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(surfaceRegion, 0);
addToRunTimeSelectionTable(fieldValue, surfaceRegion, dictionary);
addToRunTimeSelectionTable(functionObject, surfaceRegion, dictionary);
defineTypeNameAndDebug(surfaceFieldValue, 0);
addToRunTimeSelectionTable(fieldValue, surfaceFieldValue, dictionary);
addToRunTimeSelectionTable(functionObject, surfaceFieldValue, dictionary);
}
}
}
......@@ -52,7 +52,7 @@ namespace fieldValues
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceRegion::regionTypes,
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
3
>::names[] =
{
......@@ -64,7 +64,7 @@ const char* Foam::NamedEnum
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceRegion::operationType,
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
15
>::names[] =
{
......@@ -87,20 +87,20 @@ const char* Foam::NamedEnum
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceRegion::regionTypes,
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
3
> Foam::functionObjects::fieldValues::surfaceRegion::regionTypeNames_;
> Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypeNames_;
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceRegion::operationType,
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
15
> Foam::functionObjects::fieldValues::surfaceRegion::operationTypeNames_;
> Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::surfaceRegion::setFaceZoneFaces()
void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
{
label zoneId = mesh_.faceZones().findZoneID(regionName_);
......@@ -185,7 +185,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::setFaceZoneFaces()
}
void Foam::functionObjects::fieldValues::surfaceRegion::setPatchFaces()
void Foam::functionObjects::fieldValues::surfaceFieldValue::setPatchFaces()
{
const label patchid = mesh_.boundaryMesh().findPatchID(regionName_);
......@@ -222,7 +222,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::setPatchFaces()
}
void Foam::functionObjects::fieldValues::surfaceRegion::sampledSurfaceFaces
void Foam::functionObjects::fieldValues::surfaceFieldValue::sampledSurfaceFaces
(
const dictionary& dict
)
......@@ -238,7 +238,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::sampledSurfaceFaces
}
void Foam::functionObjects::fieldValues::surfaceRegion::combineMeshGeometry
void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
(
faceList& faces,
pointField& points
......@@ -359,7 +359,8 @@ void Foam::functionObjects::fieldValues::surfaceRegion::combineMeshGeometry
}
void Foam::functionObjects::fieldValues::surfaceRegion::combineSurfaceGeometry
void Foam::functionObjects::fieldValues::surfaceFieldValue::
combineSurfaceGeometry
(
faceList& faces,
pointField& points
......@@ -399,7 +400,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::combineSurfaceGeometry
Foam::scalar
Foam::functionObjects::fieldValues::surfaceRegion::totalArea() const
Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
{
scalar totalArea;
......@@ -418,7 +419,7 @@ Foam::functionObjects::fieldValues::surfaceRegion::totalArea() const
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::surfaceRegion::initialise
void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
(
const dictionary& dict
)
......@@ -533,7 +534,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::initialise
}
void Foam::functionObjects::fieldValues::surfaceRegion::writeFileHeader
void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
(
const label i
)
......@@ -566,7 +567,8 @@ void Foam::functionObjects::fieldValues::surfaceRegion::writeFileHeader
template<>
Foam::scalar Foam::functionObjects::fieldValues::surfaceRegion::processValues
Foam::scalar Foam::functionObjects::fieldValues::surfaceFieldValue::
processValues
(
const Field<scalar>& values,
const vectorField& Sf,
......@@ -597,7 +599,8 @@ Foam::scalar Foam::functionObjects::fieldValues::surfaceRegion::processValues
template<>
Foam::vector Foam::functionObjects::fieldValues::surfaceRegion::processValues
Foam::vector Foam::functionObjects::fieldValues::surfaceFieldValue::
processValues
(
const Field<vector>& values,
const vectorField& Sf,
......@@ -643,7 +646,7 @@ Foam::vector Foam::functionObjects::fieldValues::surfaceRegion::processValues
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::surfaceRegion::surfaceRegion
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
(
const word& name,
const Time& runTime,
......@@ -667,7 +670,7 @@ Foam::functionObjects::fieldValues::surfaceRegion::surfaceRegion
read(dict);
}
Foam::functionObjects::fieldValues::surfaceRegion::