View Issue Details

IDProjectCategoryView StatusLast Update
0001769OpenFOAM[All Projects] Bugpublic2015-06-30 20:06
ReporterALUAssigned Tohenry 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version14.04
Product Version 
Fixed in Version 
Summary0001769: wrong calcutation using field function object cellSource weightedAverage
DescriptionThe field function object cellSource calculates wrong values using weightedAverage.

result = sum(values)/sum(weightField)

This only gives right values if every cell in the mesh has the same volume.

The modification

result = sum(values*V)/sum(V*weightField)

gives the right results for some reason. (I would expect result = sum(values*V*weightField)/sum(V*weightField).)

The same problem may occur with faceSorce (not tested).
Steps To ReproduceCalculate the mass weighted average of a T field using rho as weightField.
Compare the results using different meshes (homogeneous and not homogeneous).
TagsNo tags attached.

Activities

henry

2015-06-30 08:47

manager   ~0005021

> gives the right results for some reason.
> (I would expect result = sum(values*V*weightField)/sum(V*weightField).)

This is a consequence of the

        // apply weight field
        values *= weightField;

in writeValues. This separation of operations is VERY confusing, I will look into changing it.

At the moment the volume average and volume integrate multiply by the cell-volumes but weighted average does not; it assumes that if you wanted to weight by rho*V the weighting field would be rho*V. This may be a bit inconvenient but if we include the volumes in the expression it would not be possible to calculate a weighted average without the volumes should it be required. Probably the best solution would be to add a new processing function which calculates the weighted volume average.

henry

2015-06-30 11:21

manager   ~0005026

Resolved in OpenFOAM-dev by commit 2127051ad542c47ae0652b5783ab1f9a667959f4

    cellSource: Added weightedVolAverage option
    faceSource: Added weightedAreaAverage option

Issue History

Date Modified Username Field Change
2015-06-30 08:26 ALU New Issue
2015-06-30 08:47 henry Note Added: 0005021
2015-06-30 11:21 henry Note Added: 0005026
2015-06-30 11:21 henry Status new => resolved
2015-06-30 11:21 henry Resolution open => fixed
2015-06-30 11:21 henry Assigned To => henry