View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0001769||OpenFOAM||[All Projects] Bug||public||2015-06-30 08:26||2015-06-30 20:06|
|Fixed in Version|
|Summary||0001769: wrong calcutation using field function object cellSource weightedAverage|
|Description||The 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.
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 Reproduce||Calculate the mass weighted average of a T field using rho as weightField.|
Compare the results using different meshes (homogeneous and not homogeneous).
|Tags||No tags attached.|
> 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.
Resolved in OpenFOAM-dev by commit 2127051ad542c47ae0652b5783ab1f9a667959f4
cellSource: Added weightedVolAverage option
faceSource: Added weightedAreaAverage option