|
[Sponsors] |
April 14, 2020, 05:16 |
cell id in udf
|
#1 |
New Member
Join Date: Mar 2020
Posts: 23
Rep Power: 6 |
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! |
|
April 14, 2020, 05:24 |
Cell ID
|
#2 |
Senior Member
|
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. |
|
April 14, 2020, 10:36 |
Reply to vinerm: objective
|
#3 |
New Member
Join Date: Mar 2020
Posts: 23
Rep Power: 6 |
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. |
|
April 14, 2020, 10:46 |
Cell ID
|
#4 |
Senior Member
|
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. |
|
April 14, 2020, 11:18 |
reply to Vinerm
|
#5 |
New Member
Join Date: Mar 2020
Posts: 23
Rep Power: 6 |
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 |
|
April 14, 2020, 11:25 |
Cell ID
|
#6 |
Senior Member
|
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. |
|
April 14, 2020, 11:42 |
Reply to Vinerm
|
#7 |
New Member
Join Date: Mar 2020
Posts: 23
Rep Power: 6 |
Dear Vinerm
The macro works perfectly! Your answer help me a lot. Appreciate for your help and thanks for your patient. Best wishes! |
|
April 14, 2020, 11:50 |
Good
|
#8 |
Senior Member
|
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. |
|
May 19, 2020, 09:54 |
|
#9 | |
New Member
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7 |
Quote:
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. |
||
May 19, 2020, 10:08 |
C_id
|
#10 |
Senior Member
|
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. |
|
May 19, 2020, 10:16 |
|
#11 | |
New Member
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7 |
Quote:
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! |
||
May 19, 2020, 10:25 |
Usage
|
#12 |
Senior Member
|
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. |
|
May 19, 2020, 10:30 |
|
#13 |
New Member
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7 |
||
May 19, 2020, 11:56 |
|
#14 |
New Member
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7 |
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.
|
|
May 19, 2020, 12:09 |
Source
|
#15 |
Senior Member
|
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. |
|
May 19, 2020, 22:45 |
|
#16 | |
New Member
Lanting li
Join Date: Nov 2019
Posts: 10
Rep Power: 7 |
Quote:
Last edited by by1704116; May 26, 2020 at 05:59. |
||
April 8, 2021, 09:05 |
|
#17 |
New Member
Join Date: Apr 2020
Posts: 5
Rep Power: 6 |
||
April 8, 2021, 22:16 |
|
#18 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may make a loop over all cells in domain and compare its global ID (c_ID) with value, which you have
__________________
best regards ****************************** press LIKE if this message was helpful |
|
April 9, 2021, 10:01 |
|
#19 |
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19 |
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 |
|
April 12, 2021, 06:07 |
|
#20 | |
New Member
Join Date: Apr 2020
Posts: 5
Rep Power: 6 |
Quote:
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. |
||
Tags |
cell id, udf |
|
|
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 |