how to get the derivative of scalar?
It seems like to need to get it using dn(x)/dx=(n(x+h)n(x))/h
Please help me to get the values of n(x+h), n(x) and h. Thanks. 
Hi Tom,
you can refer to UDF help manual (DEFINE_ADJUST 2nd example). otherwise for specific x value over a face, you can use C0 and C1 values. 
Thank you, Amir.
I followed the Manual example and constructed my udf as below ================================================== ====== #include "udf.h" #define PI (3.1415926) real x[ND_ND]; face_t f; real diff; real Kn, rc, kb, rp, diffuse, dc, G; real source, source1,source2, B , As, dp, Tau, v, np, l, g, I, v0,a0, KnD,p; real kk,e, lumda; DEFINE_DIFFUSIVITY(diffusivityN,c,t,i) { C_CENTROID(x,c,t) return C_R(c,t)*C_T(c,t); } DEFINE_SOURCE(N_source,c,t,dS,eqn) { C_CENTROID(x,c,t) v=sqrt(8.*kb*C_UDSI(c,t,0)*C_T(c,t)/(PI*C_R(c,t)*C_UDSI(c,t,1))); KnD=4.*diffuse/v; p=1.; B=(1+KnD)/(1+2*KnD*(1+KnD)/p); source=C_UDSI(c,t,0); dS[eqn]=1.; return source; } DEFINE_SOURCE(V_source,c,t,dS,eqn) { C_CENTROID(x,c,t) source1=C_UDSI(c,t,3)/C_UDSI(c,t,0); dS[eqn]=1./C_UDSI(c,t,0); return source1; } DEFINE_ADJUST(adjust_fcn1,d) { Thread *t; cell_t c; real K_EL=1.0; if(!Data_Valid_P()) return; thread_loop_c(t,d) { if(FLUID_THREAD_P(t)) { begin_c_loop_all(c,t) { C_UDSI(c,t,2)+=K_EL*NV_MAG2(C_UDSI_G(c,t,0))*C_VOL UME(c,t); } end_c_loop_all(c,t) } } } DEFINE_ADJUST(adjust_fcn2,d) { Thread *t; cell_t c; real K_EL=1.0; if(!Data_Valid_P()) return; thread_loop_c(t,d) { if(FLUID_THREAD_P(t)) { begin_c_loop_all(c,t) { C_UDSI(c,t,3)+=K_EL*NV_MAG2(C_UDSI_G(c,t,3))*C_VOL UME(c,t); } end_c_loop_all(c,t) } } } ================================================== ==== It was compiled successfully but couldn't calculate. The error message is below: ============================================== Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: #f ================================================ Is there something wrong in my UDF? And in FLUENT, the number of userdefined scalar should be 2 or 4 in my case? 
you used 4 UDS, so set that and double check and inform me...

Thank you, Amir.
I will simplify and check my udf. I have another question here: In example2 for DEFINE_ADJUST, why "C_UDSI(c,t,1)+=K_EL*NV_MAG2(C_UDSI_G(c,t,0)*C_VOL UME(c,t));" can specifies a userdefine scalar as a function of the gradient of another userdefine scalar? 
Hi Tom,
yes, you can define a UDS as a function of another UDS or it's gradient components or magnitude. note that C_UDSI stores scalar but C_UDSI_G stores vector. as you see in second example the magnitude of UDS gradient was stored in another UDS. 
All times are GMT 4. The time now is 05:37. 