From 6341de384d4343517deb9b1d976ab2f4d34e8b67 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 11 Nov 2013 12:59:21 +0000 Subject: [PATCH] ENH: faceSource function object - updates and fixes --- .../field/fieldValues/faceSource/faceSource.C | 52 +++++++++++-------- .../field/fieldValues/faceSource/faceSource.H | 10 +++- .../faceSource/faceSourceTemplates.C | 29 ++++++++++- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index ee3b626562..054ef40423 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -48,11 +48,13 @@ namespace Foam template<> - const char* NamedEnum::names[] = + const char* NamedEnum::names[] = { "none", "sum", + "sumMag", "sumDirection", + "sumDirectionBalance", "average", "weightedAverage", "areaAverage", @@ -75,7 +77,7 @@ namespace Foam const Foam::NamedEnum Foam::fieldValues::faceSource::sourceTypeNames_; -const Foam::NamedEnum +const Foam::NamedEnum 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")); + 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)); - 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]; - } - } - - 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_(), diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index 9af8c7c342..d58f1d9a57 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -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 operationTypeNames_; + static const NamedEnum operationTypeNames_; private: @@ -237,6 +242,9 @@ protected: //- Weight field name - optional word weightFieldName_; + //- Scale factor - optional + scalar scaleFactor_; + //- Global number of faces label nFaces_; diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index 8177946ffc..be7fb428e6 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -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::zero; break; } + case opSumDirectionBalance: + { + FatalErrorIn + ( + "template" + "Type Foam::fieldValues::faceSource::processSameTypeValues" + "(" + "const Field&, " + "const vectorField&, " + "const scalarField&" + ") const" + ) + << "Operation " << operationTypeNames_[operation_] + << " not available for values of type " + << pTraits::typeName + << exit(FatalError); + + result = pTraits::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()) {