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

Varying mass flow at an inlet boundary condition. Fuel mass flow.

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

Like Tree5Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 15, 2014, 07:50
Default
  #21
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thank you for your reply Ghost82

There is a sketch attached in entry #8 above dated 15 Sept.

Basically one of the inlets shown in the sketch need to act as a one way airflow.

If pressure in vessel drops below zero, than the z Cartesian inlet in the boundary Pressure Inlet condition will have 1 in the z Cartesian field, to allow air to enter. Other wise, if pressure is above 1000, then z will have a 0, to stop air flow entering or going out.

Not sure why have 0<pressure>1000?

If it makes it simpler, can rewrite to as follows (closing the gap between the 0 and 1000): -
DEFINE_PROFILE(vary,t,i)
{
real pressure;
face_t f;
begin_f_loop(f,t)
{
pressure = F_P(f,t)
if(pressure <= 0)
F_PROFILE(f,t,i) = 1;
else if(pressure > 0)
F_PROFILE(f,t,i) = 0;
}
end_f_loop(f,t)
}
visitor is offline   Reply With Quote

Old   October 15, 2014, 07:55
Default
  #22
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thank you for your reply Ghost82

There is a sketch attached in entry #8 above dated 15 Sept.

Basically one of the inlets shown in the sketch need to act as a one way airflow.

If pressure in vessel drops below zero, than the z Cartesian inlet in the boundary Pressure Inlet condition will have 1 in the z Cartesian field, to allow air to enter. Other wise, if pressure is above 1000, then z will have a 0, to stop air flow entering or going out.

Not sure why have 0<pressure>1000?

If it makes it simpler, can rewrite to as follows (closing the gap between the 0 and 1000): -
DEFINE_PROFILE(vary,t,i)
{
real pressure;
face_t f;
begin_f_loop(f,t)
{
pressure = F_P(f,t)
if(pressure <= 0)
F_PROFILE(f,t,i) = 1;
else if(pressure > 0)
F_PROFILE(f,t,i) = 0;
}
end_f_loop(f,t)
}
visitor is offline   Reply With Quote

Old   November 16, 2014, 23:46
Default
  #23
Senior Member
 
Tanjina Afrin
Join Date: May 2013
Location: South Carolina
Posts: 169
Rep Power: 12
Tanjina is on a distinguished road
Hello Everyone,

I am trying to use UDF for time varying mass flow rate at inlet and edited the UDF from UDF manual. When I try to load the UDF, it gives me the error shown in the attached figure. Here is my UDF-

For serial :
#include "udf.h"
DEFINE_PROFILE(inlet_mf,th,i)
{
face_t f;
begin_f_loop(f,th)
{
if(CURRENT_TIME <= 3.0)
F_PROFILE(f,th,i) = 10.0;
else if(CURRENT_TIME <=5.0 && CURRENT_TIME >3.0)
F_PROFILE(f,th,i) = 9.0;
else if(CURRENT_TIME <=7.0 && CURRENT_TIME >5.0)
F_PROFILE(f,th,i) = 8.0;
else if(CURRENT_TIME <=9.0 && CURRENT_TIME >7.0)
F_PROFILE(f,th,i) = 7.0;
else if(CURRENT_TIME <=10.0 && CURRENT_TIME >9.0)
F_PROFILE(f,th,i) = 6.0;
else if(CURRENT_TIME <=11.0 && CURRENT_TIME >10.0)
F_PROFILE(f,th,i) = 5.0;
else if(CURRENT_TIME <=12.0 && CURRENT_TIME >11.0)
F_PROFILE(f,th,i) = 4.0;
else if(CURRENT_TIME <=13.0 && CURRENT_TIME >12.0)
F_PROFILE(f,th,i) = 3.0;
else if(CURRENT_TIME <=15.0 && CURRENT_TIME >13.0)
F_PROFILE(f,th,i) = 3.0;
else
F_PROFILE(f,th,i) = 1.0;
}
end_f_loop(f,th);
}


and for parallel-

#include "udf.h"
DEFINE_PROFILE(inlet_mf,th,i)
{
#if !RP_HOST
face_t f;
begin_f_loop(f,th)
{
if(CURRENT_TIME <= 3.0)
F_PROFILE(f,th,i) = 10.0;
else if(CURRENT_TIME <=5.0 && CURRENT_TIME >3.0)
F_PROFILE(f,th,i) = 9.0;
else if(CURRENT_TIME <=7.0 && CURRENT_TIME >5.0)
F_PROFILE(f,th,i) = 8.0;
else if(CURRENT_TIME <=9.0 && CURRENT_TIME >7.0)
F_PROFILE(f,th,i) = 7.0;
else if(CURRENT_TIME <=10.0 && CURRENT_TIME >9.0)
F_PROFILE(f,th,i) = 6.0;
else if(CURRENT_TIME <=11.0 && CURRENT_TIME >10.0)
F_PROFILE(f,th,i) = 5.0;
else if(CURRENT_TIME <=12.0 && CURRENT_TIME >11.0)
F_PROFILE(f,th,i) = 4.0;
else if(CURRENT_TIME <=13.0 && CURRENT_TIME >12.0)
F_PROFILE(f,th,i) = 3.0;
else if(CURRENT_TIME <=15.0 && CURRENT_TIME >13.0)
F_PROFILE(f,th,i) = 3.0;
else
F_PROFILE(f,th,i) = 1.0;
}
end_f_loop(f,th);
#endif
}

Any suggestion to make it work will be highly appreciated.

Regards,
Tanjina
Attached Images
File Type: jpg Serial_node.jpg (45.3 KB, 16 views)
File Type: jpg Parallel_node.JPG (30.0 KB, 7 views)
Tanjina is offline   Reply With Quote

Old   November 17, 2014, 03:27
Default
  #24
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Are you able to compile different udfs, or is only this udf the problem?
pakk is offline   Reply With Quote

Old   November 17, 2014, 03:31
Default
  #25
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26
ghost82 will become famous soon enough
I would add to pakk's question that for your udf it is not a must to modify the udf for parallel computation; this is because it is a profile udf, and if more than one node will assign a profile to the same cell it will simply overwrite the same value.

Did you install the development tool (gcc, etc) on linux?
After installing the development tools, delete in the working folder the libudf folder, so to have only cas, dat and .c files; then recompile the .c udf and load the library.
__________________
Google is your friend and the same for the search button!

Last edited by ghost82; November 17, 2014 at 07:04.
ghost82 is offline   Reply With Quote

Old   November 17, 2014, 11:27
Default
  #26
Senior Member
 
Tanjina Afrin
Join Date: May 2013
Location: South Carolina
Posts: 169
Rep Power: 12
Tanjina is on a distinguished road
Thanks Pakk and Ghost 82.

@ Pakk, Yup I can compile other UDF.. actually before this, I only worked with one hydrostatic pressure inlet using UDF and here it is -

#include "udf.h"
DEFINE_PROFILE(pressure_profile,t,i)
{
#if !RP_HOST
real x[ND_ND];
real y;
face_t f;
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y=x[1];
F_PROFILE(f,t,i)=(0.4728-y)*998.2*9.81;
}
end_f_loop(f,t)
#endif
}

It worked perfectly.

@ Ghost82, gcc is installed on my university cluster ( I am working on Cluster). there are 3 available version in cluster 3.4,4.4 and 4.8.1

Is there something like that I have to select/call one of them ?

One more question: If I can't make this UDF work unfortunately, then if I change the flow rate manually time to time, will it work properly? ( Just asking)

Regards,
Tanjina
Tanjina is offline   Reply With Quote

Old   November 17, 2014, 11:36
Default
  #27
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26
ghost82 will become famous soon enough
Did you delete the libudf folder and recompile the udf directly on the cluster?
In your first screenshot I can see something related to 3d_node/3d_host, but you're on a 2d simulation.
Yes, of course you can manually change the values with the same effect.
__________________
Google is your friend and the same for the search button!
ghost82 is offline   Reply With Quote

Old   November 17, 2014, 11:43
Default
  #28
Senior Member
 
Tanjina Afrin
Join Date: May 2013
Location: South Carolina
Posts: 169
Rep Power: 12
Tanjina is on a distinguished road
I was thinking something like that....so I tried from my friend's account and I found the error which is something different from previous one but still I couldn't compiled the UDF. I am attaching the error image.
Attached Images
File Type: jpg error_from another acc.jpg (28.2 KB, 10 views)
Tanjina is offline   Reply With Quote

Old   November 17, 2014, 11:48
Default
  #29
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26
ghost82 will become famous soon enough
Can you interpret rather than compile your udf?
__________________
Google is your friend and the same for the search button!
ghost82 is offline   Reply With Quote

Old   November 17, 2014, 11:58
Default
  #30
Senior Member
 
Tanjina Afrin
Join Date: May 2013
Location: South Carolina
Posts: 169
Rep Power: 12
Tanjina is on a distinguished road
I interpreted...there was no problem.... I followed the procedure described in UDF guide. Define->User defined->interpret.

Then from Define->User defined->compile->source file ->add. Up to this point this is okay. then I find this error when I try to build the library and load the udf.

I am not that much comfortable with programming.... maybe I am missing something very easy. So I am seeking help from you guys.

Regards,
Tanjina
Tanjina is offline   Reply With Quote

Old   November 24, 2014, 02:20
Default
  #31
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
The UDF worked fine for me.

As you have mentioned; Interpret then from your boundary condition eg inlet or what ever, select in the field (where it usually says constant) pressure_profile.

Careful with semicolons ..

Hope I have answered your question.
visitor is offline   Reply With Quote

Old   December 2, 2014, 12:41
Post Variable Inlet velocity
  #32
New Member
 
sam
Join Date: Apr 2013
Posts: 2
Rep Power: 0
samity12 is on a distinguished road
Hello, I am studying a variable speed flow for cooling operation in a box with inlet and outlet. I want to define the inlet boundary as a function of outlet temperature, when the temperature increase or decrease below or above the set point range the inlet flow rate has to increase or decrease respectively. Is it possible to do that using UDF as you have discussed the time dependent flow? If so pls give me some hint.

Kind regards
samity12 is offline   Reply With Quote

Old   December 2, 2014, 22:23
Default
  #33
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
macfly is on a distinguished road
Hi Sam, it's totally doable.

Here's a UDF that
1. initialize some stuff
2. compute area-averaged T on a boundary at the end of each time step
3. define inlet profile as a function of what has been computed in step 2.

Code:
#include "udf.h"

/* global variables, will be used in multiple DEFINE macros */
real T_area_avg = 0.;
real sum_T_area_avg = 0.;
real area_outlet = 0.;

DEFINE_INIT(init, domain)
{
/* Compute outlet area once and for all */
Thread *thread;
face_t face;
real area[ND_ND];
area_outlet = 0.;
domain = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */
thread = Lookup_Thread(domain, 12); /* ID displayed in Boundary Conditions panel */
begin_f_loop(face, thread)
	F_AREA(area, face, thread);
	area_outlet += NV_MAG(area);
end_f_loop(face, thread)
printf("total outlet area = %g m^2 \n", area_outlet);

/* Initialize T_area_avg */
T_area_avg = 300.;
}

DEFINE_EXECUTE_AT_END(exec_at_end)
{
/* Compute area-averaged T on boundary */
Domain *domain; /* declare domain pointer since it is not passed as an argument to the DEFINE macro */
Thread *thread;
face_t face;
real area[ND_ND];
sum_T_area_avg = 0.; /* needs to be reset at each timestep */
domain = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */
thread = Lookup_Thread(domain, 12);
begin_f_loop(face, thread)
	F_AREA(area, face, thread);
	sum_T_area_avg += F_T(face, thread)*NV_MAG(area);
end_f_loop(face, thread)
T_area_avg = sum_T_area_avg/area_outlet;  /* area-averaged temperature */
}

DEFINE_PROFILE(inlet, thread, position)
{
face_t face;
begin_f_loop(face, thread)
    {
	if (T_area_avg <= 305)
		F_PROFILE(face, thread, position) = 1;
	else
		F_PROFILE(face, thread, position) = 2;
    }
end_f_loop(face, thread)
}
I think it's a fair amount of hints
samity12 and lolno like this.
macfly is offline   Reply With Quote

Old   December 10, 2014, 07:32
Default
  #34
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
This looks good and useful.

One question, if I was to monitor CO2 content rather than temperature (for an example), what changes are required?

Thanks in advance for; posting this helpful example, and answering this question.

Regards
visitor is offline   Reply With Quote

Old   December 11, 2014, 02:30
Thumbs up Re:Variable Inlet velocity
  #35
New Member
 
sam
Join Date: Apr 2013
Posts: 2
Rep Power: 0
samity12 is on a distinguished road
Quote:
Originally Posted by macfly View Post
Hi Sam, it's totally doable.

Here's a UDF that
1. initialize some stuff
2. compute area-averaged T on a boundary at the end of each time step
3. define inlet profile as a function of what has been computed in step 2.

Code:
#include "udf.h"

/* global variables, will be used in multiple DEFINE macros */
real T_area_avg = 0.;
real sum_T_area_avg = 0.;
real area_outlet = 0.;

DEFINE_INIT(init, domain)
{
/* Compute outlet area once and for all */
Thread *thread;
face_t face;
real area[ND_ND];
area_outlet = 0.;
domain = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */
thread = Lookup_Thread(domain, 12); /* ID displayed in Boundary Conditions panel */
begin_f_loop(face, thread)
    F_AREA(area, face, thread);
    area_outlet += NV_MAG(area);
end_f_loop(face, thread)
printf("total outlet area = %g m^2 \n", area_outlet);

/* Initialize T_area_avg */
T_area_avg = 300.;
}

DEFINE_EXECUTE_AT_END(exec_at_end)
{
/* Compute area-averaged T on boundary */
Domain *domain; /* declare domain pointer since it is not passed as an argument to the DEFINE macro */
Thread *thread;
face_t face;
real area[ND_ND];
sum_T_area_avg = 0.; /* needs to be reset at each timestep */
domain = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */
thread = Lookup_Thread(domain, 12);
begin_f_loop(face, thread)
    F_AREA(area, face, thread);
    sum_T_area_avg += F_T(face, thread)*NV_MAG(area);
end_f_loop(face, thread)
T_area_avg = sum_T_area_avg/area_outlet;  /* area-averaged temperature */
}

DEFINE_PROFILE(inlet, thread, position)
{
face_t face;
begin_f_loop(face, thread)
    {
    if (T_area_avg <= 305)
        F_PROFILE(face, thread, position) = 1;
    else
        F_PROFILE(face, thread, position) = 2;
    }
end_f_loop(face, thread)
}
I think it's a fair amount of hints

Thanks a lot macfly it was really very helpful. I have made some modification to make it compatible with my system and it works. Cheers!!!
samity12 is offline   Reply With Quote

Old   December 16, 2014, 08:09
Default Slight change in topic
  #36
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Dear sirs/madams:

Similar work, in UDFs.

Trying to ready CO2 content in model and then activate a boundary layer. This is in simple words. A Co2 sensor, once level exceeds a fixed figure, a boundary outlet is activated.

Used this as first attempt:

#include "udf.h"
DEFINE_PROFILE(inlet_mf,th,i)
{
face_t f;
Material *m = THREAD_MATERIAL(t);
char *name = "co2";
int i;
i = mixture_specie_index(m,name);
begin_f_loop(f,th)
{
if(i => 7e-4)
F_PROFILE(f,th,i) = 118;
else if(i < 7e-4);
}
end_f_loop(f,th)
}

- - -

Error message line 5 undeclared variable. Help anyone, please, and thanks in advance. There may be other mistakes!
visitor is offline   Reply With Quote

Old   December 16, 2014, 08:12
Default
  #37
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
According to the help, THREAD_MATERIAL is defined in threads.h. You probably need to include threads.h for it to work.
pakk is offline   Reply With Quote

Old   December 16, 2014, 08:13
Default
  #38
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Or compile it instead of interpreting. This is true in general: compiling works better than interpreting.
pakk is offline   Reply With Quote

Old   December 16, 2014, 08:29
Default
  #39
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
macfly is on a distinguished road
As Pakk wrote, it probably needs to be compiled.
macfly is offline   Reply With Quote

Old   December 17, 2014, 00:40
Default
  #40
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thanks for your responses.

Did not understand "You probably need to include threads.h for it to work".

Do I need to replace the t with h? In ;
Material *m = THREAD_MATERIAL(t);

Haven't got a compiler, need to stick with interpreter.

Thanks
visitor 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
Boudaries for bouynat driven flow with additional mass flux at inlet Charon CFX 2 April 27, 2013 08:02
Water subcooled boiling Attesz CFX 7 January 5, 2013 03:32
velocity calculations in mass flow inlet boundary condition montazer1012 FLUENT 1 October 18, 2010 03:11
Mass flow boundary condition Renato. Main CFD Forum 0 July 21, 2006 22:07
New topic on same subject - Flow around race car Tudor Miron CFX 15 April 2, 2004 06:18


All times are GMT -4. The time now is 13:20.