
[Sponsors] 
August 19, 2009, 15:10 
udf for adsorption coefficient

#1 
New Member
beibei
Join Date: Aug 2009
Posts: 6
Rep Power: 7 
I need to define my own adsorption coefficient of solid quartz as a function of x due to some chemical change. Shall I define it as a thread or cell or something else? This is my first time to use udf ever and C program since 15 years ago. Could you gurus check my code for me? thanks! Here's my C code:
/************************************************** ******************* UDF for specifying a xaxisdependent absorption property ************************************************** ********************/ #include "udf.h" DEFINE_PROPERTY(absorption_coefficient, thread, index) { real abs_lam; real x; if (0 < x < 0.2) abs_lam = 0.1111; else if (0.2 < x < 0.4) abs_lam = 0.2222; else if (0.4 < x < 0.6) abs_lam = 0.3333; else if (0.6 < x < 0.8) abs_lam = 0.4444; else abs_lam = 0.5555; return abs_lam; } 

August 20, 2009, 02:48 

#2 
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 8 
Hello Beibei,
1) if x should hold the position in xdirection of a given cell you must retrieve the coordinates of its centroid by using the macro C_CENTROID(pos,c,t) where pos is a vector with components (x,y,z). To get x use pos[0]. 2) the correct syntax for DEFINE_PROPERTY is DEFINE_PROPERTY(name,c,t), no index in it! Have a look at the udfmanuel, surely there is an example which is close to your specific application. cheers 

August 24, 2009, 15:09 

#3 
New Member
beibei
Join Date: Aug 2009
Posts: 6
Rep Power: 7 
Thank you for help! I revised my code as:
/************************************************** ******************* UDF for specifying a xaxisdependent absorption property ************************************************** ********************/ #include"udf.h" DEFINE_PROPERTY(absorption_coefficient, c, t) { real abs_coeff; real pos; C_CENTROID(pos[0],c,t); if (0 <= pos[0] < 0.2) abs_coeff = 0.1111; elseif (0.2 <= pos[0] < 0.4) abs_coeff = 0.2222; elseif (0.4 <= pos[0] < 0.6) abs_coeff = 0.3333; elseif (0.6 <= pos[0] < 0.8) abs_coeff = 0.4444; else abs_coeff = 0.5555; return abs_coeff; } But it still didn't work. FLUENT gave me the error message of "line9: subscription expression is not an array or pointer: float". This pointer stuff is killing me. I never really understand the concept. Could someone help me? Thanks a lot! Last edited by bzhu; August 24, 2009 at 23:13. 

August 25, 2009, 03:53 

#4 
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 8 
beibei, that's really basic Cstuff which you should try to understand as soon as possible if you need to use udf's.
However, as already stated pos is a vector, so you need to deslare it as one: real pos[ND_ND]; (ND_ND is a fluent macro returning the right dimension automatically for 2d/3D) then get the CellCenter_coordinates into it: C_CENTROID(pos,c,t); The rest should be o.k. cheers 

August 26, 2009, 13:14 

#5 
New Member
beibei
Join Date: Aug 2009
Posts: 6
Rep Power: 7 
Thanks! I revised my code as:
/************************************************** ******************* UDF for specifying a xaxisdependent absorption property ************************************************** ********************/ #include"udf.h" DEFINE_PROPERTY(absorption_coefficient, c, t) { real abs_coeff; real x[ND_ND]; C_CENTROID(x,c,t); if (0 <= x[0] < 0.2) abs_coeff = 0.1111; elseif (0.2 <= x[1] < 0.4) abs_coeff = 0.2222; elseif (0.4 <= x[2] < 0.6) abs_coeff = 0.3333; elseif (0.6 <= x[4] < 0.8) abs_coeff = 0.4444; else abs_coeff = 0.5555; return abs_coeff; } It could interprete to FLUENT. The problem is that after iteration, I checked the adsorption coefficient. It didn't look like a function of x position. Could you see the cause in my code? Thanks! 

August 27, 2009, 04:41 

#6 
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 8 
yes i see the reason and you should be able to find the error too. I guess you do not really intend to solve a 5D problem which would at least give some physical meaning to x[4] !
cheers 

September 17, 2009, 10:36 

#7 
New Member
beibei
Join Date: Aug 2009
Posts: 6
Rep Power: 7 
I revised my code as below and FLUENT didn't seem to render it even though it could interprete. I changed the xposition dependent to a constant jsut by replacing the ifcommand to a constant to see if fluent can exert, and it didn't. What could it be wrong? Couldn't fluent render udf on a surface? Please help! Thanks!
Here's my code: #include"udf.h" DEFINE_PROPERTY(absorption_coefficient, c, t) { real abs_coeff; real x[ND_ND]; C_CENTROID(x,c,t); if (x[0] > 0 && x[0] < 0.2) abs_coeff = 593.9187; elseif (x[0] > 0 && x[0] < 0.2) abs_coeff = 197.6521; elseif (x[0] > 0 && x[0] < 0.2) abs_coeff = 177.0521; elseif (x[0] > 0 && x[0] < 0.2) abs_coeff = 140.5854; else abs_coeff = 140.5854; Message("Abs coefficient for this cell %e = %e", x[0],abs_coeff); return abs_coeff; } 

Tags 
adsorption coefficient, code, fluent, udf 
Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Automotive test case  vinz  OpenFOAM Running, Solving & CFD  98  October 27, 2008 09:43 
how to define restituition coefficient using UDF?  haijj  FLUENT  6  July 9, 2008 23:26 
UDF for Heat transfer coefficient  Dong Wenchao  FLUENT  2  August 23, 2006 06:35 
heat transfer coefficient udf  nam su  FLUENT  0  March 25, 2005 03:28 
UDF  Heat transfer coefficient  kulasekharan  FLUENT  3  August 12, 2004 07:09 