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

how to get the derivative of scalar?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2011, 03:29
Default how to get the derivative of scalar?
  #1
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 15
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, 08:11
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
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 08:31.
Amir is offline   Reply With Quote

Old   February 18, 2011, 03:47
Default
  #3
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 15
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, 04:39
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
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, 00:23
Default
  #5
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 15
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, 08:17
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 22
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

Old   March 1, 2020, 05:51
Default
  #7
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by Amir View Post
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.
hi

do you know what is the T_derivatives function in udf??
mahdi-united is offline   Reply With Quote

Old   March 2, 2020, 03:41
Default T_derivatives
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Mahdi, I have checked and I can confirm that T_derivatives calculates gradients for temperature field in the domain. Hence, you certainly do not need it in your case. Now, the reason why you are facing issue is something else.

I'd suggest you do two things. Issue following commands and then run for a few iterations.

solve set expert

and then select Yes where it asks to keep the memory from being freed. Second command is (use the brackets as well)

(rpsetvar 'species/save-gradients? #t)

Then check for the gradients of species in contour plots. If those are not there, then there is some issue with the case setup. If those exist, then remove all the commands in your UDF that you are using to free up the allocated space, i.e., commands with Free_. Then compile the UDF and check.

Do note you have to compile it. Interpreted UDF will not work.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   March 2, 2020, 08:35
Default
  #9
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Mahdi, I have checked and I can confirm that T_derivatives calculates gradients for temperature field in the domain. Hence, you certainly do not need it in your case. Now, the reason why you are facing issue is something else.

I'd suggest you do two things. Issue following commands and then run for a few iterations.

solve set expert

and then select Yes where it asks to keep the memory from being freed. Second command is (use the brackets as well)

(rpsetvar 'species/save-gradients? #t)

Then check for the gradients of species in contour plots. If those are not there, then there is some issue with the case setup. If those exist, then remove all the commands in your UDF that you are using to free up the allocated space, i.e., commands with Free_. Then compile the UDF and check.

Do note you have to compile it. Interpreted UDF will not work.
dear vinerm i did everything you told me :
type this in TUI,(rpsetvar 'species/save-gradients? #t)
solve/set/expert and yes to answer keep temporary...?
define/models/ and yes to answer save gradients....?


and it's modified code correspond your opinion



DEFINE_ADJUST(gradient, domain)
{
Thread *t;
Thread **pt;
cell_t c;
Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE);
real voidx, voidy, voidz=0.0;
{
Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL);
Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,Vof_Deriv_Accumulate);
}

mp_thread_loop_c (t,domain,pt)
if (FLUID_THREAD_P(t))
{
Thread *tp = pt[P_PHASE];
begin_c_loop (c,t)
{

C_UDMI(c,t,0) = C_VOF_G(c,tp)[0]*C_YI_G(c,tp,0)[0] + C_VOF_G(c,tp)[1]*C_YI_G(c,tp,0)[1] + C_VOF_G(c,tp)[2]*C_YI_G(c,tp,0)[2];
}
end_c_loop (c,t)
}
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL);


}





and well compiling and initializing without error
but for bottom calculation, in the 1st iteration

FLUENT report message 'the f1 ..... could not be started' and automatically closed


but a remarkable point!!!
does it message is important(appear when case setup open)??


************************************************** ************************** ************************************************** **************************
** WARNING: Automatically switched to run in parallel -t1 mode. **
** Detected non-parallelized UDF usage, enabling parallel usage. **
** If you encounter any issues, please re-run with -t0 flag. **
************************************************** **************************
************************************************** **************************
mahdi-united is offline   Reply With Quote

Old   March 2, 2020, 08:42
Default Udf
  #10
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
The message in the end is of no value here; it only mentions new feature in Ansys Fluent that it can be run on 4 cores without HPC license.

What I meant by my previous post is not to use UDF. Just use the commands and run the simulation without the UDF. And then check the gradients reported in the Contours.

If your final objective is only to get gradients and do some calculation with those, then you don't need a UDF.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   March 3, 2020, 05:19
Default
  #11
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
The message in the end is of no value here; it only mentions new feature in Ansys Fluent that it can be run on 4 cores without HPC license.

What I meant by my previous post is not to use UDF. Just use the commands and run the simulation without the UDF. And then check the gradients reported in the Contours.

If your final objective is only to get gradients and do some calculation with those, then you don't need a UDF.
hi dear friend


one question
this command "SV_Y_G" how to alter to get 1st species?
is it right? SV_Y_0_G
mahdi-united is offline   Reply With Quote

Old   March 3, 2020, 05:39
Default Sv_y_g
  #12
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Putting the names in between will increase the variables. So, when the fields are related, vectors are used. Therefore, the SV_Y_G is used as it is and an integer identifier is used as

C_YI_G(c, t, 0)[0]

The above function will return gradient of first species with respect to x-coordinate.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply


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


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


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