# Inlet temperature as a function of outlet temperature UDF

 Register Blogs Members List Search Today's Posts Mark Forums Read

 November 5, 2018, 09:44 Inlet temperature as a function of outlet temperature UDF #1 New Member   William Harvey Join Date: Jan 2018 Location: Montréal, Québec Posts: 5 Rep Power: 7 Hi, I am currently working on a project where cooling towers need to be simulated. The cooling towers work the following way: -A constant flow of air enters the side of the tower at a certain temperature -The same flow of air exits the top of the tower at a higher temperature I'd like to use a UDF to impose a relationship between the temperature parameters (ex: T_outlet = avg(T_inlet)+30). I have UDFs where the temperature varies in time, but none where the temperature varies with respect to some other temperature in the domain. Does anybody know how I could achieve this? Thanks in advance.

 November 23, 2021, 12:05 #2 New Member   Join Date: Oct 2021 Posts: 13 Rep Power: 3 It's a shame this didn't get a reply. I'm having similar issues as I need to define an outlet temperature to equal the temperature of the fluid body immediately prior to the outlet. My simulation uses an oscillating fluid flow so defining a constant outlet temperature affects my simulation greatly. My C knowledge is minimal; I can write the basic programs to compute "hello world", convert Celsius to Fahrenheit and determine whether a number is prime or not; but composing some C-code for a UDF is a different kettle of fish entirely. #include "udf.h" DEFINE_PROPERTY(outlet_temperature) { Domain *d; real tavg =0.; real temp, volume, vol_tot; Thread *t; face_t f; d = Get_Domain(1) begin_f_loop(c,t) { volume = C_VOLUME(f,t); /* face volumes */ temp = F_T(f,t); /* face temperatures */ vol_tot += volume; tavg += temp*volume; } end_f_loop(c,t) tavg /=vol_tot } This is something that I have butchered from the UDF manual. I don't think it is even close to being correct. What I want the code to do is define the outlet temperature as equal to the temperature immediately prior to the outlet. If this is how "faces" work, then what I'd want is to define the temperature of the final face as equal to the temperature of the preceding face. I am using a laminar solver and a transient fluid flow with a defined inlet temperature, with an oscillating fluid velocity. Any help would be greatly appreciated.

 November 24, 2021, 03:44 #3 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,249 Rep Power: 32 Code: ```#include "udf.h" DEFINE_PROFILE(outlet_temperature,t,i) { face_t f; real temperature; begin_f_loop(f,t) { c0 = F_C0(f,t); /*get pointer to cell adjusted to face*/ t0 = THREAD_T0(t); /*get pointer to thred adjusted to face*/ temperature = C_T(c0,t0); /*get temperature in cell adjusted to face*/ F_PROFILE(f,t,i) = temperature; /*apply temperature from cell adjusted to face to that face*/ } end_f_loop(f,t) }``` __________________ best regards ****************************** press LIKE if this message was helpful

 November 24, 2021, 12:54 #4 New Member   Join Date: Oct 2021 Posts: 13 Rep Power: 3 Hi AlexanderZ. Many thanks for your sample code, with very helpful code comments. Apologies for the follow-up questions; Did you define t0 and c0 as real? When I try to interpret the function using ansys I get the following two errors: invalid type conversion: pointer to structure -> double (for t0 = THREAD_TO(t); ) invalid type conversion: double -> pointer to char (for temperature = C_T(c0,t0); ) I am also running this simulation with parallel processing, will this be an issue? Thank you James

 November 24, 2021, 22:21 #5 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,249 Rep Power: 32 I forgot to define c0,t0 compile code Code: ```#include "udf.h" DEFINE_PROFILE(outlet_temperature,t,i) { face_t f; cell_t c0; thread *t0; real temperature; begin_f_loop(f,t) { c0 = F_C0(f,t); /*get pointer to cell adjusted to face*/ t0 = THREAD_T0(t); /*get pointer to thred adjusted to face*/ temperature = C_T(c0,t0); /*get temperature in cell adjusted to face*/ F_PROFILE(f,t,i) = temperature; /*apply temperature from cell adjusted to face to that face*/ } end_f_loop(f,t) }``` James_mCFD likes this. __________________ best regards ****************************** press LIKE if this message was helpful

 November 25, 2021, 07:06 #6 New Member   Join Date: Oct 2021 Posts: 13 Rep Power: 3 Works perfectly, thank you!

 Tags fluent - udf, fluent 14.5, temperature bc, temperature calculation