CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Varying mass flow at an inlet boundary condition. Fuel mass flow. (https://www.cfd-online.com/Forums/fluent-udf/133883-varying-mass-flow-inlet-boundary-condition-fuel-mass-flow.html)

visitor October 15, 2014 07:50

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 October 15, 2014 07:55

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)
}

Tanjina November 16, 2014 23:46

2 Attachment(s)
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

pakk November 17, 2014 03:27

Are you able to compile different udfs, or is only this udf the problem?

ghost82 November 17, 2014 03:31

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.

Tanjina November 17, 2014 11:27

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

ghost82 November 17, 2014 11:36

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.

Tanjina November 17, 2014 11:43

1 Attachment(s)
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.

ghost82 November 17, 2014 11:48

Can you interpret rather than compile your udf?

Tanjina November 17, 2014 11:58

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

visitor November 24, 2014 02:20

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.

samity12 December 2, 2014 12:41

Variable Inlet velocity
 
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

macfly December 2, 2014 22:23

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 :D

visitor December 10, 2014 07:32

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

samity12 December 11, 2014 02:30

Re:Variable Inlet velocity
 
Quote:

Originally Posted by macfly (Post 522192)
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 :D


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!!!

visitor December 16, 2014 08:09

Slight change in topic
 
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!

pakk December 16, 2014 08:12

According to the help, THREAD_MATERIAL is defined in threads.h. You probably need to include threads.h for it to work.

pakk December 16, 2014 08:13

Or compile it instead of interpreting. This is true in general: compiling works better than interpreting.

macfly December 16, 2014 08:29

As Pakk wrote, it probably needs to be compiled.

visitor December 17, 2014 00:40

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


All times are GMT -4. The time now is 04:51.