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

udf problem

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 26, 2013, 09:14
Post udf problem
  #1
New Member
 
nabizadeh
Join Date: May 2012
Location: iran
Posts: 23
Rep Power: 13
eb.nabizadeh is on a distinguished road
i wrote an udf code for my problem in fluent but it didn't run and i didn't know my mistake.this is my code it's about a reactor that some reaction occur in it. is there any one can help me:

#include "udf.h"

# define R 8.314

# define KO_1 5.852e+17

# define KO_2 4.225e+15

# define KO_3 1.955e+6

# define KO_4 1.02e+15

# define E1 204000

# define E2 240100

# define E3 67130

# define E4 243900

# define K_CO1 4.02e+5

# define K_CO2 5.08e+4

# define K_CO3 6.65e-4

# define K_CO4 8.23e-5

# define K_CO5 6.12e-9

# define K_CO6 1.77e5

# define AH1 103500

# define AH2 66200

# define AH3 -38280

# define AH4 -70650

# define AH5 -82900

# define AH6 88680

DEFINE_SR_RATE(my_rate,f,t,r,mw,yi,rr)
{
Thread *t0 = THREAD_T0(t);

cell_t c0 = F_C0(f,t);

real y_ch4 = yi[0];
real y_h2o = yi[1];
real y_h2 = yi[2];
real y_co = yi[3];
real y_co2 = yi[4];
real y_n2 = yi[5];
real y_o2 = yi[6];

real K1, K2, K3, K4, T_w, TP ,Nsum , K_C1, K_C2, K_C3, K_C4, K_C5, K_C6, QR , keq2 , keq3 , keq4;

y_ch4 *= 1/mw[0];
y_h2o *= 1/mw[1];
y_h2 *= 1/mw[2];
y_co *= 1/mw[3];
y_co2 *= 1/mw[4];
y_n2 *= 1/mw[5];
y_o2 *= 1/mw[6];

Nsum = y_ch4 + y_h2o + y_h2 + y_co + y_co2 + y_n2 + y_o2 ;

y_ch4 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co *= 1/Nsum;
y_co2 *= 1/Nsum;
y_n2 *= 1/Nsum;
y_o2 *= 1/Nsum;

T_w = F_T(f,t);

K1 = KO_1*exp(-E1/(R*T_w));

K2 = KO_2*exp(-E2/(R*T_w));

K3 = KO_3*exp(-E3/(R*T_w));

K4 = KO_4*exp(-E4/(R*T_w));

K_C1 = K_CO1*exp((-AH1)/(R*T_w));

K_C2 = K_CO2*exp((-AH2)/(R*T_w));

K_C3 = K_CO3*exp((-AH3)/(R*T_w));

K_C4 = K_CO4*exp((-AH4)/(R*T_w));

K_C5 = K_CO5*exp((-AH5)/(R*T_w));

K_C6 = K_CO6*exp((-AH6)/(R*T_w));

TP = C_P(c0,t0)/1.0e+5;

keq2 = (5.75e+12)*exp(-11476/TP);

keq3 = (1.26e-2)*exp(4639/TP);

keq4 = (7.24e+10)*exp(-21646/TP);

QR = 1+(K_CO4*(TP*y_co))+(K_CO5*(TP*y_h2))+(K_CO1*(TP*y _ch4))+((K_CO6*(TP*y_h2o))/(TP*y_h2));

if (STREQ(r->name, "reaction-1"))
{
r1 = k1*(((TP*y_ch4)*pow(TP*y_o2,.5))/pow((1+(K_C1*(TP*y_ch4))+(K_CO2*pow(TP*y_o2,.5))), 2));

if(r1<min)
{
*rr = min;
}
else if (r1 > min && r1 < max)
*rr = r1;
else if (r1 > max){
*rr = max;
}
}
else if (STREQ(r->name, "reaction-2")){

r2=((k2/pow(TP*y_h2,2.5))*(((TP*y_ch4)*(TP*y_h2o))-((pow(TP*y_h2,3)*(TP*y_co))/(keq2)))/(pow(QR,2));

if(r2 < min)
{
*rr = min;
}
else if (r2 > min && r2 < max)
*rr = r2;
else if (r2 > max){
*rr = max;
}
}
else if (STREQ(r->name, "reaction-3"))
{
r3=((k3/(TP*y_h2))*(((TP*y_co)*(TP*y_h2o))-(((TP*y_h2)*(TP*y_co2))/(keq3)))/(pow(QR,2));
if(r3 < min)
{
*rr = min;
}
else if (r3 > min && r3 < max)
*rr = r3;
else if (r3 > max){
*rr = max;
}
}
else if (STREQ(r->name, "reaction-4")){

r4=((k4/pow(TP*y_h2,3.5))*(((TP*y_ch4)*pow(TP*y_h2o,2))-(((pow(TP*y_h2,4))*(TP*y_co2))/(keq4)))/(pow(QR,2));

if(r4 < min)
{
*rr = min;
}
else if (r4 > min && r4 < max)
*rr = r4;
else if (r4 > max){
*rr = max;
}
}
}
eb.nabizadeh is offline   Reply With Quote

Old   February 27, 2013, 03:38
Default
  #2
Senior Member
 
SSL
Join Date: Oct 2012
Posts: 226
Rep Power: 14
msaeedsadeghi is on a distinguished road
You have defined all parameters. Recheck it.
msaeedsadeghi is offline   Reply With Quote

Old   March 1, 2013, 01:28
Default
  #3
New Member
 
nabizadeh
Join Date: May 2012
Location: iran
Posts: 23
Rep Power: 13
eb.nabizadeh is on a distinguished road
you mean that the code is correct?
eb.nabizadeh is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ATTN ALL: SOLUTON TO UDF COMPILE PROBLEM Rizwan Fluent UDF and Scheme Programming 40 March 18, 2018 07:05
Problem with my udf july Fluent UDF and Scheme Programming 3 June 20, 2010 07:56
UDF problem mansha goraya FLUENT 0 October 29, 2007 01:31
udf compiling problem akr FLUENT 3 August 22, 2007 08:14
UDF problem chiseung FLUENT 4 January 10, 2002 10:58


All times are GMT -4. The time now is 01:48.