/*---------------------------------------------------------------------------*\
========= |
\\ / 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-2020 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"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::canWeight
(
const Field& weightField
) const
{
return
(
usesWeight()
&& returnReduce(!weightField.empty(), orOp()) // On some processor
);
}
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_)
{
if (sampledPtr_->interpolate())
{
const interpolationCellPoint interp(fld);
return sampledPtr_->interpolate(interp);
}
else
{
const interpolationCell interp(fld);
return sampledPtr_->sample(interp);
}
}
else
{
return filterField(fld);
}
}
if (mandatory)
{
FatalErrorInFunction
<< "Field " << fieldName << " not found in database"
<< 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 (canWeight(weightField))
{
tmp weight(weightingFactor(weightField));
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 (canWeight(weightField))
{
const scalarField factor(weightingFactor(weightField));
result = gSum(factor*values)/(gSum(factor) + ROOTVSMALL);
}
else
{
// Unweighted form
const label n = returnReduce(values.size(), sumOp