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

How to calculate grad(p) for a specific point?

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

Like Tree2Likes
  • 2 Post By Jerryfan

Reply
 
LinkBack Thread Tools Display Modes
Old   July 20, 2016, 16:13
Post How to calculate grad(p) for a specific point?
  #1
Member
 
Jack
Join Date: Dec 2011
Posts: 89
Rep Power: 7
ripperjack is on a distinguished road
Hi guys,

I know that if I do a fvc::grad(p), it will return a volScalarField with the values of pressure gradient. However, what should I do if I want fvc::grad(p) to only calculate pressure gradient at a specific grid point (instead of the whole field)? The reason I ask this is that I need to calculate the pressure gradient just for a few points (instead the whole field), and I need to do it a couple of thousand times per iteration. So it will be a waste of computational time if I calculate the pressure gradient for the whole field. Any ideas? Thanks very much in advance!

Regards,
ripperjack is offline   Reply With Quote

Old   July 21, 2016, 04:20
Default
  #2
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 5
Jerryfan is on a distinguished road
Hi ripperjack,


The following is my idea:
First of all, you need to decide what method you are going to use for the evaluation of the gradient as well as what surface interpolation scheme you want to apply to obtain values on the internal surfaces from cell center values. Take the gaussian gradient and linear interpolation scheme for example. (I am not quite familiar with the least-square gradient. If anyone knows the implementation of this method, please add.)
The first step, you need to take those cells where gradient evaluations are needed out. The information needed from those cells is as follows:
cell indexes of those cells;
owner, neighbor information around those cells;
weights information between those cells and their neighbors.

After getting all the information above, the second step is to perform a linear interpolation: gf = w*gC+(1-w)*gF to obtain the values on the internal surfaces, where w represents the weight.

The third step is to calculate gradient based on the gaussian method.

Also, depending on whether you want to apply nonorthogonal correction, between step two and step three, you can add the corrections to the interpolation values.

This is just the general idea. I hope this can help you.
Jerrydqfan and LogiDF like this.
Jerryfan is offline   Reply With Quote

Old   July 21, 2016, 10:08
Default
  #3
Member
 
Jack
Join Date: Dec 2011
Posts: 89
Rep Power: 7
ripperjack is on a distinguished road
Quote:
Originally Posted by Jerryfan View Post
Hi ripperjack,


The following is my idea:
First of all, you need to decide what method you are going to use for the evaluation of the gradient as well as what surface interpolation scheme you want to apply to obtain values on the internal surfaces from cell center values. Take the gaussian gradient and linear interpolation scheme for example. (I am not quite familiar with the least-square gradient. If anyone knows the implementation of this method, please add.)
The first step, you need to take those cells where gradient evaluations are needed out. The information needed from those cells is as follows:
cell indexes of those cells;
owner, neighbor information around those cells;
weights information between those cells and their neighbors.

After getting all the information above, the second step is to perform a linear interpolation: gf = w*gC+(1-w)*gF to obtain the values on the internal surfaces, where w represents the weight.

The third step is to calculate gradient based on the gaussian method.

Also, depending on whether you want to apply nonorthogonal correction, between step two and step three, you can add the corrections to the interpolation values.

This is just the general idea. I hope this can help you.
Hi Jerryfan,

Thank you very much for your detailed reply! However, I would like to know if I can use some high-level functions such as fvc::grad(p,pointID) which only calculate the gradient at a specific point. I understand your idea and I think it will work for pressure gradient. But I also need to calculate div, laplacian, etc. Is there a way that I don't need to write the code from scratch? Otherwise, I might need to write such class by myself. lol Thanks!
ripperjack is offline   Reply With Quote

Old   July 21, 2016, 12:43
Default
  #4
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 5
Jerryfan is on a distinguished road
Hi ripperjack,


I checked fvcGrad.H, it seems that there is no such function that evaluates gradient at specific points. I think you might end up defining all these functions yourself. This seems to be not an easy task. Good luck to you.
Jerryfan is offline   Reply With Quote

Old   July 21, 2016, 13:34
Default
  #5
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 270
Rep Power: 11
anishtain4 is on a distinguished road
1. You can point a new field to a few cells around the one you want and use the standard functions on the new field.

2. Define a separate region for that small part (probably will have more than a few cells) and do your iterations only for that part. This one will not be a very portable code though
anishtain4 is offline   Reply With Quote

Old   July 21, 2016, 13:45
Default
  #6
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 5
Jerryfan is on a distinguished road
Yeah, it might work. The problem of doing it this way is that there would be lots of problems in dealing with the indexes, boundary conditions...
Jerryfan is offline   Reply With Quote

Old   July 24, 2016, 09:59
Default
  #7
Member
 
Jack
Join Date: Dec 2011
Posts: 89
Rep Power: 7
ripperjack is on a distinguished road
Quote:
Originally Posted by anishtain4 View Post
1. You can point a new field to a few cells around the one you want and use the standard functions on the new field.

2. Define a separate region for that small part (probably will have more than a few cells) and do your iterations only for that part. This one will not be a very portable code though
Hi Mahdi,

Thanks very much for your reply. I am very interested in the first method. Can you give me more details in terms of how to point a new field to a few cells around a specific field? I did some search and it seems that creating a "fvMeshSubset" may work for my case (this post). fvMeshSubset will take care of the boundary conditions as well, which is exactly what I want. But I am not sure how to implement it in details.

Thanks very much in advance.
ripperjack is offline   Reply With Quote

Old   July 25, 2016, 12:00
Default
  #8
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 270
Rep Power: 11
anishtain4 is on a distinguished road
I took a look at it in Doxygen but couldn't figure it out!
What I would go for is to create a Field so I can pass it to grad() then. Something like
Quote:
labelList myCellList = list of labels of your cells
Field<scalar> myTinyField(p.internalField(),myCellList)
It's just off the top of my head though, it probably needs more work
anishtain4 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
How to define to right point for locationInMesh Mirage12 OpenFOAM Native Meshers: snappyHexMesh and Others 7 March 13, 2016 15:07
How to get cell labels for all the points within specific distance from a given point gxy200992243 OpenFOAM Programming & Development 7 October 11, 2014 15:17
how to calculate flow properties along the first grid point near to the wall kiran OpenFOAM Post-Processing 2 September 12, 2010 12:59
Gmsh and samplesurface touf Open Source Meshers: Gmsh, Netgen, CGNS, ... 2 December 10, 2007 03:27
Overall picture versus specific point Nick Main CFD Forum 0 October 7, 2004 11:25


All times are GMT -4. The time now is 05:19.