
[Sponsors] 
April 16, 2013, 18:44 
Spatial average over a plane

#1 
New Member
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 4 
Hello,
I want to calculate the average of a physical quantity over a plane in the computational domain during the runtime (not for postprocessing). For example: the average of pressure over the plane z=constant for a cubic computational domain. Anyone who can tell me how to do it? It should be easy to realize this function, but I am new to OpenFOAM and I am not familiar with it. Thanks. 

April 16, 2013, 22:57 

#2 
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 236
Rep Power: 7 
It is quite easy:
 identify your patch  loop over all the faces of your patch  make your calculation Your code can look like this: Code:
label patchWall = mesh.boundaryMesh().findPatchID("wall"); //patchID = id of the patch wall const fvPatch& cPatch = mesh.boundary()[patchWall]; forAll(cPatch, facei) //facei = id of the face { // Make whatever you want } 

April 17, 2013, 07:33 

#3 
New Member
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 4 
Thanks for your reply. Your code could be used to calculate the average on the boundary, but I am not sure if it is available for a given plane inside the computational domain. The plane over which the average is calculated is not necessarily a boundary.


April 17, 2013, 07:37 

#4 
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 236
Rep Power: 7 
Oh ok, then my code only works if you build the mesh with an interface.
Do you need your treatment in the solver ? Or do you simply need the value at the end of each iteration ? In the second case, you can use a sampling function just like the lift and drag function. You can include it inside the Control file and it will write the result of your computation in a dedicated file as you run the simulation. 

April 17, 2013, 07:47 

#5 
Member
Timo K.
Join Date: Feb 2010
Location: University of Stuttgart
Posts: 66
Rep Power: 7 
Have a look for swak4foam this could work


April 17, 2013, 10:37 
Runtime integration/averaging on a computational plane (NOT inlet/outlet patch)

#6 
Senior Member
Jose Rey
Join Date: Oct 2012
Posts: 122
Rep Power: 8 
I have the same question. I would greatly appreciate it if somebody can illustrate how to do this with some level of detail. michel1988, If you do come up with the answer (maybe with the guidance of fredo and Timo), please come back and leave the solution for others to learn from it. I have done this only in postprocessing by resampling and integration using paraview. However, this is prone to errors, since no matter how fine you make your meshes (both model and measurement plane), the measurement errors persist (In my model example, I get that Ux at entry is 5% greater than Ux at exit from the duct). The resampling has to interpolate from one mesh to another and it basically sucks.


April 17, 2013, 13:27 

#7 
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 236
Rep Power: 7 
Did you try to play with the interpolation scheme of the sampling functions ? Some are more accurate than others.
Also, can you give more details about your case ? Maybe a picture of the mesh ? It would help us to find a technique suitable for your case. And by the way, why do you want to do it at each time step ? To check the Mass Balance in your domain ? 

April 18, 2013, 10:20 

#8 
New Member
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 4 
Sorry for the unclear description of my problem. I just want to calculate the spatial average over the directions of homogeneity. For example, the streamwise and spanwise directions in channel flow. I want to employ the averaged information to a turbulence model. That why I need to do it at each time step.
Thanks 

April 18, 2013, 11:16 

#9 
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 236
Rep Power: 7 
Is it a structured of unstructured mesh ?
I know there is a command to find the closest cell center from a given point but the algorithm you have to build is a bit complicated. If it is a structured mesh, you can try to loop over the neighbors cells and make a displacement over "i" or "j". 

April 22, 2013, 08:28 

#10 
New Member
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 4 
The mesh is generated by blockMesh in OpenFOAM. So I think it should be unstructured mesh.


April 23, 2013, 19:43 

#11  
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,911
Rep Power: 40 
Quote:
Somebody else in this thread already suggest swak4Foam. But I'll do it again: the snipplet in the following example for instance gives you the areaweighted average of the zcomponent of the velocity on a plane. Code:
surfacePlane { type swakExpression; valueType surface; surfaceName testPlane; surface { type plane; basePoint (0.0001 0.0001 0.0001); normalVector (0 0 1); interpolate false; } verbose true; expression "U.z"; accumulations ( min max weightedAverage ); }
__________________
Note: I don't use "Friend"feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request 

April 25, 2013, 00:02 

#12  
New Member
Ken Tay
Join Date: Oct 2012
Location: Singapore
Posts: 5
Rep Power: 4 
Quote:
Would you be, by any chance, working on a model that requires the mean strain in the xy plane at all z levels? 

April 25, 2013, 03:23 

#13 
New Member
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 4 
Not exactly but similarly. Although this kind of spatial average may not be necessary (sometimes it is possible to use time average instead), it is better when the flow is homogeneous in the specific directions.


April 25, 2013, 04:37 

#14  
New Member
Ken Tay
Join Date: Oct 2012
Location: Singapore
Posts: 5
Rep Power: 4 
Quote:
Like michel1988, I am looking to implement this spatial averaging within a turbulence model. How would I go about invoking this function within the turbulence file? Also, since I wish to get the spatial average at every z level, if there a way to let the basepoint definition vary dynamically? Thanks 

April 25, 2013, 11:40 

#15  
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,911
Rep Power: 40 
Quote:
Please be more specific about "reference". Only then can I tell you what might work (there ARE ways to access swakresults from the solver. The question is whether it is worth the while for your application) Quote:
__________________
Note: I don't use "Friend"feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request 

April 26, 2013, 00:27 

#16  
New Member
Ken Tay
Join Date: Oct 2012
Location: Singapore
Posts: 5
Rep Power: 4 
Quote:
That is to say at z = 1, I need to get the averages of S_xy, S_xz, S_yz etc at this level and repeat for all z. Then, having obtained the plane average tensor, I will use each strain to compute the respective tau_ij. I will also be using the double inner product of <S_ij> to obtain a scalar parameter. Hence, I first need a runTime function that can do this plane average, then I will need to be able to use the calculated values in the turbulence model at each time step. So when I said "reference", I meant accessing/using the output of the plane averaging function. Yes, thanks for the tip of looking into sampledPlane. I am working on generating the planes at every basepoint. 

April 26, 2013, 05:10 

#17  
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,911
Rep Power: 40 
Quote:
__________________
Note: I don't use "Friend"feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request 

November 30, 2014, 03:41 

#18 
Member
Niu
Join Date: Apr 2014
Posts: 42
Rep Power: 3 
Hi,HECKMANN,
your code is used for averaging based on area, yes? Do you know how to average based on point value? 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Problem with Gmsh  nishant_hull  Open Source Meshers: Gmsh, Netgen, CGNS, ...  18  April 22, 2015 08:43 
y+ and u+ values with lowRe RANS turbulence models: utility + testcase  florian_krause  OpenFOAM  107  March 14, 2015 10:21 
finding average values for a plane in the vertical direction  NJG  OpenFOAM PostProcessing  13  March 25, 2013 12:22 
boundaries with gmshToFoam  ouafa  Open Source Meshers: Gmsh, Netgen, CGNS, ...  7  May 21, 2010 12:43 
average value in any plane  aloise  CFX  3  July 26, 2006 15:30 