udf for adsorption coefficient
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 x-axis-dependent 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; } |
Hello Beibei,
1) if x should hold the position in x-direction 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 udf-manuel, surely there is an example which is close to your specific application. cheers |
Thank you for help! I revised my code as:
/************************************************** ******************* UDF for specifying a x-axis-dependent 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! |
beibei, that's really basic C-stuff 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 Cell-Center_coordinates into it: C_CENTROID(pos,c,t); The rest should be o.k. cheers |
Thanks! I revised my code as:
/************************************************** ******************* UDF for specifying a x-axis-dependent 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! |
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 5-D problem which would at least give some physical meaning to x[4] !
cheers |
I revised my code as below and FLUENT didn't seem to render it even though it could interprete. I changed the x-position dependent to a constant jsut by replacing the if-command 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; } |
All times are GMT -4. The time now is 12:40. |