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

when to use UDF (UDF v UDS)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 4, 2016, 21:28
Default when to use UDF (UDF v UDS)
  #1
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Hi folks,

I have a question that might be a little general.
When should we use UDM? and why we should use it if we can relate everything to UDS in the code?
What is the advantage of UDM other than postprocessing some desired variables?
alinik is offline   Reply With Quote

Old   November 7, 2016, 17:22
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
User-defined functions (UDF) are functions that can be loaded with the Fluent solver to customise or add features to the program; UDF are written in both cases of user-defined memory (UDM) and user-defined scalars (UDS).

UDM allocates an extra space in memory (real data type) for each cell and face (or alternatively nodes). UDM could be used to store time-averaged temperature or mass fluxes on boundaries which could be used to alter boundary conditions mid-simulation (or ignored; and used exclusively for postproccessing).

UDS are for adding another transport equation to your model. For example, instead of using the energy equation for tracking the temperature field, you could use a UDS. Likewise a reacting species could interact with the default transport equations via their source terms.
`e` is offline   Reply With Quote

Old   November 7, 2016, 17:39
Default
  #3
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Thanks for the reply.
I have written a UDF code for two transport equations(basically I would like to recreate the SST turbulence model). The code is compiled successfully but upon starting the simulation it says that there is a segmentation violation error and for that reason solver crashes. I did a little bit of research and found that it could be attributed to some variables or parameters whose value is not stored and some people suggested that I better use UDM but honestly I do not know what should I do and that is why I asked this question in the first place.

Shall I store the value of the transported quantities in a UDM? or it is automatically stored since I have defined UDS? and if yes then what could be the reason I get that error?

I would be happy to post my code here for you to take a brief look at it in case you have time?

Thank you so much again.

Ali
alinik is offline   Reply With Quote

Old   November 7, 2016, 18:17
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The values should be available from the UDS with the F_UDSI macro. Sure, post your code and we'll take a look.
`e` is offline   Reply With Quote

Old   November 7, 2016, 18:38
Default
  #5
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Thanks.
The UDF is attached here. I would really appreciate it if you can take a look at it.
I have used C_UDSI since I assumed they would be cell values not face values.
There are somethings that I wanted to share with you about the UDF.
I have used DEFINE_ADJUST for modifying the laminar viscosity and the effect of eddy viscosity is added to laminar viscosity in this section of the code. I did it this way since C_MU_T apparently is not a write-in parameter but I can adjust C_MU_L anytime. Also since I will uncheck turbulence in flow solution controls>equations>turbulence, I figured even if I use DEFINE_TURBULENT_VISCOSITY the solver would not find the viscosity through this. So the 0.001003 value that you see in DEFINE_ADJUST is the laminar viscosity of the fluid.

The UDF file is attached. Please find the attachment.
Thanks again for you help in advance.

Ali
Attached Files
File Type: c sst.c (3.6 KB, 89 views)
alinik is offline   Reply With Quote

Old   November 7, 2016, 19:10
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Use trailing periods on integers to avoid erroneous type casts:

Code:
#define ALPHA1 5./9.
#define ALPHA2 0.44
#define BETA1 3./40.
#define BETA2 0.0828
Another good coding practice is to declare all your functions at the top of the script with function prototypes (otherwise the order of functions become important for dependents etc). For example, if the function mu was called before its declaration, the program wouldn't know its arguments and return types.

The code generally looks good and no obvious errors, are you sure you've allocated two UDS in Fluent? Otherwise, try finding the location of the error by eliminating lines of code and/or using Message() to print to the screen every few lines to determine how far Fluent has reached through your code.
`e` is offline   Reply With Quote

Old   November 7, 2016, 21:35
Default
  #7
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Thanks.
I tried adding periods. It did not solve the issue.
alinik is offline   Reply With Quote

Old   November 8, 2016, 01:46
Default
  #8
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Adding periods for the real data types would only help evaluating the fractions correctly (5/9 = 0.555... instead of truncating to zero). Have you tried my other suggestions?
`e` is offline   Reply With Quote

Old   November 8, 2016, 12:47
Default
  #9
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
I am trying to put messages in between the lines but it gives me this message

error: conflicting types for CX_Message

my command for inputting message is:

Message("1");

Is this wrong?
alinik is offline   Reply With Quote

Old   November 8, 2016, 13:37
Default
  #10
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
One question, If the first Macro I use is DEFINE_SOURCE and in that I am using a value stored in a UDM, shall I bring the DEFINE_ADJUST macro before source macro?(the parameter value is assigned to UDM in the DEFINE_ADJUST macro)

Thanks,

Ali
alinik is offline   Reply With Quote

Old   November 9, 2016, 04:26
Default
  #11
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by alinik View Post
I am trying to put messages in between the lines but it gives me this message

error: conflicting types for CX_Message

my command for inputting message is:

Message("1");

Is this wrong?
Should work fine, try using it within its own DEFINE_ON_DEMAND macro to double check. Also use \n for line break at the end (but shouldn't be causing that error).

Quote:
Originally Posted by alinik View Post
One question, If the first Macro I use is DEFINE_SOURCE and in that I am using a value stored in a UDM, shall I bring the DEFINE_ADJUST macro before source macro?(the parameter value is assigned to UDM in the DEFINE_ADJUST macro)
The order of the Fluent macros in your UDF is not important, Fluent calls these functions at particular hooks in the solver. DEFINE_ADJUST is called at the beginning of each iteration whereas DEFINE_SOURCE is called for the transport equations.
`e` is offline   Reply With Quote

Old   December 9, 2016, 17:36
Default segmentation fault error from thread_loop_c (t,domain)
  #12
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Hi again,

apparently this line is creating the problem:

thread_loop_c (t,domain)

I get segmentation fault error from this line. Any idea?

Thanks,
Ali
alinik is offline   Reply With Quote

Old   December 9, 2016, 20:23
Default
  #13
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Duplicate post, responses are at: Error: received a fatal signal (Segmentation fault). Error Object: #f
`e` 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
UDS or UDF for modify shear stress equations..? aeroprince1986 Fluent UDF and Scheme Programming 0 April 14, 2015 05:16
UDF diffusivity (strain rate)-UDS Lilly Fluent UDF and Scheme Programming 0 September 6, 2013 03:47
UDS & UDF geg FLUENT 0 May 25, 2006 13:06
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01
UDF: different diffusivities for different uds Elmar Riesmeier FLUENT 1 May 6, 2001 20:53


All times are GMT -4. The time now is 19:10.