Home / Featured / How can I drive Fluent UDF Parameters directly from ANSYS Workbench?

How can I drive Fluent UDF Parameters directly from ANSYS Workbench?

Our support team is tasked with helping our customers to extract maximum value from their CFD simulations, and we are always striving to help customers who work at the bleeding edge of CFD.  A common question is: How can I drive Fluent UDF parameters directly from ANSYS Workbench?

The ANSYS Fluent User Defined Function (UDF) framework gives Fluent users an almost unlimited ability to modify the physics solved in their simulation model. Customisation can extend from simple properties such as boundary condition profiles, through to complex particle-fluid interaction laws. The ANSYS Workbench interface provides the infrastructure to specify parameters that can be used to drive any simulation inputs (such as geometric dimensions or boundary condition values). By coupling the functionality of Workbench Parameters with Fluent UDF's, we can realize the ability to perform parametric studies on any parameter imaginable. The process for coupling Workbench Parameters into Fluent UDF's is as follows:

  1. In an open Fluent Window; first initialise the scheme variables in Fluent. In the TUI, type the following line:
    (rp-var-define ‘leap 0.0 ‘real #f)
  2. Repeat the above line of code for every variable needed by replacing “leap” with a representative variable name. This name will be used to call the variable in the UDF.
  3. In the Fluent window, go to "Define">"Parameters". In the displayed window, go to "More" > "Use In Scheme Procedure". Click the "Select" button next to the Input Parameter box at the top and click “New Parameter” to create a new parameter. Name the parameter with a representative name. This will be the name of the parameter referenced in Workbench.
  4. Click OK on the two windows until you get back to the “Use Input Parameter in Scheme Procedure” window. In the Scheme Procedure box, type the following Scheme code:
    (lambda (param) (rpsetvar ‘leap param))
  5. Click the “Define” button to link the WB parameter to the UDF accessable scheme parameter.
  6. Do the same for any subsequent parameters, choosing unique and representative names for each.

The parameters are now setup. To access the value in the UDF, use the following function in the source code:

RP_Get_Real("leap")

Where the argument in the Scheme name of the variable as defined in the rpsetvar command.

Now that the associations are properly setup, you can change the value of the parameter in Workbench, causing Fluent to notify that there has been an upstream change. When you click OK, the parameter value will be pushed through to the Scheme variable. After the Scheme variable has been updated, any UDFs will have access to the new value when the RP_Get_Real("leap") function is called.

NOTE: For best performance, assign the value returned from the RP_Get_Real function to a local variable if using in loops, e.g.
real leap_param = RP_Get_Real("leap")
Therefore the value is saved in a local variable and the program will not have to query the Scheme interpretor at each iteration  of the loop.

It is also a best practise to catch errors by checking that the Scheme variable exists from the UDF program and returning a warning if the Scheme variable is absent. The function for checking existence of variables is:
RP_Variable_Exists_P("leap")

This functionality closely coupling Fluent into the Workbench will open the door to all types of parametric studies (such as simple "What if?" studies) through to more detailed optimisation techniques (incorporating Response Surfaces and Design of Experiments) that can be performed using DesignXplorer in your ANSYS Workbench project.

4 comments

  • Thanks!
    I was wondering, if you can assign a parameter without defining it using Scheme, and still use it in UDF? Here, the option “Use Input Parameter in Scheme Procedure” was used. What about “Use Input Parameter in UDF” option? Any thoughts?

  • Hi, I am running blood flow transient simulation using Fluent 16.0. I wish to know whether I can drive Fluent UDF Parameters directly from ANSYS Workbench to set up pulsatile parabolic velocity profile for my inlet boundary condition.

    Albert

    • Hi Albert, to apply your boundary condition, you will need to write a UDF in C to be interpreted or compiled within Fluent. There are several macros already written to aid this procedure though, including DEFINE_PROFILE. Further details can be found in the Fluent Customization Manual.

Leave a Reply

Your email address will not be published. Required fields are marked *