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

udf code:hydrogenation raction

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2017, 12:27
Default udf code:hydrogenation raction
  #1
New Member
 
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9
mataus is on a distinguished road
Hai folks
I am new to this fluent UDF coding and I would like to write a UDF for energy source term for hydrogen absorption in metal hydride.
The equations used in this reaction are given below

ds=ρ_s⋅wt⋅(1-ε)([h+T_s (C_pg-C_ps )]/M_g )).dX/dt

dX/dt=C_a⋅(((p-p_eq ))/p_eq )⋅(exp((-E_a)/(R_g*T_s )))⋅2/3⋅((1-X)^(2/3)/(1-(1-X)^(1/3) ))

X=1-[1-√({C_a *(((P-P_eq ))/P_eq )*(e^(((-E_a)/(R_g*T_s )) ) )*t} )]^3

Peq=(h/(R_g T_s ))-(s/R_g )*〖10〗^5

I wrote udf but,,I found some errors when it interpreted .the udf code and errors are given, I really expect some advice...

#include "udf.h"

#define h -75000 //(J/mol)
#define s -135.6 //(J/mol.K)
#define Rg 8.314 //(J/mol.K)
#define Ca 2.9e8 //(1/s)
#define Ea 124 //(J/mol)
#define rho_s 1800 //(kg/m3)
#define epsilon 0.31
#define Cpg 14000 //J/(kg.K)
#define Cps 1545 //J/(kg.K)
#define por 0.5
#define wt 0.06
#define M_g 0.002 //kg/mol

DEFINE_ON_DEMAND(Pellet)
{
Domain *d;
int zone_id=5;
Thread *t = Lookup_Thread(d,zone_id);
cell_t c;
d = Get_Domain(1); /* Get the domain using ANSYS Fluent utility */
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = 0;
}
end_c_loop(c,t)
}
}
DEFINE_ADJUST(ReactionR,d)
{
int zone_id=5;
Thread *t = Lookup_Thread(d,zone_id);
cell_t c;
real P_eq;
real dxdt;
real physical_dt;
real cond;
real ts;
real P;
ts=C_T(c,t);
P=C_P(c,t) /* get cell pressure */

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
P_eq=exp((h/(Rg*ts))- (s/Rg))*pow(10,5);
C_UDMI(c,t,1)=P_eq; /* calculate equilibrium pressure*/
cond=(P/C_UDMI(c,t,1))-1;
if(cond>0)
{
physical_dt=RP_Get_Real("physical time step")
C_UDMI(c,t,2)=1-pow((1-(sqrt(Ca*((P/C_UDMI(c,t,1))-1)* exp(-Ea/(Rg*ts)))* physical_dt)),3);/* calculate reacted fraction*/
dxdt=(2/3)*Ca*((P/C_UDMI(c,t,1))-1)*exp(-Ea/(Rg*ts))*((pow((1-C_UDMI(c,t,2)),(2/3)))/(1-(pow((1-C_UDMI(c,t,2)),(1/3)))));/* calculate reacted fraction*/
}
else
{
dxdt=0;
}
C_UDMI(c,t,3)=dxdt;
}
end_c_loop(c,t)
}
}
DEFINE_SOURCE(heat_generation,c,t,ds,eqn)
{
real q_a;
q_a=((rho_s*wt*(1-por)*(h+ (ts*( Cpg- Cps))))/ M_g)* C_UDMI(c,t,3);
ds[eqn]=0;
C_UDMI(c,t,4)=q_a; /* Memory allocation for storing 'heat generation' */
return q_a;
}

The errors are
1. line 46: parse error.
2. line 46: parse error.
3.c_loop_last: undeclared variable

Thank you
mataus is offline   Reply With Quote

Old   June 29, 2017, 07:56
Default
  #2
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
You missed the ; after P=C_P(c,t).

Do not use the // for comments in udf. Some compilers don't understand it. Only use /* */.
KaLium is offline   Reply With Quote

Old   June 30, 2017, 02:45
Default
  #3
New Member
 
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9
mataus is on a distinguished road
thanks for the reply.
I have changed the udf as per your direction but still experiencing one error.
Error: received a fatal signal (Segmentation fault).

Error: received a fatal signal (Segmentation fault).
Error Object: #f

any help??
mataus is offline   Reply With Quote

Old   July 3, 2017, 07:31
Default
  #4
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Have you defined the UDM in fluent?
KaLium is offline   Reply With Quote

Old   July 3, 2017, 08:02
Default
  #5
New Member
 
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9
mataus is on a distinguished road
yes, I have assigned 4 udms.
mataus is offline   Reply With Quote

Old   July 3, 2017, 09:00
Default
  #6
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
You need 5 UDMs

(UDM-0, UDM-1, UDM-2, UDM-3, UDM-4)
KaLium is offline   Reply With Quote

Old   July 3, 2017, 09:38
Default
  #7
New Member
 
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9
mataus is on a distinguished road
Thank you.
I changed UDM to 5...but still error persists..
mataus is offline   Reply With Quote

Old   July 3, 2017, 10:57
Default
  #8
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Quote:
Originally Posted by mataus View Post
Thank you.
I changed UDM to 5...but still error persists..
Are you sure that the zone_id is correct?

Last edited by KaLium; July 3, 2017 at 11:07. Reason: typo
KaLium is offline   Reply With Quote

Old   July 3, 2017, 11:02
Default
  #9
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
physical_dt=RP_Get_Real("physical time step")
Is also missing ;
KaLium is offline   Reply With Quote

Reply


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
UDF Compilation Error - Loading Library - COMMON Problem! Help! robtheslob Fluent UDF and Scheme Programming 8 July 24, 2015 01:53
Parallelize UDF? Which kind of UDF? Lilly FLUENT 5 March 25, 2014 03:05
Help! Delete the UDM codes in the UDF Messi Fluent UDF and Scheme Programming 2 January 28, 2014 10:01
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


All times are GMT -4. The time now is 19:13.