Commit 6341de38 authored by andy's avatar andy
Browse files

ENH: faceSource function object - updates and fixes

parent 63595880
......@@ -48,11 +48,13 @@ namespace Foam
template<>
const char* NamedEnum<fieldValues::faceSource::operationType, 12>::names[] =
const char* NamedEnum<fieldValues::faceSource::operationType, 14>::names[] =
{
"none",
"sum",
"sumMag",
"sumDirection",
"sumDirectionBalance",
"average",
"weightedAverage",
"areaAverage",
......@@ -75,7 +77,7 @@ namespace Foam
const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>
Foam::fieldValues::faceSource::sourceTypeNames_;
const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 12>
const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 14>
Foam::fieldValues::faceSource::operationTypeNames_;
......@@ -450,6 +452,11 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
Info<< " weight field = " << weightFieldName_;
}
if (dict.readIfPresent("scaleFactor", scaleFactor_))
{
Info<< " scale factor = " << scaleFactor_;
}
Info<< nl << endl;
if (valueOutput_)
......@@ -499,24 +506,15 @@ Foam::scalar Foam::fieldValues::faceSource::processValues
{
case opSumDirection:
{
const vector direction(dict_.lookup("direction"));
scalar v = 0.0;
forAll(Sf, i)
{
scalar d = Sf[i] & direction;
if (d > 0)
{
v += pos(values[i])*values[i];
}
else
{
v += neg(values[i])*values[i];
}
}
vector n(dict_.lookup("direction"));
return sum(pos(values*(Sf & n))*mag(values));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
const scalarField nv(values*(Sf & n));
return v;
return sum(pos(nv)*mag(values) - neg(nv)*mag(values));
}
default:
{
......@@ -539,8 +537,19 @@ Foam::vector Foam::fieldValues::faceSource::processValues
{
case opSumDirection:
{
const vector direction(dict_.lookup("direction"));
return sum(pos(values & direction)*values);
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return sum(pos(nv)*n*(nv));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return sum(pos(nv)*n*(nv));
}
case opAreaNormalAverage:
{
......@@ -576,6 +585,7 @@ Foam::fieldValues::faceSource::faceSource
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
scaleFactor_(1.0),
nFaces_(0),
faceId_(),
facePatchId_(),
......
......@@ -71,6 +71,7 @@ Description
sourceName | name of face source if required | no |
operation | operation to perform | yes |
weightField | name of field to apply weighting | no |
scaleFactor | scale factor | no | 1
fields | list of fields to operate on | yes |
\endtable
......@@ -87,7 +88,9 @@ Description
\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
......@@ -177,7 +180,9 @@ public:
{
opNone,
opSum,
opSumMag,
opSumDirection,
opSumDirectionBalance,
opAverage,
opWeightedAverage,
opAreaAverage,
......@@ -190,7 +195,7 @@ public:
};
//- Operation type names
static const NamedEnum<operationType, 12> operationTypeNames_;
static const NamedEnum<operationType, 14> operationTypeNames_;
private:
......@@ -237,6 +242,9 @@ protected:
//- Weight field name - optional
word weightFieldName_;
//- Scale factor - optional
scalar scaleFactor_;
//- Global number of faces
label nFaces_;
......
......@@ -141,6 +141,11 @@ Type Foam::fieldValues::faceSource::processSameTypeValues
result = sum(values);
break;
}
case opSumMag:
{
result = sum(cmptMag(values));
break;
}
case opSumDirection:
{
FatalErrorIn
......@@ -161,6 +166,26 @@ Type Foam::fieldValues::faceSource::processSameTypeValues
result = pTraits<Type>::zero;
break;
}
case opSumDirectionBalance:
{
FatalErrorIn
(
"template<class Type>"
"Type Foam::fieldValues::faceSource::processSameTypeValues"
"("
"const Field<Type>&, "
"const vectorField&, "
"const scalarField&"
") const"
)
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits<Type>::typeName
<< exit(FatalError);
result = pTraits<Type>::zero;
break;
}
case opAverage:
{
result = sum(values)/values.size();
......@@ -304,8 +329,8 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
);
}
// apply weight field
values *= weightField;
// apply scale factor and weight field
values *= scaleFactor_*weightField;
if (Pstream::master())
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment