This section contains methods for hooking general purpose UDFs
to Ansys Fluent. General purpose UDFs are those that have been defined
using macros described in General Purpose DEFINE
Macros and then interpreted or compiled and loaded using methods described
in Interpreting UDFs or Compiling UDFs, respectively.
For more information, see the following sections:
- 6.1.1. Hooking DEFINE_ADJUST UDFs
- 6.1.2. Hooking DEFINE_DELTAT UDFs
- 6.1.3. Hooking DEFINE_EXECUTE_AT_END UDFs
- 6.1.4. Hooking DEFINE_EXECUTE_AT_EXIT UDFs
- 6.1.5. Hooking DEFINE_INIT UDFs
- 6.1.6. Hooking DEFINE_ON_DEMAND UDFs
- 6.1.7. Hooking DEFINE_RW_FILE and DEFINE_RW_HDF_FILE UDFs
- 6.1.8. User-Defined Memory Storage
After you interpreted (Interpreting UDFs) or compiled (Compiling UDFs) your DEFINE_ADJUST
UDF, the name of the function you supplied as a DEFINE
macro argument can be hooked using the User-Defined Function
Hooks dialog box (Figure 6.1: The User-Defined Function Hooks Dialog Box). Note that you can hook multiple adjust UDFs to your model, if
desired.
To hook the UDF to Ansys Fluent, open the User-Defined Function Hooks dialog box (Figure 6.1: The User-Defined Function Hooks Dialog Box).
Parameters & Customization → User Defined Functions Function Hooks...
Click the Edit... button next to Adjust to open the Adjust Functions dialog box (Figure 6.2: The Adjust Functions Dialog Box).
Select the function(s) you want to hook to your model from the Available Adjust Functions list. Click Add and then to close the dialog box. The name of the function you selected will be displayed in the Adjust field of the User-Defined Function Hooks dialog box. If you select more than one function, the number will be displayed (for example, 2 selected). Click in the User-Defined Function Hooks dialog box to apply the settings.
See
DEFINE_ADJUST
for details
about defining adjust functions using the DEFINE_ADJUST
macro.
After you have interpreted (Interpreting UDFs) or compiled (Compiling UDFs) your DEFINE_DELTAT
UDF,
the name of the function you supplied as a DEFINE
macro argument
will become visible and selectable in the Run Calculation task page in
Ansys Fluent.
To hook the UDF to Ansys Fluent, right-click the General branch of the tree and select Transient from the Analysis Type sub-menu.
Setup → General Analysis Type → Transient
Then open the Run Calculation task page.
Solution → Run Calculation
Select User-Defined Function from the Type drop-down list, and then select the function name (for example, mydeltat::libudf) from the User-Defined Time Step Size drop-down list.
See
DEFINE_DELTAT
for details about defining
DEFINE_DELTAT
functions.
After you have interpreted (Interpreting UDFs) or compiled (Compiling UDFs) your DEFINE_EXECUTE_AT_END
UDF, it is ready to be hooked to Ansys Fluent. Note that you can hook
multiple at-end UDFs to your model, if desired.
To hook the UDF to Ansys Fluent, open the User-Defined Function Hooks dialog box (Figure 6.3: The User-Defined Function Hooks Dialog Box).
Parameters & Customization → User Defined Functions Function Hooks...
Click the Edit... button next to Execute At End to open the Execute At End Functions dialog box (Figure 6.4: The Execute At End Functions Dialog Box).
Select the function(s) you want to hook to your model from the Available Execute at End Functions list. Click Add and then to close the dialog box. The name of the function you selected will be displayed in the Execute at End field of the User-Defined Function Hooks dialog box. If you select more than one function, the number will be displayed (for example, 2 selected). Click in the User-Defined Function Hooks dialog box to apply the settings.
See
DEFINE_EXECUTE_AT_END
for
details about defining DEFINE_EXECUTE_AT_END
functions.
After you have interpreted (Interpreting UDFs) or compiled (Compiling UDFs) your DEFINE_EXECUTE_AT_EXIT
UDF, it is ready to be hooked to Ansys Fluent. Note that you can hook
multiple at-exit UDFs to your model, if desired.
To hook the UDF to Ansys Fluent, open the User-Defined Function Hooks dialog box (Figure 6.5: The User-Defined Function Hooks Dialog Box).
Parameters & Customization → User Defined Functions Function Hooks...
Click the Edit... button next to Execute at Exit to open the Execute at Exit Functions dialog box (Figure 6.6: The Execute at Exit Functions Dialog Box).
Select the function(s) you want to hook to your model from the Available Execute at Exit Functions list. Click Add and then to close the dialog box. The name of the function you selected will be displayed in the Execute at Exit field of the User-Defined Function Hooks dialog box. If you select more than one function, the number will be displayed (for example, 2 selected). Click in the User-Defined Function Hooks dialog box to apply the settings.
See
DEFINE_EXECUTE_AT_EXIT
for
details about defining DEFINE_EXECUTE_AT_EXIT
functions.
After you have interpreted (Interpreting UDFs) or compiled (Compiling UDFs) your DEFINE_INIT
UDF, it is ready to be hooked to Ansys Fluent. Note that you can hook
multiple initialization UDFs to your model, if desired.
To hook the UDF to Ansys Fluent, open the User-Defined Function Hooks dialog box (Figure 6.7: The User-Defined Function Hooks Dialog Box).
Parameters & Customization → User Defined Functions Function Hooks...
Click the Edit... button next to Initialization to open the Initialization Functions dialog box (Figure 6.8: The Initialization Functions Dialog Box).
Select the function(s) you want to hook to your model from the Available Initialization Functions list. Click Add and then to close the dialog box. The name of the function you selected will be displayed in the Initialization field of the User-Defined Function Hooks dialog box. If you select more than one function, the number will be displayed (for example, 2 selected). Click in the User-Defined Function Hooks dialog box to apply the settings.
See
DEFINE_INIT
for details about
defining DEFINE_INIT
functions.
After you have interpreted (Interpreting UDFs) or compiled (Compiling UDFs) your DEFINE_ON_DEMAND
UDF, the name of the function you supplied as a DEFINE
macro argument will become visible and selectable in the Execute On Demand dialog box (Figure 6.9: The Execute On Demand Dialog Box) in Ansys Fluent.
To hook the UDF to Ansys Fluent, open the Execute On Demand dialog box.
Parameters & Customization → User Defined Functions Execute on Demand...
Select the function name (for example, on_demand_calc::libudf) in the Execute On Demand drop-down list and click Execute. Ansys Fluent will execute the UDF immediately. Click Close to close the dialog box.
See
DEFINE_ON_DEMAND
for details
about defining DEFINE_ON_DEMAND
functions.
After you have interpreted (Interpreting UDFs) or compiled
(Compiling UDFs) your DEFINE_RW_FILE
or DEFINE_RW_HDF_FILE
UDF, it is ready to be hooked to Ansys Fluent.
Note that you can hook multiple read/write file UDFs to your model, if desired.
To hook the UDF to Ansys Fluent, open the User-Defined Function Hooks dialog box (Figure 6.10: The User-Defined Function Hooks Dialog Box).
Parameters & Customization → User Defined Functions Function Hooks...
You have the choice of hooking a UDF to read and write a case and data file. Below is a description of what each function does.
Read Legacy Case is called when you read a legacy case file into Ansys Fluent. It will specify the customized section that is to be read from the case file.
Read Case is called when you read a CFF case file into Ansys Fluent. It will specify the customized section that is to be read from the case file.
Write Legacy Case is called when you write a legacy case file from Ansys Fluent. It will specify the customized section that is to be written to the case file.
Write Case is called when you write a CFF case file from Ansys Fluent. It will specify the customized section that is to be written to the case file.
Read Legacy Data is called when you read a legacy data file into Ansys Fluent. It will specify the customized section that is to be read from the data file.
Read Data is called when you read a CFF data file into Ansys Fluent. It will specify the customized section that is to be read from the data file.
Write Legacy Data is called when you write a legacy data file from Ansys Fluent. It will specify the customized section that is to be written to the data file.
Write Data is called when you write a CFF data file from Ansys Fluent. It will specify the customized section that is to be written to the data file.
To hook a read legacy case file UDF, for example, click the Edit... button next to Read Case to open the Read Legacy Case Functions dialog box (Figure 6.11: The Read Case Functions Dialog Box).
Select the function(s) you want to hook to your model from the Available Read Legacy Case Functions list. Click Add and then to close the dialog box. The name of the function you selected will be displayed in the Read Case field of the User-Defined Function Hooks dialog box. If you select more than one function, the number will be displayed (for example, 2 selected). Click in the User-Defined Function Hooks dialog box to apply the settings.
See
DEFINE_RW_FILE
and
DEFINE_RW_HDF_FILE
for details about defining
DEFINE_RW_FILE
and DEFINE_RW_HDF_FILE
functions.
You can store values computed by your UDF in memory so that they can be retrieved later, either by a UDF or for postprocessing within Ansys Fluent. In order to have access to this memory, you will need to allocate memory by specifying the Number of User-Defined Memory Locations and Number of User-Defined Node Memory Locations in the User-Defined Memory dialog box (Figure 6.12: The User-Defined Memory Dialog Box).
To improve performance, you can limit the user-defined memory (UDM) to specific zones by enabling Zone-Based Memory Allocation, and selecting the desired zones in the Select UDM Zones dialog box (accessed by clicking within the User-Defined Memory dialog box).
Parameters & Customization → User Defined Memory Edit...
The macros C_UDMI
, F_UDMI
, or
N_UDMI
can be used in your UDF to access a particular
user-defined memory location in a cell, face, or node. See Cell Macros and Face Macros for
details.
Field values that have been stored in user-defined memory or user-defined node memory will be saved to the data file. These fields will also appear in the User Defined Memory... category in the drop-down lists in Ansys Fluent’s postprocessing dialog boxes. They will be named User Memory 0, User Memory 1, and so on, and User Node Memory 0, User Node Memory 1, and so on, based on the memory and node memory location index, respectively. The total number of memory locations is limited to 500. For large numbers of user-defined memory locations, system memory requirements will increase.
Important: When writing data files in the legacy format
(.dat
files), you must select the UDM quantities using the
Data File Quantities dialog box in order to postprocess them in
CFD-Post. Alternatively, you have the option of exporting the desired quantities to a
.cdat
file. This will ensure that all the UDM quantities are
available for postprocessing in CFD-Post. Refer to the Ansys CFD-Post manual for more
information.