diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 14a6fa310e..d69ac989ad 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,10 +48,11 @@ namespace Foam template<> - const char* NamedEnum::names[] = + const char* NamedEnum::names[] = { "none", "sum", + "sumDirection", "average", "weightedAverage", "areaAverage", @@ -74,7 +75,7 @@ namespace Foam const Foam::NamedEnum Foam::fieldValues::faceSource::sourceTypeNames_; -const Foam::NamedEnum +const Foam::NamedEnum Foam::fieldValues::faceSource::operationTypeNames_; @@ -486,6 +487,46 @@ void Foam::fieldValues::faceSource::writeFileHeader(const label i) } +template<> +Foam::scalar Foam::fieldValues::faceSource::processValues +( + const Field& values, + const vectorField& Sf, + const scalarField& weightField +) const +{ + switch (operation_) + { + 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]; + } + } + + return v; + } + default: + { + // Fall through to other operations + return processSameTypeValues(values, Sf, weightField); + } + } +} + + template<> Foam::vector Foam::fieldValues::faceSource::processValues ( @@ -496,14 +537,35 @@ Foam::vector Foam::fieldValues::faceSource::processValues { switch (operation_) { + case opSumDirection: + { + const vector direction(dict_.lookup("direction")); + + vector v(vector::zero); + + forAll(Sf, i) + { + scalar d = Sf[i] & direction; + if (d > 0) + { + v += pos(values[i] & direction)*values[i]; + } + else + { + v += neg(values[i] & direction)*values[i]; + } + } + + return v; + } case opAreaNormalAverage: { - scalar result = sum(values&Sf)/sum(mag(Sf)); + scalar result = sum(values & Sf)/sum(mag(Sf)); return vector(result, 0.0, 0.0); } case opAreaNormalIntegrate: { - scalar result = sum(values&Sf); + scalar result = sum(values & Sf); return vector(result, 0.0, 0.0); } default: diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index 42bc27a311..9af8c7c342 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -87,6 +87,7 @@ Description \plaintable none | no operation sum | sum + sumDirection | sum values which are positive in given direction average | ensemble average weightedAverage | weighted average areaAverage | area weighted average @@ -176,6 +177,7 @@ public: { opNone, opSum, + opSumDirection, opAverage, opWeightedAverage, opAreaAverage, @@ -188,7 +190,7 @@ public: }; //- Operation type names - static const NamedEnum operationTypeNames_; + static const NamedEnum operationTypeNames_; private: @@ -366,8 +368,17 @@ public: }; -//- Specialisation of processing vectors for opAreaNormalAverage, -// opAreaNormalIntegrate (use inproduct - dimension reducing operation) +//- Specialisation of processing scalars +template<> +scalar faceSource::processValues +( + const Field& values, + const vectorField& Sf, + const scalarField& weightField +) const; + + +//- Specialisation of processing vectors template<> vector faceSource::processValues ( diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index a82f489036..8177946ffc 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -141,6 +141,26 @@ Type Foam::fieldValues::faceSource::processSameTypeValues result = sum(values); break; } + case opSumDirection: + { + 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(); diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C index 5cb2faa3b6..50d47d8198 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,6 +43,8 @@ void Foam::fieldValue::read(const dictionary& dict) { if (active_) { + dict_ = dict; + log_ = dict.lookupOrDefault("log", false); dict.lookup("fields") >> fields_; dict.lookup("valueOutput") >> valueOutput_; @@ -78,6 +80,7 @@ Foam::fieldValue::fieldValue functionObjectFile(obr, name, valueType), name_(name), obr_(obr), + dict_(dict), active_(true), log_(false), sourceName_(dict.lookupOrDefault("sourceName", "sampledSurface")), diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H index 1b2f2621e7..b7994383d5 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -75,6 +75,9 @@ protected: //- Database this class is registered to const objectRegistry& obr_; + //- Construction dictionary + dictionary dict_; + //- Active flag bool active_; @@ -149,6 +152,9 @@ public: //- Return the reference to the object registry inline const objectRegistry& obr() const; + //- Return the reference to the construction dictionary + inline const dictionary& dict() const; + //- Return the active flag inline bool active() const; diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H index aaee816af2..55651a3539 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,6 +40,12 @@ inline const Foam::objectRegistry& Foam::fieldValue::obr() const } +inline const Foam::dictionary& Foam::fieldValue::dict() const +{ + return dict_; +} + + inline bool Foam::fieldValue::active() const { return active_;