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

UDF-How to calculate gradient of a scalar

Register Blogs Community New Posts Updated Threads Search

Like Tree27Likes
  • 2 Post By Tony Tonton
  • 4 Post By Graham Goldin
  • 1 Post By Ilkay Sensoy
  • 1 Post By Ilkay Sensoy
  • 1 Post By Greg Perkins
  • 1 Post By n.phililipova
  • 1 Post By wond
  • 5 Post By billwangard
  • 1 Post By wond
  • 1 Post By n.phililipova
  • 1 Post By billwangard
  • 2 Post By n.phililipova
  • 1 Post By n.phililipova
  • 1 Post By Azy
  • 1 Post By syavash
  • 1 Post By Azy
  • 1 Post By mvee
  • 1 Post By Maryam-A

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 18, 2000, 13:33
Default UDF-How to calculate gradient of a scalar
  #1
Tony Tonton
Guest
 
Posts: n/a
Hi! I am trying to write a UDF for fluent. I need to calculate the gradient of a scalar. Does anybody have any idea how can I do that. That is, what are the macros available in Fluent that I can usse to calculate the gradient? Thanking you in advance Tony
  Reply With Quote

Old   February 20, 2000, 15:44
Default Re: UDF-How to calculate gradient of a scalar
  #2
Graham Goldin
Guest
 
Posts: n/a
Fluent will store the gradient of all User Defined Scalars. So, enable a scalar in the Define -> Models -> User Defined Scalars panel, and turn off it's solution in the Solve -> Controls panel. Then, in your UDF, copy the scalar that you want (say temperature) into the User Defined Scalar ( C_UDSI(c,t,0) ), and you can use it's gradient ( C_UDSI(c,t,0)[i], where i=0,1 and 2 in 3D).
  Reply With Quote

Old   February 22, 2000, 16:24
Default Re: UDF-How to calculate gradient of a scalar
  #3
Ilkay Sensoy
Guest
 
Posts: n/a
Hi Everbody I would like to thank Graham very much for his reply. On the other hand, I will need more help on this. I am trying to get the gradient of a scalar that I get by using UDS in Fluent. That is, I want to use the gradient of C_UDSI(c,t,0) in my UDF code. Is C_UDSI_G(c,t,0) will give me the gradient of C_UDSI(c,t,0)?

If that is correct why in my UDF the gradient returns no value?

Thanking you in advance Regards

Светлана likes this.
  Reply With Quote

Old   February 22, 2000, 19:09
Default Re: UDF-How to calculate gradient of a scalar
  #4
Ilkay Sensoy
Guest
 
Posts: n/a
Hi Everybody, I post a message concerning the calculation of a gradient of a scalar. I would like to share more information on that. There is a sample program in Fluent files. It calculates the magnitude of the gradient of T^4.I have tried to compile that code. But,the code did not generate an executable file. So there is something missing. I think I need to do something in fluent to make that code to work but I do not know what. I will aprciate your help Thanking you in advance Ilkay
Светлана likes this.
  Reply With Quote

Old   February 24, 2000, 01:51
Default Re: UDF-How to calculate gradient of a scalar
  #5
Greg Perkins
Guest
 
Posts: n/a
Graham,

Thanks for your suggestions.

Is it necessary to copy the scalar to a UDS as you suggest in order to determine the gradient??

For example, for temperature can one access the gradient through the macro:

C_T_G(cell,thread)[x], where x = 0, 1, 2 for the spatial direction

I notice that in mem.h, C_DUDX (which calculates the gradient of the velocity component U in the x-direction) and others are actually defined as:-

C_U_G(cell,thread)[0] etc.

Also, how do you determine the temporal gradient of a scalar in transient calculations? In particular if I have a UDS how do I get access to the transient term, to add as a source term to one of the other transport equations???

Thanks

Regards

Greg Perkins
Светлана likes this.
  Reply With Quote

Old   July 7, 2013, 06:42
Default UDF- How to retrieve WSS from Fluent and calculate temporal and spatial gradients?
  #6
New Member
 
Nina Philipova
Join Date: Jul 2012
Posts: 11
Rep Power: 13
n.phililipova is on a distinguished road
How to retrieve WSS from Fluent and calculate temporal and spatial gradients in UDF?
Светлана likes this.
n.phililipova is offline   Reply With Quote

Old   July 14, 2013, 05:03
Default
  #7
New Member
 
Join Date: Jun 2013
Posts: 18
Rep Power: 12
wond is on a distinguished road
Hi,Greg Perkins,

Implemented of the source term is a way, but there may be a convergence problem.

I'm not sure if i understand U, but, in my opinion,the DEFINE_UDS_UNSTEADY udf is a good reference.

Wond
Светлана likes this.
wond is offline   Reply With Quote

Old   July 16, 2013, 12:37
Default How to calculate UDS gradient
  #8
New Member
 
Bill Wangard
Join Date: Jan 2011
Posts: 21
Rep Power: 0
billwangard is on a distinguished road
The following code should poplulate the UDS gradient variable:

Code:
#include "udf.h"
#include "sg.h"

DEFINE_ADJUST(adjust,d)
{
   int n;
   for(n=0; n<n_uds; ++n) uds_derivatives(d, n);

   /* The UDS gradients are now available */
   
   
}

void uds_derivatives(Domain *d, int n)
{
   /* Code to compute derivative of a variable.  Variable storage allocation first.... */
        MD_Alloc_Storage_Vars(d, SV_UDSI_RG(n), SV_UDSI_G(n), SV_NULL);
        Scalar_Reconstruction(d, SV_UDS_I(n), -1, SV_UDSI_RG(n), NULL);
        Scalar_Derivatives(d, SV_UDS_I(n), -1, SV_UDSI_G(n), SV_UDSI_RG(n), NULL);
        return;
}


Then, in your UDF, you can access the gradient with C_UDSI_G(c,t). Remember, this is a vector quantity.
billwangard is offline   Reply With Quote

Old   July 17, 2013, 01:16
Default
  #9
New Member
 
Join Date: Jun 2013
Posts: 18
Rep Power: 12
wond is on a distinguished road
Quote:
Originally Posted by billwangard View Post
The following code should poplulate the UDS gradient variable:

Code:
#include "udf.h"
#include "sg.h"

DEFINE_ADJUST(adjust,d)
{
   int n;
   for(n=0; n<n_uds; ++n) uds_derivatives(d, n);

   /* The UDS gradients are now available */
   
   
}

void uds_derivatives(Domain *d, int n)
{
   /* Code to compute derivative of a variable.  Variable storage allocation first.... */
        MD_Alloc_Storage_Vars(d, SV_UDSI_RG(n), SV_UDSI_G(n), SV_NULL);
        Scalar_Reconstruction(d, SV_UDS_I(n), -1, SV_UDSI_RG(n), NULL);
        Scalar_Derivatives(d, SV_UDS_I(n), -1, SV_UDSI_G(n), SV_UDSI_RG(n), NULL);
        return;
}


Then, in your UDF, you can access the gradient with C_UDSI_G(c,t). Remember, this is a vector quantity.
Hi, Bill,

As we know, The ANSYS FLUENT (V.13 or higher) have the couple level-set option. Do you have any idea to export the level-set function by udf?

Thanks a lot!

Wond
Светлана likes this.
wond is offline   Reply With Quote

Old   July 17, 2013, 04:03
Default UDS Gradient variable
  #10
New Member
 
Nina Philipova
Join Date: Jul 2012
Posts: 11
Rep Power: 13
n.phililipova is on a distinguished road
A would like to thank you so much to Bill Wangard for his immediate reply and for his help!
Wish you great further successes!
Nina Philipova
Светлана likes this.
n.phililipova is offline   Reply With Quote

Old   July 17, 2013, 18:50
Default
  #11
New Member
 
Bill Wangard
Join Date: Jan 2011
Posts: 21
Rep Power: 0
billwangard is on a distinguished road
Regarding coupled level-sets, I don't have any information for you. Sorry.
Светлана likes this.
billwangard is offline   Reply With Quote

Old   July 20, 2013, 08:00
Default Calculating WSS components and their derivatives
  #12
New Member
 
Nina Philipova
Join Date: Jul 2012
Posts: 11
Rep Power: 13
n.phililipova is on a distinguished road
I found a code, that calculate WSS as a magnitude of viscous fources vector. Area vector is given also as a magnitude of a vector.
I need to calculate components of WSS and their gradients, I don't need a magnitude of vector.
Can someone help with advise, please!



#include "udf.h"
DEFINE_ON_DEMAND(wall_shear_calc)
{
Domain *d;
real wall_shear_force, area;
face_t f;
real A[ND_ND];
cell_t c, c0;
Thread *t,*t0, *c_thread;
int Zone_ID=6; /* Zone ID of the wall on which shear stress has to be calculated */
/* It can be obtained from the boundary condition panel.*/
d=Get_Domain(1);
/* Initialize the UDM value to zero in complete domain */
thread_loop_c(c_thread,d)
{
begin_c_loop(c, c_thread)
{
C_UDMI(c,c_thread,0)= 0;
}
end_c_loop(c, c_thread)
}
/* Calculate wall shear stress and store them in UDM */
t=Lookup_Thread(d,Zone_ID);
begin_f_loop(f, t)
{
F_AREA(A,f,t);
area = NV_MAG(A);
wall_shear_force = NV_MAG(F_STORAGE_R_N3V(f,t, SV_WALL_SHEAR));
c0 = F_C0(f,t);
t0 = THREAD_T0(t);
C_UDMI(c0,t0,0)= wall_shear_force/area;
}
end_f_loop(f, t)
}
/* *********************************************** */
weilin and Светлана like this.
n.phililipova is offline   Reply With Quote

Old   July 22, 2013, 03:28
Default How to Calculate WSS Spatial and Temporal Gradients
  #13
New Member
 
Nina Philipova
Join Date: Jul 2012
Posts: 11
Rep Power: 13
n.phililipova is on a distinguished road
Please, exuse my misunderstanding!
If I correctly understood, I must retrieve calculated by Fluent Wall Shear Stress not to caculated them again. I am not sure that the available gradients and the stored variable are exactly WSS In code of Bill Wangard. Excuse me for that. I have just a small atempt in UDF. How can I assign exactly x-, y-, z-derivatives of WSS components and to calculate WSS temporal or spatial gradient.
Светлана likes this.

Last edited by n.phililipova; July 23, 2013 at 07:26.
n.phililipova is offline   Reply With Quote

Old   July 16, 2014, 15:19
Smile
  #14
Azy
New Member
 
Azadeh Saeedi
Join Date: Mar 2014
Location: Canada
Posts: 23
Rep Power: 12
Azy is on a distinguished road
does anybody here know that how to calculate velocity gradient over tracked particles?
Светлана likes this.
Azy is offline   Reply With Quote

Old   July 18, 2014, 18:56
Default
  #15
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Quote:
Originally Posted by Azy View Post
does anybody here know that how to calculate velocity gradient over tracked particles?
Hi,

Isn't it possible to identify the cell at which particle is present at a specific moment?! If yes, I think it would be a good approximation to use velocity gradient of the cell instead of the particle.

Bests.
Светлана likes this.
syavash is offline   Reply With Quote

Old   July 18, 2014, 20:34
Default
  #16
Azy
New Member
 
Azadeh Saeedi
Join Date: Mar 2014
Location: Canada
Posts: 23
Rep Power: 12
Azy is on a distinguished road
Quote:
Originally Posted by syavash View Post
Hi,

Isn't it possible to identify the cell at which particle is present at a specific moment?! If yes, I think it would be a good approximation to use velocity gradient of the cell instead of the particle.

Bests.
your suggestion is really wise, I have to think about it, and also try it.

Thanks alot
Светлана likes this.
Azy is offline   Reply With Quote

Old   February 9, 2015, 01:12
Default UDS gradient
  #17
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 16
mvee is on a distinguished road
Hi Bill

I found your code of gradient is not working.
Have you checked at your end?
Can you please tell me the procedure?

Thank you
Светлана likes this.
mvee is offline   Reply With Quote

Old   September 21, 2015, 09:13
Default
  #18
Member
 
Join Date: Nov 2014
Posts: 42
Rep Power: 11
Maryam-A is on a distinguished road
Thanks for all posts.
Светлана likes this.

Last edited by Maryam-A; September 22, 2015 at 03:16.
Maryam-A is offline   Reply With Quote

Old   October 6, 2020, 04:43
Default
  #19
New Member
 
Join Date: May 2018
Posts: 2
Rep Power: 0
a_dejong is on a distinguished road
Hi mvee

With Bill's code my gradients were all 0. I found that using Alloc_Storage_Vars instead of Md_Alloc made it work.
a_dejong is offline   Reply With Quote

Old   November 20, 2023, 08:13
Default
  #20
New Member
 
anonymous96
Join Date: Nov 2022
Posts: 17
Rep Power: 3
anonymous96_ is on a distinguished road
Hi
I am also getting my gradients involved term zero and I tried the above code both ways and none is working for me. Can you please help me?
anonymous96_ 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
Wall shear stress gradient udf Andrew FLUENT 3 April 4, 2018 01:36
How to calculate the gradient along the boundaries from a known volScalarFiled? shddx1 OpenFOAM Programming & Development 7 March 16, 2017 10:47
how to calculate scalar data at a particular plane premchand Siemens 4 May 27, 2008 10:32
Calculated gradient boundary condition similar to gammaContactAngle adona058 OpenFOAM Running, Solving & CFD 0 September 26, 2007 15:23
Gradient of Scalar calculation in 3D BFCskew grids james T Phoenics 0 March 28, 2007 07:12


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