CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF: Given coordinates, How to identify the cell?

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

Like Tree11Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 4, 2008, 14:44
Default UDF: Given coordinates, How to identify the cell?
  #1
Zhang
Guest
 
Posts: n/a
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
  Reply With Quote

Old   August 6, 2008, 03:32
Default Re: UDF: Given coordinates, How to identify the ce
  #2
Jura
Guest
 
Posts: n/a
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

by1704116 likes this.
  Reply With Quote

Old   August 6, 2008, 12:15
Default Re: UDF: Given coordinates, How to identify the ce
  #3
Zhang
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   August 6, 2008, 18:48
Default Re: UDF: Given coordinates, How to identify the ce
  #4
Allan Walsh
Guest
 
Posts: n/a
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.
wc34071209, qiang92 and by1704116 like this.
  Reply With Quote

Old   August 7, 2008, 12:48
Default Re: UDF: Given coordinates, How to identify the ce
  #5
Zhang
Guest
 
Posts: n/a
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).
  Reply With Quote

Old   August 7, 2008, 17:48
Default Re: UDF: Given coordinates, How to identify the ce
  #6
finding coordinates
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   August 7, 2008, 18:08
Default Re: UDF: Given coordinates, How to identify the ce
  #7
Zhang
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   August 7, 2008, 22:49
Default Re: UDF: Given coordinates, How to identify the ce
  #8
finding coordinates
Guest
 
Posts: n/a
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.

  Reply With Quote

Old   August 8, 2008, 10:26
Default Re: UDF: Given coordinates, How to identify the ce
  #9
Zhang
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   August 10, 2008, 21:07
Default Re: UDF: Given coordinates, How to identify the ce
  #10
finding coordinates
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   August 11, 2008, 10:58
Default Re: UDF: Given coordinates, How to identify the ce
  #11
Zhang
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   August 11, 2008, 22:24
Default Re: UDF: Given coordinates, How to identify the ce
  #12
finding coordinates
Guest
 
Posts: n/a
my company said we will patent it. :-D

  Reply With Quote

Old   August 12, 2008, 10:24
Default Re: UDF: Given coordinates, How to identify the ce
  #13
Zhang
Guest
 
Posts: n/a
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?
  Reply With Quote

Old   August 12, 2008, 18:07
Default Re: UDF: Given coordinates, How to identify the ce
  #14
finding coordinates
Guest
 
Posts: n/a
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).
  Reply With Quote

Old   March 11, 2010, 20:30
Default
  #15
New Member
 
Join Date: Nov 2009
Posts: 8
Rep Power: 16
psc3 is on a distinguished road
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
psc3 is offline   Reply With Quote

Old   May 15, 2010, 13:00
Default code example
  #16
New Member
 
User Simplename
Join Date: May 2010
Posts: 1
Rep Power: 0
md5encrypted is on a distinguished road
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]
md5encrypted is offline   Reply With Quote

Old   November 5, 2010, 04:48
Default Particle source in cell (PSI-C) UDF
  #17
Member
 
john
Join Date: Nov 2010
Posts: 50
Rep Power: 15
johnwinter is on a distinguished road
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
johnwinter is offline   Reply With Quote

Old   March 8, 2011, 13:59
Default CX_Start_ND_Point_Search(); Error
  #18
New Member
 
Join Date: Mar 2011
Posts: 2
Rep Power: 0
jeff8541 is on a distinguished road
Quote:
Originally Posted by md5encrypted View Post
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?
jeff8541 is offline   Reply With Quote

Old   March 12, 2012, 10:33
Default
  #19
New Member
 
JH
Join Date: Jan 2012
Posts: 4
Rep Power: 14
Seppl is on a distinguished road
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?
Seppl is offline   Reply With Quote

Old   June 6, 2012, 17:23
Default
  #20
Member
 
Vitaly
Join Date: Jan 2012
Posts: 32
Rep Power: 14
Vitaly is on a distinguished road
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.
mm.abdollahzadeh likes this.
Vitaly is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Technical] How to identify cell neighbours booz OpenFOAM Meshing & Mesh Conversion 59 November 20, 2017 00:40
How to identify boundary cell and internal cell dbxmcf OpenFOAM Running, Solving & CFD 2 November 6, 2016 09:11
?? How to get cell center coordinates? erica FLUENT 0 May 11, 2005 22:02
identify Cell face Sunlight007 Siemens 3 August 30, 2003 05:30
How to get nodes coordinates for a certain cell ? mikhail FLUENT 2 November 1, 2000 10:18


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