|
[Sponsors] |
March 15, 2019, 13:46 |
UDF to copy temperature every t seconds
|
#1 |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Hello,
I am trying to develop a code to, after some time, copy the temperature of a solid to another solid with the same geometry and similar mesh. I intend to simulate a transient solution of similar moving objects without the computational effort of calculating and remeshing every time step. This way the object would "jump" to the next position every few specified time. In order to do this I have developed the UDF: Code:
DEFINE_ADJUST(temp_adjust, domain) { real current_time; current_time = CURRENT_TIME; div_t divide; real dt; dt = 0.5; divide = div(current_time * 100., dt * 100.); cell_t c; int i; real Temp1[408]; real Temp2[408]; Thread *t1 = Lookup_Thread(domain, 18); Thread *t2 = Lookup_Thread(domain, 19); if (divide.rem == 0){ /*----------------body 1 -----------------*/ i = 0; begin_c_loop (c, t2) { Temp1[i] = C_T(c, t1); C_T(c, t1) = 300.; i ++; } end_c_loop (c, t1) /*----------------body 2 -----------------*/ i = 0; begin_c_loop (c, t1) { Temp2[i] = C_T(c, t2); C_T(c, t2) = Temp1[i]; i ++; } end_c_loop (c, t2) } } The code is compiled without issues, yet during the run, when it is evaluated for the first time the Fluent crashes. Can anyone help me with this? I can't figure out what may be the issue, even because I am new to UDFs. Thanks in advance. |
|
March 17, 2019, 21:33 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
your temperature array has 408 elements
Code:
Temp2[408] best regards |
|
March 18, 2019, 03:45 |
|
#3 | |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Quote:
Even because this mesh refers to the solid elements where there is only conduction. |
||
March 18, 2019, 21:30 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
was
Code:
begin_c_loop (c, t2) { Temp1[i] = C_T(c, t1); C_T(c, t1) = 300.; i ++; } end_c_loop (c, t1) /*----------------body 2 -----------------*/ i = 0; begin_c_loop (c, t1) { Temp2[i] = C_T(c, t2); C_T(c, t2) = Temp1[i]; i ++; } end_c_loop (c, t2) Code:
begin_c_loop (c, t1) { Temp1[i] = C_T(c, t1); C_T(c, t1) = 300.; i ++; } end_c_loop (c, t1) /*----------------body 2 -----------------*/ i = 0; begin_c_loop (c, t2) { Temp2[i] = C_T(c, t2); C_T(c, t2) = Temp1[i]; i ++; } end_c_loop (c, t2) best regards |
|
March 19, 2019, 04:12 |
|
#5 | |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Quote:
Thank you so much AlexanderZ. That was definitely an issue, yet I changed the code according to your suggestion and I am still with problems. I have placed: Code:
Message("Ti = %g \n", Temp1[i]); Thank you once again. |
||
March 19, 2019, 07:17 |
|
#6 |
Senior Member
Join Date: Nov 2011
Posts: 109
Rep Power: 15 |
Are you executing the UDF in parallel or in serial solver?
|
|
March 19, 2019, 07:19 |
|
#7 |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
||
March 19, 2019, 07:34 |
|
#8 |
Senior Member
Join Date: Nov 2011
Posts: 109
Rep Power: 15 |
In this case you have to consider that not all calculation nodes will have access to the whole mesh and that the two arrays Temp1 and Temp2 will exist as a separate copy in each calculation node!
When executing the first loop Temp1 is filled only in the core (or cores) that have a share of cells belonging to that boundary. If the second loop is not executed by the same core (quite likely and in any case something you have no control over) because the faces belonging to such boundary have been assigned to another core by mesh partitioning, then you will be assigning garbage values stored in Temp1 (not initialized at this point) to C_T(c,t2). I advice you to first execute the UDF in serial mode and check that it works. Then work on the parallel version but for this you need basic understanding of MPI and, in general, how distributed memory calculations work. Hope it helps, Roberto |
|
March 19, 2019, 07:49 |
|
#9 | |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Quote:
Thank you robboflea that makes a lot of sense and explains the different issues I have been experiencing during my tests. I will do has you suggested and try in serial. But if that is the case how can I control the place where data is stored? Something I have tried, and have abandoned later, was to write temperatures for a txt file and then read from it in the second loop, although I didn't manage to put it to work as well. Greetings. |
||
March 19, 2019, 08:15 |
|
#10 |
Senior Member
Join Date: Nov 2011
Posts: 109
Rep Power: 15 |
You cannot control it (not that I am aware of).
However if you look in the Fluent manual, in the section named "Parallel UDF considerations" (or something similar) it will explain you in great detail how to deal with parallel UDFs and transfer data to/from nodes. Rob |
|
March 25, 2019, 06:28 |
|
#11 |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Thank you for the explanations.
I followed your suggestion and I have been reading the fluent udf parallel information and I have been trying to understand how this code should be adapted to the parallel approach, but I am completely lost! How can I access to variables? I have been playing with the #if !RP_HOST, #if RP_NODE, node_to_host_real(Temp1), but so far nothing have worked. Can anyone give me a guide? Thank you. |
|
March 25, 2019, 06:44 |
|
#12 |
Senior Member
Join Date: Nov 2011
Posts: 109
Rep Power: 15 |
The macros that you mentioned are only used to identify particular nodes. In order to access the solution variables (temperature, velocity...) you need to use the same access macros that you would use for serial implementation. No difference here.
There is a section on "Cell MAcros" on the Fluent manual. For example, to access density in a cell you'd use C_R(c,t). All the info you need are in the fluent manual. If you have any specific issue you can post it here and me (or other people) may get a chance in guessing what's wrong but without being specific I cannot do anything but refer you to the fluent manual Good luck! |
|
March 25, 2019, 07:05 |
|
#13 | |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Once again, I am very pleased with your help.
I am trying to solve the issue you mentioned. Quote:
Thank you so much. Here it is my current code: Code:
DEFINE_ADJUST(temp_adjust, domain) { real current_time; current_time = CURRENT_TIME; div_t divide; real dt; dt = RP_Get_Real("dt"); divide = div(current_time * 100., dt * 100.); cell_t c; int i; real Temp1[408]; real Temp2[408]; #if !RP_HOST if (divide.rem == 0){ Thread *t1 = Lookup_Thread(domain, 18); Thread *t2 = Lookup_Thread(domain, 19); /*----------------body 1 -----------------*/ i = 0; begin_c_loop (c, t1) { Temp1[i] = C_T(c, t1); C_T(c, t1) = 300.; i ++; } end_c_loop (c, t1) node_to_host_real_1(Temp1); /*----------------body 2 -----------------*/ i = 0; begin_c_loop (c, t2) { Message("Temperatura = %g \n", Temp1[i]); Temp2[i] = C_T(c, t2); C_T(c, t2) = Temp1[i]; i ++; } end_c_loop (c, t2) } #endif } |
||
March 25, 2019, 07:29 |
|
#14 |
Senior Member
Join Date: Nov 2011
Posts: 109
Rep Power: 15 |
What are you trying to achieve is not easy and you are not using the correct strategy. Is your mesh conformal at the interface? Do you have an exact mapping between the nodes at the interface of the two domains?
If not you have to interpolate your data when passing the information and that is not easy. Also another issue is that you're passing data by node ID. Your first loop fills Temp1[i] with the cell temperature but, even if you were to pass correctly this array to the second wall, you cannot be sure that C_T(c,t2) corresponds to the same node where Temp1[i] has been recorded. You have to check that the coordinates are the same (within tolerance). You cannot even be sure that the second loop is shorter than the first one. If not your code will segf when trying to access Temp1[i] on a out of bound index. Also, when passing arrays between nodes you have to first communicate the dimension of the array. I suggest you study a bit of MPI to understand how data communication works. Have you tried communicating boundary conditions by just exporting and reading boundary profiles from Fluent? Fluent can interpolate those data on non conformal grids for you (not sure about the quality of the interpolation, I always work with conformal grids) but I think it's worth a shot Last edited by robboflea; March 25, 2019 at 07:30. Reason: added more details |
|
March 25, 2019, 07:54 |
|
#15 | |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Quote:
In reality, both solid have similarly structured mesh. Nevertheless, I am not sure if both have the same cell numbering order (most probably not). Because both meshes are "equal", with the same number of volumes, I believe I can avoid the interpolation you mention. It is just a translation of the temperature with step size. My first approach was writing coordinates and temperatures to a file, but I got the same kind of issues so I gave up. Do you believe it would be a better approach? Is there a way to refer to a cell by its coordinates? Thanks. |
||
March 25, 2019, 08:21 |
|
#16 |
Senior Member
Join Date: Nov 2011
Posts: 109
Rep Power: 15 |
There is no way to refer to the cell by coordinates but it is possible to access to the cell centroid and check its coordinates. With this you may be able to check that you're passing the information between the same node. However it is a very time-consuming and tedious process (and you don't want to do this every time you do the passing of information).
If I were you I'd just avoid using UDFs in your situation and use .prof files. |
|
March 25, 2019, 08:25 |
|
#17 | |
New Member
Sérgio Cavaleiro Costa
Join Date: Nov 2017
Location: Lisbon, Portugal
Posts: 12
Rep Power: 9 |
Quote:
I will see profile files then. |
||
Tags |
temperature, transient 3d, udf crash |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inlet temperature as a function of outlet temperature UDF | wimblo | Fluent UDF and Scheme Programming | 5 | November 25, 2021 07:06 |
whats the cause of error? | immortality | OpenFOAM Running, Solving & CFD | 13 | March 24, 2021 08:15 |
problem in temperature and liquid fraction value in the udf | durg | FLUENT | 0 | October 23, 2018 02:52 |
Outlet temperature to temperature boundary condition of velocity inlet. (UDF) | dillon | Fluent UDF and Scheme Programming | 3 | March 25, 2018 12:06 |
UDF slip and temperature jump from IFRT | abir | Fluent UDF and Scheme Programming | 1 | July 30, 2012 06:44 |