CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF program for calculating the mass flow outlet with a pulsed output flow

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

Like Tree4Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 26, 2019, 03:26
Default UDF program for calculating the mass flow outlet with a pulsed output flow
  #1
New Member
 
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 2
Benito89 is on a distinguished road
Hi everyone, I need some help with writing a UDF. I need write a code for simulating a car airbox for my final tesis, where you have an velocity inlet costant of 53m / s and 4 output tubes that have a mass flow outlet of 0.0045kg / s each. This outflows should have a pulsed output flow. Furthermore the exit from the pipes should take place in this order like a normal engine ignition configuration.(pipe 1;pipe 3;pipe 4;pipe 2).
Can you help me with this issue.
Thank you
Benito89 is offline   Reply With Quote

Old   July 28, 2019, 23:51
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,250
Rep Power: 20
AlexanderZ will become famous soon enough
you should describe functionality of your UDF in more details.
you should put here your code, so other members could fix it

if you wanna time dependent outflow mass-flow rate -> you can use DEFINE_PROFILE macro

you can find good example in Ansys Fluent Customization manual (use google)

best regards
Benito89 likes this.
AlexanderZ is offline   Reply With Quote

Old   July 30, 2019, 05:54
Default
  #3
New Member
 
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 2
Benito89 is on a distinguished road
Thanks to your instructions, I found the udf code (2.3.20.10. Example 8 - Target Mass Flow Rate UDF as a Function of Physical Flow Time) and I adapted it to my needs.
#include "udf.h"
DEFINE_PROFILE(tm_pout2, t, nv)
{
face_t f ;
real flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.2)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.045 kg/s \n") ;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.045 ;
}
end_f_loop(f,t)
} }


Only it always gives me a solution as 0. How can I change it?
18 1.6981e-01 4.1807e-03 2.9109e-03 2.6440e-03 0:00:30 2
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
19 1.7504e-01 4.3283e-03 3.0188e-03 2.6914e-03 0:00:16 1
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
Time = 0.000000 sec.
Targeted mass-flow rate set at 0.0 kg/s
20 1.8807e-01 5.0708e-03 3.5272e-03 3.1685e-03 0:00:00 0
Benito89 is offline   Reply With Quote

Old   July 31, 2019, 00:05
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,250
Rep Power: 20
AlexanderZ will become famous soon enough
Code:
#include "udf.h"
DEFINE_PROFILE(tm_pout2, t, nv)
{
face_t f ;
real flow_time;
flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.2)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.045 kg/s \n") ;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.045 ;
}
end_f_loop(f,t)
} }
best regards
AlexanderZ is offline   Reply With Quote

Old   July 31, 2019, 12:30
Default
  #5
New Member
 
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 2
Benito89 is on a distinguished road
Thank you very much AlexanderZ, it works perfectly.
But now I have another request, sorry if I always ask but it's the first time I use FLUENT. If instead of imposing a constant input speed, I set a pulsating speed written like this:
#include "udf.h"

DEFINE_PROFILE (my_velocity, thread, position)
{
face_t f;
real t = CURRENT_TIME;

begin_f_loop (f, thread)
{
F_PROFILE (f, thread, position) = - 26.76 * cos (t * 3.14159) + 26.76 ;
}
end_f_loop (f, thread)
}

I always associate this code with that of the always pulsating air outlet mass.
Can you do this? and above all the program how do you understand that the t of the two codes must be the same at the same time?For example if t = 2 should return 0 from both codes
Benito89 is offline   Reply With Quote

Old   August 1, 2019, 00:51
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,250
Rep Power: 20
AlexanderZ will become famous soon enough
I didn't understand, what you want

if you want to define 2 boundary conditions in your UDF you can use 2 DEFINE_PROFILE macros (same way as you did before):
Code:
#include "udf.h"
DEFINE_PROFILE(tm_pout2, t, nv)
{
...
}
DEFINE_PROFILE (my_velocity, thread, position)
{
...
}
your second UDF is correct also.

t (which is time probably) is the same for the whole your simulation as it is controlled by solver, but you only check its value using macro
Code:
flow_time = RP_Get_Real("flow-time");
I recommend you to use this macro
Dont do this:
Code:
real flow_time  = CURRENT_TIME;
but use
Code:
real flow_time ;
flow_time = CURRENT_TIME;
or
flow_time = RP_Get_Real("flow-time");
best regards
Benito89 likes this.
AlexanderZ is offline   Reply With Quote

Old   August 20, 2019, 06:48
Default
  #7
New Member
 
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 2
Benito89 is on a distinguished road
Thanks AlexanderZ, you are of great help.
I tried to channel the air sequentially like this: tube1, tube3, tube4, tube2. I did it through this code:
#include "udf.h"
DEFINE_PROFILE(tm_pout, t, nv)
{
face_t f ;
real flow_time;
flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.2)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.045 kg/s \n") ;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.045 ;
}
end_f_loop(f,t)
} }
DEFINE_PROFILE(tm_pout3, t, nv)
{
face_t f ;
real flow_time;
flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.3)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.045 kg/s \n") ;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.045 ;
}
end_f_loop(f,t)
} }
DEFINE_PROFILE(tm_pout4, t, nv)
{
face_t f ;
real flow_time;
flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.4)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.045 kg/s \n") ;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.045 ;
}
end_f_loop(f,t)
} }
DEFINE_PROFILE(tm_pout2, t, nv)
{
face_t f ;
real flow_time;
flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.5)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 0.045 kg/s \n") ;

begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 0.045 ;
}
end_f_loop(f,t)
} }
DEFINE_PROFILE (my_velocity, t, position)
{
face_t f;
real flow_time;
flow_time = RP_Get_Real("flow-time");

begin_f_loop (f, t)
{
F_PROFILE (f, t, position) = - 26.76 * cos (flow_time * 3.14159) + 26.76 ;
}
end_f_loop (f, t)
}

but now I would like to impose a new condition:
the tube1 opens at 0.2s and closes at 0.3s;
the tube3 opens at 0.3s and closes at 0.4s;
the tube4 opens at 0.4s and closes at 0.5s;
the tube2 opens at 0.5s and closes at 0.6s.
When the tube2 closes, the tube1 must be opened again and then start again with the cycle, how can I do?
Benito89 is offline   Reply With Quote

Old   August 21, 2019, 00:12
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,250
Rep Power: 20
AlexanderZ will become famous soon enough
use sin with period 0.6s - 0.2 s = 0.4 s

best regards
Benito89 likes this.
AlexanderZ is offline   Reply With Quote

Old   August 21, 2019, 05:06
Default
  #9
New Member
 
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 2
Benito89 is on a distinguished road
Excuse ignorance but where do I put this function?
Benito89 is offline   Reply With Quote

Old   August 21, 2019, 23:57
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,250
Rep Power: 20
AlexanderZ will become famous soon enough
in my vision, you should put it in if statement:
Code:
if (flow_time*sin(your_function) > 0)
best regards
Benito89 likes this.
AlexanderZ is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Match Pressure Inlet/Outlet Boundary Condition Mass Flow Rate MSchneid Fluent UDF and Scheme Programming 3 February 23, 2019 06:00
Mass flow rate at inlet and outlet are not equal jiaen961997 FLUENT 1 January 9, 2019 03:18
Please help (an UDF for regulating the mass flow rate) swidi Fluent UDF and Scheme Programming 2 July 30, 2015 12:32
UDF for Mass Flow at the Outlet: ERROR ACCESS VIOLATION I-mech Fluent UDF and Scheme Programming 1 May 23, 2014 12:37
UDF in Fluent to Match Mass Flow at Pressure Outlet Jonas Larsson Main CFD Forum 1 April 29, 1999 10:44


All times are GMT -4. The time now is 08:41.