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

udf for heat generation rate

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

Like Tree2Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   May 27, 2013, 04:07
Default source energy
  #41
New Member
 
hossein
Join Date: May 2013
Posts: 1
Rep Power: 0
hosseinr is on a distinguished road
hi
Where is my problem udf?
#include "udf.h"

DEFINE_SR_RATE(my_rate,f,t,r,mw,yi,rr)
{
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_o2 = yi[6];
real y_n2 = yi[5];
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;
real r1,T_WALL,A, r2 ,r3, r4, k3,k4, min=0, max=1e+5, k1, k2;
Thread *t0 = THREAD_T0(t);
cell_t c0 = F_C0(f,t);
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_o2 *= 1/mw[6];
y_n2 *= 1/mw[5];
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_o2 *= 1/Nsum;
y_n2 *= 1/Nsum;
T_w = F_T(f,t);
begin_c_loop(c0,t0)
{
T_WALL = C_T(c0,t0);
C_UDSI(c0,t0,0) = T_WALL;
}
end_c_loop(c0,t0)
/* ki( Kmol*m^-2*s ) */
K1 = KO_1*exp(-E1/(R*T_w))*aa;
K2 = KO_2*exp(-E2/(R*T_w))*aa;
K3 = KO_3*exp(-E3/(R*T_w))*aa;
K4 = KO_4*exp(-E4/(R*T_w))*aa;
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( bar ) */
TP = C_P(c0,t0)/ad;
keq2 = (ab)*exp(ac/T_w);
keq3 = (ae)*exp(af/T_w);
keq4 = (ag)*exp(ah/T_w);
QR = 1+(K_C4*(TP*y_co))+(K_C5*(TP*y_h2))+(K_C3*(TP*y_ch 4))+((K_C6*(TP*y_h2o))/(TP*y_h2));
/* rr (Kmol*m^-2*s)*/
if (STREQ(r->name, "reaction-1"))
{
r1 = k1*(((TP*y_ch4)*pow(TP*y_o2,.5))/pow((1+(K_C1*(TP*y_ch4))+(K_C2*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;
}
}
}
DEFINE_ON_DEMAND(copy_uds_to_udm)
{
Domain* d = Get_Domain(1);
Thread* t;
cell_t c;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
Thread* t0;
cell_t c0;
{
C_UDMI(c0,t0,0) =C_UDSI(c0,t0,0);
}
end_c_loop(c,t)
}
return;
}

DEFINE_SOURCE(energy,c,t,dS,eqn)
{


real source;
source = C_UDMI(c0,t0,0);
dS[eqn] = 0;

return source;
}
hosseinr 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
strain rate in UDF Paulina FLUENT 11 November 20, 2014 04:06
UDF to measure Mass Flow Rate a.lynchy Fluent UDF and Scheme Programming 21 February 15, 2014 03:18
UDF for critical strain rate to extinction Birute Bunkute FLUENT 1 March 25, 2010 16:40
surface reaction rate with udf yellow-stuff FLUENT 4 January 29, 2010 13:53
heat generation rate w/m3 in 2D Laszlo FLUENT 1 May 6, 2004 11:58


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