CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Spatial average over a plane

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

Like Tree1Likes
  • 1 Post By michel1988

Reply
 
LinkBack Thread Tools Display Modes
Old   April 16, 2013, 18:44
Default Spatial average over a plane
  #1
New Member
 
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 3
michel1988 is on a distinguished road
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.
JR22 likes this.
michel1988 is offline   Reply With Quote

Old   April 16, 2013, 22:57
Default
  #2
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 231
Rep Power: 7
fredo490 is on a distinguished road
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
     }
fredo490 is offline   Reply With Quote

Old   April 17, 2013, 07:33
Default
  #3
New Member
 
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 3
michel1988 is on a distinguished road
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.
michel1988 is offline   Reply With Quote

Old   April 17, 2013, 07:37
Default
  #4
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 231
Rep Power: 7
fredo490 is on a distinguished road
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.
fredo490 is offline   Reply With Quote

Old   April 17, 2013, 07:47
Default
  #5
Member
 
Timo K.
Join Date: Feb 2010
Location: University of Stuttgart
Posts: 66
Rep Power: 6
timo_IHS is on a distinguished road
Have a look for swak4foam this could work
timo_IHS is offline   Reply With Quote

Old   April 17, 2013, 10:37
Question Runtime integration/averaging on a computational plane (NOT inlet/outlet patch)
  #6
Senior Member
 
JR22's Avatar
 
Jose Rey
Join Date: Oct 2012
Posts: 113
Rep Power: 7
JR22 will become famous soon enough
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.
JR22 is offline   Reply With Quote

Old   April 17, 2013, 13:27
Default
  #7
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 231
Rep Power: 7
fredo490 is on a distinguished road
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 ?
fredo490 is offline   Reply With Quote

Old   April 18, 2013, 10:20
Default
  #8
New Member
 
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 3
michel1988 is on a distinguished road
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
michel1988 is offline   Reply With Quote

Old   April 18, 2013, 11:16
Default
  #9
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 231
Rep Power: 7
fredo490 is on a distinguished road
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".
fredo490 is offline   Reply With Quote

Old   April 22, 2013, 08:28
Default
  #10
New Member
 
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 3
michel1988 is on a distinguished road
The mesh is generated by blockMesh in OpenFOAM. So I think it should be unstructured mesh.
michel1988 is offline   Reply With Quote

Old   April 23, 2013, 19:43
Default
  #11
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,772
Rep Power: 37
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by michel1988 View Post
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
gschaider is offline   Reply With Quote

Old   April 25, 2013, 00:02
Default
  #12
New Member
 
Ken Tay
Join Date: Oct 2012
Location: Singapore
Posts: 5
Rep Power: 3
kentriarch is on a distinguished road
Quote:
Originally Posted by michel1988 View Post
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?
kentriarch is offline   Reply With Quote

Old   April 25, 2013, 03:23
Default
  #13
New Member
 
LI Bo
Join Date: Apr 2013
Posts: 13
Rep Power: 3
michel1988 is on a distinguished road
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.
michel1988 is offline   Reply With Quote

Old   April 25, 2013, 04:37
Default
  #14
New Member
 
Ken Tay
Join Date: Oct 2012
Location: Singapore
Posts: 5
Rep Power: 3
kentriarch is on a distinguished road
Quote:
Originally Posted by gschaider View Post
"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
kentriarch is offline   Reply With Quote

Old   April 25, 2013, 11:40
Default
  #15
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,772
Rep Power: 37
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by kentriarch View Post
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 View Post
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
gschaider is offline   Reply With Quote

Old   April 26, 2013, 00:27
Default
  #16
New Member
 
Ken Tay
Join Date: Oct 2012
Location: Singapore
Posts: 5
Rep Power: 3
kentriarch is on a distinguished road
Quote:
Originally Posted by gschaider View Post
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.
kentriarch is offline   Reply With Quote

Old   April 26, 2013, 05:10
Default
  #17
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,772
Rep Power: 37
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by kentriarch View Post
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.
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
gschaider is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 103 May 22, 2014 01:24
finding average values for a plane in the vertical direction NJG OpenFOAM Post-Processing 13 March 25, 2013 12:22
boundaries with gmshToFoam‏ ouafa Open Source Meshers: Gmsh, Netgen, CGNS, ... 7 May 21, 2010 12:43
Problem with Gmsh nishant_hull Open Source Meshers: Gmsh, Netgen, CGNS, ... 17 December 7, 2007 01:33
average value in any plane aloise CFX 3 July 26, 2006 15:30


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