UDF: exporting a variable between two DEFINE function

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

 August 17, 2009, 12:31 UDF: exporting a variable between two DEFINE function #1 New Member   Carlo Locci Join Date: Apr 2009 Posts: 8 Rep Power: 9 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!!

 August 18, 2009, 13:25 #2 Member   Allan Walsh Join Date: Mar 2009 Posts: 55 Rep Power: 9 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.

 August 18, 2009, 13:55 Thanks! #3 New Member   Carlo Locci Join Date: Apr 2009 Posts: 8 Rep Power: 9 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.

 August 19, 2009, 12:21 #4 Member   Allan Walsh Join Date: Mar 2009 Posts: 55 Rep Power: 9 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 Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post gaottino OpenFOAM Native Meshers: blockMesh 7 July 19, 2010 14:11 Wiggy Fluent UDF and Scheme Programming 1 July 27, 2009 15:59 gfcoppola OpenFOAM Installation 20 November 2, 2007 14:38 Christian Main CFD Forum 2 February 27, 2007 07:27 greg FLUENT 1 June 3, 2006 03:44

All times are GMT -4. The time now is 12:42.