|
[Sponsors] |
Asking about UDF of Pressure Inlet Boundary Condition |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 17, 2019, 03:39 |
Asking about UDF of Pressure Inlet Boundary Condition
|
#1 |
New Member
Pham Van Chien
Join Date: Oct 2018
Location: Korea
Posts: 9
Rep Power: 8 |
Dear CFD Experts,
I am trying to simulate the combustion process of an internal combustion engine. In my simulation, the fuel injection is an intermittent process, not a continuous process. The following is the injection feature: - The inlet pressure will be 180bar (18238500 Pa) if time <= 0.03333333 seconds. - The inlet pressure will be 0bar if time > 0.03333333 seconds. The following is the UDF that I tried to use: #include "udf.h" DEFINE_PROFILE(inlet_press,th,i) { real pressure_profile; face_t f; real t = CURRENT_TIME; begin_f_loop(f,th) { if (CURRENT_TIME <= 0.03333333) { pressure_profile = 18238500; } else { pressure_profile = 0; } F_PROFILE(f,th,i) = pressure_profile; } end_f_loop(f,th); } However, when evaluating the results (velocity contour), I realized that the fuel injection feature is not the same as I wanted, it is still a continuous injection process with a constant pressure of 180bar from the beginning to the end of the simulation. I have no experience in writing UDF, so I have not found the wrong points I have made. Hope you see my UDF and give me advice on how I should edit my UFD. I posted this thread looking forward to receiving everyone's help. Your help is really helpful to me. Thank in advance! Pham Van Chien |
|
January 17, 2019, 07:12 |
|
#2 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
CURRENT_TIME is a macro not a variable, and I forget its return structure when called to be evaluated. Instead of
Code:
if (CURRENT_TIME <= 0.03333333) Code:
if (t <= 0.03333333) |
|
January 17, 2019, 08:06 |
|
#3 |
New Member
Pham Van Chien
Join Date: Oct 2018
Location: Korea
Posts: 9
Rep Power: 8 |
Dear Mr. LuckyTran,
Thank you so much for your replying. I will edit my UDF as your advice and calculate the solution again for checking the edited UDF. Hope to continue to receive your advice in the future. Best Regards Pham Van Chien |
|
December 3, 2020, 05:04 |
Transient pressure inlet
|
#4 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Pham,
did you try the edited code? Did it work? I want to solve a similar problem. |
|
December 4, 2020, 05:06 |
Transient pressure inlet
|
#5 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Lucky Tran,
Could you please comment on the following UDF. My simulation is similar to as stated in the above discussion. I have a pressure inlet but the pressure decreases gradually with time, and after 3 seconds there is no flow into the domain from the inlet. I've used a UDF but I can see the pressure velocity profiles still after 3 seconds. I'm not familiar with coding. I need some suggestions and if I made a mistake please correct me. /************************************************** ******************** unsteady.c UDF for specifying a transient pressure profile boundary condition ************************************************** *********************/ #include "udf.h" DEFINE_PROFILE(inlet_press,th,i) { real pressure_profile; face_t f; real t = CURRENT_TIME; begin_f_loop(f,th) { if (t <= 0.5) { pressure_profile = 150000; } else if (0.5 <= t <= 1) { pressure_profile = 140000; } else if (1 <= t <= 1.5) { pressure_profile = 130000; } else if (1.5 <= t <= 2.3) { pressure_profile = 120000; } else if (2.3 <= t <= 3) { pressure_profile = 110000; } else { pressure_profile = 0; } F_PROFILE(f,th,i) = pressure_profile; } end_f_loop(f,th); } |
|
December 4, 2020, 15:14 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
||
December 29, 2020, 09:23 |
Temperature should rise as a step
|
#7 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Pak,
Thanks for the instantaneous reply. In addition, I've one more concern. In this heat transfer problem, after some time (let's say some xx minutes), the temperature of the solid reaches 380K (threshold value). After reaching this threshold value, the temperature of the solid should increase as a step up to 700K. I've done this in COMSOL using 'events'. How to achieve this in Fluent? Thank you |
|
December 30, 2020, 06:36 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
in fluent interface check zone ID of your solid.
With UDF find temperature of that solid zone using loop over cells in that thread (in other words in that zone) If criteria is met, change temperature in solid zone
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 3, 2021, 12:26 |
Writing UDF
|
#9 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Alexander, thanks for sharing your knowledge.
But to be honest, I've no idea in writing UDF, I tried to figure it out by looking at the user manuals and some tutorials online but no one has done this or at least a similar one. So, could you please write an example UDF for this issue. the zone id's are 78, 81, 98 (example). This would be a great help. and moreover, I have no idea where to interpret this UDF in this problem. For example, when we are using a UDF for inlet velocity, we can interpret this in the boundary condition. But in the above case, I don't know where to interpret the UDF. Thank you. |
|
January 11, 2021, 07:27 |
Updating temperature values after reaching threshold values
|
#10 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Could someone sort this out for me.
I have a reply from one person, but I'm not sure how to interpret or implement it. In this heat transfer problem, after some time (let's say some xx minutes), the temperature of the solid reaches 380K (threshold value). After reaching this threshold value, the temperature of the solid should increase as a step up to 700K. I've done this in COMSOL using 'events'. How to achieve this in Fluent? Thank you[/QUOTE] |
|
January 13, 2021, 03:16 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
the thing is, you are writing code by your own, learn how to do it.
if code doesnt work, you put it here with description of problems users are trying to help you if possible, others can learn something from your case either as an exception I'm giving you this code(only because the main part of it is in examples in manual, ansys fluent customization manual) this is code for zone 78 only. for other zones you should do it by your own. you may make 3 define_adjust macro for each zone, or modify this macro to call it for 3 zones compile code Code:
#include "udf.h" DEFINE_ADJUST(check_temperature_zone78, d) { real tavg = 0.; real temp,volume,vol_tot; Thread *t; int nid = 78; cell_t c; t = Lookup_Thread (d, nid); /* Loop over all cells in zone with id 78*/ begin_c_loop(c,t) { volume = C_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */ vol_tot += volume; tavg += temp*volume; } end_c_loop(c,t) #if RP_NODE vol_tot = PRF_GRSUM1(vol_tot); tavg = PRF_GRSUM1(tavg) #endif /* RP_NODE */ tavg /= vol_tot; Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg); /* Check criteria, 380K*/ if (tavg > 380) { begin_c_loop(c,t) { C_T(c,t) = 700; } end_c_loop(c,t) } }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 20, 2021, 11:49 |
|
#12 | |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Alexanderz, thank you so much for the code.
But I encountered issues during compiling. I have managed to resolve a syntax error, but due to my poor knowledge of coding, I'm left with one warning. The code is: /************************************************** ******************** unsteady.c UDF for changing temperature ************************************************** *********************/ #include "udf.h" DEFINE_ADJUST(check_temperature_zone38, d) { real tavg = 0; real temp,volume,vol_tot; Thread *t; int nid = 38; cell_t c; t = Lookup_Thread (d, nid); /* Loop over all cells in zone with id 38*/ begin_c_loop(c,t) { volume = C_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */ vol_tot += volume; tavg += temp*volume; } end_c_loop(c,t) #if RP_NODE vol_tot = PRF_GRSUM1(vol_tot); tavg = PRF_GRSUM1(tavg); #endif /* RP_NODE */ tavg /= vol_tot; Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg); /* Check criteria, 301K*/ if (tavg > 301) { begin_c_loop(c,t) { C_T(c,t) = 700; } end_c_loop(c,t) } } And the warning during compiling: "warning C4700: uninitialized local variable 'vol_tot' used" May be because of this warning, the results are unchanged which are actually supposed to change after compiling this code. And here is what it shows after clicking 'build' Copied H:\Lithium\Mesh\Codes\Code editors/H:\Lithium\Mesh\Codes\Code editors\zone38.c to libudf\src Creating user_nt.udf file for 3ddp_host ... (system "copy "C:\PROGRA~1\ANSYSI~1\v192\fluent"\fluent19.2.0\sr c\udf\makefile_nt.udf "libudf\win64\3ddp_host\makefile" ") 1 file(s) copied. (chdir "libudf")(chdir "win64\3ddp_host")# Generating ud_io1.h zone38.c H:\Lithium\Mesh\Codes\Code editors\libudf\src\zone38.c(23) : warning C4700: uninitialized local variable 'vol_tot' used # Generating udf_names.c because of makefile zone38.obj udf_names.c # Linking libudf.dll because of makefile user_nt.udf udf_names.obj zone38.obj Microsoft (R) Incremental Linker Version 14.28.29336.0 Copyright (C) Microsoft Corporation. All rights reserved. Creating library libudf.lib and object libudf.exp Creating user_nt.udf file for 3ddp_node ... (system "copy "C:\PROGRA~1\ANSYSI~1\v192\fluent"\fluent19.2.0\sr c\udf\makefile_nt.udf "libudf\win64\3ddp_node\makefile" ") 1 file(s) copied. (chdir "libudf")(chdir "win64\3ddp_node")# Generating ud_io1.h zone38.c H:\Lithium\Mesh\Codes\Code editors\libudf\src\zone38.c(23) : warning C4700: uninitialized local variable 'vol_tot' used # Generating udf_names.c because of makefile zone38.obj udf_names.c # Linking libudf.dll because of makefile user_nt.udf udf_names.obj zone38.obj Microsoft (R) Incremental Linker Version 14.28.29336.0 Copyright (C) Microsoft Corporation. All rights reserved. Creating library libudf.lib and object libudf.exp Done. Quote:
Last edited by virothi; January 20, 2021 at 13:34. |
||
January 21, 2021, 02:09 |
|
#13 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
was
Code:
t = Lookup_Thread (d, nid); /* Loop over all cells in zone with id 38*/ begin_c_loop(c,t) Code:
t = Lookup_Thread (d, nid); vol_tot = 0; /* Loop over all cells in zone with id 38*/ begin_c_loop(c,t)
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 21, 2021, 06:06 |
|
#14 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Alexanderz,
I really appreciate your interest in solving the issues posted. I've now successfully compiled the code without any errors. But I can see that there is no change in the temperature profile after compiling the code and running the simulation. I have attached 3 screenshots 1. After clicking build 2. After clicking Load 3. After running the simulation. I gave it for zone 37 and asked to change the temperature to 700K after reaching an average temperature of 301K in that zone. Here is the entire code which you have provided me after editing Code:
#include "udf.h" DEFINE_ADJUST(check_temperature_zone37, d) { real tavg = 0; real temp,volume,vol_tot; Thread *t; int nid = 37; cell_t c; t = Lookup_Thread (d, nid); vol_tot = 0; /* Loop over all cells in zone with id 37*/ begin_c_loop(c,t) { volume = C_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */ vol_tot += volume; tavg += temp*volume; } end_c_loop(c,t) #if RP_NODE vol_tot = PRF_GRSUM1(vol_tot); tavg = PRF_GRSUM1(tavg); #endif /* RP_NODE */ tavg /= vol_tot; Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg); /* Check criteria, 301K*/ if (tavg > 301) { begin_c_loop(c,t) { C_T(c,t) = 700; } end_c_loop(c,t) } } |
|
January 21, 2021, 06:25 |
|
#15 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
most likely you didn't hook adjust function
user-defined -> function hooks -> adjust -> select udf function you should have message in console on each timestep: Agerage temperature of zone 37 is Tavg = ....
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 21, 2021, 06:33 |
|
#16 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Thank you.
I did it and it worked. cheers to your patience and explanations. |
|
January 25, 2021, 10:43 |
|
#17 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
Dear Alexanderz, could you please share your comments on the attached results.
After setting up a step increase in temperature up to 700K, I can see the temperature is not getting down which is unrealistic during heat transfer. Is this because of the code which we compiled?? Best regards. |
|
January 25, 2021, 22:34 |
|
#18 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
in code you have criteria
Code:
if (tavg > 301) C_T(c,t) = 700; change condition statement, if you want something else
__________________
best regards ****************************** press LIKE if this message was helpful |
|
February 17, 2021, 12:09 |
Write file: data didn't save completely
|
#19 |
Member
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 8 |
In the report definitions, I have created a 'report plot' and 'write file' to visualize the temperature w.r.t flow time. I can see the plots while the simulation is running but the data saved in 'write file' is only upto 2.4 seconds for 300 seconds.
How can I retrieve the other data? Any suggestions, please? |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pressure Inlet Boundary Condition for gas-solid fluidized bed | m.uzair | Fluent Multiphase | 0 | January 18, 2018 07:08 |
Question about adaptive timestepping | Guille1811 | CFX | 25 | November 12, 2017 18:38 |
Basic Nozzle-Expander Design | karmavatar | CFX | 20 | March 20, 2016 09:44 |
Question about heat transfer coefficient setting for CFX | Anna Tian | CFX | 1 | June 16, 2013 07:28 |
Error finding variable "THERMX" | sunilpatil | CFX | 8 | April 26, 2013 08:00 |