Spatial average over a plane
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?:confused: It should be easy to realize this function, but I am new to OpenFOAM and I am not familiar with it. Thanks. 
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 
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.

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. 
Have a look for swak4foam this could work

Runtime integration/averaging on a computational plane (NOT inlet/outlet patch)
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.

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 ? 
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 
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". 
The mesh is generated by blockMesh in OpenFOAM. So I think it should be unstructured mesh.

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 
Quote:
Would you be, by any chance, working on a model that requires the mean strain in the xy plane at all z levels? 
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.

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

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

Hi,HECKMANN,
your code is used for averaging based on area, yes? Do you know how to average based on point value? 
All times are GMT 4. The time now is 10:29. 