# UDF-How to calculate gradient of a scalar

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

 February 18, 2000, 13:33 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 Светлана and adarshvasa like this.

 February 20, 2000, 15:44 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). camilo_costa, Светлана, Hesam_Ami and 1 others like this.

 February 22, 2000, 16:24 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.

 February 22, 2000, 19:09 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.

 July 7, 2013, 06:42 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: 11 How to retrieve WSS from Fluent and calculate temporal and spatial gradients in UDF? Светлана likes this.

 July 14, 2013, 05:03 #7 New Member   Join Date: Jun 2013 Posts: 18 Rep Power: 10 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.

 July 16, 2013, 12:37 How to calculate UDS gradient #8 New Member   Bill Wangard Join Date: Jan 2011 Posts: 21 Rep Power: 0 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

July 17, 2013, 01:16
#9
New Member

Join Date: Jun 2013
Posts: 18
Rep Power: 10
Quote:
 Originally Posted by billwangard 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
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

 July 17, 2013, 04:03 UDS Gradient variable #10 New Member   Nina Philipova Join Date: Jul 2012 Posts: 11 Rep Power: 11 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.

 July 17, 2013, 18:50 #11 New Member   Bill Wangard Join Date: Jan 2011 Posts: 21 Rep Power: 0 Regarding coupled level-sets, I don't have any information for you. Sorry. Светлана likes this.

 July 22, 2013, 03:28 How to Calculate WSS Spatial and Temporal Gradients #13 New Member   Nina Philipova Join Date: Jul 2012 Posts: 11 Rep Power: 11 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.

 July 16, 2014, 15:19 #14 New Member   Azadeh Saeedi Join Date: Mar 2014 Location: Canada Posts: 23 Rep Power: 9 does anybody here know that how to calculate velocity gradient over tracked particles? Светлана likes this.

July 18, 2014, 18:56
#15
Senior Member

Ehsan Asgari
Join Date: Apr 2010
Posts: 471
Rep Power: 15
Quote:
 Originally Posted by Azy 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.

July 18, 2014, 20:34
#16
New Member

Join Date: Mar 2014
Posts: 23
Rep Power: 9
Quote:
 Originally Posted by syavash 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

 February 9, 2015, 01:12 UDS gradient #17 Senior Member   Vaze Join Date: Jun 2009 Posts: 171 Rep Power: 14 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.

 September 21, 2015, 09:13 #18 Member   Join Date: Nov 2014 Posts: 42 Rep Power: 8 Thanks for all posts. Светлана likes this. Last edited by Maryam-A; September 22, 2015 at 03:16.

 October 6, 2020, 04:43 #19 New Member   Join Date: May 2018 Posts: 2 Rep Power: 0 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.