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

cell id in udf

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 14, 2020, 05:16
Default cell id in udf
  #1
New Member
 
Join Date: Mar 2020
Posts: 23
Rep Power: 6
loving_cfd is on a distinguished road
Execuse me, I have a question perplexing me a lot.

I want to get the cell id of each cell in my udf on a parallel process.

I notice that I can plot the cell id in the GUI. The cell id is queued up in row orderly.

I have not find the corresponding cell macro storaging the cell id.
Thus, I try to use cell loop to assign the id in udm. However, I discovered that the cell loop is not in the order of the plotted cell id. It is unordered!

So I wonder is there any method to make this come true.

Thanks for your patient!
loving_cfd is offline   Reply With Quote

Old   April 14, 2020, 05:24
Default Cell ID
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Cells are not looped over in order of cell IDs rather in order of connectivity. What is your objective to fetch cell IDs in order?
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 14, 2020, 10:36
Default Reply to vinerm: objective
  #3
New Member
 
Join Date: Mar 2020
Posts: 23
Rep Power: 6
loving_cfd is on a distinguished road
Dear vinerm,

Thanks for your reply.

I try to search the 4 neighbor cells of every cell in the domain and assign them according to the value of this cell. (cellular automaton)

So I set an array, the size of which is the same as the grids (such as x[40][20], while the mesh is 40*20), in order to record the relative position of the cells (such as x[i+1][j] is one the east of x[i][j]).

Thus, it is necessary to establish the relationship between the array and the cells. I attempt to employ cell IDs, but no macro can be found. So I partition the domain with X-coordinate and use the cell loop to record the sequence. It doesn't work properly on the first partition zone, while it works perfectly on the rest partition zones.

Part of my code is as follows (my program has to be performed on a parallel process):
#include "udf.h"
/* define the number of cells */
#define xnum 40
#define ynum 20
/* the array */
int cell[xnum+1][ynum+1];
/* initialize the cell IDs */
DEFINE_INIT(assign_array_neighbor,d)
{
#if RP_NODE
cell_t c;
Thread *t;
int x=1,y=0; /* the first row the cells in the current partition */
int partid=0; /* partition id */
int initx=0; /* to determine if it is the first row */
int counter=0; /* to count the cell id */
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
partid=C_PART(c,t);
counter=counter+1;
if(initx==0)
{x=x+partid*xnum/partnum;
initx=1;}
y=y+1;
if(y>ynum)
{y=y-ynum;x=x+1;} /* to calculate the cell position */
cell[x][y]=0; /* assign the value in the array, then the array will be employed to assign the cells in the domain */
C_UDMI(c,t,1)=counter; /* record the cell ID */
C_UDMI(c,t,2)=x; /* record x */
C_UDMI(c,t,3)=y; /* record y */
}
end_c_loop(c,t)
}
#endif
}
The result of udm3 is in the attachment. It can be discovered that the first two rows are wrongly ordered.
Attached Images
File Type: png y_position.png (91.4 KB, 51 views)
loving_cfd is offline   Reply With Quote

Old   April 14, 2020, 10:46
Default Cell ID
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
You don't need a macro to fetch cell ID. c is the cell ID, i.e., cell_t c; Furthermore, if you enable three UDMs in Fluent, then those are addressed using 0, 1, and 2 and not 1, 2, and 3. This is due to C, which has indexing starting from 0.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 14, 2020, 11:18
Default reply to Vinerm
  #5
New Member
 
Join Date: Mar 2020
Posts: 23
Rep Power: 6
loving_cfd is on a distinguished road
Dear Vinerm

Appreciate for your reply!

I use the udm0 to store the value of "c". This part of program is:
DEFINE_INIT(check_c,d)
{
#if RP_NODE
cell_t c;
Thread *t;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=c;
}
end_c_loop(c,t)
}

The results of udm0 and cellid are shown in the attachment. It can be found that the "c" is different from the cell ID, especially in the first two rows along y-coordinate.

Emmm, I am still kind of confused. Can you give me some more suggestions please?

Best regards
Attached Images
File Type: png udm0.png (131.9 KB, 48 views)
File Type: jpg cellid.jpg (93.6 KB, 54 views)
loving_cfd is offline   Reply With Quote

Old   April 14, 2020, 11:25
Default Cell ID
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Cell IDs used in UDF are reset to 0 for each partition. There is a macro called C_ID in Fluent. This, hopefully, is global and maintained across partitions.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 14, 2020, 11:42
Default Reply to Vinerm
  #7
New Member
 
Join Date: Mar 2020
Posts: 23
Rep Power: 6
loving_cfd is on a distinguished road
Dear Vinerm

The macro works perfectly! Your answer help me a lot.

Appreciate for your help and thanks for your patient.

Best wishes!
loving_cfd is offline   Reply With Quote

Old   April 14, 2020, 11:50
Default Good
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Good that it works.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 19, 2020, 09:54
Smile
  #9
New Member
 
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7
by1704116 is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Cell IDs used in UDF are reset to 0 for each partition. There is a macro called C_ID in Fluent. This, hopefully, is global and maintained across partitions.
Dear vinerm,sorry to bother you.I've referred to the udf mannual

but can't find the macro C_ID. Now I also want to use this kind of global cell id,can you please tell me how to use this macro or where i can find the detail about this macro?
Best Regards.
by1704116 is offline   Reply With Quote

Old   May 19, 2020, 10:08
Default C_id
  #10
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
It is an undocumented macro. Just use it like any other cell macro, such as, C_T or C_P. It returns an integer.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 19, 2020, 10:16
Default
  #11
New Member
 
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7
by1704116 is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It is an undocumented macro. Just use it like any other cell macro, such as, C_T or C_P. It returns an integer.
Dear vinerm,thanks a lot for your quik reply.
I have a try in a short code, "Message("\n%g %g %d %d %d c%d %d\n",z,r,n,myid,cell_p,c,C_ID)",
but after I compile it ,the console tells me "error C2065: “C_ID” "and it's an undeclared identifier. Could you please help me with this problem?
Please forget it,I 've found the reason,it should be C_ID(c,t),and it works well.I still need more practice on udf ~~Thanks!
by1704116 is offline   Reply With Quote

Old   May 19, 2020, 10:25
Default Usage
  #12
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
It requires two arguments

C_ID(cell_t c, Thread *t)
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 19, 2020, 10:30
Default
  #13
New Member
 
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7
by1704116 is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It requires two arguments

C_ID(cell_t c, Thread *t)
You're right.Thanks a lot! You're indeed an expert on udf .
by1704116 is offline   Reply With Quote

Old   May 19, 2020, 11:56
Default
  #14
New Member
 
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7
by1704116 is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It requires two arguments

C_ID(cell_t c, Thread *t)
Dear vinerm,sorry to bother you again.Are you familiar with the maro DEFINE_SOURCE? I'm parallelizing my udf for the first time, but I'm confused with this macro in parallel. In serial, DEFINE_SOURCE loops over the specific zone's cells automatically.While in parallel, I use a rectangle zone with mesh 4*4, and 4 node processes to test. I've run one iteration and printf the order of the cell which macro loops over in sequence. I've found that this macro also loops over exterior cells for a node process. I'm confused and I wanna know if DEFINE_SOURCE loops over not only interior cells. If it works like this, I think it adds extra source on cells that I don't want it to loop over.
by1704116 is offline   Reply With Quote

Old   May 19, 2020, 12:09
Default Source
  #15
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
If you are using same equation for source, then it does not matter. It is equivalent to assigning a value of 1 to x and then assigning same value while node 2. However, if you want to assign different values to each cell based on which node they lie, then you should check for cell being interior. But as far as source is concerned, you should not worry about it.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 19, 2020, 22:45
Smile
  #16
New Member
 
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7
by1704116 is on a distinguished road
Quote:
Originally Posted by vinerm View Post
If you are using same equation for source, then it does not matter. It is equivalent to assigning a value of 1 to x and then assigning same value while node 2. However, if you want to assign different values to each cell based on which node they lie, then you should check for cell being interior. But as far as source is concerned, you should not worry about it.
Dear vinerm, thanks for your help again.

Last edited by by1704116; May 26, 2020 at 05:59.
by1704116 is offline   Reply With Quote

Old   April 8, 2021, 09:05
Default
  #17
New Member
 
Join Date: Apr 2020
Posts: 5
Rep Power: 6
Lucifinil is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Cell IDs used in UDF are reset to 0 for each partition. There is a macro called C_ID in Fluent. This, hopefully, is global and maintained across partitions.
Dear vinerm,
Do you know the opposite macro of C_ID, which uses the global id to get the cell_t integer?
Lucifinil is offline   Reply With Quote

Old   April 8, 2021, 22:16
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by Lucifinil View Post
Dear vinerm,
Do you know the opposite macro of C_ID, which uses the global id to get the cell_t integer?
you may make a loop over all cells in domain and compare its global ID (c_ID) with value, which you have
Lucifinil likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   April 9, 2021, 10:01
Default
  #19
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
looping over faces of a cell
Code:
c_face_loop(c, t, n)         /* loops over all faces of a cell */
  {
  .
  .
  .
  f = C_FACE(c,t,n);
  tf = C_FACE_THREAD(c,t,n);
  .
  .
  .
  }

For any face, F_C0, F_C1 macros give you the cells on both sides. Check the manual for detail

By the way, the cell id is different from a node to another. Each node has its own order of cells.

Last edited by Yasser; April 9, 2021 at 10:04. Reason: adding comment
Yasser is offline   Reply With Quote

Old   April 12, 2021, 06:07
Default
  #20
New Member
 
Join Date: Apr 2020
Posts: 5
Rep Power: 6
Lucifinil is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
you may make a loop over all cells in domain and compare its global ID (c_ID) with value, which you have
Thanks for your reply! I think it works. I thought of using this method before.
But the problem is, I want to transfer data of partition exterior cell between compute node in parallel computation. This method will be time-consuming if large amounts of mesh are adopted.
I'm just curious how Fluent itself implements data synchronization of partition boundary cells during solver calculation.
Lucifinil is offline   Reply With Quote

Reply

Tags
cell id, udf


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
Neighboring cells in tetrahedral mesh vishwesh OpenFOAM Programming & Development 9 November 10, 2017 08:06
How to get the global index of a cell in UDF chuyi Fluent UDF and Scheme Programming 6 October 23, 2017 13:28
UDF Internal Reforming in Fuel Cell Kashif Rashid Fluent UDF and Scheme Programming 0 September 23, 2014 23:23
Journal file error magicalmarshmallow FLUENT 3 April 4, 2014 13:25
cell values in UDF gayatri FLUENT 2 February 27, 2007 19:18


All times are GMT -4. The time now is 17:20.