/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2022 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 .
\*---------------------------------------------------------------------------*/
#include "surfaceFieldValue.H"
#include "surfaceFields.H"
#include "polySurfaceFields.H"
#include "volFields.H"
#include "sampledSurface.H"
#include "surfaceWriter.H"
#include "interpolationCell.H"
#include "interpolationCellPoint.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template
Foam::tmp
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
(
const Field& weightField,
const bool useMag /* ignore */
)
{
// The scalar form is specialized.
// Other types: use mag() to generate a scalar field.
return mag(weightField);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::canWeight
(
const Field& fld
) const
{
// Non-empty on some processor
return returnReduceOr(!fld.empty());
}
template
bool Foam::functionObjects::fieldValues::surfaceFieldValue::validField
(
const word& fieldName
) const
{
typedef GeometricField sf;
typedef GeometricField vf;
typedef DimensionedField smt;
return
(
foundObject(fieldName)
|| foundObject(fieldName)
|| (withSurfaceFields() && foundObject(fieldName))
);
}
template
Foam::tmp>
Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
(
const word& fieldName,
const bool mandatory
) const
{
typedef GeometricField sf;
typedef GeometricField vf;
typedef DimensionedField smt;
if (foundObject(fieldName))
{
return lookupObject(fieldName);
}
else if (withSurfaceFields() && foundObject(fieldName))
{
return filterField(lookupObject(fieldName));
}
else if (foundObject(fieldName))
{
const vf& fld = lookupObject(fieldName);
if (sampledPtr_)
{
// Could be runtime selectable
// auto sampler = interpolation::New(sampleFaceScheme_, fld);
// const interpolationCellPoint interp(fld);
const interpolationCell interp(fld);
return sampledPtr_->sample(interp);
}
else
{
return filterField(fld);
}
}
if (mandatory)
{
FatalErrorInFunction
<< "Field " << fieldName << " not found in database" << nl
<< abort(FatalError);
}
return tmp>::New();
}
template
Type Foam::functionObjects::fieldValues::surfaceFieldValue::
processSameTypeValues
(
const Field& values,
const vectorField& Sf,
const Field& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opNone:
{
break;
}
case opMin:
{
result = gMin(values);
break;
}
case opMax:
{
result = gMax(values);
break;
}
case opSumMag:
{
result = gSum(cmptMag(values));
break;
}
case opSum:
case opWeightedSum:
case opAbsWeightedSum:
{
if (is_weightedOp() && canWeight(weightField))
{
tmp weight
(
weightingFactor(weightField, Sf, is_magOp())
);
result = gSum(weight*values);
}
else
{
// Unweighted form
result = gSum(values);
}
break;
}
case opSumDirection:
case opSumDirectionBalance:
{
FatalErrorInFunction
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits::typeName
<< exit(FatalError);
break;
}
case opAverage:
case opWeightedAverage:
case opAbsWeightedAverage:
{
if (is_weightedOp() && canWeight(weightField))
{
const scalarField factor
(
weightingFactor(weightField, Sf, is_magOp())
);
result = gSum(factor*values)/(gSum(factor) + ROOTVSMALL);
}
else
{
// Unweighted form
const label n = returnReduce(values.size(), sumOp