|
[Sponsors] |
c_udmi returns zero when called in another udf |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 29, 2018, 12:03 |
c_udmi returns zero when called in another udf
|
#1 |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
Hi!
I am trying to create a udf which finds the average temperature at the outlet of the domain and then applies it to the inlet (increased by 7.58). I wrote the following udf but in the DEFINE_PROFILE the c_udmi returns zero and thus the F_PROFILE(f,t,nv) gets equal to 7.58 constantly......can someone help please?? DEFINE_EXECUTE_AT_END(average_exit_temp) { face_t f; cell_t c0; Domain *d=Get_Domain(1); Thread *t=Lookup_Thread(d,8), *t0; real vol=0, tavg=0, temp=0, vol_tot=0; t0=THREAD_T0(t); begin_f_loop(f,t) { c0=F_C0(f,t); vol=C_VOLUME(c0,t0); vol_tot+=vol; temp=C_T(c0,t0); tavg+=temp*vol; } end_f_loop(f,t) tavg/=vol_tot; begin_f_loop(f,t) { c0=F_C0(f,t); C_UDMI(c0,t,0)= tavg; printf("\n Average temperature is: %g\n",C_UDMI(c0,t,0)); } end_f_loop(f,t) } DEFINE_PROFILE(inlet_temperature, t, nv) { face_t f; Thread *t0; cell_t c0; real tavg; t0=THREAD_T0(t); begin_f_loop(f,t) { c0=F_C0(f,t); F_PROFILE(f,t,nv)= C_UDMI(c0,t0,0) + 7.58; printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv)); } end_f_loop(f,t) } |
|
August 29, 2018, 21:12 |
|
#2 |
Senior Member
|
You just need to store one value "tavg", what do you need a "UDM" for? You can simply declare "tavg" in the file scope.
The "c0" in "DEFINE_PROFILE" is the cell index adjacent to inlet boundary, which has no overlap with cell index adjacent to outlet boundary. Suppose there is a grid with 100*100 cells and is number from top left to bottom right. The inlet and outlet boundary are located at the left and right ends, respectively. Then in the "DEFINE_EXECUTE_AT_END" you assigned values for cells with index ranging 9900 to 9999, then in the "DEFINE_PROFILE" you obtain values from cells with index ranging 0 to 99. |
|
August 30, 2018, 04:38 |
|
#3 | |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
Quote:
So as far as I understood from what you wrote, in my case, I could use the following code, wright? #include "udf.h" real tavg=280.; DEFINE_EXECUTE_AT_END(average_exit_temp) { face_t f; cell_t c0; Domain *d=Get_Domain(1); Thread *t=Lookup_Thread(d,8), *t0; real vol=0, temp=0, vol_tot=0; t0=THREAD_T0(t); begin_f_loop(f,t) { c0=F_C0(f,t); vol=C_VOLUME(c0,t0); vol_tot+=vol; temp=C_T(c0,t0); tavg+=temp*vol; } end_f_loop(f,t) tavg/=vol_tot; } DEFINE_PROFILE(inlet_temperature, t, nv) { face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,nv)= tavg + 7.58; printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv)); } end_f_loop(f,t) } The problem is though that although it is interpreted without a problem, when I start the calculation I get a "floating poitn axception error". Also the "printf" I used says that "Inlet temperature is: inf"......what could be the problem? Thank you very much for your time! |
||
August 30, 2018, 06:23 |
|
#4 |
Senior Member
|
You should check whether the thread is empty or the sum of volume is non-zero. What is the output of the code below?
Code:
#include "udf.h" real tavg=280.0; DEFINE_EXECUTE_AT_END(average_exit_temp) { face_t f; cell_t c0; Domain *d=Get_Domain(1); Thread *t=Lookup_Thread(d,8), *t0; real vol=0, temp=0, vol_tot=0; t0=THREAD_T0(t); Message("number of faces: %d\n", THREAD_N_ELEMENTS(t)); begin_f_loop(f,t) { c0 = F_C0(f,t); vol = C_VOLUME(c0,t0); vol_tot += vol; temp = C_T(c0,t0); tavg += temp*vol; } end_f_loop(f,t); Message("sum of volumes: %g\n", vol_tot); tavg /= vol_tot; } DEFINE_PROFILE(inlet_temperature1, t, nv) { face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,nv)= tavg + 7.58; printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv)); } end_f_loop(f,t) } |
|
August 30, 2018, 06:42 |
|
#5 |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
So I run the code (actually changed the "message" with "printf" because I could not interpret it) and it printed this:
number of faces: 0 sum of volumes: 0 number of faces: 0 sum of volumes: 0 number of faces: 0 sum of volumes: 0 number of faces: 6 sum of volumes: 1.33696e-07 number of faces: 0 sum of volumes: 0 |
|
August 30, 2018, 06:48 |
|
#7 |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
I just checked, it is correct (8) for the outlet of the domain.....
|
|
August 30, 2018, 07:28 |
|
#8 |
Senior Member
|
You can use the following code (just paste them to the the fluent TUI, i.e., the console below the graphics window)
Code:
(rp-var-define 'jos-thread-id-list () 'list #f) (rpsetvar 'jos-thread-id-list ()) (for-each (lambda (t) (rpsetvar 'jos-thread-id-list (list-add (rpgetvar 'jos-thread-id-list) (thread-id t)))) (get-all-threads)) (rpgetvar 'jos-thread-id-list) (rp-var-define 'jos-thread-name-list () 'list #f) (rpsetvar 'jos-thread-name-list ()) (for-each (lambda (t) (rpsetvar 'jos-thread-name-list (list-add (rpgetvar 'jos-thread-name-list) (thread-name t)))) (get-all-threads)) (rpgetvar 'jos-thread-name-list) |
|
August 30, 2018, 08:13 |
|
#9 | |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Quote:
Are you using 5 cores? best regards |
||
August 30, 2018, 08:18 |
|
#10 | |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
Quote:
jos-thread-id-list > jos-thread-id-list > > (6 3 14 2 8 7 13 1 9 10 11 12 5) > adapt/ file/ solve/ adjoint/ mesh/ surface/ close-fluent parallel/ views/ define/ plot/ display/ report/ > adapt/ file/ solve/ adjoint/ mesh/ surface/ close-fluent parallel/ views/ define/ plot/ display/ report/ > jos-thread-name-list > jos-thread-name-list > > (zone_wall part_4-surface_body interior-zone_wall-shadow interior-zone_wall outlet inlet symmetry interior-part_4-surface_body wall_tank-part_4-surface_body-zone_wall wall_tank-zone_wall plates-part_4-surface_body plates-zone_wall wall_tank-part_4-surface_body-zone_wall-shadow) > |
||
August 30, 2018, 08:19 |
|
#11 |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
||
August 30, 2018, 09:42 |
|
#12 |
Senior Member
|
Did not see that coming. Please try the following code:
Code:
#include "udf.h" real tavg=280.0; DEFINE_EXECUTE_AT_END(average_exit_temp) { face_t f; cell_t c0; Domain *d=Get_Domain(1); Thread *t=Lookup_Thread(d,8), *t0; real vol=0, temp=0, vol_tot=0; t0=THREAD_T0(t); tavg = 0.0; #if RP_NODE || !PARALLEL begin_f_loop(f,t) { c0 = F_C0(f,t); vol = C_VOLUME(c0,t0); vol_tot += vol; temp = C_T(c0,t0); tavg += temp*vol; } end_f_loop(f,t); tavg = PRF_GRSUM1(tavg); vol_tot = PRF_GRSUM1(vol_tot); tavg /= vol_tot; Message("processor: %d,tavg: %g\n", myid, vol_tot); #endif } DEFINE_PROFILE(inlet_temperature1, t, nv) { face_t f; #if RP_NODE || !PARALLEL begin_f_loop(f,t) { F_PROFILE(f,t,nv)= tavg + 7.58; printf("\n Inlet temperature is: %g\n",F_PROFILE(f,t,nv)); } end_f_loop(f,t) #endif } |
|
August 30, 2018, 09:52 |
|
#13 |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
||
August 30, 2018, 11:09 |
|
#15 | |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
Quote:
So just to understand exactly what happened, the problem was that each core was calculating a different value? Or something else? |
||
August 30, 2018, 21:23 |
|
#16 |
Senior Member
|
The solver processes are composed of one host node plus n (n=4 in your case) computing nodes. The host process definitely have no data of your outlet thread, so it will always result in 0./0. (i.e., FPE error you have encountered). Depending on the mesh partition, the computing node may or may not have data of your outlet thread, so it may cause FPE. Besides, the (temperature*volume) and (volume) should be summed from all computing nodes and then compute the average value, which is done with PRF_GRSUM1.
|
|
August 31, 2018, 04:05 |
|
#17 | |
New Member
Jannis
Join Date: Aug 2018
Posts: 12
Rep Power: 8 |
Quote:
Best regards, Jannis |
||
Tags |
c_udmi, fluent - udf, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF: How to load data from an external file into a vector | EmiS | Fluent UDF and Scheme Programming | 17 | January 14, 2019 02:55 |
dynamic contact angle udf returns no value to solver | shiraz_man67 | Fluent UDF and Scheme Programming | 5 | July 3, 2018 15:51 |
Help with unsteady calculation with source/sink UDF | RobV | Fluent UDF and Scheme Programming | 3 | March 10, 2016 04:45 |
Source Term UDF VS Porous Media Model | pchoopanya | Fluent UDF and Scheme Programming | 1 | August 28, 2013 07:12 |
Help me to check my UDF | Liufeng_ustb | Fluent UDF and Scheme Programming | 2 | May 7, 2013 11:25 |