mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
GIT: Initial state after latest Foundation merge
This commit is contained in:
@ -0,0 +1,785 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "surfaceFieldValue.H"
|
||||
#include "fvMesh.H"
|
||||
#include "cyclicPolyPatch.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "coupledPolyPatch.H"
|
||||
#include "sampledSurface.H"
|
||||
#include "mergePoints.H"
|
||||
#include "indirectPrimitivePatch.H"
|
||||
#include "PatchTools.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace fieldValues
|
||||
{
|
||||
defineTypeNameAndDebug(surfaceFieldValue, 0);
|
||||
addToRunTimeSelectionTable(fieldValue, surfaceFieldValue, dictionary);
|
||||
addToRunTimeSelectionTable(functionObject, surfaceFieldValue, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
|
||||
3
|
||||
>::names[] =
|
||||
{
|
||||
"faceZone",
|
||||
"patch",
|
||||
"sampledSurface"
|
||||
};
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
|
||||
15
|
||||
>::names[] =
|
||||
{
|
||||
"none",
|
||||
"sum",
|
||||
"sumMag",
|
||||
"sumDirection",
|
||||
"sumDirectionBalance",
|
||||
"average",
|
||||
"weightedAverage",
|
||||
"areaAverage",
|
||||
"weightedAreaAverage",
|
||||
"areaIntegrate",
|
||||
"min",
|
||||
"max",
|
||||
"CoV",
|
||||
"areaNormalAverage",
|
||||
"areaNormalIntegrate"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
|
||||
3
|
||||
> Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypeNames_;
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
|
||||
15
|
||||
> Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
|
||||
{
|
||||
label zoneId = mesh_.faceZones().findZoneID(regionName_);
|
||||
|
||||
if (zoneId < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
|
||||
<< " Unknown face zone name: " << regionName_
|
||||
<< ". Valid face zones are: " << mesh_.faceZones().names()
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
const faceZone& fZone = mesh_.faceZones()[zoneId];
|
||||
|
||||
DynamicList<label> faceIds(fZone.size());
|
||||
DynamicList<label> facePatchIds(fZone.size());
|
||||
DynamicList<label> faceSigns(fZone.size());
|
||||
|
||||
forAll(fZone, i)
|
||||
{
|
||||
label facei = fZone[i];
|
||||
|
||||
label faceId = -1;
|
||||
label facePatchId = -1;
|
||||
if (mesh_.isInternalFace(facei))
|
||||
{
|
||||
faceId = facei;
|
||||
facePatchId = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
facePatchId = mesh_.boundaryMesh().whichPatch(facei);
|
||||
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
|
||||
if (isA<coupledPolyPatch>(pp))
|
||||
{
|
||||
if (refCast<const coupledPolyPatch>(pp).owner())
|
||||
{
|
||||
faceId = pp.whichFace(facei);
|
||||
}
|
||||
else
|
||||
{
|
||||
faceId = -1;
|
||||
}
|
||||
}
|
||||
else if (!isA<emptyPolyPatch>(pp))
|
||||
{
|
||||
faceId = facei - pp.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
faceId = -1;
|
||||
facePatchId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (faceId >= 0)
|
||||
{
|
||||
if (fZone.flipMap()[i])
|
||||
{
|
||||
faceSigns.append(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
faceSigns.append(1);
|
||||
}
|
||||
faceIds.append(faceId);
|
||||
facePatchIds.append(facePatchId);
|
||||
}
|
||||
}
|
||||
|
||||
faceId_.transfer(faceIds);
|
||||
facePatchId_.transfer(facePatchIds);
|
||||
faceSign_.transfer(faceSigns);
|
||||
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "Original face zone size = " << fZone.size()
|
||||
<< ", new size = " << faceId_.size() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldValues::surfaceFieldValue::setPatchFaces()
|
||||
{
|
||||
const label patchid = mesh_.boundaryMesh().findPatchID(regionName_);
|
||||
|
||||
if (patchid < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
|
||||
<< " Unknown patch name: " << regionName_
|
||||
<< ". Valid patch names are: "
|
||||
<< mesh_.boundaryMesh().names() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
const polyPatch& pp = mesh_.boundaryMesh()[patchid];
|
||||
|
||||
label nFaces = pp.size();
|
||||
if (isA<emptyPolyPatch>(pp))
|
||||
{
|
||||
nFaces = 0;
|
||||
}
|
||||
|
||||
faceId_.setSize(nFaces);
|
||||
facePatchId_.setSize(nFaces);
|
||||
faceSign_.setSize(nFaces);
|
||||
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
|
||||
|
||||
forAll(faceId_, facei)
|
||||
{
|
||||
faceId_[facei] = facei;
|
||||
facePatchId_[facei] = patchid;
|
||||
faceSign_[facei] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldValues::surfaceFieldValue::sampledSurfaceFaces
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
surfacePtr_ = sampledSurface::New
|
||||
(
|
||||
name(),
|
||||
mesh_,
|
||||
dict.subDict("sampledSurfaceDict")
|
||||
);
|
||||
surfacePtr_().update();
|
||||
nFaces_ = returnReduce(surfacePtr_().faces().size(), sumOp<label>());
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
|
||||
(
|
||||
faceList& faces,
|
||||
pointField& points
|
||||
) const
|
||||
{
|
||||
List<faceList> allFaces(Pstream::nProcs());
|
||||
List<pointField> allPoints(Pstream::nProcs());
|
||||
|
||||
labelList globalFacesIs(faceId_);
|
||||
forAll(globalFacesIs, i)
|
||||
{
|
||||
if (facePatchId_[i] != -1)
|
||||
{
|
||||
label patchi = facePatchId_[i];
|
||||
globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
|
||||
}
|
||||
}
|
||||
|
||||
// Add local faces and points to the all* lists
|
||||
indirectPrimitivePatch pp
|
||||
(
|
||||
IndirectList<face>(mesh_.faces(), globalFacesIs),
|
||||
mesh_.points()
|
||||
);
|
||||
allFaces[Pstream::myProcNo()] = pp.localFaces();
|
||||
allPoints[Pstream::myProcNo()] = pp.localPoints();
|
||||
|
||||
Pstream::gatherList(allFaces);
|
||||
Pstream::gatherList(allPoints);
|
||||
|
||||
// Renumber and flatten
|
||||
label nFaces = 0;
|
||||
label nPoints = 0;
|
||||
forAll(allFaces, proci)
|
||||
{
|
||||
nFaces += allFaces[proci].size();
|
||||
nPoints += allPoints[proci].size();
|
||||
}
|
||||
|
||||
faces.setSize(nFaces);
|
||||
points.setSize(nPoints);
|
||||
|
||||
nFaces = 0;
|
||||
nPoints = 0;
|
||||
|
||||
// My own data first
|
||||
{
|
||||
const faceList& fcs = allFaces[Pstream::myProcNo()];
|
||||
forAll(fcs, i)
|
||||
{
|
||||
const face& f = fcs[i];
|
||||
face& newF = faces[nFaces++];
|
||||
newF.setSize(f.size());
|
||||
forAll(f, fp)
|
||||
{
|
||||
newF[fp] = f[fp] + nPoints;
|
||||
}
|
||||
}
|
||||
|
||||
const pointField& pts = allPoints[Pstream::myProcNo()];
|
||||
forAll(pts, i)
|
||||
{
|
||||
points[nPoints++] = pts[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Other proc data follows
|
||||
forAll(allFaces, proci)
|
||||
{
|
||||
if (proci != Pstream::myProcNo())
|
||||
{
|
||||
const faceList& fcs = allFaces[proci];
|
||||
forAll(fcs, i)
|
||||
{
|
||||
const face& f = fcs[i];
|
||||
face& newF = faces[nFaces++];
|
||||
newF.setSize(f.size());
|
||||
forAll(f, fp)
|
||||
{
|
||||
newF[fp] = f[fp] + nPoints;
|
||||
}
|
||||
}
|
||||
|
||||
const pointField& pts = allPoints[proci];
|
||||
forAll(pts, i)
|
||||
{
|
||||
points[nPoints++] = pts[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge
|
||||
labelList oldToNew;
|
||||
pointField newPoints;
|
||||
bool hasMerged = mergePoints
|
||||
(
|
||||
points,
|
||||
SMALL,
|
||||
false,
|
||||
oldToNew,
|
||||
newPoints
|
||||
);
|
||||
|
||||
if (hasMerged)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "Merged from " << points.size()
|
||||
<< " down to " << newPoints.size() << " points" << endl;
|
||||
}
|
||||
|
||||
points.transfer(newPoints);
|
||||
forAll(faces, i)
|
||||
{
|
||||
inplaceRenumber(oldToNew, faces[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||
combineSurfaceGeometry
|
||||
(
|
||||
faceList& faces,
|
||||
pointField& points
|
||||
) const
|
||||
{
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
const sampledSurface& s = surfacePtr_();
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
// Dimension as fraction of mesh bounding box
|
||||
scalar mergeDim = 1e-10*mesh_.bounds().mag();
|
||||
|
||||
labelList pointsMap;
|
||||
|
||||
PatchTools::gatherAndMerge
|
||||
(
|
||||
mergeDim,
|
||||
primitivePatch
|
||||
(
|
||||
SubList<face>(s.faces(), s.faces().size()),
|
||||
s.points()
|
||||
),
|
||||
points,
|
||||
faces,
|
||||
pointsMap
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
faces = s.faces();
|
||||
points = s.points();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
|
||||
{
|
||||
scalar totalArea;
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
totalArea = gSum(surfacePtr_().magSf());
|
||||
}
|
||||
else
|
||||
{
|
||||
totalArea = gSum(filterField(mesh_.magSf(), false));
|
||||
}
|
||||
|
||||
return totalArea;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
dict.lookup("name") >> regionName_;
|
||||
|
||||
switch (regionType_)
|
||||
{
|
||||
case stFaceZone:
|
||||
{
|
||||
setFaceZoneFaces();
|
||||
break;
|
||||
}
|
||||
case stPatch:
|
||||
{
|
||||
setPatchFaces();
|
||||
break;
|
||||
}
|
||||
case stSampledSurface:
|
||||
{
|
||||
sampledSurfaceFaces(dict);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):"
|
||||
<< nl << " Unknown region type. Valid region types are:"
|
||||
<< regionTypeNames_.sortedToc() << nl << exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
if (nFaces_ == 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
|
||||
<< " Region has no faces" << exit(FatalError);
|
||||
}
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
surfacePtr_().update();
|
||||
}
|
||||
|
||||
totalArea_ = totalArea();
|
||||
|
||||
Info<< type() << " " << name() << ":" << nl
|
||||
<< " total faces = " << nFaces_ << nl
|
||||
<< " total area = " << totalArea_ << nl;
|
||||
|
||||
if (dict.readIfPresent("weightField", weightFieldName_))
|
||||
{
|
||||
Info<< " weight field = " << weightFieldName_ << nl;
|
||||
|
||||
if (regionType_ == stSampledSurface)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Cannot use weightField for a sampledSurface"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
if (dict.found("orientedWeightField"))
|
||||
{
|
||||
if (weightFieldName_ == "none")
|
||||
{
|
||||
dict.lookup("orientedWeightField") >> weightFieldName_;
|
||||
if (log_) Info << " weight field = " << weightFieldName_ << nl;
|
||||
orientWeightField_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Either weightField or orientedWeightField can be supplied, "
|
||||
<< "but not both"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
List<word> orientedFields;
|
||||
if (dict.readIfPresent("orientedFields", orientedFields))
|
||||
{
|
||||
orientedFieldsStart_ = fields_.size();
|
||||
fields_.append(orientedFields);
|
||||
}
|
||||
|
||||
Info<< nl << endl;
|
||||
|
||||
if (writeFields_)
|
||||
{
|
||||
const word surfaceFormat(dict.lookup("surfaceFormat"));
|
||||
|
||||
surfaceWriterPtr_.reset
|
||||
(
|
||||
surfaceWriter::New
|
||||
(
|
||||
surfaceFormat,
|
||||
dict.subOrEmptyDict("formatOptions").
|
||||
subOrEmptyDict(surfaceFormat)
|
||||
).ptr()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::fieldValues::faceSource::writeFileHeader(Ostream& os) const
|
||||
{
|
||||
if (operation_ != opNone)
|
||||
{
|
||||
writeCommented(os, "Region type : ");
|
||||
os << regionTypeNames_[regionType_] << " " << regionName_ << endl;
|
||||
|
||||
writeHeaderValue(os, "Faces", nFaces_);
|
||||
writeHeaderValue(os, "Area", totalArea_);
|
||||
writeHeaderValue(os, "Scale factor", scaleFactor_);
|
||||
|
||||
writeCommented(os, "Time");
|
||||
if (writeArea_)
|
||||
{
|
||||
os << tab << "Area";
|
||||
}
|
||||
|
||||
forAll(fields_, i)
|
||||
{
|
||||
os << tab << operationTypeNames_[operation_]
|
||||
<< "(" << fields_[i] << ")";
|
||||
}
|
||||
|
||||
os << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
Foam::scalar Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||
processValues
|
||||
(
|
||||
const Field<scalar>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
switch (operation_)
|
||||
{
|
||||
case opSumDirection:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
return gSum(pos(values*(Sf & n))*mag(values));
|
||||
}
|
||||
case opSumDirectionBalance:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
const scalarField nv(values*(Sf & n));
|
||||
|
||||
return gSum(pos(nv)*mag(values) - neg(nv)*mag(values));
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Fall through to other operations
|
||||
return processSameTypeValues(values, Sf, weightField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
Foam::vector Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||
processValues
|
||||
(
|
||||
const Field<vector>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
switch (operation_)
|
||||
{
|
||||
case opSumDirection:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
n /= mag(n) + ROOTVSMALL;
|
||||
const scalarField nv(n & values);
|
||||
|
||||
return gSum(pos(nv)*n*(nv));
|
||||
}
|
||||
case opSumDirectionBalance:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
n /= mag(n) + ROOTVSMALL;
|
||||
const scalarField nv(n & values);
|
||||
|
||||
return gSum(pos(nv)*n*(nv));
|
||||
}
|
||||
case opAreaNormalAverage:
|
||||
{
|
||||
scalar result = gSum(values & Sf)/gSum(mag(Sf));
|
||||
return vector(result, 0.0, 0.0);
|
||||
}
|
||||
case opAreaNormalIntegrate:
|
||||
{
|
||||
scalar result = gSum(values & Sf);
|
||||
return vector(result, 0.0, 0.0);
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Fall through to other operations
|
||||
return processSameTypeValues(values, Sf, weightField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldValue(name, runTime, dict, typeName),
|
||||
surfaceWriterPtr_(nullptr),
|
||||
regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
|
||||
operation_(operationTypeNames_.read(dict.lookup("operation"))),
|
||||
weightFieldName_("none"),
|
||||
orientWeightField_(false),
|
||||
orientedFieldsStart_(labelMax),
|
||||
scaleFactor_(1.0),
|
||||
writeArea_(dict.lookupOrDefault("writeArea", false)),
|
||||
nFaces_(0),
|
||||
faceId_(),
|
||||
facePatchId_(),
|
||||
faceSign_()
|
||||
{
|
||||
read(dict);
|
||||
writeFileHeader(file());
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldValue(name, obr, dict, typeName),
|
||||
surfaceWriterPtr_(nullptr),
|
||||
regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
|
||||
operation_(operationTypeNames_.read(dict.lookup("operation"))),
|
||||
weightFieldName_("none"),
|
||||
orientWeightField_(false),
|
||||
orientedFieldsStart_(labelMax),
|
||||
scaleFactor_(1.0),
|
||||
writeArea_(dict.lookupOrDefault("writeArea", false)),
|
||||
nFaces_(0),
|
||||
faceId_(),
|
||||
facePatchId_(),
|
||||
faceSign_()
|
||||
{
|
||||
read(dict);
|
||||
writeFileHeader(file());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::~surfaceFieldValue()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
fieldValue::read(dict);
|
||||
initialise(dict);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValues::surfaceFieldValue::write()
|
||||
{
|
||||
if (operation_ != opNone)
|
||||
{
|
||||
fieldValue::write();
|
||||
}
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
surfacePtr_().update();
|
||||
}
|
||||
|
||||
if (operation_ != opNone && Pstream::master())
|
||||
{
|
||||
writeTime(file());
|
||||
}
|
||||
|
||||
if (writeArea_)
|
||||
{
|
||||
totalArea_ = totalArea();
|
||||
if (operation_ != opNone && Pstream::master())
|
||||
{
|
||||
file() << tab << totalArea_;
|
||||
}
|
||||
Log << " total area = " << totalArea_ << endl;
|
||||
}
|
||||
|
||||
// Construct weight field. Note: zero size means weight = 1
|
||||
scalarField weightField;
|
||||
if (weightFieldName_ != "none")
|
||||
{
|
||||
weightField =
|
||||
getFieldValues<scalar>
|
||||
(
|
||||
weightFieldName_,
|
||||
true,
|
||||
orientWeightField_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Process the fields
|
||||
forAll(fields_, i)
|
||||
{
|
||||
const word& fieldName = fields_[i];
|
||||
bool ok = false;
|
||||
|
||||
bool orient = i >= orientedFieldsStart_;
|
||||
ok = ok || writeValues<scalar>(fieldName, weightField, orient);
|
||||
ok = ok || writeValues<vector>(fieldName, weightField, orient);
|
||||
ok = ok
|
||||
|| writeValues<sphericalTensor>(fieldName, weightField, orient);
|
||||
ok = ok || writeValues<symmTensor>(fieldName, weightField, orient);
|
||||
ok = ok || writeValues<tensor>(fieldName, weightField, orient);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Requested field " << fieldName
|
||||
<< " not found in database and not processed"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (operation_ != opNone && Pstream::master())
|
||||
{
|
||||
file() << endl;
|
||||
}
|
||||
|
||||
Log << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,474 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::fieldValues::surfaceFieldValue
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
Provides a 'face regionType' variant of the fieldValues function object.
|
||||
|
||||
Given a list of user-specified fields and a selection of mesh (or general
|
||||
surface) faces, a number of operations can be performed, such as sums,
|
||||
averages and integrations.
|
||||
|
||||
For example, to calculate the volumetric or mass flux across a patch,
|
||||
apply the 'sum' operator to the flux field (typically \c phi)
|
||||
|
||||
Examples of function object specification:
|
||||
\verbatim
|
||||
movingWallPatch
|
||||
{
|
||||
type surfaceFieldValue;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
|
||||
log true;
|
||||
writeControl writeTime;
|
||||
writeFields true;
|
||||
|
||||
regionType patch;
|
||||
name movingWall;
|
||||
|
||||
operation areaAverage;
|
||||
|
||||
fields
|
||||
(
|
||||
p
|
||||
phi
|
||||
U
|
||||
);
|
||||
}
|
||||
|
||||
surfaceFieldValue1
|
||||
{
|
||||
type surfaceFieldValue;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
|
||||
log true;
|
||||
writeControl writeTime;
|
||||
writeFields true;
|
||||
|
||||
surfaceFormat none;
|
||||
regionType faceZone;
|
||||
name f0;
|
||||
|
||||
operation sum;
|
||||
|
||||
weightField alpha1;
|
||||
|
||||
fields
|
||||
(
|
||||
p
|
||||
phi
|
||||
U
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: surfaceFieldValue | yes |
|
||||
log | write data to standard output | no | no
|
||||
writeFields | Write the region field values | yes |
|
||||
writeArea | Write the area of the surfaceFieldValue | no |
|
||||
surfaceFormat | output value format | no |
|
||||
regionType | face regionType: see below | yes |
|
||||
name | name of face regionType if required | no |
|
||||
operation | operation to perform | yes |
|
||||
weightField | name of field to apply weighting | no |
|
||||
orientedWeightField | name of oriented field to apply weighting | no |
|
||||
scaleFactor | scale factor | no | 1
|
||||
fields | list of fields to operate on | yes |
|
||||
orientedFields | list of oriented fields to operate on | no |
|
||||
\endtable
|
||||
|
||||
Where \c regionType is defined by
|
||||
\plaintable
|
||||
faceZone | requires a 'name' entry to specify the faceZone
|
||||
patch | requires a 'name' entry to specify the patch
|
||||
sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
|
||||
\endplaintable
|
||||
|
||||
The \c operation is one of:
|
||||
\plaintable
|
||||
none | no operation
|
||||
sum | sum
|
||||
sumMag | sum of component magnitudes
|
||||
sumDirection | sum values which are positive in given direction
|
||||
sumDirectionBalance | sum of balance of values in given direction
|
||||
average | ensemble average
|
||||
weightedAverage | weighted average
|
||||
areaAverage | area weighted average
|
||||
weightedAreaAverage | weighted area average
|
||||
areaIntegrate | area integral
|
||||
min | minimum
|
||||
max | maximum
|
||||
CoV | coefficient of variation: standard deviation/mean
|
||||
areaNormalAverage| area weighted average in face normal direction
|
||||
areaNormalIntegrate | area weighted integral in face normal directon
|
||||
\endplaintable
|
||||
|
||||
Note
|
||||
- The values reported by the areaNormalAverage and areaNormalIntegrate
|
||||
operations are written as the first component of a field with the same
|
||||
rank as the input field.
|
||||
- faces on empty patches get ignored
|
||||
- if the field is a volField the \c faceZone can only consist of boundary
|
||||
faces
|
||||
- the `oriented' entries relate to mesh-oriented fields, such as the
|
||||
flux, phi. These fields will be oriented according to the face normals.
|
||||
- using \c sampledSurface:
|
||||
- not available for surface fields
|
||||
- if interpolate=true they use \c interpolationCellPoint
|
||||
otherwise they use cell values
|
||||
- each triangle in \c sampledSurface is logically only in one cell
|
||||
so interpolation will be wrong when triangles are larger than
|
||||
cells. This can only happen for sampling on a \c triSurfaceMesh
|
||||
- take care when using isoSurfaces - these might have duplicate
|
||||
triangles and so integration might be wrong
|
||||
|
||||
See also
|
||||
Foam::fieldValues
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
surfaceFieldValue.C
|
||||
surfaceFieldValueTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_surfaceFieldValue_H
|
||||
#define functionObjects_surfaceFieldValue_H
|
||||
|
||||
#include "fieldValue.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class sampledSurface;
|
||||
class surfaceWriter;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace fieldValues
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surfaceFieldValue Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class surfaceFieldValue
|
||||
:
|
||||
public fieldValue
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
//- region type enumeration
|
||||
enum regionTypes
|
||||
{
|
||||
stFaceZone,
|
||||
stPatch,
|
||||
stSampledSurface
|
||||
};
|
||||
|
||||
//- region type names
|
||||
static const NamedEnum<regionTypes, 3> regionTypeNames_;
|
||||
|
||||
|
||||
//- Operation type enumeration
|
||||
enum operationType
|
||||
{
|
||||
opNone,
|
||||
opSum,
|
||||
opSumMag,
|
||||
opSumDirection,
|
||||
opSumDirectionBalance,
|
||||
opAverage,
|
||||
opWeightedAverage,
|
||||
opAreaAverage,
|
||||
opWeightedAreaAverage,
|
||||
opAreaIntegrate,
|
||||
opMin,
|
||||
opMax,
|
||||
opCoV,
|
||||
opAreaNormalAverage,
|
||||
opAreaNormalIntegrate
|
||||
};
|
||||
|
||||
//- Operation type names
|
||||
static const NamedEnum<operationType, 15> operationTypeNames_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Set faces to evaluate based on a face zone
|
||||
void setFaceZoneFaces();
|
||||
|
||||
//- Set faces to evaluate based on a patch
|
||||
void setPatchFaces();
|
||||
|
||||
//- Set faces according to sampledSurface
|
||||
void sampledSurfaceFaces(const dictionary&);
|
||||
|
||||
//- Combine mesh faces and points from multiple processors
|
||||
void combineMeshGeometry
|
||||
(
|
||||
faceList& faces,
|
||||
pointField& points
|
||||
) const;
|
||||
|
||||
//- Combine surface faces and points from multiple processors
|
||||
void combineSurfaceGeometry
|
||||
(
|
||||
faceList& faces,
|
||||
pointField& points
|
||||
) const;
|
||||
|
||||
//- Calculate and return total area of the surfaceFieldValue: sum(magSf)
|
||||
scalar totalArea() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Surface writer
|
||||
autoPtr<surfaceWriter> surfaceWriterPtr_;
|
||||
|
||||
//- region type
|
||||
regionTypes regionType_;
|
||||
|
||||
//- Operation to apply to values
|
||||
operationType operation_;
|
||||
|
||||
//- Weight field name - optional
|
||||
word weightFieldName_;
|
||||
|
||||
//- Flag to indicate if flipMap should be applied to the weight field
|
||||
bool orientWeightField_;
|
||||
|
||||
//- Start index of fields that require application of flipMap
|
||||
label orientedFieldsStart_;
|
||||
|
||||
//- Total area of the surfaceFieldValue
|
||||
scalar totalArea_;
|
||||
|
||||
//- Optionally write the area of the surfaceFieldValue
|
||||
bool writeArea_;
|
||||
|
||||
//- Global number of faces
|
||||
label nFaces_;
|
||||
|
||||
|
||||
// If operating on mesh faces (faceZone, patch)
|
||||
|
||||
//- Local list of face IDs
|
||||
labelList faceId_;
|
||||
|
||||
//- Local list of patch ID per face
|
||||
labelList facePatchId_;
|
||||
|
||||
//- List of +1/-1 representing face flip map
|
||||
// (1 use as is, -1 negate)
|
||||
labelList faceSign_;
|
||||
|
||||
|
||||
// If operating on sampledSurface
|
||||
|
||||
//- Underlying sampledSurface
|
||||
autoPtr<sampledSurface> surfacePtr_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Initialise, e.g. face addressing
|
||||
void initialise(const dictionary& dict);
|
||||
|
||||
//- Return true if the field name is valid
|
||||
template<class Type>
|
||||
bool validField(const word& fieldName) const;
|
||||
|
||||
//- Return field values by looking up field name
|
||||
template<class Type>
|
||||
tmp<Field<Type>> setFieldValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const bool mustGet = false,
|
||||
const bool applyOrientation = false
|
||||
) const;
|
||||
|
||||
//- Apply the 'operation' to the values. Operation has to
|
||||
// preserve Type.
|
||||
template<class Type>
|
||||
Type processSameTypeValues
|
||||
(
|
||||
const Field<Type>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const;
|
||||
|
||||
//- Apply the 'operation' to the values. Wrapper around
|
||||
// processSameTypeValues. See also template specialisation below.
|
||||
template<class Type>
|
||||
Type processValues
|
||||
(
|
||||
const Field<Type>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const;
|
||||
|
||||
//- Output file header information
|
||||
virtual void writeFileHeader(Ostream& os) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("surfaceFieldValue");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from name, Time and dictionary
|
||||
surfaceFieldValue
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct from name, objectRegistry and dictionary
|
||||
surfaceFieldValue
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~surfaceFieldValue();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Return the region type
|
||||
inline const regionTypes& regionType() const;
|
||||
|
||||
//- Return the local list of face IDs
|
||||
inline const labelList& faceId() const;
|
||||
|
||||
//- Return the local list of patch ID per face
|
||||
inline const labelList& facePatch() const;
|
||||
|
||||
//- Return the list of +1/-1 representing face flip map
|
||||
inline const labelList& faceSign() const;
|
||||
|
||||
//- Return the output directory
|
||||
inline fileName outputDir() const;
|
||||
|
||||
//- Templated helper function to output field values
|
||||
template<class Type>
|
||||
bool writeValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalarField& weightField,
|
||||
const bool orient
|
||||
);
|
||||
|
||||
//- Filter a surface field according to faceIds
|
||||
template<class Type>
|
||||
tmp<Field<Type>> filterField
|
||||
(
|
||||
const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
|
||||
const bool applyOrientation
|
||||
) const;
|
||||
|
||||
//- Filter a volume field according to faceIds
|
||||
template<class Type>
|
||||
tmp<Field<Type>> filterField
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& field,
|
||||
const bool applyOrientation
|
||||
) const;
|
||||
|
||||
//- Read from dictionary
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate and write
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
//- Specialisation for scalar
|
||||
template<>
|
||||
scalar surfaceFieldValue::processValues
|
||||
(
|
||||
const Field<scalar>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const;
|
||||
|
||||
|
||||
//- Specialisation for vector
|
||||
template<>
|
||||
vector surfaceFieldValue::processValues
|
||||
(
|
||||
const Field<vector>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fieldValues
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "surfaceFieldValueI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "surfaceFieldValueTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "surfaceFieldValue.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes&
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::regionType() const
|
||||
{
|
||||
return regionType_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::faceId() const
|
||||
{
|
||||
return faceId_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::facePatch() const
|
||||
{
|
||||
return facePatchId_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::faceSign() const
|
||||
{
|
||||
return faceSign_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::outputDir() const
|
||||
{
|
||||
return baseFileDir()/name()/"surface"/obr_.time().timeName();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,448 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "surfaceFieldValue.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "volFields.H"
|
||||
#include "sampledSurface.H"
|
||||
#include "surfaceWriter.H"
|
||||
#include "interpolationCellPoint.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::fieldValues::surfaceFieldValue::validField
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
|
||||
if (regionType_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (obr_.foundObject<vf>(fieldName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C
|
||||
Foam::tmp<Foam::Field<Type>> Foam::fieldValues::faceSource::setFieldValues
|
||||
=======
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
|
||||
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C
|
||||
(
|
||||
const word& fieldName,
|
||||
const bool mustGet,
|
||||
const bool applyOrientation
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
|
||||
if (regionType_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
|
||||
{
|
||||
return filterField(obr_.lookupObject<sf>(fieldName), applyOrientation);
|
||||
}
|
||||
else if (obr_.foundObject<vf>(fieldName))
|
||||
{
|
||||
const vf& fld = obr_.lookupObject<vf>(fieldName);
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
if (surfacePtr_().interpolate())
|
||||
{
|
||||
const interpolationCellPoint<Type> interp(fld);
|
||||
tmp<Field<Type>> tintFld(surfacePtr_().interpolate(interp));
|
||||
const Field<Type>& intFld = tintFld();
|
||||
|
||||
// Average
|
||||
const faceList& faces = surfacePtr_().faces();
|
||||
tmp<Field<Type>> tavg
|
||||
(
|
||||
new Field<Type>(faces.size(), Zero)
|
||||
);
|
||||
Field<Type>& avg = tavg.ref();
|
||||
|
||||
forAll(faces, facei)
|
||||
{
|
||||
const face& f = faces[facei];
|
||||
forAll(f, fp)
|
||||
{
|
||||
avg[facei] += intFld[f[fp]];
|
||||
}
|
||||
avg[facei] /= f.size();
|
||||
}
|
||||
|
||||
return tavg;
|
||||
}
|
||||
else
|
||||
{
|
||||
return surfacePtr_().sample(fld);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return filterField(fld, applyOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
if (mustGet)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Field " << fieldName << " not found in database"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return tmp<Field<Type>>(new Field<Type>(0));
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||
processSameTypeValues
|
||||
(
|
||||
const Field<Type>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
Type result = Zero;
|
||||
switch (operation_)
|
||||
{
|
||||
case opSum:
|
||||
{
|
||||
result = gSum(values);
|
||||
break;
|
||||
}
|
||||
case opSumMag:
|
||||
{
|
||||
result = gSum(cmptMag(values));
|
||||
break;
|
||||
}
|
||||
case opSumDirection:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Operation " << operationTypeNames_[operation_]
|
||||
<< " not available for values of type "
|
||||
<< pTraits<Type>::typeName
|
||||
<< exit(FatalError);
|
||||
|
||||
result = Zero;
|
||||
break;
|
||||
}
|
||||
case opSumDirectionBalance:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Operation " << operationTypeNames_[operation_]
|
||||
<< " not available for values of type "
|
||||
<< pTraits<Type>::typeName
|
||||
<< exit(FatalError);
|
||||
|
||||
result = Zero;
|
||||
break;
|
||||
}
|
||||
case opAverage:
|
||||
{
|
||||
label n = returnReduce(values.size(), sumOp<label>());
|
||||
result = gSum(values)/(scalar(n) + ROOTVSMALL);
|
||||
break;
|
||||
}
|
||||
case opWeightedAverage:
|
||||
{
|
||||
label wSize = returnReduce(weightField.size(), sumOp<label>());
|
||||
|
||||
if (wSize > 0)
|
||||
{
|
||||
result =
|
||||
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
|
||||
}
|
||||
else
|
||||
{
|
||||
label n = returnReduce(values.size(), sumOp<label>());
|
||||
result = gSum(values)/(scalar(n) + ROOTVSMALL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case opAreaAverage:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
result = gSum(magSf*values)/gSum(magSf);
|
||||
break;
|
||||
}
|
||||
case opWeightedAreaAverage:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
label wSize = returnReduce(weightField.size(), sumOp<label>());
|
||||
|
||||
if (wSize > 0)
|
||||
{
|
||||
result = gSum(weightField*magSf*values)/gSum(magSf*weightField);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = gSum(magSf*values)/gSum(magSf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case opAreaIntegrate:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
result = gSum(magSf*values);
|
||||
break;
|
||||
}
|
||||
case opMin:
|
||||
{
|
||||
result = gMin(values);
|
||||
break;
|
||||
}
|
||||
case opMax:
|
||||
{
|
||||
result = gMax(values);
|
||||
break;
|
||||
}
|
||||
case opCoV:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
const scalar gSumMagSf = gSum(magSf);
|
||||
|
||||
Type meanValue = gSum(values*magSf)/gSumMagSf;
|
||||
|
||||
const label nComp = pTraits<Type>::nComponents;
|
||||
|
||||
for (direction d=0; d<nComp; ++d)
|
||||
{
|
||||
scalarField vals(values.component(d));
|
||||
scalar mean = component(meanValue, d);
|
||||
scalar& res = setComponent(result, d);
|
||||
|
||||
res =
|
||||
sqrt(gSum(magSf*sqr(vals - mean))/gSumMagSf)
|
||||
/(mean + ROOTVSMALL);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case opAreaNormalAverage:
|
||||
{}
|
||||
case opAreaNormalIntegrate:
|
||||
{}
|
||||
case opNone:
|
||||
{}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
|
||||
(
|
||||
const Field<Type>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
return processSameTypeValues(values, Sf, weightField);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalarField& weightField,
|
||||
const bool orient
|
||||
)
|
||||
{
|
||||
const bool ok = validField<Type>(fieldName);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Field<Type> values(setFieldValues<Type>(fieldName, true, orient));
|
||||
|
||||
vectorField Sf;
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
// Get oriented Sf
|
||||
Sf = surfacePtr_().Sf();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get oriented Sf
|
||||
Sf = filterField(mesh_.Sf(), true);
|
||||
}
|
||||
|
||||
// Write raw values on surface if specified
|
||||
if (surfaceWriterPtr_.valid())
|
||||
{
|
||||
Field<Type> allValues(values);
|
||||
combineFields(allValues);
|
||||
|
||||
faceList faces;
|
||||
pointField points;
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
combineSurfaceGeometry(faces, points);
|
||||
}
|
||||
else
|
||||
{
|
||||
combineMeshGeometry(faces, points);
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
surfaceWriterPtr_->write
|
||||
(
|
||||
outputDir(),
|
||||
regionTypeNames_[regionType_] + ("_" + regionName_),
|
||||
points,
|
||||
faces,
|
||||
fieldName,
|
||||
allValues,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (operation_ != opNone)
|
||||
{
|
||||
// Apply scale factor
|
||||
values *= scaleFactor_;
|
||||
|
||||
Type result = processValues(values, Sf, weightField);
|
||||
|
||||
file()<< tab << result;
|
||||
|
||||
Log << " " << operationTypeNames_[operation_]
|
||||
<< "(" << regionName_ << ") of " << fieldName
|
||||
<< " = " << result << endl;
|
||||
|
||||
// Write state/results information
|
||||
const word& opName = operationTypeNames_[operation_];
|
||||
word resultName =
|
||||
opName + '(' + sourceName_ + ',' + fieldName + ')';
|
||||
this->setResult(resultName, result);
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& field,
|
||||
const bool applyOrientation
|
||||
) const
|
||||
{
|
||||
tmp<Field<Type>> tvalues(new Field<Type>(faceId_.size()));
|
||||
Field<Type>& values = tvalues.ref();
|
||||
|
||||
forAll(values, i)
|
||||
{
|
||||
label facei = faceId_[i];
|
||||
label patchi = facePatchId_[i];
|
||||
if (patchi >= 0)
|
||||
{
|
||||
values[i] = field.boundaryField()[patchi][facei];
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):"
|
||||
<< nl
|
||||
<< " Unable to process internal faces for volume field "
|
||||
<< field.name() << nl << abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
if (applyOrientation)
|
||||
{
|
||||
forAll(values, i)
|
||||
{
|
||||
values[i] *= faceSign_[i];
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
|
||||
(
|
||||
const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
|
||||
const bool applyOrientation
|
||||
) const
|
||||
{
|
||||
tmp<Field<Type>> tvalues(new Field<Type>(faceId_.size()));
|
||||
Field<Type>& values = tvalues.ref();
|
||||
|
||||
forAll(values, i)
|
||||
{
|
||||
label facei = faceId_[i];
|
||||
label patchi = facePatchId_[i];
|
||||
if (patchi >= 0)
|
||||
{
|
||||
values[i] = field.boundaryField()[patchi][facei];
|
||||
}
|
||||
else
|
||||
{
|
||||
values[i] = field[facei];
|
||||
}
|
||||
}
|
||||
|
||||
if (applyOrientation)
|
||||
{
|
||||
forAll(values, i)
|
||||
{
|
||||
values[i] *= faceSign_[i];
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user