CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to calculate grad(p) for a specific point? (https://www.cfd-online.com/Forums/openfoam-programming-development/174904-how-calculate-grad-p-specific-point.html)

ripperjack July 20, 2016 16:13

How to calculate grad(p) for a specific point?
 
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,

Jerryfan July 21, 2016 04:20

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.

ripperjack July 21, 2016 10:08

Quote:

Originally Posted by Jerryfan (Post 610617)
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!

Jerryfan July 21, 2016 12:43

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.

anishtain4 July 21, 2016 13:34

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

Jerryfan July 21, 2016 13:45

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

ripperjack July 24, 2016 09:59

Quote:

Originally Posted by anishtain4 (Post 610733)
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.

anishtain4 July 25, 2016 12:00

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

giovastabile December 21, 2017 04:26

Facing similar issue
 
Dear all,

I'm facing a similar issue and I wanted to know if you had success. I'm implementing the discrete empirical interpolation method in OpenFOAM and for this reason, I would need to evaluate only some of the matrix coefficients coming from a discretized differential operator and without constructing the whole matrix.

Is "fvMeshSubset" a viable way to do this?

Best,

Giovanni


All times are GMT -4. The time now is 18:49.