CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

How to write equation into UDF?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   May 8, 2009, 04:41
Default How to write equation into UDF?
  #1
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8
Jane is on a distinguished road
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...
Attached Images
File Type: jpg shear rate.JPG (7.1 KB, 466 views)
Jane is offline   Reply With Quote

Old   May 8, 2009, 06:22
Default
  #2
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 8
Daniel Tanner is on a distinguished road
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].
Daniel Tanner is offline   Reply With Quote

Old   May 8, 2009, 08:09
Default
  #3
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8
Jane is on a distinguished road
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??
Jane is offline   Reply With Quote

Old   May 8, 2009, 09:04
Default
  #4
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 8
Daniel Tanner is on a distinguished road
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.
Daniel Tanner is offline   Reply With Quote

Old   May 8, 2009, 09:52
Default
  #5
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8
Jane is on a distinguished road
Thank you very much Daniel Tanner

i will try to rewrite it.

Thank you again.
Jane is offline   Reply With Quote

Old   May 9, 2009, 20:58
Default
  #6
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8
Jane is on a distinguished road
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
Jane is offline   Reply With Quote

Old   May 10, 2009, 20:49
Default
  #7
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 8
Jane is on a distinguished road
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.
Jane is offline   Reply With Quote

Old   May 15, 2009, 15:32
Default
  #8
Member
 
Join Date: Mar 2009
Location: Istanbul, Turkiye
Posts: 45
Rep Power: 8
gemini is on a distinguished road
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:
Originally Posted by Jane View Post
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
gemini is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 05:26.