
[Sponsors] 
May 8, 2009, 04:41 
How to write equation into UDF?

#1 
New Member
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8 
I want to write the shear rate equation (as shown in attachment) into UDF
But i don't know how to translate the equation into UDF language. Please help me... 

May 8, 2009, 06:22 

#2 
Member
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 8 
Here is some info to get you started:
1) You can loop over all the cells in your domain and calculate your variables of interest using the UDF at the weblink below (remove the second loop "begin_f_loop(f,t)"): How to find the cells adjacent to the wall? 2) At each cell you calculate your equation and can save it in user defined memory (C_UDMI). There are macros that will help by allowing you to access the cell velocity gradient variables. Read the UDF manual or type Cell Macros in to google. The macros will have the form: C_U_G(c,t)[i], C_V_G(c,t)[i], C_W_G(c,t)[i]. 

May 8, 2009, 08:09 

#3 
New Member
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8 
Thank you Daniel Tanner
i've tried to write the equation to the UDF but there are still have something that i'm not understand. i define the u, v, w as: real shear_rate; real u = C_U_G(cell, thread); real v = C_V_G(cell, thread); real w = C_W_G(cell, thread); when i compiled the UDF file, then fluent show the below messages ..\..\src\viscosity1SR.c(23) : error C2440: 'initializing' : cannot convert from 'real *' to 'real' ..\..\src\viscosity1SR.c(24) : error C2440: 'initializing' : cannot convert from 'real *' to 'real' ..\..\src\viscosity1SR.c(25) : error C2440: 'initializing' : cannot convert from 'real *' to 'real' the number 23,24,25 refer to u, v, w that i define above. why the messages show cannot convert from 'real *' to 'real', what should i define the u, v, w?? 

May 8, 2009, 09:04 

#4 
Member
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 8 
It's worth browsing UDF examples on the net to figure out how they are structured. It will be something like this:
real u, v, w; thread_loop_c(ct, d) { begin_c_loop(c,ct) { /* For each Cell you loop over you perform calculation and store */ u = C_U_G(c, ct)[1]; v = C_V_G(c, ct)[1]; w = C_W_G(c, ct)[1]; Answer = u + v  w; /* This stores the calculation */ C_UDMI(c,ct,0) = Answer; } end_c_loop(c,ct) } } Be careful C_U_G(c, ct)[0] returns dU/dx where [0] tells the macros you want dx, i.e., [1] = y and [2] z (google them!). Similarly C_V_G is for V and C_W_G for W components of velocity. Good luck. 

May 8, 2009, 09:52 

#5 
New Member
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8 
Thank you very much Daniel Tanner
i will try to rewrite it. Thank you again. 

May 9, 2009, 20:58 

#6 
New Member
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8 
if i want to calculate another equation that require shear rate value, so which shear rate or C_UDMI(c,ct,0) i need to taking account into 2nd equation??
eg. (1) X= shear_rate*a/b or (2) X= C_UDMI(c,ct,0)*a/b 

May 10, 2009, 20:49 

#7 
New Member
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8 
i have some question about "return" function in the UDF writing.
for example i found most of the equation in UDF end with eg. "return X" like eg. from fluent documentation: DEFINE_SOURCE(p1_source, c, t, dS, eqn) { real source; int P1 = ...; dS[eqn] = abs_coeff; source = abs_coeff *(4.* SIGMA_SBC * pow(C_T(c,t),4.)  C_UDSI(c,t,P1)); return source; } why we need to put return for the equation??? if no return function for equation, what would happen??? Please explain for me....i cannot found the reason in fluent documentation....help Last edited by Jane; May 10, 2009 at 23:02. 

May 15, 2009, 15:32 

#8  
Member
Join Date: Mar 2009
Location: Istanbul, Turkiye
Posts: 45
Rep Power: 8 
Hi,
in your example, source term is being calculated and store in variable source. but you have to pass the value of source into fluent solver. thus in most of the functions/macros you add return XXX pass your calculation result (value of source in this example) into the FLUENT solver. Quote:


Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
How to add a UDF to a compiled UDF library  kim  FLUENT  3  October 26, 2011 21:38 
how to write UDF to define 2 profiles at inlet?  emma  FLUENT  5  January 30, 2011 06:22 
UDF to write a data file  lichun Dong  FLUENT  2  August 4, 2005 11:21 
UDF (write a data file) problem  lichun Dong  FLUENT  2  July 29, 2005 11:39 
how to write a udf about roatation of rigid.  ccgwin  FLUENT  3  December 11, 2002 09:14 