# Spatial average over a plane

 Register Blogs Members List Search Today's Posts Mark Forums Read

 April 16, 2013, 18:44 Spatial average over a plane #1 New Member   LI Bo Join Date: Apr 2013 Posts: 13 Rep Power: 5 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. Pagoda and JR22 like this.

 April 16, 2013, 22:57 #2 Senior Member   HECKMANN Frédéric Join Date: Jul 2010 Posts: 237 Rep Power: 9 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: 5 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: 237 Rep Power: 9 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: 8 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: 128 Rep Power: 10 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 post-processing 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: 237 Rep Power: 9 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: 5 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: 237 Rep Power: 9 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: 5 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,953
Rep Power: 41
Quote:
 Originally Posted by michel1988 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
"Doing at every timestep": the answer is usually a functionObject.

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 area-weighted average of the z-component 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
);
}```
(this is just an excerpt from the controlDict)
__________________
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: 6
Quote:
 Originally Posted by michel1988 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
Hi, I have the same issue as you. Am still looking for a solution to this problem of doing spatial average and wanting to implement this into a turbulence model.

Would you be, by any chance, working on a model that requires the mean strain in the x-y plane at all z levels?

 April 25, 2013, 03:23 #13 New Member   LI Bo Join Date: Apr 2013 Posts: 13 Rep Power: 5 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: 6
Quote:
 Originally Posted by gschaider "Doing at every timestep": the answer is usually a functionObject. 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 area-weighted average of the z-component 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 ); }``` (this is just an excerpt from the controlDict)
Yes, I understand that this snippet will give an output of the average of U.z of the xy-plane at z=0.0001. But how can I reference to these values during runTime when solving?

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,953
Rep Power: 41
Quote:
 Originally Posted by kentriarch Yes, I understand that this snippet will give an output of the average of U.z of the xy-plane at z=0.0001. But how can I reference to these values during runTime when solving?
It said nothing about "reference" in the original posting. Only later there was something about using that value in a turbulence model.

Please be more specific about "reference". Only then can I tell you what might work (there ARE ways to access swak-results from the solver. The question is whether it is worth the while for your application)

Quote:
 Originally Posted by kentriarch 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
Well. You might want to take a look at the sampledPlane in Doxygen and figure out how to use that in your program. You'll have to create a new plane for every basepoint
__________________
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: 6
Quote:
 Originally Posted by gschaider It said nothing about "reference" in the original posting. Only later there was something about using that value in a turbulence model. Please be more specific about "reference". Only then can I tell you what might work (there ARE ways to access swak-results from the solver. The question is whether it is worth the while for your application) Well. You might want to take a look at the sampledPlane in Doxygen and figure out how to use that in your program. You'll have to create a new plane for every basepoint
In the turbulence model that I am trying to implement, I need to get the plane average for the strain tensor, <S_ij> at every z level.

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,953
Rep Power: 41
Quote:
 Originally Posted by kentriarch In the turbulence model that I am trying to implement, I need to get the plane average for the strain tensor, at every z level. 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 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.
As the quantity you want to sample is fixed the flexibility of swak4foam is a bit of an overkill here (a bit like using dynamite for going after moles: a lot of fun, but the garden looks messy afterwards and the neighbours complain and usually the moles survive). So I'd go for using samplePlanes inside your turbulence model if you need that kind of stuff
__________________
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: 44 Rep Power: 4 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 Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post florian_krause OpenFOAM 110 April 21, 2016 11:54 nishant_hull Open Source Meshers: Gmsh, Netgen, CGNS, ... 23 August 5, 2015 02:09 NJG OpenFOAM Post-Processing 13 March 25, 2013 12:22 ouafa Open Source Meshers: Gmsh, Netgen, CGNS, ... 7 May 21, 2010 12:43 aloise CFX 3 July 26, 2006 15:30

All times are GMT -4. The time now is 03:35.