# how to calculate a derivative through UDF

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

 April 27, 2014, 11: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, 03: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); waouyouy and CarolC like this.

 April 29, 2014, 15: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

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post behest Fluent UDF and Scheme Programming 1 February 28, 2014 14:32 neangiee Fluent UDF and Scheme Programming 0 May 9, 2013 22:39 peter FLUENT 0 December 9, 2005 01:42 Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01

All times are GMT -4. The time now is 19:11.