Commit 2da5570c authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Further simplification and rationalization using the...

functionObjects: Further simplification and rationalization using the fvMeshFunctionObject base-class
parent 8339b572
......@@ -52,6 +52,18 @@ Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
{}
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
regionFunctionObject(name, obr, dict),
mesh_(refCast<const fvMesh>(obr_))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fvMeshFunctionObject::~fvMeshFunctionObject()
......
......@@ -100,6 +100,14 @@ public:
const dictionary& dict
);
//- Construct from the region objectRegistry and dictionary
fvMeshFunctionObject
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~fvMeshFunctionObject();
......
......@@ -103,18 +103,12 @@ Foam::functionObjects::fieldMinMax::fieldMinMax
const dictionary& dict
)
:
regionFunctionObject(name, runTime, dict),
fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name),
location_(true),
mode_(mdMag),
fieldSet_()
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
resetName(typeName);
}
......@@ -130,7 +124,7 @@ Foam::functionObjects::fieldMinMax::~fieldMinMax()
bool Foam::functionObjects::fieldMinMax::read(const dictionary& dict)
{
regionFunctionObject::read(dict);
fvMeshFunctionObject::read(dict);
location_ = dict.lookupOrDefault<Switch>("location", true);
......
......@@ -67,7 +67,7 @@ Usage
Output data is written to the file \<timeDir\>/fieldMinMax.dat
See also
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles
SourceFiles
......@@ -78,7 +78,7 @@ SourceFiles
#ifndef functionObjects_fieldMinMax_H
#define functionObjects_fieldMinMax_H
#include "regionFunctionObject.H"
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "vector.H"
......@@ -95,7 +95,7 @@ namespace functionObjects
class fieldMinMax
:
public regionFunctionObject,
public fvMeshFunctionObject,
public logFiles
{
public:
......
......@@ -109,10 +109,9 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFields
const label proci = Pstream::myProcNo();
const fieldType& field = obr_.lookupObject<fieldType>(fieldName);
const fvMesh& mesh = field.mesh();
const volVectorField::Boundary& CfBoundary =
mesh.C().boundaryField();
mesh_.C().boundaryField();
switch (mode)
{
......@@ -126,7 +125,7 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFields
List<vector> minCs(Pstream::nProcs());
label minProci = findMin(magField);
minVs[proci] = magField[minProci];
minCs[proci] = field.mesh().C()[minProci];
minCs[proci] = mesh_.C()[minProci];
labelList maxIs(Pstream::nProcs());
......@@ -134,7 +133,7 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFields
List<vector> maxCs(Pstream::nProcs());
label maxProci = findMax(magField);
maxVs[proci] = magField[maxProci];
maxCs[proci] = field.mesh().C()[maxProci];
maxCs[proci] = mesh_.C()[maxProci];
forAll(magFieldBoundary, patchi)
{
......@@ -198,7 +197,7 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFields
List<vector> minCs(Pstream::nProcs());
label minProci = findMin(field);
minVs[proci] = field[minProci];
minCs[proci] = field.mesh().C()[minProci];
minCs[proci] = mesh_.C()[minProci];
Pstream::gatherList(minVs);
Pstream::gatherList(minCs);
......@@ -207,7 +206,7 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFields
List<vector> maxCs(Pstream::nProcs());
label maxProci = findMax(field);
maxVs[proci] = field[maxProci];
maxCs[proci] = field.mesh().C()[maxProci];
maxCs[proci] = mesh_.C()[maxProci];
forAll(fieldBoundary, patchi)
{
......
......@@ -49,7 +49,7 @@ Foam::functionObjects::fieldValue::fieldValue
const word& valueType
)
:
regionFunctionObject(name, runTime, dict),
fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name),
dict_(dict),
regionName_(word::null),
......@@ -68,7 +68,7 @@ Foam::functionObjects::fieldValue::fieldValue
const word& valueType
)
:
regionFunctionObject(name, obr, dict),
fvMeshFunctionObject(name, obr, dict),
logFiles(obr_, name),
dict_(dict),
regionName_(word::null),
......@@ -89,8 +89,12 @@ Foam::functionObjects::fieldValue::~fieldValue()
bool Foam::functionObjects::fieldValue::read(const dictionary& dict)
{
dict_ = dict;
regionFunctionObject::read(dict);
if (dict != dict_)
{
dict_ = dict;
}
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> fields_;
dict.lookup("writeFields") >> writeFields_;
......
......@@ -32,7 +32,7 @@ Description
See also
Foam::functionObject
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles
SourceFiles
......@@ -43,7 +43,7 @@ SourceFiles
#ifndef functionObjects_fieldValue_H
#define functionObjects_fieldValue_H
#include "regionFunctionObject.H"
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "Switch.H"
#include "Field.H"
......@@ -65,7 +65,7 @@ namespace functionObjects
class fieldValue
:
public regionFunctionObject,
public fvMeshFunctionObject,
public logFiles
{
......@@ -169,9 +169,6 @@ public:
//- Return the output field values flag
inline const Switch& writeFields() const;
//- Helper function to return the reference to the mesh
inline const fvMesh& mesh() const;
//- Return access to the latest set of results
inline const dictionary& resultDict() const;
......
......@@ -53,12 +53,6 @@ Foam::functionObjects::fieldValue::writeFields() const
}
inline const Foam::fvMesh& Foam::functionObjects::fieldValue::mesh() const
{
return refCast<const fvMesh>(obr_);
}
inline const Foam::dictionary&
Foam::functionObjects::fieldValue::resultDict() const
{
......
......@@ -112,12 +112,6 @@ Foam::functionObjects::fieldValues::fieldValueDelta::fieldValueDelta
region1Ptr_(nullptr),
region2Ptr_(nullptr)
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
resetName(typeName);
}
......
......@@ -102,7 +102,7 @@ const Foam::NamedEnum
void Foam::functionObjects::fieldValues::surfaceRegion::setFaceZoneFaces()
{
label zoneId = mesh().faceZones().findZoneID(regionName_);
label zoneId = mesh_.faceZones().findZoneID(regionName_);
if (zoneId < 0)
{
......@@ -110,11 +110,11 @@ void Foam::functionObjects::fieldValues::surfaceRegion::setFaceZoneFaces()
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Unknown face zone name: " << regionName_
<< ". Valid face zones are: " << mesh().faceZones().names()
<< ". Valid face zones are: " << mesh_.faceZones().names()
<< nl << exit(FatalError);
}
const faceZone& fZone = mesh().faceZones()[zoneId];
const faceZone& fZone = mesh_.faceZones()[zoneId];
DynamicList<label> faceIds(fZone.size());
DynamicList<label> facePatchIds(fZone.size());
......@@ -126,15 +126,15 @@ void Foam::functionObjects::fieldValues::surfaceRegion::setFaceZoneFaces()
label faceId = -1;
label facePatchId = -1;
if (mesh().isInternalFace(facei))
if (mesh_.isInternalFace(facei))
{
faceId = facei;
facePatchId = -1;
}
else
{
facePatchId = mesh().boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh().boundaryMesh()[facePatchId];
facePatchId = mesh_.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
if (isA<coupledPolyPatch>(pp))
{
if (refCast<const coupledPolyPatch>(pp).owner())
......@@ -187,7 +187,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::setFaceZoneFaces()
void Foam::functionObjects::fieldValues::surfaceRegion::setPatchFaces()
{
const label patchid = mesh().boundaryMesh().findPatchID(regionName_);
const label patchid = mesh_.boundaryMesh().findPatchID(regionName_);
if (patchid < 0)
{
......@@ -196,11 +196,11 @@ void Foam::functionObjects::fieldValues::surfaceRegion::setPatchFaces()
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Unknown patch name: " << regionName_
<< ". Valid patch names are: "
<< mesh().boundaryMesh().names() << nl
<< mesh_.boundaryMesh().names() << nl
<< exit(FatalError);
}
const polyPatch& pp = mesh().boundaryMesh()[patchid];
const polyPatch& pp = mesh_.boundaryMesh()[patchid];
label nFaces = pp.size();
if (isA<emptyPolyPatch>(pp))
......@@ -230,7 +230,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::sampledSurfaceFaces
surfacePtr_ = sampledSurface::New
(
name(),
mesh(),
mesh_,
dict.subDict("sampledSurfaceDict")
);
surfacePtr_().update();
......@@ -253,15 +253,15 @@ void Foam::functionObjects::fieldValues::surfaceRegion::combineMeshGeometry
if (facePatchId_[i] != -1)
{
label patchi = facePatchId_[i];
globalFacesIs[i] += mesh().boundaryMesh()[patchi].start();
globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
}
}
// Add local faces and points to the all* lists
indirectPrimitivePatch pp
(
IndirectList<face>(mesh().faces(), globalFacesIs),
mesh().points()
IndirectList<face>(mesh_.faces(), globalFacesIs),
mesh_.points()
);
allFaces[Pstream::myProcNo()] = pp.localFaces();
allPoints[Pstream::myProcNo()] = pp.localPoints();
......@@ -372,7 +372,7 @@ void Foam::functionObjects::fieldValues::surfaceRegion::combineSurfaceGeometry
if (Pstream::parRun())
{
// Dimension as fraction of mesh bounding box
scalar mergeDim = 1e-10*mesh().bounds().mag();
scalar mergeDim = 1e-10*mesh_.bounds().mag();
labelList pointsMap;
......@@ -409,7 +409,7 @@ Foam::functionObjects::fieldValues::surfaceRegion::totalArea() const
}
else
{
totalArea = gSum(filterField(mesh().magSf(), false));
totalArea = gSum(filterField(mesh_.magSf(), false));
}
return totalArea;
......@@ -664,12 +664,6 @@ Foam::functionObjects::fieldValues::surfaceRegion::surfaceRegion
facePatchId_(),
faceSign_()
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......@@ -694,12 +688,6 @@ Foam::functionObjects::fieldValues::surfaceRegion::surfaceRegion
facePatchId_(),
faceSign_()
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......
......@@ -291,7 +291,7 @@ bool Foam::functionObjects::fieldValues::surfaceRegion::writeValues
else
{
// Get oriented Sf
Sf = filterField(mesh().Sf(), true);
Sf = filterField(mesh_.Sf(), true);
}
// Combine onto master
......
......@@ -95,24 +95,24 @@ void Foam::functionObjects::fieldValues::volRegion::setCellZoneCells()
{
dict().lookup("name") >> regionName_;
label zoneId = mesh().cellZones().findZoneID(regionName_);
label zoneId = mesh_.cellZones().findZoneID(regionName_);
if (zoneId < 0)
{
FatalErrorInFunction
<< "Unknown cell zone name: " << regionName_
<< ". Valid cell zones are: " << mesh().cellZones().names()
<< ". Valid cell zones are: " << mesh_.cellZones().names()
<< nl << exit(FatalError);
}
cellId_ = mesh().cellZones()[zoneId];
cellId_ = mesh_.cellZones()[zoneId];
nCells_ = returnReduce(cellId_.size(), sumOp<label>());
break;
}
case stAll:
{
cellId_ = identity(mesh().nCells());
cellId_ = identity(mesh_.nCells());
nCells_ = returnReduce(cellId_.size(), sumOp<label>());
break;
}
......@@ -134,7 +134,7 @@ void Foam::functionObjects::fieldValues::volRegion::setCellZoneCells()
Foam::scalar Foam::functionObjects::fieldValues::volRegion::volume() const
{
return gSum(filterField(mesh().V()));
return gSum(filterField(mesh_.V()));
}
......@@ -218,12 +218,6 @@ Foam::functionObjects::fieldValues::volRegion::volRegion
weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......@@ -243,12 +237,6 @@ Foam::functionObjects::fieldValues::volRegion::volRegion
weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......
......@@ -165,7 +165,7 @@ bool Foam::functionObjects::fieldValues::volRegion::writeValues
if (ok)
{
Field<Type> values(setFieldValues<Type>(fieldName));
scalarField V(filterField(mesh().V()));
scalarField V(filterField(mesh_.V()));
scalarField weightField(values.size(), 1.0);
if (weightFieldName_ != "none")
......
......@@ -75,15 +75,9 @@ Foam::functionObjects::histogram::histogram
const dictionary& dict
)
:
regionFunctionObject(name, runTime, dict),
fvMeshFunctionObject(name, runTime, dict),
file_(obr_, name)
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......@@ -120,8 +114,6 @@ bool Foam::functionObjects::histogram::write()
{
Log << type() << " " << name() << " write:" << nl;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
autoPtr<volScalarField> fieldPtr;
if (obr_.foundObject<volScalarField>(fieldName_))
{
......@@ -137,12 +129,12 @@ bool Foam::functionObjects::histogram::write()
IOobject
(
fieldName_,
mesh.time().timeName(),
mesh,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
mesh_
)
);
}
......@@ -166,7 +158,7 @@ bool Foam::functionObjects::histogram::write()
}
scalarField volFrac(nBins_, 0);
const scalarField& V = mesh.V();
const scalarField& V = mesh_.V();
forAll(field, celli)
{
......
......@@ -59,7 +59,7 @@ Usage
See also
Foam::functionObject
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
......@@ -70,7 +70,7 @@ SourceFiles
#ifndef functionObjects_histogram_H
#define functionObjects_histogram_H
#include "regionFunctionObject.H"
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "writer.H"
......@@ -87,7 +87,7 @@ namespace functionObjects
class histogram
:
public regionFunctionObject
public fvMeshFunctionObject
{
// Private data
......
......@@ -355,8 +355,6 @@ bool Foam::functionObjects::nearWallFields::write()
vtf_[i].write();
}
Log << endl;
return true;
}
......
......@@ -173,7 +173,6 @@ void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
Foam::Map<Foam::label>
Foam::functionObjects::regionSizeDistribution::findPatchRegions
(
const polyMesh& mesh,
const regionSplit& regions
) const
{
......@@ -181,19 +180,19 @@ Foam::functionObjects::regionSizeDistribution::findPatchRegions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Count number of patch faces (just for initial sizing)
const labelHashSet patchIDs(mesh.boundaryMesh().patchSet(patchNames_));
const labelHashSet patchIDs(mesh_.boundaryMesh().patchSet(patchNames_));
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
{
nPatchFaces += mesh.boundaryMesh()[iter.key()].size();
nPatchFaces += mesh_.boundaryMesh()[iter.key()].size();
}
Map<label> patchRegions(nPatchFaces);
forAllConstIter(labelHashSet, patchIDs, iter)
{
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
const polyPatch& pp = mesh_.boundaryMesh()[iter.key()];
// Collect all regions on the patch
const labelList& faceCells = pp.faceCells();
......@@ -330,17 +329,11 @@ Foam::functionObjects::regionSizeDistribution::regionSizeDistribution
const dictionary& dict
)
:
regionFunctionObject(name, runTime, dict),
fvMeshFunctionObject(name, runTime, dict),
file_(obr_, name),
alphaName_(dict.lookup("field")),
patchNames_(dict.lookup("patches"))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
......@@ -389,8 +382,6 @@ bool Foam::functionObjects::regionSizeDistribution::write()
{
Info<< type() << " " << name() << " write:" << nl;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
autoPtr<volScalarField> alphaPtr;
if (obr_.foundObject<volScalarField>(alphaName_))
{
......@@ -406,12 +397,12 @@ bool Foam::functionObjects::regionSizeDistribution::write()
IOobject
(
alphaName_,