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 get cell labels for all the points within specific distance from a given point (https://www.cfd-online.com/Forums/openfoam-programming-development/142761-how-get-cell-labels-all-points-within-specific-distance-given-point.html)

gxy200992243 October 8, 2014 23:11

How to get cell labels for all the points within specific distance from a given point
 
Hi, everyone!

I need cell labels for all the points within specific distance from a given point. For example, the coordinate for the given point is (x,y,z), and I need velocity values of all the points within 3cm from this point to interpolate the velocity at this point. Could anyone help me with it?

Billions of thanks!

Xiangyu

PHS- October 10, 2014 13:17

I am not sure if this functionnality is available directly in OpenFOAM :confused:.
However, this is how I would do :

- First, get the cell centers coordinates of your mesh by using writeCellCentres. It writes the coordinates in the files ccx, ccy and ccz for the specified times.

- Then, write a code in a scripting language (for example python) that reads the files for the cell centers and the velocity file U, and extract the lines corresponding to cells that are within 3cm of your point.

There is certainly a way to do this directly in OpenFOAM but if you are not familiar with the OpenFOAM source code or C++, this is probably the simplest option :)

gxy200992243 October 10, 2014 13:28

Quote:

Originally Posted by PHS- (Post 513750)
I am not sure if this functionnality is available directly in OpenFOAM :confused:.
However, this is how I would do :

- First, get the cell centers coordinates of your mesh by using writeCellCentres. It writes the coordinates in the files ccx, ccy and ccz for the specified times.

- Then, write a code in a scripting language (for example python) that reads the files for the cell centers and the velocity file U, and extract the lines corresponding to cells that are within 3cm of your point.

There is certainly a way to do this directly in OpenFOAM but if you are not familiar with the OpenFOAM source code or C++, this is probably the simplest option :)

Thank you very much for the reply! This interpolation must be done during the simulation, not after, because I must feed the interpolated value for next time step. Could you please kindly give me some hints about how to do it? My current solution is to feed the coordinate of all the points within 3cm from given point directly to the solver and get the label.

PHS- October 10, 2014 14:18

My bad, I didn't understand the question properly :P

I guess you could loop over all the cells and access the coordinates with:
mesh.C[celli].component(0) (for the x-coordinate), and if the cell is within 3cm of your point, then just put its label in a list.

Then you just have to iterate over the labels in the list and interpolate the velocities.
Hope this helps..

gxy200992243 October 10, 2014 20:05

Sorry for bothering you again. Now I am facing a new problem. I am running my case in parallel. This is how I get the label and velocity for a given point:

vector probepoint(x[0],x[1],x[2]);
label m=iMesh.findCell(probepoint);
U_in[0]=U[m].x();
U_in[1]=U[m].y();
U_in[2]=U[m].z();

It works well in serial, but in parallel, I have the problem below:

I decompose the domain into 16 parts, and the given point can only be in one part (let's say part 3). The label search works well in part 3, but in other parts, the solver gives me m=-1, which will make U_in[0]=U[m].x() impossible and kill the simulation.

Do you know how to let the label search happen in only part 3?

Thank you,

Xiangyu

PHS- October 10, 2014 22:18

To find a label in parallel, check out this thread : http://www.cfd-online.com/Forums/ope...-parallel.html

gxy200992243 October 11, 2014 12:43

Thank you very much, the information you provided is really helpful! Now the problem has been solved!

gxy200992243 October 11, 2014 15:17

Sorry for my endless questions. I need to use findcell for 60 points per time step, which means I have to loop the domain for 60 times. It will take a lot of time. Is there a way to find the labels for all 60 points in only one loop? I tried to feed a vector list to find cell to findcell in order to get a label list, of course, it did not work. Could you please give me any hints?

Thank you very much,

Xiangyu


All times are GMT -4. The time now is 06:29.