CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF: exporting a variable between two DEFINE function (https://www.cfd-online.com/Forums/fluent/67507-udf-exporting-variable-between-two-define-function.html)

Carlo August 17, 2009 13:31

UDF: exporting a variable between two DEFINE function
 
Hi to all. Here's my problem:
I'm dealing with coal combustion; in my case I have also gas recirculation. In particular, I have an UDF that computes the outlet NOx mass fraction; this value must be imposed in an inlet (due to the recirculation). Any idea to do it? Here's my UDF:

#include "udf.h"

DEFINE_ADJUST(noflux, domain)
{
int zone_ID = 4;
Thread *t = Lookup_Thread(domain,zone_ID);
face_t f;
real summ=0.;
real m;
real sumnox=0.;
real mnox;
real nox;
real sumarea=0.;
real area;
real Cnox;
real NV_VEC (A);
begin_f_loop(f,t)
{
F_AREA(A,f,t);
nox=C_POLLUT(f,t,1); /*Pollutant mass fraction Kg(NO)/Kg(g) in each face*/
mnox=F_U(f,t)*F_R(f,t)*NV_MAG(A)*6.28*nox; /*[Kg(NO)/Kg(g)]*[Kg(g)/s]=[Kg(NO)/s] in each face*/
sumnox += mnox; /*Kg(NO)/s in the whole domain*/
m=F_U(f,t)*F_R(f,t)*NV_MAG(A)*6.28;
summ += m; /*Kg(g)/s in the whole domain*/
area=NV_MAG(A)*6.28;
sumarea += area;
}
end_f_loop(f,t)
Cnox=sumnox/summ; /*[Kg(NO)/s]/[Kg(g)/s]*/
printf("massf: %g,%g,%g,%g\n", summ,sumnox,Cnox,sumarea);
}

real Cnox; /*Why do I have to declare it twice? Does fluent hold it?*/
DEFINE_PROFILE(noflux_b, t, nv)
{
face_t f;
begin_f_loop(f, t)
{
F_PROFILE(f,t,nv) = Cnox;
}
end_f_loop(f, t)
}

The ID=4 corresponds to the outlet. Am I doing it right? After having compiled and loaded the UDF, I hooked the noxflux function (DEFINE_ADJUST) whereas in the boundary condition of the considered inlet, in the NO mass fraction menu I set the noxflux_b function (DEFINE_PROFILE).
I'm not sure about this way to proceed. Indeed I don't know if the second DEFINE holds the Cnox variable value or if It clears it. I think this because if I don't declare "real Cnox" before starting the second DEFINE, I get the error "undeclared...etc", as if it had seen the Cnox variable for the first time! Any Idea?
Thanks!!

Allan Walsh August 18, 2009 14:25

What about using an external variable that is available in both your define macros? I must admit that I have only glanced at your macros, but it is something we use for what sounds like a similar issue.

Carlo August 18, 2009 14:55

Thanks!
 
Ok. The macro works really fine until the computing of the Cnox variable which is correctly computed and printed. Then I think that fluent doesn't get the value in the inlet (I'm aware of this when I plot the NOx mass fraction in it, where I get zero).
If you might be so gentle to explain me something more about external variables, I would be glad...you have to bring in mind that the variable has to be something computed through an UDF.

Allan Walsh August 19, 2009 13:21

Variables that you define in a macro will only have meaning in that macro. However, you can define a variable outside the macro, or macros, so that it can be used globally. So, in Fluent, in your c++ code, after your $ include statements and before your define macros you would have some lines like extern real varx and extern real vary. Then you can use varx and vary in whatever macros you have defined.
This is just basic c++, not even sure if it addresses your issue, but it is another tool.


All times are GMT -4. The time now is 06:40.