|
[Sponsors] |
UDF: exporting a variable between two DEFINE function |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
New Member
Carlo Locci
Join Date: Apr 2009
Posts: 8
Rep Power: 17 ![]() |
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!! |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Member
Allan Walsh
Join Date: Mar 2009
Posts: 56
Rep Power: 17 ![]() |
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.
|
|
![]() |
![]() |
![]() |
![]() |
#3 |
New Member
Carlo Locci
Join Date: Apr 2009
Posts: 8
Rep Power: 17 ![]() |
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. |
|
![]() |
![]() |
![]() |
![]() |
#4 |
Member
Allan Walsh
Join Date: Mar 2009
Posts: 56
Rep Power: 17 ![]() |
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. |
|
![]() |
![]() |
![]() |
Tags |
udf exporting variable |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[blockMesh] BlockMesh FOAM warning | gaottino | OpenFOAM Meshing & Mesh Conversion | 7 | July 19, 2010 14:11 |
UDF parse error at profile function line | Wiggy | Fluent UDF and Scheme Programming | 1 | July 27, 2009 15:59 |
OpenFoam 14 installation problem | gfcoppola | OpenFOAM Installation | 20 | November 2, 2007 13:38 |
Droplet Evaporation | Christian | Main CFD Forum | 2 | February 27, 2007 06:27 |
define profile UDF | greg | FLUENT | 1 | June 3, 2006 03:44 |