CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

Fluent UDF urgent! Variable reaction rate

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

Reply
 
LinkBack Thread Tools Display Modes
Old   July 4, 2011, 16:48
Default Fluent UDF urgent! Variable reaction rate
  #1
Member
 
Nathan
Join Date: Aug 2010
Posts: 64
Rep Power: 6
natantyt is on a distinguished road
Hi

I've written a UDF in Fluent for a volumetric reaction rate. I want to know how I can make the reaction rate variable along my reactor due to variation in catalyst activity. Any idea?

Example:

r= p* k C^2 ( p is a function of distance into the reactor)

How do you implement this, I'm new to UDf

Thanks
natantyt is offline   Reply With Quote

Old   July 6, 2011, 05:24
Default
  #2
New Member
 
Kristian Etienne Einarsrud
Join Date: Oct 2010
Location: Trondheim
Posts: 29
Rep Power: 6
KristianEtienne is on a distinguished road
Hi,

I guess what you need is a function which gives you the position of the each cell center, which is C_CENTROID(x,c,ct). Here, x is an array which holds the x,y,z coordinates, while c and ct are the cell and thread pointers which are passed from the solver through an appropriate macro.

Assuming you are using a DEFINE_ADJUST macro to update your reaction rate, and that your reaction rate is r=x*k*C^2 (x being the x-coordinate), I would use
------
DEFINE_ADJUST(adjustRXR,domain)
{
Thread *ct;
cell_t c;
real x[ND_ND];
real k, C,r,pos;
k=0.25; /* just an example*/
C=0.1; /* just an example*/
r=0.0; /* initialization to be sure*/
pos=0.0; /* initialization to be sure*/
thread_loop_c(ct,domain) /*Loop over the threads in the domain*/
{
begin_c_loop(c,ct) /*Loop over all cells in the thread*/
{
C_CENTROID(x,c,ct); /*Find position of cell and store in x*/
pos = x[0]; /*Store the x-coordinate as pos. y-coordinate is x[1],
z-coordinate is x[2]*/
r=pos*k*C*C; /*Store reaction rate in local variable r*/
C_UDMI(c,ct,0) = r; /*Store reaction rate in user defined memory position 0 so that other functions can access it*/
}end_c_loop(c,ct)
}
}
-----
You will need one UDM to store the reaction rate if you do it in this way. Remember to hook the DEFINE_ADJUST function before running your simulations.

For a more complete example, see section 2.3.22.3 in the UDF-guide.

Good luck!

-KE
KristianEtienne is offline   Reply With Quote

Old   July 6, 2011, 16:36
Default
  #3
Member
 
Nathan
Join Date: Aug 2010
Posts: 64
Rep Power: 6
natantyt is on a distinguished road
Thanks A lot for the comment
The problem is my reaction is defined through a volumetric reaction rate DEFINE_VR_RATE , the reaction needs the temperature and mass fraction of each node (300000 nodes) at each iteration. Apparently inside the ADJUST udf we don't ahve access to node values. I get error. Below is my original UDf for VR_Rate, if you like take a look at it.

#include"udf.h"
DEFINE_VR_RATE(proprate,c,t,r,mw,yi,rr,rr_t)
{

/*mass fraction of species i */

real y_c3h8=yi[3];
real y_h2o=yi[4];
real y_h2=yi[0];
real y_co=yi[1];
real y_co2=yi[2];
real y_n2=yi[5];
real Nsum, R, Keq1, T_w, r1,r2;
/*calculate species i in the unit of kgmol i/kg mix*/
y_c3h8 *= 1/mw[3];
y_h2o *= 1/mw[4];
y_h2 *= 1/mw[0];
y_co *= 1/mw[1];
y_co2 *= 1/mw[2];
y_n2 *= 1/mw[5];
Nsum = y_c3h8+ y_h2o + y_h2 + y_co + y_co2 + y_n2;
y_c3h8 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co *= 1/Nsum;
y_co2 *= 1/Nsum;
y_n2 *= 1/Nsum;
R=8.314;
T_w=C_T(c,t);
Keq1=pow(10,(2073/T_w)-2.029);

if(STREQ(r->name, "reaction-1")){
/*unit for rr, kg/m3s*/
r1= 44*3e8*exp(-105000/(R*T_w))*(y_c3h8*y_h2o)/(1+105*exp(3000/(R*T_w))*pow(y_c3h8,2));
*rr = r1;
}
elseif (STREQ(r->name, "reaction-2")){
r2= 28*3.4e9*exp(-130000/(R*T_w))*(y_co*y_h2o-(y_h2*y_co2)/Keq1) ;
*rr = r2;
}
}
natantyt is offline   Reply With Quote

Old   July 7, 2011, 03:59
Default
  #4
New Member
 
Kristian Etienne Einarsrud
Join Date: Oct 2010
Location: Trondheim
Posts: 29
Rep Power: 6
KristianEtienne is on a distinguished road
Hello again,

If I understand your original post correctly, your problem is that you want to include a position dependency in your DEFINE_VR_RATE?

This can be done by the following modification (I have made my changes in bold text for clarity):
#include"udf.h"
DEFINE_VR_RATE(proprate,c,t,r,mw,yi,rr,rr_t)
{

/*mass fraction of species i */
real Nsum, R, Keq1, T_w, r1,r2,x[ND_ND],xpos,ypos,zpos;
real y_c3h8=yi[3];
real y_h2o=yi[4];
real y_h2=yi[0];
real y_co=yi[1];
real y_co2=yi[2];
real y_n2=yi[5];

/* Find and store coordinates for each cell*/
C_CENTROID(x,c,t); /* store position in array x*/
xpos = x[0];

ypos = x[1];
zpos = 0.0;
#if RP_3D
zpos = x[2];
#endif
/* The above #if statement ensures that you only can access the z-position (x[2]) if you are doing a 3D-simulation */

/* The coordinates of each cell are now stored in xpos,ypos and zpos (if 3D) for future use*/
/*calculate species i in the unit of kgmol i/kg mix*/
y_c3h8 *= 1/mw[3];
y_h2o *= 1/mw[4];
y_h2 *= 1/mw[0];
y_co *= 1/mw[1];
y_co2 *= 1/mw[2];
y_n2 *= 1/mw[5];
Nsum = y_c3h8+ y_h2o + y_h2 + y_co + y_co2 + y_n2;
y_c3h8 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co *= 1/Nsum;
y_co2 *= 1/Nsum;
y_n2 *= 1/Nsum;
R=8.314;
T_w=C_T(c,t);
Keq1=pow(10,(2073/T_w)-2.029);

if(STREQ(r->name, "reaction-1")){
/*unit for rr, kg/m3s*/
r1= 44*3e8*exp(-105000/(R*T_w))*(y_c3h8*y_h2o)/(1+105*exp(3000/(R*T_w))*pow(y_c3h8,2));
*rr = r1;
}
elseif (STREQ(r->name, "reaction-2")){
r2= 28*3.4e9*exp(-130000/(R*T_w))*(y_co*y_h2o-(y_h2*y_co2)/Keq1) ;
*rr = r2;
}
}

Another point; note that the values you are using are *not* node values but *cell* values, as it is the cell pointer "c" which is passed from the macro DEFINE_VR_RATE.

Happy simulating!

-KE
KristianEtienne is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Problem of Fluent Interpreted UDF: parse error knight Fluent UDF and Scheme Programming 11 December 8, 2013 10:00
Two questions on Fluent UDF Steven Fluent UDF and Scheme Programming 4 September 20, 2013 16:30
using rate equation for volumetric reaction byronsmith FLUENT 3 April 8, 2009 11:58
case files UDF volumetric reaction rate Marie-Anne Main CFD Forum 2 February 24, 2006 10:43
chemical reaction - decompostition La S. Hyuck CFX 1 May 23, 2001 00:07


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