|
[Sponsors] |
June 28, 2017, 12:27 |
udf code:hydrogenation raction
|
#1 |
New Member
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9 |
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 |
|
June 29, 2017, 07:56 |
|
#2 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
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 /* */. |
|
June 30, 2017, 02:45 |
|
#3 |
New Member
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9 |
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?? |
|
July 3, 2017, 07:31 |
|
#4 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
Have you defined the UDM in fluent?
|
|
July 3, 2017, 08:02 |
|
#5 |
New Member
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9 |
yes, I have assigned 4 udms.
|
|
July 3, 2017, 09:00 |
|
#6 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
You need 5 UDMs
(UDM-0, UDM-1, UDM-2, UDM-3, UDM-4) |
|
July 3, 2017, 09:38 |
|
#7 |
New Member
Mat
Join Date: Jan 2017
Posts: 23
Rep Power: 9 |
Thank you.
I changed UDM to 5...but still error persists.. |
|
July 3, 2017, 10:57 |
|
#8 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
Are you sure that the zone_id is correct?
Last edited by KaLium; July 3, 2017 at 11:07. Reason: typo |
|
July 3, 2017, 11:02 |
|
#9 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
physical_dt=RP_Get_Real("physical time step")
Is also missing ; |
|
|
|
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 |