|
[Sponsors] |
July 15, 2018, 17:10 |
UDF for function defined by parts
|
#1 |
New Member
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8 |
Hi, I'm currently working on a model to define the pressure and temperature of the atmospheric air, in an altitude dependant model(see attached file).
I'm reading a lot of different guides, but I'm not familiar with the define types and every example I can find involves different profiles(as shown in the udf guide). It should be pretty easy to make my case, I hope any of you can give me a hand or give me any tips so I can start to understand the coding. Thanks in advance! PS: I will change the h in the ecuations, since my model has a 4 m/s ascend velocity it will be h=4*time Last edited by miguwhynot; July 15, 2018 at 18:50. |
|
July 15, 2018, 18:13 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Use the DEFINE_PROFILE macro, loop through all faces on the boundary and find the height with F_CENTROID (where x[1] would correspond to the y-direction in the Cartesian coordinate system) and then use conditional if statements to apply the relevant equation.
The examples in the UDF manual provide starting codes for this task. Example 2 contains one conditional statement, and you would then extend to include three sections: Code:
if ( (h > 0.) && (h <= 11.e3) ) { // Eq. 2a } else if (h <= 20.e3) { // Eq. 2b } else if (h <= 32.e3) { // Eq. 2c } else { // Capture h values outside the allowed range: // print a message to the console and stop. Message("%d: Error: h=%e not allowed.\n",myid,h); return; } |
|
July 15, 2018, 19:18 |
|
#3 |
New Member
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8 |
Thank you for your fast reply, it has been really helpfull. I've checked the example and it was indeed pretty similar to my needs.
Based on my model, I now have a pressure defined only by time dependant ecuations as follows: For times between 0s and 2750s Eq 1 For times between 2750 and 5000s Eq 2 For times between 5000 and 8000s Eq 3 I want to use this equations to set the value of my inlet flow pressure. This is what I have so far (thanks for the coding from your previous reply): #include "udf.h" DEFINE_PROFILE(pressure_inlet, thread, position) { face_t f; real t = CURRENT_TIME; begin_f_loop(f, thread) { if (t <= 2750) ) { F_PROFILE(f, thread, position) = 101325.0*((288.15-0.0065*4*t)/288.15)^5.25577; } else if (t <= 5000) { F_PROFILE(f, thread, position) = 22632^(-(4*t-1000)/6341.62); } else if (h <= 8000) { F_PROFILE(f, thread, position) = 5474.87*((216.65+0.010*(4*t-20000))/216.65)^-34.163; } else { // Capture h values outside the allowed range: // print a message to the console and stop. Message("%d: Error: h=%e not allowed.\n",myid,h); return; } end_ |
|
July 15, 2018, 19:23 |
|
#4 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
||
July 15, 2018, 19:36 |
|
#5 |
New Member
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8 |
Thanks again, for your fast reply.
Final code: #include "udf.h" DEFINE_PROFILE(pressure_inlet, thread, position) { face_t f; real t = CURRENT_TIME; begin_f_loop(f, thread) { if (t <= 2750) ) { F_PROFILE(f, thread, position) = 101325.0*pow((288.15-0.0065*4*t)/288.15,5.25577) } else if (t <= 5000) { F_PROFILE(f, thread, position) = pow(22632,(-(4*t-1000)/6341.62)); } else if (t <= 8000) { F_PROFILE(f, thread, position) = 5474.87*pow(((216.65+0.010*(4*t-20000))/216.65),-34.163); } else { // Capture t values outside the allowed range: // print a message to the console and stop. Message("%d: Error: t=%e not allowed.\n",myid,t); return; } end_ Would this be a correct answer? Thank you again for your time and efforts. |
|
July 15, 2018, 19:52 |
|
#6 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
You're missing the end_f_loop and a few brackets are not matching. Carefully check each opening bracket has a closing bracket and is where it should be, and then try compiling the UDF (the compilation notifications are usually helpful to identify errors in your code).
|
|
July 15, 2018, 20:52 |
|
#7 |
New Member
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8 |
Compilation notifications were really useful.
I think I know have it: #include "udf.h" DEFINE_PROFILE(pressure_inlet, thread, position) { face_t f; real t = CURRENT_TIME; begin_f_loop(f, thread) { if (t <= 2750) { F_PROFILE(f, thread, position) = 101325.0*pow((288.15-0.0065*4*t)/288.15,5.25577); } else if (t <= 5000) { F_PROFILE(f, thread, position) = pow(22632,(-(4*t-1000)/6341.62)); } else if (t <= 8000) { F_PROFILE(f, thread, position) = 5474.87*pow(((216.65+0.010*(4*t-20000))/216.65),-34.163); } else { // Capture t values outside the allowed range: // print a message to the console and stop. Message("%d: Error: t=%e not allowed.\n",myid,t); return; } end_f_loop(f,thread) } } Compilation seemed to work just fine. Is it just correct? Thank you again for your time and sorry for my many questions. |
|
July 17, 2018, 02:55 |
|
#8 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Sounds good, try running the simulations and see if the results are as expected. You could monitor the inlet conditions with a surface monitor to double check that the correct values have been applied.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Not able to use Interpreted in User Defined Function (UDF) | Touré | FLUENT | 0 | March 8, 2017 20:15 |
UDF error:strcpy has already been defined in the curren | alinik | FLUENT | 0 | November 2, 2016 21:17 |
Velocity inlet user defined function UDF in fluent | Ammofreak | Fluent UDF and Scheme Programming | 0 | January 14, 2014 05:59 |
Fluent User defined Scalars and UDF | Anirudh_Deodhar | Fluent UDF and Scheme Programming | 0 | February 16, 2011 21:16 |
UDF...UDF...UDF...UDF | Luc SEMINEL | FLUENT | 0 | November 25, 2002 05:03 |