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

How to get the global index of a cell in UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2017, 04:58
Default How to get the global index of a cell in UDF
  #1
New Member
 
Join Date: Oct 2017
Posts: 4
Rep Power: 9
chuyi is on a distinguished road
Hi, all.
I want to use DEFINE_SOURCE macro to import thermal power from other softwares. However, I encountered a difficulty that I can only get the local index of a cell instead of its global index. So can anyone tell me how to get the global index of a cell in UDF? Does Fluent supply a macro for cells like C_FACE for faces which returns the global index of a face?

I got an idea to solve it, but I do not know whether it is right.
Firstly, I find that in the case file of Fluent, all cells are recorded in global indexes. For example, there are 3 cell zones including A, B, C, and the cell index ranges of there are [1, N1], [N1+1, N2] and [N2+1, N3] respectively, whose total range is [1, N3]. I guess every cell has a unique global index and all indexes are continuous and not missing. Is it right?

Then, I find in the DEFINE_SOURCE (name, c, t, dS, eqn), c denotes a local cell index. That is the local index range of the 3 cell zones are [0, N1-1], [0, N2-N1-1] and [0, N3-N2-1] respectively, so I can convert a global index to the local index. Is it right?
chuyi is offline   Reply With Quote

Old   October 20, 2017, 08:25
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I think you are approaching this from the wrong perspective. You are asking the wrong question.

Your real question is: how do I import thermal power from other software into Fluent?

How this is best done, depends on which other software you are using. Does the other software also use a mesh? If so, are you using exactly the same mesh as Fluent?
The approach of "global" and "local" cells is not the way to go. I see two approaches, in pseudo-code:
Code:
For each cell thread in Fluent {
  For each cell in this cell thread {
    Find the center of this cell;
    Find the corresponding cell in the other software;
    Put the corresponding thermal power from cell in the other software into this cell in Fluent.
  }
}
Code:
For each cell thread in the other software {
    Find the center of this cell;
    Find the corresponding cell(s) in Fluent;
    Put the corresponding thermal power from cell in the other software into these cell(s) in Fluent.
}
Do something with the cells in Fluent that were not visited in the procedure;
The first one is probably easier, but that depends on how easy you can find the corresponding cell in the other software.
pakk is offline   Reply With Quote

Old   October 21, 2017, 10:04
Default
  #3
New Member
 
Join Date: Oct 2017
Posts: 4
Rep Power: 9
chuyi is on a distinguished road
Quote:
Originally Posted by pakk View Post
I think you are approaching this from the wrong perspective. You are asking the wrong question.

Your real question is: how do I import thermal power from other software into Fluent?

How this is best done, depends on which other software you are using. Does the other software also use a mesh? If so, are you using exactly the same mesh as Fluent?
The approach of "global" and "local" cells is not the way to go. I see two approaches, in pseudo-code:
Code:
For each cell thread in Fluent {
  For each cell in this cell thread {
    Find the center of this cell;
    Find the corresponding cell in the other software;
    Put the corresponding thermal power from cell in the other software into this cell in Fluent.
  }
}
Code:
For each cell thread in the other software {
    Find the center of this cell;
    Find the corresponding cell(s) in Fluent;
    Put the corresponding thermal power from cell in the other software into these cell(s) in Fluent.
}
Do something with the cells in Fluent that were not visited in the procedure;
The first one is probably easier, but that depends on how easy you can find the corresponding cell in the other software.

Dear pakk,
Thank you a lot for the kind reply. However, my question is just what I want to ask.

Actually I have import the thermal power data into Fluent with a method similar to yours. That is firstly I create a geometric mapping between the two softwares which have different mesh, and then the power is interpolated into Fluent weighed by volume. However, because I need to iteratively calculate the same Fluent case with different power distribution, the interpolation scheme, which only needs to be created once, is created in my program instead of in the UDF, and the mesh info of Fluent is read from its case file. Then before every Fluent calculation, I use the same interpolation scheme to interpolate power data from the other software, which is efficient. Otherwise, if the interpolation scheme is created in the UDF, the same scheme will be created repeatedly, which is inefficient.

What confuses me is that the power data are saved with the mesh body indexes in the case file, but the mesh body indexes in the case file and in the UDF are different, as shown in post 1, so I do not know how to correspond the body index in the UDF to that in the case file. Can you give me some suggestions?
chuyi is offline   Reply With Quote

Old   October 22, 2017, 22:51
Default
  #4
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 chuyi View Post
Otherwise, if the interpolation scheme is created in the UDF, the same scheme will be created repeatedly, which is inefficient.
why it will be created repeatedly? repeatedly means on each iteration?
What is the difference between other software and UDF script?

Best regards
AlexanderZ is offline   Reply With Quote

Old   October 23, 2017, 05:49
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by chuyi View Post
Can you give me some suggestions?
Yes: don't go this route.
You might get it working, but it would have to rely on undocumented features of Fluent, that might get changed in the next version, and then your code does not work anymore, and you have to debug everything. This is the best advise I can think of...
(If you are anything like me, you will ignore this advise, and find out how it works anyway, good luck! )
pakk is offline   Reply With Quote

Old   October 23, 2017, 12:33
Default
  #6
New Member
 
Join Date: Oct 2017
Posts: 4
Rep Power: 9
chuyi is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
why it will be created repeatedly? repeatedly means on each iteration?
What is the difference between other software and UDF script?

Best regards
Repeatedly means on each multi-physics iteration.

The background is that I am developing a coupling simulation program which coupling Fluent and another program called A. In every iteration of my program Fluent is first run to supply temperature distribution to A, then A is run and feed back thermal power distribution to Fluent. The above process is conducted repeatedly until temperature and thermal power both converge.

So I want to create the interpolation scheme only once before the coupling simulation starts, then in every iteration of the coupling simulation the power data are just interpolated in Fluent mesh according to the scheme, which is very fast. The interpolation of every iteration is also conducted in my program instead of Fluent, the latter only reading and use interpolated data.
chuyi is offline   Reply With Quote

Old   October 23, 2017, 13:28
Default
  #7
New Member
 
Join Date: Oct 2017
Posts: 4
Rep Power: 9
chuyi is on a distinguished road
Quote:
Originally Posted by pakk View Post
Yes: don't go this route.
You might get it working, but it would have to rely on undocumented features of Fluent, that might get changed in the next version, and then your code does not work anymore, and you have to debug everything. This is the best advise I can think of...
(If you are anything like me, you will ignore this advise, and find out how it works anyway, good luck! )
As you mentioned, there are some risks in my method. Actually I can not even guarantee the method is correct in my version of Fluent, because I am not very familiar with Fluent and do not study enough cases.

In order to ensure both ensure efficiency and generalization, I plan to continue to use method, but a extra check is added to find whether the correspondence of body indexes in my method are right. My idea for the check is to compare the centroids of bodies in the case file and in the UDFs. If the check is not passed, then centroids are also used to find right correspondence.

I just don't know why Fluent adopts two kind of indexes and give no introduction. Should the case file not be read? However, its help document really describes the format of case files.
chuyi is offline   Reply With Quote

Reply

Tags
cell index, define_source, 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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
Floating point exception error lpz_michele OpenFOAM Running, Solving & CFD 53 October 19, 2015 03:50
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 22:58
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 05:15


All times are GMT -4. The time now is 16:25.