CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   Including Two Reactions in single UDF..!! (

sri31049 September 16, 2010 15:40

Including Two Reactions in single UDF..!!
I have two separate surface reactions. I have individual UDF's for each reaction. But we can hook only one UDF in fluent.
I have two square channels separated by a wall. In one channel one surface reaction and in another channel other surface reaction. How to include both reactions in single UDF. How can we assign the threads for each reaction independently. I was trying since 3 months but i could not solve this problem.

Note: The surface reaction is only at the wall. I need to get thread only for a wall.

Please suggests some macros/methods.

Thanks in Advance

byronsmith September 17, 2010 03:08

write both the reaction udf in a single file one below the other with different names and compile it, hook into fluent and when you go to the boundary conditions on source terms you will find both the reaction names where you can select the corresponding reaction name.
hope this helps

sri31049 September 18, 2010 02:05

The problem is that I have two different reactions. I have to give the two reactions in two different places.

Initially i tried your method but it produces two rates even in hook itself, but it allows only one rate to hook.

Thanks for Reply....!!

byronsmith September 18, 2010 03:39

I am not getting why you have a problem. you need to create the fluid zone separately and apply the reactions individually or write the UDF in such a way that you call the cell domain for the corresponding reacion and include the reaction rates for th e domains

sri31049 September 18, 2010 06:46

I have included both reactions in single UDF. One of the method i Tried is as follows......!! Here i got the id numbers from the fluent boundary conditions.

#include "udf.h"
#define R 83140000
#define R1 8.314
#define p 1013250
#define pi 3.14159


Domain *domain;
int id;
if(id == 4)
real c3h8 = yi[3];
real o2 = yi[4];
real co2 = yi[5];
real h2o = yi[6];
real n2 = yi[7];

real rho_w, sd = 2.49e-8, T_w;
real o_s,o_vac;
real xc3h8=1, xo2=1;
real tn,Ea3, Ea4, Ea5;
real rA3, rA4, rA5,rk3, rk4, rk5;
real ro,rate;

Thread *t0=Lookup_Thread(domain, id)->t0;
cell_t c0=F_C0(f,t0);
T_w = F_T(f,t);
rho_w = C_R(c0,t0)*C_T(c0,t0)/T_w;

c3h8 *= rho_w/mw[3];
o2 *= rho_w/mw[4];
co2 *= rho_w/mw[5];
h2o *= rho_w/mw[6];
n2 *= rho_w/mw[7];

xc3h8 = c3h8/(c3h8+o2+co2 +h2o+n2);
xo2 = o2/(c3h8+o2+co2 +h2o+n2);

tn = T_w/300;

Ea3 = 0.0;
Ea4 = 0.126*tn*tn*tn*tn - 1.849*tn*tn*tn + 9.124*tn*tn - 13.253*tn + 23.903;
Ea5 = 4.0;

Ea3 *= 4184e7;
Ea4 *= 4184e7;
Ea5 *= 4184e7;

rA3 = (0.0542)*pow(tn,0.766);
rA4 = (8.41e12)*pow(tn,-0.796);
rA5 = (0.06)*pow(tn,0.154);
rk3 = (rA3/(sd*sd))*sqrt(R*T_w/(2*pi*mw[1]))*(p/(R*T_w));
rk4 = (rA4/sd)*exp(-Ea4/(R*T_w));
rk5 = (rA5/(sd*sd))*sqrt(R*T_w/(2*pi*mw[0]))*(p/(R*T_w))*exp(-Ea5/(R*T_w));

ro = sqrt(rk3*xo2/rk4);
o_s = ro/(1+ro);
o_vac = 1-o_s;
rate = rk5*xc3h8*(sd*sd)*pow(o_vac,2);

if (STREQ(r->name, "reaction-1"))
{ *rr = rate*pow(10,1)*1.7; }


if(id == 3)

Thread *t0=Lookup_Thread(domain, id)->t0;

cell_t c1=F_C0(f,t0);

real nh3= yi[0];
real n2r = yi[1];
real h2=yi[2];

real rho_w1, sd1 = 1.66e-7, T_w1; /* sd1-kmol/m2 */
real xnh3, xn2r, xh2;
real Eh2, En2, Enh3, Er, En2d;
real ah,an,anh,ar,and;
real Kha,Kna,Knh3,Kr,knd;
real omega,rate1,denom;

T_w1 = F_T(f,t);
rho_w1 = C_R(c1,t0)*C_T(c1,t0)/T_w1;

nh3 *= rho_w1/mw[0];
h2 *= rho_w1/mw[1];
n2r *= rho_w1/mw[2];

xnh3 = nh3/(nh3+n2r+h2);
xn2r = n2r/(nh3+n2r+h2);
xh2 = h2/(nh3+n2r+h2);

Eh2 = -21.8*4187; /* kcal/mol -> e-7*ergs/mol (or jol/mole) */
En2 = -23.1*4187;
Enh3 = -18.2*4187;






if (STREQ(r->name, "reaction-2"))
*rr = rate1;

byronsmith September 18, 2010 07:11

Dear Paaresh
I could not sit down and decipher your UDF but by going through a glance i suggest you to use get domain () to identify the domain you want to use and the if loop may not be necesary. could you compile the udf u have written and what problems are you encountering

sri31049 September 18, 2010 15:16

The UDF is running without errors but reaction is not happening. I checked individual UDF's they worked well.
some problem assigning thread i guess...! because of that I could not able to solve..!

chaozhong.qin September 19, 2010 15:58

The wall should have a shadow wall.

The key is to discriminate the two threads.


int zone_id;
zone_id == THREAD_ID(t);
if ( zone_id == wall index )
if (zone_id == shadow wall index)

Hope it is useful to you.

sri31049 September 20, 2010 02:05

I have used exact wall ID from the Boundary conditions panel. So it should assign the proper thread. But still I tried your method but the problem continues again.....!!

byronsmith September 24, 2010 06:23

I think you can also use the lookup_Thread(d,ZoneID) to identify the thread. see if that could work

Mahboobe365 June 14, 2013 21:42

Hi, I have the similar problem. can you help me??

All times are GMT -4. The time now is 02:05.