|
[Sponsors] |
April 27, 2014, 12:00 |
how to calculate a derivative through UDF
|
#1 |
New Member
Join Date: Apr 2014
Posts: 2
Rep Power: 0 |
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? |
|
April 28, 2014, 04:24 |
|
#2 |
New Member
Christophe Lorant
Join Date: Apr 2014
Posts: 2
Rep Power: 0 |
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. With the cell volume (or surface in 2D), the value of the variable on the face f and 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); |
|
April 29, 2014, 16:32 |
|
#3 |
New Member
Join Date: Apr 2014
Posts: 2
Rep Power: 0 |
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 |
|
Tags |
fluent - udf |
|
|
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 |