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

How to write equation into UDF?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 8, 2009, 05:41
Default How to write equation into UDF?
  #1
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
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, 1117 views)
Jane is offline   Reply With Quote

Old   May 8, 2009, 07:22
Default
  #2
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
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)"):
http://www.cfd-online.com/Forums/flu...cent-wall.html

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, 09:09
Default
  #3
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
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, 10:04
Default
  #4
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
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, 10:52
Default
  #5
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
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, 21:58
Default
  #6
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
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, 21:49
Default
  #7
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
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 11, 2009 at 00:02.
Jane is offline   Reply With Quote

Old   May 15, 2009, 16:32
Default
  #8
Member
 
Join Date: Mar 2009
Location: Istanbul, Turkiye
Posts: 47
Rep Power: 17
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

Old   August 29, 2023, 03:23
Default How to write two reaction rates equations in UDF
  #9
Member
 
George Corner
Join Date: Dec 2016
Posts: 30
Rep Power: 9
sam_cfdd is on a distinguished road
Hello,

I want to know how to write two reaction rates in a single UDF. I mean two reaction rate equations (Volumetric rate) in UDF. In the UDF manual (April 2009 p: 8-38), there is an example only for one reaction rate, but I am wondering how to extend it to two or more.

Thanks a lot.
sam_cfdd is offline   Reply With Quote

Old   August 30, 2023, 00:03
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
make the second reaction rate macro with other name
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   August 30, 2023, 05:53
Default
  #11
Member
 
George Corner
Join Date: Dec 2016
Posts: 30
Rep Power: 9
sam_cfdd is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
make the second reaction rate macro with other name
Thanks but when I change the name I faced with the error.
sam_cfdd is offline   Reply With Quote

Reply


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 Off
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 22: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 12:21
UDF (write a data file) problem lichun Dong FLUENT 2 July 29, 2005 12: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 15:48.