TAGGED: compressor, udf, udf-fluent
-
-
June 24, 2021 at 4:52 pm
sebastiancg26
SubscriberHow to do a UDF to simulate the opening and closing of compressor valves, wich depends on the pressure?
June 25, 2021 at 10:05 amRob
Forum ModeratorIt depends on how you want to mimic the valve closure. More details would be helpful.
June 25, 2021 at 5:09 pmsebastiancg26
SubscriberIt could be as an orifice with constant area or as a reed valve. What is really important is that these valves open or close according to a certain pressure. IÔÇÖd aprecciate very much your help!
June 29, 2021 at 11:02 amRob
Forum ModeratorThat would be an FSI problem. Because the motion is relatively large you'll need to use System Coupling to link to Mechanical and full remeshing in Fluent. Don't think you'll need UDFs in this case.
June 29, 2021 at 6:27 pmsebastiancg26
SubscriberCan you help me with that? It would be very helpful
June 30, 2021 at 8:30 amRob
Forum ModeratorOther than point you at the tutorials, no. If you read the rules we can offer hints and "simple" answers only. Click on "Help" and have a look at Mechanical, Fluent and System Coupling.
June 30, 2021 at 8:15 pmYasserSelima
SubscriberYou can define your valve as a porous zone and use a UDF to change the properties
June 30, 2021 at 9:58 pmsebastiancg26
SubscriberWich parameter should I change? viscous resistance profile or porous resistance direction vector? and how could I change? so that it varies with pressure..
July 1, 2021 at 12:13 amYasserSelima
Subscriberpermeability
July 1, 2021 at 12:25 amsebastiancg26
SubscriberI have read the UDF User guide, but I didn't find any information about how to change the permeability.. could you tell me how I can change the permeability based on pressure? how can I write the code? I'd really aprecciate your help, solving this problem is really important..
July 1, 2021 at 2:47 pmRob
Forum ModeratorYou will need to change alpha and C2, which are coefficients linked to how permeable the porous media is. In your case they will be found by obtaining the valve pressure loss at different flow rates and open fractions.
Note, this will mimic the valve effect but won't provide any useful details on flow in the actual valve.
July 1, 2021 at 5:06 pmsebastiancg26
Subscriber
Thanks Rob!
Do you know where I can find some information about how to change this properties based on pressure in UDF? I didn't find something similar like that in the UDF user's guide..
July 1, 2021 at 8:06 pmYasserSelima
SubscriberFirst, you need to use DEFINE_ADJUST to check the difference .. the Macro C_P or F_P can give you the pressure of a cell or face. Then use DEFINE_PROPERTY to set the permeability
July 1, 2021 at 10:01 pmsebastiancg26
SubscriberDear Yasser.
I'm very grateful to you. Finally, I have an idea of how I can start the code, I'm rookie in this topics but I'll continue studying the UDF user guide. If it's not too much to ask, could yo give me a way to contact us? In case I need any other help..
July 1, 2021 at 11:05 pmYasserSelima
Subscriberyou can message me here on the forum or mention me in a comment
July 2, 2021 at 10:33 amRob
Forum ModeratorThe porous model uses DEFINE_PROFILE (I think!), the rest you'll need to work out with help from the community.
July 3, 2021 at 12:18 amsebastiancg26
Subscriber
Hi Yasser! I've found a UDF of "viscous resistance profile" in the UDF user guide. But, this UDF is a function of "y".. How can I change that? How can I write the same code but based on pressure? I need the outlet valve closes at 600 kPa and the inlet valve opens at 100 kPa (those pressures are the outlet and intlet boundary conditions, respectively).. here, I'm going to paste the code that I found.
#include "udf.h"
DEFINE_PROFILE(vis_res,t,i)
{
real x[ND_ND];
real a;
cell_t c;
begin_c_loop(c,t)
{
C_CENTROID(x,c,t);
if(x[1] < (x[0]-0.01))
a = 1e9;
else
a = 1.0;
F_PROFILE(c,t,i) = a;
}
end_c_loop(c,t)
}
In a nutshell, I need something like these..
if (P>100)
a=1E12;
else
a=1;
Yasser, thank you very much for your cooperation!!
July 3, 2021 at 4:48 pmYasserSelima
SubscriberThanks for clarification.
Using DEFINE_ADJUST
Define_adjust is called before every iterations. You can check the condition at the valve and then change an integer variable between 0 and 1 ... then in the DEFINE_PROFILE check if the variable is 1 or 0.
I believe in your case, you need to close the valve based on the pressure in the last time step .. so, you need to check the pressure only one time before the time step. In the manual, there is an example that lists some commands to be done at iteration 1 only.
July 4, 2021 at 9:07 pmJuly 5, 2021 at 1:10 amYasserSelima
Subscriber"Define adjust" and "define profile" are two different functions. Go to the manual and look for examples on define-adjust
July 6, 2021 at 9:48 amJuly 6, 2021 at 10:25 amRob
Forum Moderator6DOF tends to be used for free moving objects, which generally don't deform. They also don't hit anything. You want to model a valve closing so need to fix the motion and figure out when to stop the motion so the valve doesn't fully close. As it's a reed valve (so the valve deflects, or at least in the type I've seen they do) you can't just assume a motion.
July 6, 2021 at 4:28 pmsebastiancg26
Subscriberif I understood you correclty.. I wrote two codes, both for DEFINE_ADJUST and DEFINE_PROFILE, but I still can't get it, could you help me?
This is the DEFINE_ADJUST code..
#include "udf.h"
DEFINE_ADJUST(outvalve,d)
{
Thread *t;
cell_t c;
real P=0.;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
P = C_P(c,t);
end_c_loop(c,t)
}
printf("Pressure: %g\n", P);
}
.. and this is the DEFINE_PROFILE code
#include "udf.h"
DEFINE_PROFILE(outletvalve,t,i)
{
real P = C_P(c,t); /*pressure*/
real a; /*viscous resistance = 1/permeability*/
begin_c_loop(c,t)
{
if(P > 500000)
a = 1.0;
else
a = 1e12;
F_PROFILE(c,t,i) = a;
}
end_c_loop(c,t)
}
July 6, 2021 at 6:20 pmYasserSelima
SubscriberAssuming your code is right .. you need to put them below each other in the same file and remove #include "udf.h" from in between.
Second, you need to define a global variable at the top, you set its value in define adjust, then use it in define profile ... something like this
#include "udf.h"
int my_variable;
DEFINE_ADJUST(outvalve,d)
{
/* Loop and check the condition */
if( condition ) {
my_variable = 1;
} else {
my_variable = 0;
}
}
DEFINE_PROFILE(outletvalve,t,i)
{
real P = C_P(c,t); /*pressure*/
real a; /*viscous resistance = 1/permeability*/
begin_c_loop(c,t)
{
if( my_variable == 1)
a = 1.0;
else
a = 1e12;
F_PROFILE(c,t,i) = a;
}
end_c_loop(c,t)
}
July 6, 2021 at 6:24 pmYasserSelima
SubscriberIf you want the valve to open\close at certain pressure without knowing the valve mechanism, mass or spring stiffness, you will need to go through trial and error which would take months of simulations.
July 7, 2021 at 12:41 amsebastiancg26
Subscriberfinally, this is my code..
/*UDF that simulates the opening and closing of the inlet valve based on pressure*/
#include "udf.h"
intmy_variable;
cell_t c;
Thread *t;
DEFINE_ADJUST(invalve,d)
{
real P; /*pressure*/
P = C_P(c,t);
/* Loop and check the condition */
if( P < 100000 ) {
my_variable = 1; /*OPEN VALVE*/
}else{
my_variable = 0; /*CLOSE VALVE*/
}
}
DEFINE_PROFILE(inletvalve,t,i)
{
real a; /*viscous resistance = 1/permeability*/
begin_c_loop(c,t)
{
if( my_variable == 1)
a = 1.0;
else
a = 1e12;
F_PROFILE(c,t,i) = a;
}
end_c_loop(c,t)
}
but I don't know if there are errors.. what do you think?
July 7, 2021 at 7:07 amEmperor
Subscriberif we know all the characteristics of our valve, i.e. spring stiffness, mass... we can use the interface then?
July 7, 2021 at 9:03 amYasserSelima
SubscriberYou need to find the pressure inside define_adjust ... P is the pressure of which cell ... is it average? Are you going to change the value of my_variable each iteration? I guess no .. should be only first iteration of each time step.
I guess yes you can use SDOF in this case and treat the valve gate as a moving object under spring force. However, depending on the complex of your geometry you might need to use a UDF to move your gate
July 7, 2021 at 9:06 amEmperor
Subscriberthank you for your answers. But then the pressure at the inlet just can't move the valve?
July 7, 2021 at 6:11 pmYasserSelima
SubscriberNot immediately ... the pressure would cause a fluid forces on the valve which moves the valve with some time lag. I believe this is more realistic simulation of an actual valve but it comes at a cost. If you are interested in valve design/optimisation, you have to do this ... if the valve is not your interest or you have a solenoid that is controlled by a signal, you can do some assumptions to simplify your simulation.
July 8, 2021 at 6:51 amEmperor
Subscribercan you please come into this discussion and tell me what you think? I will be very pleased. We patched the pressure during the initialization, but during the deforming mesh other complications appear. I am interested in any hypothesis to make (I am still trying to consolidate my knowledge in fluid simulation)
July 8, 2021 at 2:25 pmsebastiancg26
SubscriberI have made this based on the manual..
#include "udf.h"
static int last_ts = -1; /* Global variable. Time step is never <0 */
DEFINE_ADJUST(first_iter_only, domain)
{
int curr_ts;
int my_variable;
face_t f;
Thread *t;
curr_ts = N_TIME;
if (last_ts != curr_ts)
{
last_ts = curr_ts;
{
real P; /*pressure*/
P = F_P(f,t);
/* Loop and check the condition */
if( P > 1000000 ) {
my_variable = 1; /*OPEN VALVE*/
} else {
my_variable = 0; /*CLOSE VALVE*/
}
}
}
}
DEFINE_PROFILE(outletvalve,t,i)
{
real a; /*viscous resistance = 1/permeability*/
begin_f_loop(f,t)
{
if( my_variable == 1)
a = 1.0;
else
a = 1e12;
F_PROFILE(f,t,i) = a;
}
end_f_loop(f,t)
}
what do you think?
July 8, 2021 at 3:48 pmYasserSelima
SubscriberP = F_P(f,t);
Which face f, and which thread t?
July 8, 2021 at 4:27 pmsebastiancg26
Subscriber#include "udf.h"
static int last_ts = -1; /* Global variable. Time step is never <0 */
DEFINE_ADJUST(first_iter_only, domain)
{
int curr_ts;
curr_ts = N_TIME;
if (last_ts != curr_ts)
{
last_ts = curr_ts;
{
intmy_variable;
cell_t c;
Thread *t;
real P; /*pressure*/
P = C_P(c,t);
/* Loop and check the condition */
if( P > 1000000 ) {
my_variable = 1;/*OPEN VALVE*/
}else{
my_variable = 0;/*CLOSE VALVE*/
}
}
}
}
DEFINE_PROFILE(outletvalve,t,i)
{
real a; /*viscous resistance = 1/permeability*/
begin_c_loop(c,t)
{
if( my_variable == 1)
a = 1.0;
else
a = 1e12;
F_PROFILE(c,t,i) = a;
}
end_c_loop(c,t)
}
that's how it is?
in the manual, there is an example wich allows me to calculate only in the first iteration, the code is...
/**********************************************************************
Example UDF that uses N_TIME
***********************************************************************/
static int last_ts = -1; /* Global variable. Time step is never <0 */
DEFINE_ADJUST(first_iter_only, domain)
{
int curr_ts;
curr_ts = N_TIME;
if (last_ts != curr_ts)
{
last_ts = curr_ts;
/* things to be done only on first iteration of each time step
can be put here */
}
}
July 20, 2021 at 6:14 pmsebastiancg26
Subscriberafter many attempts, I think I managed to do the UDF to calculate the value of "my_variable" for each time step (only in the first iteration). But, but now the problem is that I don't know how to include the UDF in ansys fluent, I have to put it in "Functions hook" or in the cell zone task manager or both .. could you help me please?
July 21, 2021 at 12:55 pmRob
Forum ModeratorHave a look at the macro in the UDF manual, it'll explain where to hook it up. You then need a separate section of code to do whatever you want it to once the Adjust function is called, that's hooked into it's own part of the code (again the manual will generally say where it goes). For porous values it'll be either the Porous Jump boundary or porous media cell zone.
Viewing 35 reply threads- The topic ‘How to do a UDF to simulate the opening and closing of compressor valves?’ is closed to new replies.
Ansys Innovation SpaceTrending discussionsTop Contributors-
3472
-
1057
-
1051
-
934
-
897
Top Rated Tags© 2025 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-