View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002452 | OpenFOAM | Contribution | public | 2017-02-06 13:43 | 2017-02-06 15:56 |
Reporter | tniemi | Assigned To | henry | ||
Priority | low | Severity | feature | Reproducibility | N/A |
Status | resolved | Resolution | fixed | ||
Fixed in Version | dev | ||||
Summary | 0002452: Weighted sum option for surfaceFieldValue and volFieldValue | ||||
Description | It appears that the surfaceFieldValue and volFieldValue function objects are lacking weighted sum operations, only weighted averages are available. Calculating weighted sums is useful for eg. calculating the total flow of a scalar using phi or alphaRhoPhi as a weight field. I have attached a minimal patch, which adds weighted sums and weighted integral ops to surfaceFieldValue and volFieldValue. | ||||
Tags | No tags attached. | ||||
|
patch.diff (8,662 bytes)
diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index b532696..8d602e3 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -65,11 +65,12 @@ template<> const char* Foam::NamedEnum < Foam::functionObjects::fieldValues::surfaceFieldValue::operationType, - 15 + 17 >::names[] = { "none", "sum", + "weightedSum", "sumMag", "sumDirection", "sumDirectionBalance", @@ -78,6 +79,7 @@ const char* Foam::NamedEnum "areaAverage", "weightedAreaAverage", "areaIntegrate", + "weightedAreaIntegrate", "min", "max", "CoV", @@ -94,7 +96,7 @@ const Foam::NamedEnum const Foam::NamedEnum < Foam::functionObjects::fieldValues::surfaceFieldValue::operationType, - 15 + 17 > Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_; diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H index 7a58ba5..c94c108 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H @@ -116,6 +116,7 @@ Usage \plaintable none | no operation sum | sum + weightedSum | weighted sum sumMag | sum of component magnitudes sumDirection | sum values which are positive in given direction sumDirectionBalance | sum of balance of values in given direction @@ -124,6 +125,7 @@ Usage areaAverage | area weighted average weightedAreaAverage | weighted area average areaIntegrate | area integral + weightedAreaIntegrate | weighted area integral min | minimum max | maximum CoV | coefficient of variation: standard deviation/mean @@ -209,6 +211,7 @@ public: { opNone, opSum, + opWeightedSum, opSumMag, opSumDirection, opSumDirectionBalance, @@ -217,6 +220,7 @@ public: opAreaAverage, opWeightedAreaAverage, opAreaIntegrate, + opWeightedAreaIntegrate, opMin, opMax, opCoV, @@ -225,7 +229,7 @@ public: }; //- Operation type names - static const NamedEnum<operationType, 15> operationTypeNames_; + static const NamedEnum<operationType, 17> operationTypeNames_; private: diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C index cfcd2c2..308b73d 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C @@ -141,6 +141,18 @@ processSameTypeValues result = sum(values); break; } + case opWeightedSum: + { + if (weightField.size()) + { + result = sum(weightField*values); + } + else + { + result = sum(values); + } + break; + } case opSumMag: { result = sum(cmptMag(values)); @@ -213,6 +225,20 @@ processSameTypeValues result = sum(magSf*values); break; } + case opWeightedAreaIntegrate: + { + const scalarField magSf(mag(Sf)); + + if (weightField.size()) + { + result = sum(weightField*magSf*values); + } + else + { + result = sum(magSf*values); + } + break; + } case opMin: { result = min(values); diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C index 5f3667e..89a92ce 100644 --- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C +++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C @@ -48,17 +48,19 @@ const char* Foam::NamedEnum < Foam::functionObjects::fieldValues::volFieldValue::operationType, - 11 + 13 >::names[] = { "none", "sum", + "weightedSum", "sumMag", "average", "weightedAverage", "volAverage", "weightedVolAverage", "volIntegrate", + "weightedVolIntegrate", "min", "max", "CoV" @@ -67,7 +69,7 @@ Foam::NamedEnum const Foam::NamedEnum < Foam::functionObjects::fieldValues::volFieldValue::operationType, - 11 + 13 > Foam::functionObjects::fieldValues::volFieldValue::operationTypeNames_; diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H index d8d94b5..112f8be 100644 --- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H +++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.H @@ -79,17 +79,19 @@ Usage The \c operation is one of: \plaintable - none | No operation - sum | Sum - sumMag | Sum of component magnitudes - average | Ensemble average - weightedAverage | Weighted average - volAverage | Volume weighted average - weightedVolAverage | Weighted volume average - volIntegrate | Volume integral - min | Minimum - max | Maximum - CoV | Coefficient of variation: standard deviation/mean + none | No operation + sum | Sum + weightedSum | Weighted sum + sumMag | Sum of component magnitudes + average | Ensemble average + weightedAverage | Weighted average + volAverage | Volume weighted average + weightedVolAverage | Weighted volume average + volIntegrate | Volume integral + weightedVolIntegrate | Weighted volume integral + min | Minimum + max | Maximum + CoV | Coefficient of variation: standard deviation/mean \endplaintable See also @@ -136,19 +138,21 @@ public: { opNone, opSum, + opWeightedSum, opSumMag, opAverage, opWeightedAverage, opVolAverage, opWeightedVolAverage, opVolIntegrate, + opWeightedVolIntegrate, opMin, opMax, opCoV }; //- Operation type names - static const NamedEnum<operationType, 11> operationTypeNames_; + static const NamedEnum<operationType, 13> operationTypeNames_; protected: @@ -158,7 +162,7 @@ protected: //- Operation to apply to values operationType operation_; - //- Weight field name - only used for opWeightedAverage mode + //- Weight field name - only used for weighted modes word weightFieldName_; diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C index 54b9e2d..0234af5 100644 --- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C +++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValueTemplates.C @@ -87,6 +87,11 @@ Type Foam::functionObjects::fieldValues::volFieldValue::processValues result = gSum(values); break; } + case opWeightedSum: + { + result = gSum(weightField*values); + break; + } case opSumMag: { result = gSum(cmptMag(values)); @@ -117,6 +122,11 @@ Type Foam::functionObjects::fieldValues::volFieldValue::processValues result = gSum(V*values); break; } + case opWeightedVolIntegrate: + { + result = gSum(weightField*V*values); + break; + } case opMin: { result = gMin(values); |
|
Thanks Timo. Resolved by commit f5b91be3d98376b8787e7d0a6b31ebdc2395757f |
Date Modified | Username | Field | Change |
---|---|---|---|
2017-02-06 13:43 | tniemi | New Issue | |
2017-02-06 13:43 | tniemi | File Added: patch.diff | |
2017-02-06 15:38 | wyldckat | Relationship added | related to 0001270 |
2017-02-06 15:38 | wyldckat | Relationship added | related to 0000688 |
2017-02-06 15:56 | henry | Assigned To | => henry |
2017-02-06 15:56 | henry | Status | new => resolved |
2017-02-06 15:56 | henry | Resolution | open => fixed |
2017-02-06 15:56 | henry | Fixed in Version | => dev |
2017-02-06 15:56 | henry | Note Added: 0007711 |