CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF: Given coordinates, How to identify the cell? (http://www.cfd-online.com/Forums/fluent-udf/48958-udf-given-coordinates-how-identify-cell.html)

Zhang August 4, 2008 14:44

UDF: Given coordinates, How to identify the cell?
 
Hello,

I have a question about UDF: given a point (x,y,z coordinates), how to identify the cell (cell ID and thread ID) the given point is in?

Thanks in advance

Jura August 6, 2008 03:32

Re: UDF: Given coordinates, How to identify the ce
 
Hello,

you ought to use macro C_CENTROID(x,c,c_thread) I would expect enclose it in cell looping macro begin_c_loop(c, c_thread) - end_c_loop(...) -> then you can check if x=x[0],y=x[1],z=x[2] matches your coordinates via if-function. If it matches then use variable "c" which is passed to you by Fluent as reference to your cell. Variable "c" is the simple integer value and yoou can later use it as a reference to your cell together with thread id.

Hopefully it'll be useful to you ;)


Zhang August 6, 2008 12:15

Re: UDF: Given coordinates, How to identify the ce
 
Thank you Jura.

What you described only works for a few points. The cell looping takes too much time if I have many many points to be located.

I believe there must be faster way to do this. For instance, if we define a "file" injection for DPM model, we provide the location of each particle and FLUENT put these particles in corresponding cells. So, FLUENT needs to find the cell for each particle with given location. I do not think FLUENT performs cell looping for each particle.

Allan Walsh August 6, 2008 18:48

Re: UDF: Given coordinates, How to identify the ce
 
I have used RP_CELL and RP_THREAD which are macros in the surf.h header file. They are referenced in the UDF manual for DPM macros. There isn't much description but they work fine for cell temperature and other properties as a function of particle position.

Zhang August 7, 2008 12:48

Re: UDF: Given coordinates, How to identify the ce
 
Thank you Allan.

RP_CELL and RP_THREAD work with PARTICLE not POSITION. As particle moves, FLUENT somehow finds the cell and thread and stores this information in the particle structure. What RP_CELL and RP_THREAD do is just read and return this information.

What I am trying to find is a function/macro that returns cell/thread for a given position (x, y, z coordinates).

finding coordinates August 7, 2008 17:48

Re: UDF: Given coordinates, How to identify the ce
 
what you are trying to do is very difficult indeed. And if you could find a better way that let us know.

As far as fluent is concerned, as i understand it uses kd-tree structure to locate cell id for position. Now this brings us to question whether you could acess this with any macro or not. Because this is likely to be advanced feature and mostly likely not available to usual user. Fluent is unstructured grid solver so it is very difficult to find a simple formula to do this.

Zhang August 7, 2008 18:08

Re: UDF: Given coordinates, How to identify the ce
 
I think I found the function. If you are interested, play with this function, CX_Find_Cell_With_Point. It is a FLUENT_EXPORT function defined in cxiface.h.

finding coordinates August 7, 2008 22:49

Re: UDF: Given coordinates, How to identify the ce
 
I think thats wonderful if you found the function. I personally really doubted it whether it will be available.

But for me, i need to do the same in my own code so for me this function is of no use. I am trying to find or devise an efficient algorithm to do so.

So far I am only able to devise good function of non uniform cartesian type meshes. (gives me index in one function call). I have no idea how to do it in unstructured grids as contructing kd-tree is time consuming process and when grid sizes increase these search process is indeed difficult thing to do in real time.

I am searching and searching.


Zhang August 8, 2008 10:26

Re: UDF: Given coordinates, How to identify the ce
 
I tried the function I just mentioned and seems like it works.

I used kd-tree for 2-D grids in one of our small projects and the number of grids is small. I have no experience of how it works in large scale problems.

Are you aware of the open source code VTK (The Visualization Toolkit)? You may find something interesting in their website: http://www.vtk.org/. I was very interesting in this code but did not get time to learn it.

finding coordinates August 10, 2008 21:07

Re: UDF: Given coordinates, How to identify the ce
 
i have written kd-tree programs for nearest neighbor search and my programs were faster than any implementation i have seen. (i took around 100 minutes for 100 million randomly distributed points and it was finding 5 nearest neighbours).

but my program did not use the suggested nearest neighbour search algo for kd-tree method. instead i used a little modified version (i deviced a better way of implementing).

Anyway i am still not happy with it, so want to get even faster method.

For me, kd-tree method and nearest neighbour search part have little history. I first needed to solve this problem for some project i was thinking in 1999. So came up with a algorithm that i thought was the fastest algo to solve this problem. I was happy but discovered that the algo i came up with is called kd-tree algo. (i found it out after 1 year of i thought of this). Anyway, i was not happy that time about that algo and i am still not happy.

So for the practical applications where i might need this type of search (for example, nearest neighbor search of points of one grid to another, -> chimera grids) i have come up with another method and that beats kd-tree search method hands down. If kd-tree takes 5 minutes , that algo would only take less than 1 minute).

But still there is no universal algo and i still think about solving this problem sometimes.

Zhang August 11, 2008 10:58

Re: UDF: Given coordinates, How to identify the ce
 
Sounds very interesting! You should publish your method if it is new and performs so greatly.

Other than kd-tree, I know little about searching algo. I would not be able to give you any suggestion regarding this. But what you are doing is very interesting. I hope you can publish it to benifit other people, including me of course :)

Good luck.

finding coordinates August 11, 2008 22:24

Re: UDF: Given coordinates, How to identify the ce
 
my company said we will patent it. :-D


Zhang August 12, 2008 10:24

Re: UDF: Given coordinates, How to identify the ce
 
That's not good, for us :)

By the way, I am wondering how you can patent an algorithm. What if someone else comes up with the same idea?

finding coordinates August 12, 2008 18:07

Re: UDF: Given coordinates, How to identify the ce
 
i have no idea, how can we patent it, but it is very useful for us, and my boss probably meant the whole method of solving the problem. (kd-tree is main part of it).

psc3 March 11, 2010 21:30

Quote:

Originally Posted by Zhang
;152719
I think I found the function. If you are interested, play with this function, CX_Find_Cell_With_Point. It is a FLUENT_EXPORT function defined in cxiface.h.

Hi

Can you give me a simple code applying that function in the search of a cell ID, thread.

I've found it in cxiface.h but I don't have much experience in UDF programming. I think if I have to use it inside a cell loop or something like that but I'm not sure.

There is nothing in the manual, and if i search "CX_Find_Cell_With_Point" in google, the only result is this topic...:(

thanks in advance!

Pedro

md5encrypted May 15, 2010 13:00

code example
 
I found this code (source: http://www.cfluid.com/bbs/viewthread...able&tid=76550)

Code:

cell_t c;
Thread *t;
CX_Cell_Id cx_cell;
real NV_VEC(pt);
real c_centroid[ND_ND];

NV_D(pt, =, 1,1,1);  //coordinate of your specified location,it must be in the domain coordinate range
CX_Start_ND_Point_Search();
cx_cell=*CX_Find_Cell_With_Point(pt);
CX_End_ND_Point_Search();
c=RP_CELL(&cx_cell);  //the right cell number
t = RP_THREAD(&cx_cell);  //  the thread

C_CENTROID(c_centroid,c,t);
Message0("coordinate of the specified point: x=%g,y=%g,z=%g\n",pt[0],pt[1],pt[2]);
Message0("coordinate of the cell found: x=%g,y=%g,z=%g,T=%g\n",c_centroid[0],c_centroid[1],c_centroid[2],C_T(c,t));

It works, but if requested point located outside mesh, CX_Find_Cell_With_Point returns NULL, and therefore causes access violation (dereferencing NULL).


[off] I know I'm late with answer, but hope it will be useful [/off]

johnwinter November 5, 2010 05:48

Particle source in cell (PSI-C) UDF
 
Hi All,

Does any body know how to write UDF for averaging particle in the cell in Lagrangian Particle tracking method i.e., DPM.

My problem is I wanted to moniter particle concentration at different locations in the domain uisng DPM, any clues?

Thanks
John

jeff8541 March 8, 2011 14:59

CX_Start_ND_Point_Search(); Error
 
Quote:

Originally Posted by md5encrypted (Post 258930)
I found this code (source: http://www.cfluid.com/bbs/viewthread...able&tid=76550)

Code:

cell_t c;
Thread *t;
CX_Cell_Id cx_cell;
real NV_VEC(pt);
real c_centroid[ND_ND];
 
NV_D(pt, =, 1,1,1);  //coordinate of your specified location,it must be in the domain coordinate range
CX_Start_ND_Point_Search();
cx_cell=*CX_Find_Cell_With_Point(pt);
CX_End_ND_Point_Search();
c=RP_CELL(&cx_cell);  //the right cell number
t = RP_THREAD(&cx_cell);  //  the thread
 
C_CENTROID(c_centroid,c,t);
Message0("coordinate of the specified point: x=%g,y=%g,z=%g\n",pt[0],pt[1],pt[2]);
Message0("coordinate of the cell found: x=%g,y=%g,z=%g,T=%g\n",c_centroid[0],c_centroid[1],c_centroid[2],C_T(c,t));

It works, but if requested point located outside mesh, CX_Find_Cell_With_Point returns NULL, and therefore causes access violation (dereferencing NULL).


[off] I know I'm late with answer, but hope it will be useful [/off]


When I try to use:

CX_Start_ND_Point_Search();

I get a define variable error.

I included cxiface.h

Does anyone know why this error arises?

Seppl March 12, 2012 11:33

Hello I found the following lines in the header
"cxndsearch.h"

Quote:

/* point search functions */

FLUENT_EXPORT ND_Search *CX_Start_ND_Point_Search(ND_Search *, cxboolean do_domain, int t_id);
FLUENT_EXPORT CX_Cell_Id *CX_Find_Cell_With_Point(ND_Search *,
float v[3]);
FLUENT_EXPORT CX_Cell_Id *CX_Find_Closest_Cell_To_Point(ND_Search *,
float v[3], float *dist, float eps);
FLUENT_EXPORT ND_Search *CX_End_ND_Point_Search(ND_Search *);
FLUENT_EXPORT
void SV_Fill_ND_Points(CX_Cell_Id *pdata, double *values,
double *tot_min, double *tot_max, int dim);



Can anyone explain what the input argument " ND_Search * " means? And how to use it for the problem described above?

Vitaly June 6, 2012 17:23

Hello,

In my cxndsearch.h file, the input arguments are different:

FLUENT_EXPORT CX_Cell_Id *CX_Find_Cell_With_Point(ND_Search *, double v[3], double time);

I have no idea what "time" means, but I set it to 0.0 and it worked.


All times are GMT -4. The time now is 23:50.