CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Post-Processing (
-   -   Area Weighted Average (

balkrishna July 19, 2010 09:27

Area Weighted Average
Please can someone document a method to find the area weighted average of a variable in OpenFOAM. The source code is really complex to figure out for someone who has a basic programmers insight. Would be of great help if anyone would do so . The Doxygen documentation is not very helpful either for beginners .All it gives are links to headers files without actual descripton of what a variable is . Also please comment a lot when writing any solver for OpenFOAM . A very good example is the way Linux source code is written. Loads of comments explaining every line in detail.

deepsterblue July 19, 2010 09:55

It's not entirely clear what you intend by an 'area-weighted' average. Do you intend to perform a weighted average based on mesh face-patch values? OpenFOAM is a three-dimensional code, so volume-weighted averages for cell variables are usually the norm.

Either way, you can perform a weighted average (either patch face-areas or cell-volumes) using the DimensionedField member function:

//- Calculate and return weighted average
dimensioned<Type> weightedAverage
const DimensionedField<scalar, GeoMesh>&
) const;

Take a look at $FOAM_SRC/finiteVolume/cfdTools/general/include/volContinuity.H for a cue on how it's done.

Also, writing code is hard work, and documenting it can be often time-consuming, which is why it may not be done at all times. Of course, if you're willing to pay for it, I'm sure you'll find a bunch of people who would oblige.

balkrishna July 20, 2010 01:21

Thanks . But how do i actually use it while solving a case . Like how do I call the function to actually find the volume weighted average .

balkrishna July 20, 2010 05:10

What i want to calculate is the pressure area weighted average on any face ....
sum(Af*p)/sum(A) on the boundary .... how do I go about it ?

herbert July 20, 2010 05:15

If you only want to calculate average values on patches for postprocessing, you can use simpleFunctionObjects.


santos July 20, 2010 05:49

Another option is to run:
patchAverage <field> <patch>

Jose Santos

WiWo February 28, 2011 18:17


Sorry if this comes like a stupid question ...
I was intending to use the patchAverage utility exactly as described above - works fine. BUT - where are the results actually written to? I don't see any additional files being created anywhere ...

Thanks for your help!

santos February 28, 2011 18:21

Results are not written to any file unless you instruct it to, they are just output to the terminal.

If you want to write results to a file 'file' without any output in the terminal you can try:
patchAverage <field> <patch> > file &


WiWo March 1, 2011 20:21

Hi Jose,

Thanks a lot for your expeditious response! I was able to redirect the output of patchAverage to a file.
Unfortunately the style of the output with the accompanying text is not ideal for further processing. Thus I decided to change the code of patchAverage a little :-)


balkrishna March 2, 2011 08:05

instead of meddling with the code i pass the file through tr and awk filters .... and get the output in the format i want it to be ...

All times are GMT -4. The time now is 02:09.