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:
- 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)
- 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.
- 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.
- 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))
- Click the “Define” button to link the WB parameter to the UDF accessable scheme parameter.
- 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:
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.
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:
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.