From 04c715a19b6c4bece2984e1db0bb5d2d8e2871e1 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 20 Mar 2012 14:14:49 +0000 Subject: [PATCH] ENH: faceSource: add area-normal integration or averaging --- .../field/fieldValues/controlDict | 15 ++-- .../field/fieldValues/faceSource/faceSource.C | 37 +++++++++- .../field/fieldValues/faceSource/faceSource.H | 45 +++++++++-- .../faceSource/faceSourceTemplates.C | 74 ++++++++++++++++--- 4 files changed, 139 insertions(+), 32 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldValues/controlDict b/src/postProcessing/functionObjects/field/fieldValues/controlDict index 24b3ddbad4..ff5007f18d 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/controlDict +++ b/src/postProcessing/functionObjects/field/fieldValues/controlDict @@ -67,17 +67,14 @@ functions sourceName movingWall; //// if sampledSurface: dictionary with a sampledSurface - //// Note: the sampledSurfaces will have cell-values, i.e. - //// non-interpolated. Also will not sample surface fields. + //// Note: will not sample surface fields. //sampledSurfaceDict //{ - // type cuttingPlane; - // planeType pointAndNormal; - // pointAndNormalDict - // { - // basePoint (0 0.099 0); - // normalVector (0 1 0); - // } + // // Sampling on triSurface + // type sampledTriSurfaceMesh; + // surface integrationPlane.stl; + // source cells; // sample cells or boundaryFaces + // interpolate true; //} // Operation: areaAverage/sum/weightedAverage ... diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 97f244c60b..6ce7b3350d 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -53,7 +53,7 @@ namespace Foam const char* Foam::NamedEnum < Foam::fieldValues::faceSource::operationType, - 9 + 11 >::names[] = { "none", @@ -64,7 +64,9 @@ namespace Foam "areaIntegrate", "min", "max", - "CoV" + "CoV", + "areaNormalAverage", + "areaNormalIntegrate" }; } @@ -73,7 +75,7 @@ namespace Foam const Foam::NamedEnum Foam::fieldValues::faceSource::sourceTypeNames_; -const Foam::NamedEnum +const Foam::NamedEnum Foam::fieldValues::faceSource::operationTypeNames_; @@ -313,6 +315,35 @@ void Foam::fieldValues::faceSource::writeFileHeader() } +template<> +Foam::vector Foam::fieldValues::faceSource::processValues +( + const Field& values, + const vectorField& Sf, + const scalarField& weightField +) const +{ + switch (operation_) + { + case opAreaNormalAverage: + { + scalar result = sum(values&Sf)/sum(mag(Sf)); + return vector(result, 0.0, 0.0); + } + case opAreaNormalIntegrate: + { + scalar result = sum(values&Sf); + return vector(result, 0.0, 0.0); + } + default: + { + // Fall through to other operations + return processSameTypeValues(values, Sf, weightField); + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::fieldValues::faceSource::faceSource diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index b7a2924035..fd95788894 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 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -65,7 +65,9 @@ Description - min - max - CoV (Coefficient of variation: standard deviation/mean) - + - areaNormalAverage (vector with first component (average of) inproduct + of value and face area vector) + - areaNormalIntegrate ( ,, ,, (sum of) ,, Notes: - faces on empty patches get ignored @@ -75,7 +77,11 @@ Description negative pressure) - using sampledSurfaces: - they do not do surface fields - - they use cell values - they do not do any interpolation. + - if interpolate=true they use interpolationCellPoint + otherwise they use cell values + - each triangle in sampledSurface is logically only in one cell + so interpolation will be wrong when triangles are larger than + cells. This can only happen for sampling on triSurfaceMesh. - take care when using isoSurfaces - these might have duplicate triangles so integration might be wrong @@ -138,11 +144,13 @@ public: opAreaIntegrate, opMin, opMax, - opCoV + opCoV, + opAreaNormalAverage, + opAreaNormalIntegrate }; //- Operation type names - static const NamedEnum operationTypeNames_; + static const NamedEnum operationTypeNames_; private: @@ -194,7 +202,6 @@ protected: autoPtr surfacePtr_; - // Protected Member Functions //- Initialise, e.g. face addressing @@ -212,12 +219,23 @@ protected: const bool mustGet = false ) const; - //- Apply the 'operation' to the values + //- Apply the 'operation' to the values. Operation has to + // preserve Type. + template + Type processSameTypeValues + ( + const Field& values, + const vectorField& Sf, + const scalarField& weightField + ) const; + + //- Apply the 'operation' to the values. Wrapper around + // processSameTypeValues. See also template specialisation below. template Type processValues ( const Field& values, - const scalarField& magSf, + const vectorField& Sf, const scalarField& weightField ) const; @@ -292,6 +310,17 @@ public: }; +//- Specialisation of processing vectors for opAreaNormalAverage, +// opAreaNormalIntegrate (use inproduct - dimension reducing operation) +template<> +vector faceSource::processValues +( + const Field& values, + const vectorField& Sf, + const scalarField& weightField +) const; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace fieldValues diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index 79c031818f..892593d036 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -27,6 +27,7 @@ License #include "surfaceFields.H" #include "volFields.H" #include "sampledSurface.H" +#include "interpolationCellPoint.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -65,13 +66,44 @@ Foam::tmp > Foam::fieldValues::faceSource::getFieldValues } else if (obr_.foundObject(fieldName)) { + const vf& fld = obr_.lookupObject(fieldName); + if (surfacePtr_.valid()) { - return surfacePtr_().sample(obr_.lookupObject(fieldName)); + if (surfacePtr_().interpolate()) + { + const interpolationCellPoint interp(fld); + tmp > tintFld(surfacePtr_().interpolate(interp)); + const Field& intFld = tintFld(); + + // Average + const faceList& faces = surfacePtr_().faces(); + tmp > tavg + ( + new Field(faces.size(), pTraits::zero) + ); + Field& avg = tavg(); + + forAll(faces, faceI) + { + const face& f = faces[faceI]; + forAll(f, fp) + { + avg[faceI] += intFld[f[fp]]; + } + avg[faceI] /= f.size(); + } + + return tavg; + } + else + { + return surfacePtr_().sample(fld); + } } else { - return filterField(obr_.lookupObject(fieldName), true); + return filterField(fld, true); } } @@ -94,12 +126,11 @@ Foam::tmp > Foam::fieldValues::faceSource::getFieldValues template -Type Foam::fieldValues::faceSource::processValues +Type Foam::fieldValues::faceSource::processSameTypeValues ( const Field& values, - const scalarField& magSf, + const vectorField& Sf, const scalarField& weightField - ) const { Type result = pTraits::zero; @@ -122,11 +153,15 @@ Type Foam::fieldValues::faceSource::processValues } case opAreaAverage: { + const scalarField magSf = mag(Sf); + result = sum(values*magSf)/sum(magSf); break; } case opAreaIntegrate: { + const scalarField magSf = mag(Sf); + result = sum(values*magSf); break; } @@ -142,6 +177,8 @@ Type Foam::fieldValues::faceSource::processValues } case opCoV: { + const scalarField magSf = mag(Sf); + Type meanValue = sum(values*magSf)/sum(magSf); const label nComp = pTraits::nComponents; @@ -169,6 +206,19 @@ Type Foam::fieldValues::faceSource::processValues } +template +Type Foam::fieldValues::faceSource::processValues +( + const Field& values, + const vectorField& Sf, + const scalarField& weightField +) const +{ + return processSameTypeValues(values, Sf, weightField); +} + + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -186,22 +236,22 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) weightField = getFieldValues(weightFieldName_, true); } - scalarField magSf; + vectorField Sf; if (surfacePtr_.valid()) { - // Get unoriented magSf - magSf = surfacePtr_().magSf(); + // Get oriented Sf + Sf = surfacePtr_().Sf(); } else { - // Get unoriented magSf - magSf = filterField(mesh().magSf(), false); + // Get oriented Sf + Sf = filterField(mesh().Sf(), false); } // Combine onto master combineFields(values); - combineFields(magSf); + combineFields(Sf); combineFields(weightField); // apply weight field @@ -210,7 +260,7 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) if (Pstream::master()) { - Type result = processValues(values, magSf, weightField); + Type result = processValues(values, Sf, weightField); if (valueOutput_) {