diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 14a6fa310e7d7cad49c36119fc7d1a1b8eeec0f4..d69ac989ad92813cd1b93a1469f666aa540d3a71 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<fieldValues::faceSource::operationType, 11>::names[] = + const char* NamedEnum<fieldValues::faceSource::operationType, 12>::names[] = { "none", "sum", + "sumDirection", "average", "weightedAverage", "areaAverage", @@ -74,7 +75,7 @@ namespace Foam const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3> Foam::fieldValues::faceSource::sourceTypeNames_; -const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 11> +const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 12> 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<scalar>& 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 42bc27a311e5a10764a72c73da2555e801894c66..9af8c7c3424ec0c30d12102df70bab35b83a176a 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<operationType, 11> operationTypeNames_; + static const NamedEnum<operationType, 12> 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<scalar>& 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 a82f4890361b3de7284e28a9606fdddaf14fc844..8177946ffc332295680f1dddd52764d79e756ae5 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<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(); diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C index 5cb2faa3b69d207a9f0dcc23541af9314372b8b2..50d47d8198f2303682fff96fa3e922c1c71da804 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<Switch>("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<word>("sourceName", "sampledSurface")), diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H index 1b2f2621e7b240737f6e5953356bd5d252a07019..b7994383d51c83321dcfe7a9dafc78af610af5ba 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 aaee816af205747697031b269fc8e62c63044d52..55651a3539ed50705d18fe6a75cf10f4425e9d59 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_;