|
[Sponsors] |
ANSYS UDF target temperature be a function of the physical flowrate |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 2, 2021, 12:40 |
ANSYS UDF target temperature be a function of the physical flowrate
|
#1 |
Member
|
I'm trying to write UDF, which will govern the velocity or mass flowrate at inlet, to keep the tempreture defined at outlet constant at 120 degree Celsius. can anyone find any mistakes in written UDF that I posted below Code:
#include "udf.h" DEFINE_PROFILE(flowrate_Temp,c,t) { face_t f ; F_PROFILE(f,t,nv) = 1.0; real flow_tmp = C_T(c,t); if (flow_tmp > 120.) { printf("Tempreture = %f celcius \n",flow_tmp); printf("Targeted mass-flow rate set at 3.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 3.0; } end_f_loop(f,t) } else if (flow_tmp < 120.) { printf("Time = %f celcius \n",flow_tmp); printf("Targeted mass-flow rate set at 2.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 2.0; } end_f_loop(f,t) } else if (flow_tmp == 120.) { printf("Time = %f celcius \n",flow_tmp); printf("Targeted mass-flow rate set at 1.5 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 1.5; } end_f_loop(f,t) } } |
|
February 2, 2021, 14:36 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Have you tried it? Does it seem to do what you want?
|
|
February 2, 2021, 19:04 |
|
#3 |
Member
|
Nope, didn't work!
I received error on this line Code:
F_PROFILE(f,t,nv) = 1.0; Then I want UDF to find out corresponding tempreture at outlet based upon the flowrate. then it goes through conditional statement, that is, if the tempreture is less than specified/desired value. then the UDF will change the flowrate. and again the iterations will run. like that, it shall reach to desired value, of outlet tempreture, after than keep running the iterations until it reaches to solution convergence. |
|
February 2, 2021, 22:04 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
your header is wonrg
you've mixed up cells with faces compile the code and read log, fix errors read ansys fluent customization manual for examples if you want to apply profile to boundary use faces (F_PROFILE(f,t,i), F_T(f,t)), to apply to zones use cells (F_PROFILE(c,t,i), C_T(c,t))
__________________
best regards ****************************** press LIKE if this message was helpful |
|
February 4, 2021, 14:12 |
|
#5 |
Member
|
Hello,
First of all, thank you 'AlexanderZ', and 'pakk' for replying quickly and effectively to post. I guess, and I don't want to do a comparison here, but based upon the responses, the ANSYS forum is faster and more active than the OpenFOAM forum. Alrighty going back to the post, so this is the newly written UDF code: Code:
#include "udf.h" DEFINE_PROFILE(flowrate_TempBased,t,i) { face_t f ; F_PROFILE(f,t,i) = 1.0; real flow_tmp = F_T(f,t); if (flow_tmp > 774.) { printf("Tempreture = %f celcius \n",flow_tmp); printf("Targeted mass-flow rate set at 3.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,i) = 3.0; } end_f_loop(f,t) } else if (flow_tmp < 772.) { printf("Time = %f celcius \n",flow_tmp); printf("Targeted mass-flow rate set at 2.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,i) = 2.0; } end_f_loop(f,t) } else if (flow_tmp == 773.) { printf("Time = %f celcius \n",flow_tmp); printf("Targeted mass-flow rate set at 1.5 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,i) = 1.5; } end_f_loop(f,t) } } 1. First, I define a certain flowrate during initialization or at the first line of the above-defined UDF. 2. That flowrate will be used for a certain number of iterations until it reaches the particular value of temperature, lets say 120°C. 3. now, the UDF will follow the if loop in which it will see if the temperature reached the desired temperature or not if the desired temperature is 124°C, then it shall increase the flowrate value to 'current_flowrate + 0.01'. 4. Now if the temperature reaches to, let's say 130°C, then it will follow the next if loop where it does 'current_flowrate - 0.01' execution. 5. Once the temperature reaches to the desired value, which is 124°C, it'll keep iterating with that constant value of the temperature until residuals reach to set convergence value. And then, I want to do a set of 500 iterations in between these outlet face temperature checks. Now all these things how to do that? for example: does current running flowrate or velocity can be acquired the same way as the time is acquired, which is: Code:
time=CURRENT_TIME; OR real t = RP_Get_Real("flow-time"); Code:
flowrate=CURRENT_FLOWRATE; OR real fl = RP_Get_Real("flow-rate"); Code:
Temp=CURRENT_TEMP; OR real T = RP_Get_Real("tempreture"); |
|
February 4, 2021, 18:17 |
|
#6 | |
Member
|
Quote:
So this is what I got for the above defined requirement for UDF, please correct me if I am wrong Code:
DEFINE_PROFILE(velocity_TempBased,th,position) { Domain *d; face_t f; real t_avg = 0.; Thread *t; real tmp_e,vol,vol_tot,area; real A[ND_ND]; d = Get_Domain(1); thread_loop_f(t,d) { if (THREAD_ID(t) == 11) { begin_f_loop(f,t) { vol = F_AREA(A,f,t); /* get cell volume */ tmp_e = F_T(f,t); area = NV_MAG(A); vol_tot += area; t_avg += (tmp_e*area); } end_f_loop(f,t) t_avg /= vol_tot; } } begin_f_loop(f,th) { if (t_avg = 301.) F_PROFILE(t,th,position) = 0.1; if (t_avg > 301.) F_PROFILE(f,th,position) = 0.; } end_f_loop(f,th) } |
||
February 5, 2021, 13:15 |
|
#7 |
Member
|
Hello All,
This is another UDF I have generated, haven't got chance to run it yet. Posting here on website, because if anyone wants to try it. Feel free! Although, couple of things I still not been able to figure it out: 1. Instead of providing fixed value for flowrate/velocity at inlet in each if loop as the tempreture at outlet face changes, I not able to figure it out how to provide the value for flowrate/velocity at inlet as 'current_flowrate + 0.01' or 'current_flowrate - 0.01', where 'current_flowrate' is taken from FLUENT system. 2. How to let fluent run the solver with the specific settings for few iterations, let say 500 iterations, and then allow it read the tempreture at outlet face, and as per that change the inlet flowrate or velocity value. Code:
#include "udf.h" DEFINE_PROFILE(velocity_TempBased,th,position) { Domain *d; face_t f; real t_avg = 0.; Thread *t; real tmp_e,vol,vol_tot,area; real A[ND_ND]; d = Get_Domain(1); thread_loop_f(t,d) { if (THREAD_ID(t) == 11) { begin_f_loop(f,t) { vol = F_AREA(A,f,t); /* get cell volume */ tmp_e = F_T(f,t); area = NV_MAG(A); vol_tot += area; t_avg += (tmp_e*area); } end_f_loop(f,t) t_avg /= vol_tot; } } begin_f_loop(f,th) { if (t_avg > 774.) { printf("Tempreture = %f Kelvin \n",t_avg); printf("Targeted mass-flow rate set at 3.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,i) = 3.0; } end_f_loop(f,t) } else if (t_avg < 772.) { printf("Time = %f Kelvin \n",t_avg); printf("Targeted mass-flow rate set at 2.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,i) = 2.0; } end_f_loop(f,t) } else if (t_avg == 773.) { printf("Time = %f Kelvin \n",t_avg); printf("Targeted mass-flow rate set at 1.5 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,i) = 1.5; } end_f_loop(f,t) } } end_f_loop(f,th) } Last edited by Ash Kot; February 5, 2021 at 13:22. Reason: Forgot to add the things that I haven't been able to accomplish yet |
|
March 9, 2021, 00:49 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may use journal file to control number of iterations
according to your code, compile it first and read log as far as I know, there is no "current_flowrate" build_in macro so you should make it by your own. there are few threads which discuss how to get flow rate
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 22, 2024, 10:08 |
|
#9 |
New Member
Join Date: Nov 2023
Posts: 2
Rep Power: 0 |
Hello, I need exactly such a UDF code. Were you able to solve the problem? If you solved it, can you share it? Thank you...
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF to get the average temperature of a face and use it to define a property | gdb | Fluent UDF and Scheme Programming | 19 | November 3, 2022 04:11 |
How To write a Correct UDF (FLUENT) for Specific heat as Function of Temperature for | atulsbhat | FLUENT | 4 | December 10, 2019 11:57 |
Calculation of the Governing Equations | Mihail | CFX | 7 | September 7, 2014 07:27 |
ParaView for OF-1.6-ext | Chrisi1984 | OpenFOAM Installation | 0 | December 31, 2010 07:42 |
Droplet Evaporation | Christian | Main CFD Forum | 2 | February 27, 2007 07:27 |