CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

how to get the derivative of scalar?

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

Reply
 
LinkBack Thread Tools Display Modes
Old   February 9, 2011, 04:29
Default how to get the derivative of scalar?
  #1
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 6
tompa is on a distinguished road
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.
tompa is offline   Reply With Quote

Old   February 9, 2011, 09:11
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
Amir is on a distinguished road
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.

Last edited by Amir; February 9, 2011 at 09:31.
Amir is offline   Reply With Quote

Old   February 18, 2011, 04:47
Default
  #3
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 6
tompa is on a distinguished road
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 user-defined scalar should be 2 or 4 in my case?
tompa is offline   Reply With Quote

Old   February 18, 2011, 05:39
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
Amir is on a distinguished road
you used 4 UDS, so set that and double check and inform me...
Amir is offline   Reply With Quote

Old   February 19, 2011, 01:23
Default
  #5
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 6
tompa is on a distinguished road
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 user-define scalar as a function of the gradient of another user-define scalar?
tompa is offline   Reply With Quote

Old   February 19, 2011, 09:17
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
Amir is on a distinguished road
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.
Amir is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
dieselFoam problem!! trying to introduce a new heat transfer model vivek070176 OpenFOAM Programming & Development 10 December 24, 2014 00:48
Fluent udf--spatial derivative of user-defined scalar tas38 Fluent UDF and Scheme Programming 1 February 9, 2011 04:05
derivative of scalar lig Main CFD Forum 3 December 26, 2010 05:02
the derivative of Scalar on time ? owen FLUENT 0 March 5, 2009 05:59
scalar and its derivative sucker Main CFD Forum 1 April 15, 2008 13:28


All times are GMT -4. The time now is 23:27.