CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Area Weighted Average (https://www.cfd-online.com/Forums/openfoam-post-processing/78345-area-weighted-average.html)

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.

Regards,
Stefan

santos July 20, 2010 05:49

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

Regards,
Jose Santos

WiWo February 28, 2011 18:17

Hi!

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!
Cheers,
Wolfgang

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 &

Regards,
Jose

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 :-)

Cheers,
Wolfgang

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 ...

srv537 February 16, 2017 08:54

Quote:

Originally Posted by santos (Post 297388)
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 &

Regards,
Jose

Hi santos,
actually, I am using OpenFOAM4 and interested to find Area Weighted Average for each time step.
I modified pimplefoam and it calculates gradT and average of gradT over patch surface.
Quote:

gradT.boundaryFieldRef()[patchi]=T.boundaryFieldRef()[patchi].snGrad();

scalar area1 = gSum(mesh.magSf().boundaryField()[patchi]);
scalar sumField1 = 0;

if (area1 > 0)
{
sumField1 = gSum
(
mesh.magSf().boundaryField()[patchi]
* gradT.boundaryField()[patchi]
)/ area1;
}

Info<< " Average of gradT over patch 1 = " << sumField1 << endl;
and then i use to calculate Nu=(L/deltaT)*gradT.

in openfoam4 i have used
"mypimpleFoam -postProcess -func 'patchAverage(name=HEATEDWALL,gradT)' >log"
but it gives me Zero value and only at those time that i have saved for postProcessing.

Region type : patch HEATEDWALL
# Faces : 351
# Area : 3.50000000e-03
# Time average(gradT)
0 0.00000000e+00
1 0.00000000e+00
2 0.00000000e+00
3 0.00000000e+00
4 0.00000000e+00
5 0.00000000e+00
6 0.00000000e+00
7 0.00000000e+00
8 0.00000000e+00
9 0.00000000e+00
10 0.00000000e+00
10 0.00000000e+00

I want to save average(gradT) and average(wallShearStress) that i have calculated by " mypimpleFoam -postProcess -func wallShearStress" at all time step how can i do this, please suggest me.

Kind Regards,
srv


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