CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   how to get the derivative of scalar? (http://www.cfd-online.com/Forums/fluent-udf/84798-how-get-derivative-scalar.html)

 tompa February 9, 2011 04:29

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

Thanks.

 Amir February 9, 2011 09:11

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.

 tompa February 18, 2011 04:47

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;
}

{
cell_t c;
real K_EL=1.0;
if(!Data_Valid_P())
return;
{
{
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)
}
}
}

{
cell_t c;
real K_EL=1.0;
if(!Data_Valid_P())
return;
{
{
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:
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
Error:
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
Error Object: #f
================================================

Is there something wrong in my UDF?
And in FLUENT, the number of user-defined scalar should be 2 or 4 in my case?

 Amir February 18, 2011 05:39

you used 4 UDS, so set that and double check and inform me...

 tompa February 19, 2011 01:23

Thank you, Amir.
I will simplify and check my udf.

I have another question here: