|
[Sponsors] |
October 20, 2017, 04:58 |
How to get the global index of a cell in UDF
|
#1 |
New Member
Join Date: Oct 2017
Posts: 4
Rep Power: 9 |
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? |
|
October 20, 2017, 08:25 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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; |
|
October 21, 2017, 10:04 |
|
#3 | |
New Member
Join Date: Oct 2017
Posts: 4
Rep Power: 9 |
Quote:
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? |
||
October 22, 2017, 22:51 |
|
#4 | |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Quote:
What is the difference between other software and UDF script? Best regards |
||
October 23, 2017, 05:49 |
|
#5 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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! ) |
|
October 23, 2017, 12:33 |
|
#6 | |
New Member
Join Date: Oct 2017
Posts: 4
Rep Power: 9 |
Quote:
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. |
||
October 23, 2017, 13:28 |
|
#7 | |
New Member
Join Date: Oct 2017
Posts: 4
Rep Power: 9 |
Quote:
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. |
||
Tags |
cell index, define_source, udf |
|
|
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 |