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 calculate a derivative through UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 6 Post By christophelorant

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 27, 2014, 12:00
Default how to calculate a derivative through UDF
  #1
New Member
 
Join Date: Apr 2014
Posts: 2
Rep Power: 0
Rigid is on a distinguished road
Hi, all.
In my task I need to calculate a derivative from (du/dx+dv/y) by x and y.
How can i do this in my UDF ? I tried to do so

( (C_DUDX(c,t)+C_DVDY(c,t)) - (C_DUDX(c-1,t)+C_DVDY(c-1,t)) )/hx

but it is wrong, and I have no other ideas. Can anyone help me with this problem?
Rigid is offline   Reply With Quote

Old   April 28, 2014, 04:24
Default
  #2
New Member
 
Christophe Lorant
Join Date: Apr 2014
Posts: 2
Rep Power: 0
christophelorant is on a distinguished road
Hello Rigid,

The way you're trying to compute gradient will certainly not work because it is only a valid approximation for 1D meshes. What you could do to solve your problem is to use the way Fluent itself computes other gradients: The Green-Gauss theorem.

\vec{\nabla}\phi = \frac{1}{\Omega}\sum_f{\phi_{f}\vec{A_{f}}}

With \Omega the cell volume (or surface in 2D), \phi_f the value of the variable on the face f and \vec{A_f} the face vector.

You could try the following to compute your gradient in one cell:

Code:
/* c is the index of cell where the gradient has to be computed and t the corresponding cell thread*/

Thread *tf;
real A[2], phi_f, grad[2];
int i;

grad[0] = 0;
grad[1] = 0;

c_face_loop(c, t, i)
{
    f = C_FACE(c,t,i);
    tf = C_FACE_THREAD(c,t,i);
    phi_f = 0.5 * ( C_U_G(F_C0(f,tf),THREAD_T0(tf))[0] + C_U_G(F_C1(f,tf),THREAD_T1(tf))[0] );
    phi_f += 0.5 * ( C_V_G(F_C0(f,tf),THREAD_T0(tf))[1] + C_V_G(F_C1(f,tf),THREAD_T1(tf))[1] );
    F_AREA(A,f,ft);
    grad[0] += phi_f*A[0];
    grad[1] += phi_f*A[1];
}

grad = grad/C_VOLUME(c,t);
christophelorant is offline   Reply With Quote

Old   April 29, 2014, 16:32
Default
  #3
New Member
 
Join Date: Apr 2014
Posts: 2
Rep Power: 0
Rigid is on a distinguished road
Hello, christophelorant !

Thank you very much for your answer and code, now my udf works correct (imho).

I fixed some bugs in your code:

1. Variable f must be defined as face_t

2. String

grad = grad/C_VOLUME(c,t)

leading to compilation error, so i updated
this as following

grad[0] = grad[0]/C_VOLUME(c,t)
grad[1] = grad[1]/C_VOLUME(c,t)

and i hope this is correct.


Because in this code a "c_face_loop" is used, udf source file must be compiled
(not interpreted) in Fluent.

Regards, Rigid
Rigid is offline   Reply With Quote

Reply

Tags
fluent - udf


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 calculate the area of a boundary in UDF? peter FLUENT 2 May 31, 2021 21:54
calculate dot product of two gradient vector in UDF behest Fluent UDF and Scheme Programming 1 February 28, 2014 14:32
UDF value error when i calculate a log function neangiee Fluent UDF and Scheme Programming 0 May 9, 2013 23:39
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


All times are GMT -4. The time now is 16:48.