udf code:hydrogenation raction
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 |
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 /* */. |
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?? |
Have you defined the UDM in fluent?
|
yes, I have assigned 4 udms.:confused:
|
You need 5 UDMs
(UDM-0, UDM-1, UDM-2, UDM-3, UDM-4) |
Thank you.
I changed UDM to 5...but still error persists..:( |
Quote:
|
physical_dt=RP_Get_Real("physical time step")
Is also missing ; |
All times are GMT -4. The time now is 21:06. |