在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例Windows系统编程 → Fluent udf手册

Fluent udf手册

Windows系统编程

下载此实例
  • 开发语言:C/C++
  • 实例大小:14.15M
  • 下载次数:38
  • 浏览次数:197
  • 发布时间:2021-08-09
  • 实例类别:Windows系统编程
  • 发 布 人:tornadozhangyu
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: Fluent UDF 手册

实例介绍

【实例简介】Fluent udf手册

【实例截图】ANSYS_Fluent_UDF_Manual.pdf

from clipboard

【核心代码】

Table of Contents
Using This Manual ................................................................................................................................... xxxiii
1.The Contents of This Manual .......................................................................................................... xxxiii
2. Typographical Conventions ............................................................................................................ xxxv
3. Mathematical Conventions ........................................................................................................... xxxvii
1. Creating and Using User Defined Functions ........................................................................................... 1
1. Overview of User-Defined Functions (UDFs) .................................................................................... 3
1.1.What is a User-Defined Function? ................................................................................................ 3
1.2. Limitations ................................................................................................................................. 4
1.3. Defining Your UDF Using DEFINE Macros ................................................................................... 5
1.3.1. Including the udf.h Header File in Your Source File ........................................................... 6
1.4. Interpreting and Compiling UDFs ................................................................................................ 7
1.4.1. Compiled UDFs .................................................................................................................. 7
1.4.2. Interpreted UDFs ............................................................................................................... 7
1.4.3. Differences Between Interpreted and Compiled UDFs ......................................................... 8
1.5. Hooking UDFs to Your ANSYS Fluent Model ................................................................................. 9
1.6. Mesh Terminology ...................................................................................................................... 9
1.7. Data Types in ANSYS Fluent ....................................................................................................... 11
1.8. UDF Calling Sequence in the Solution Process ........................................................................... 12
1.8.1. Pressure-Based Segregated Solver .................................................................................... 13
1.8.2. Pressure-Based Coupled Solver ......................................................................................... 14
1.8.3. Density-Based Solver ........................................................................................................ 14
1.9. Special Considerations for Multiphase UDFs .............................................................................. 15
1.9.1. Multiphase-specific Data Types ......................................................................................... 15
2. DEFINE Macros ............................................................................................................................... 19
2.1. Introduction ............................................................................................................................. 19
2.2. General Purpose DEFINE Macros ............................................................................................. 20
2.2.1. DEFINE_ADJUST .......................................................................................................... 21
2.2.1.1. Description ............................................................................................................. 21
2.2.1.2. Usage ...................................................................................................................... 21
2.2.1.3. Example 1 ............................................................................................................... 21
2.2.1.4. Example 2 ............................................................................................................... 22
2.2.1.5. Hooking an Adjust UDF to ANSYS Fluent .................................................................. 23
2.2.2. DEFINE_DELTAT .......................................................................................................... 23
2.2.2.1. Description ............................................................................................................. 23
2.2.2.2. Usage ...................................................................................................................... 23
2.2.2.3. Example .................................................................................................................. 23
2.2.2.4. Hooking an Adaptive Time Step UDF to ANSYS Fluent .............................................. 24
2.2.3. DEFINE_EXECUTE_AT_END ......................................................................................... 24
2.2.3.1. Description ............................................................................................................. 24
2.2.3.2. Usage ...................................................................................................................... 24
2.2.3.3. Example .................................................................................................................. 25
2.2.3.4. Hooking an Execute-at-End UDF to ANSYS Fluent ..................................................... 25
2.2.4.DEFINE_EXECUTE_AT_EXIT ....................................................................................... 25
2.2.4.1. Description ............................................................................................................. 25
2.2.4.2. Usage ...................................................................................................................... 25
2.2.4.3. Hooking an Execute-at-Exit UDF to ANSYS Fluent ..................................................... 26
2.2.5. DEFINE_EXECUTE_FROM_GUI .................................................................................... 26
2.2.5.1. Description ............................................................................................................. 26
2.2.5.2. Usage ...................................................................................................................... 26
iii
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
2.2.5.3. Example .................................................................................................................. 27
2.2.5.4. Hooking an Execute From GUI UDF to ANSYS Fluent ................................................. 27
2.2.6. DEFINE_EXECUTE_ON_LOADING ................................................................................ 28
2.2.6.1. Description ............................................................................................................. 28
2.2.6.2. Usage ...................................................................................................................... 28
2.2.6.3. Example 1 ............................................................................................................... 29
2.2.6.4. Example 2 ............................................................................................................... 29
2.2.6.5. Hooking an Execute On Loading UDF to ANSYS Fluent ............................................. 30
2.2.7. DEFINE_EXECUTE_AFTER_CASE/DATA ..................................................................... 30
2.2.7.1. Description ............................................................................................................. 30
2.2.7.2. Usage ...................................................................................................................... 30
2.2.7.3. Example .................................................................................................................. 31
2.2.7.4. Hooking an Execute After Reading Case and Data File UDF to ANSYS Fluent .............. 31
2.2.8. DEFINE_INIT ............................................................................................................... 31
2.2.8.1. Description ............................................................................................................. 31
2.2.8.2. Usage ...................................................................................................................... 32
2.2.8.3. Example .................................................................................................................. 32
2.2.8.4. Hooking an Initialization UDF to ANSYS Fluent ......................................................... 33
2.2.9. DEFINE_ON_DEMAND .................................................................................................... 33
2.2.9.1. Description ............................................................................................................. 33
2.2.9.2. Usage ...................................................................................................................... 33
2.2.9.3. Example .................................................................................................................. 33
2.2.9.4. Hooking an On-Demand UDF to ANSYS Fluent ......................................................... 35
2.2.10. DEFINE_REPORT_DEFINITION_FN .......................................................................... 35
2.2.10.1. Description ............................................................................................................ 35
2.2.10.2. Usage .................................................................................................................... 35
2.2.10.3. Example ................................................................................................................ 36
2.2.10.4. Hooking a User Defined Report Definition to ANSYS Fluent .................................... 36
2.2.11. DEFINE_RW_FILE ...................................................................................................... 36
2.2.11.1. Description ............................................................................................................ 36
2.2.11.2. Usage .................................................................................................................... 37
2.2.11.3. Example ................................................................................................................ 37
2.2.11.4. Hooking a Read/Write Legacy Case or Data File UDF to ANSYS Fluent ..................... 38
2.2.12. DEFINE_RW_HDF_FILE ............................................................................................. 38
2.2.12.1. Description ............................................................................................................ 38
2.2.12.2. Usage .................................................................................................................... 38
2.2.12.3. Helper Functions ................................................................................................... 39
2.2.12.4. Examples ............................................................................................................... 44
2.2.12.5. Hooking a Read/Write CFF Case or Data File UDF to ANSYS Fluent ........................... 45
2.3. Model-Specific DEFINE Macros ................................................................................................ 45
2.3.1. DEFINE_ANISOTROPIC_CONDUCTIVITY ................................................................... 53
2.3.1.1. Description ............................................................................................................. 53
2.3.1.2. Usage ...................................................................................................................... 53
2.3.1.3. Example .................................................................................................................. 53
2.3.1.4. Hooking an Anisotropic Conductivity UDF to ANSYS Fluent ...................................... 54
2.3.2. DEFINE_CHEM_STEP .................................................................................................... 55
2.3.2.1. Description ............................................................................................................. 55
2.3.2.2. Usage ...................................................................................................................... 55
2.3.2.3. Example .................................................................................................................. 56
2.3.2.4. Hooking a Chemistry Step UDF to ANSYS Fluent ....................................................... 56
2.3.3. DEFINE_CPHI ............................................................................................................... 56
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
iv of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.3.1. Description ............................................................................................................. 56
2.3.3.2. Usage ...................................................................................................................... 56
2.3.3.3. Hooking a Mixing Constant UDF to ANSYS Fluent ..................................................... 57
2.3.4. DEFINE_CURVATURE_CORRECTION_CCURV .............................................................. 57
2.3.4.1. Description ............................................................................................................. 57
2.3.4.2. Usage ...................................................................................................................... 57
2.3.4.3. Example .................................................................................................................. 58
2.3.4.4. Hooking a UDF for Curvature Correction Coefficient to ANSYS Fluent ........................ 58
2.3.5. DEFINE_DIFFUSIVITY ............................................................................................... 58
2.3.5.1. Description ............................................................................................................. 58
2.3.5.2. Usage ...................................................................................................................... 58
2.3.5.3. Example .................................................................................................................. 59
2.3.5.4. Hooking a Diffusivity UDF to ANSYS Fluent .............................................................. 59
2.3.6. DEFINE_DOM_DIFFUSE_REFLECTIVITY ................................................................... 59
2.3.6.1. Description ............................................................................................................. 59
2.3.6.2. Usage ...................................................................................................................... 60
2.3.6.3. Example .................................................................................................................. 60
2.3.6.4. Hooking a Discrete Ordinates Model (DOM) Diffuse Reflectivity UDF to ANSYS Fluent ..................................................................................................................................... 61
2.3.7.DEFINE_DOM_SOURCE .................................................................................................. 61
2.3.7.1. Description ............................................................................................................. 61
2.3.7.2. Usage ...................................................................................................................... 61
2.3.7.3. Example .................................................................................................................. 62
2.3.7.4. Hooking a DOM Source UDF to ANSYS Fluent ........................................................... 62
2.3.8.DEFINE_DOM_SPECULAR_REFLECTIVITY ................................................................. 63
2.3.8.1. Description ............................................................................................................. 63
2.3.8.2. Usage ...................................................................................................................... 63
2.3.8.3. Example .................................................................................................................. 64
2.3.8.4. Hooking a Discrete Ordinates Model (DOM) Specular Reflectivity UDF to ANSYS Fluent ..................................................................................................................................... 64
2.3.9. DEFINE_ECFM_SOURCE ............................................................................................... 64
2.3.9.1. Description ............................................................................................................. 64
2.3.9.2. Usage ...................................................................................................................... 64
2.3.9.3. Example .................................................................................................................. 65
2.3.9.4. Hooking an ECFM Flame Density Area Source UDF to ANSYS Fluent .......................... 66
2.3.10. DEFINE_ECFM_SPARK_SOURCE ................................................................................ 66
2.3.10.1. Description ............................................................................................................ 66
2.3.10.2. Usage .................................................................................................................... 66
2.3.10.3. Example ................................................................................................................ 67
2.3.10.4. Hooking an ECFM Spark Source UDF to ANSYS Fluent ............................................. 67
2.3.11. DEFINE_EC_KINETICS_PARAMETER ....................................................................... 67
2.3.11.1. Description ............................................................................................................ 67
2.3.11.2. Usage .................................................................................................................... 67
2.3.11.3. Example - Electrochemical Reaction Kinetics Parameter Using UDF ......................... 68
2.3.11.4. Hooking an Electrochemical Reaction Kinetics Parameter UDF to ANSYS Fluent ...... 68
2.3.12. DEFINE_EC_RATE ...................................................................................................... 68
2.3.12.1. Description ............................................................................................................ 68
2.3.12.2. Usage .................................................................................................................... 68
2.3.12.3. Example - Electrochemical Reaction Rate Using UDF .............................................. 69
2.3.12.4. Hooking an Electrochemical Reaction Rate UDF to ANSYS Fluent ............................ 70
2.3.13. DEFINE_EDC_MDOT .................................................................................................... 70
v
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.13.1. Description ............................................................................................................ 70
2.3.13.2. Usage .................................................................................................................... 71
2.3.13.3. Example ................................................................................................................ 71
2.3.13.4. Hooking a DEFINE_EDC_MDOT UDF to ANSYS Fluent ........................................... 72
2.3.14. DEFINE_EDC_SCALES ................................................................................................ 72
2.3.14.1. Description ............................................................................................................ 72
2.3.14.2. Usage .................................................................................................................... 72
2.3.14.3. Example ................................................................................................................ 73
2.3.14.4. Hooking a DEFINE_EDC_SCALES UDF to ANSYS Fluent ....................................... 73
2.3.15. DEFINE_EMISSIVITY_WEIGHTING_FACTOR .......................................................... 74
2.3.15.1. Description ............................................................................................................ 74
2.3.15.2. Usage .................................................................................................................... 74
2.3.15.3. Example ................................................................................................................ 74
2.3.15.4. Hooking an Emissivity Weighting Factor UDF to ANSYS Fluent ................................ 75
2.3.16. DEFINE_FLAMELET_PARAMETERS ............................................................................ 75
2.3.16.1. Description ............................................................................................................ 75
2.3.16.2. Usage .................................................................................................................... 75
2.3.16.3. Example ................................................................................................................ 76
2.3.16.4. Hooking a Flamelet Parameters UDF to ANSYS Fluent ............................................. 77
2.3.17. DEFINE_ZONE_MOTION ............................................................................................. 77
2.3.17.1. Description ............................................................................................................ 77
2.3.17.2. Usage .................................................................................................................... 77
2.3.17.3. Example ................................................................................................................ 78
2.3.17.4. Hooking a Frame Motion UDF to ANSYS Fluent ....................................................... 78
2.3.18. DEFINE_GRAY_BAND_ABS_COEFF ............................................................................ 78
2.3.18.1. Description ............................................................................................................ 78
2.3.18.2. Usage .................................................................................................................... 79
2.3.18.3. Example ................................................................................................................ 79
2.3.18.4. Hooking a Gray Band Coefficient UDF to ANSYS Fluent ........................................... 79
2.3.19. DEFINE_HEAT_FLUX .................................................................................................. 80
2.3.19.1. Description ............................................................................................................ 80
2.3.19.2. Usage .................................................................................................................... 80
2.3.19.3. Example ................................................................................................................ 81
2.3.19.4. Hooking a Heat Flux UDF to ANSYS Fluent .............................................................. 81
2.3.20. DEFINE_IGNITE_SOURCE ......................................................................................... 81
2.3.20.1. Description ............................................................................................................ 81
2.3.20.2. Usage .................................................................................................................... 81
2.3.20.3. Example ................................................................................................................ 82
2.3.20.4. Hooking an Ignition Source UDF to ANSYS Fluent ................................................... 83
2.3.21. DEFINE_KW_GEKO Coefficients and Blending Function ................................................... 83
2.3.21.1. Description ............................................................................................................ 83
2.3.21.2. Usage .................................................................................................................... 83
2.3.21.3. Example ................................................................................................................ 84
2.3.21.4. Hooking a UDF for GEKO Coefficients or Blending Function to ANSYS Fluent ........... 84
2.3.22. DEFINE_MASS_TR_PROPERTY .................................................................................. 85
2.3.22.1. Description ............................................................................................................ 85
2.3.22.2. Usage .................................................................................................................... 85
2.3.22.3. Example ................................................................................................................ 86
2.3.22.4. Hooking a DEFINE_MASS_TR_PROPERTY UDF to ANSYS Fluent ......................... 87
2.3.23. DEFINE_NET_REACTION_RATE ................................................................................ 87
2.3.23.1. Description ............................................................................................................ 87
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
vi of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.23.2. Usage .................................................................................................................... 87
2.3.23.3. Example ................................................................................................................ 88
2.3.23.4. Hooking a Net Reaction Rate UDF to ANSYS Fluent ................................................. 89
2.3.24. DEFINE_NOX_RATE .................................................................................................... 89
2.3.24.1. Description ............................................................................................................ 89
2.3.24.2. Usage .................................................................................................................... 89
2.3.24.3. Example 1 ............................................................................................................. 90
2.3.24.4. Example 2 ............................................................................................................. 92
2.3.24.5. Hooking a NOx Rate UDF to ANSYS Fluent .............................................................. 93
2.3.25. DEFINE_PDF_TABLE .................................................................................................. 93
2.3.25.1. Description ............................................................................................................ 93
2.3.25.2. Usage .................................................................................................................... 94
2.3.25.3. Example ................................................................................................................ 97
2.3.25.4. Hooking a DEFINE_PDF_TABLE UDF to ANSYS Fluent .............................................. 98
2.3.26. DEFINE_PR_RATE ...................................................................................................... 98
2.3.26.1. Description ............................................................................................................ 98
2.3.26.2. Usage .................................................................................................................... 99
2.3.26.3. Auxiliary function ................................................................................................ 100
2.3.26.4. Example 1 ............................................................................................................ 100
2.3.26.5. Example 2 ............................................................................................................ 100
2.3.26.6. Hooking a Particle Reaction Rate UDF to ANSYS Fluent ......................................... 102
2.3.27. DEFINE_PRANDTL UDFs ............................................................................................ 102
2.3.27.1. DEFINE_PRANDTL_D ....................................................................................... 102
2.3.27.2. Description .......................................................................................................... 102
2.3.27.3. Usage .................................................................................................................. 102
2.3.27.4. Example .............................................................................................................. 103
2.3.27.5. Hooking a Prandtl Number UDF to ANSYS Fluent .................................................. 103
2.3.27.6. DEFINE_PRANDTL_K ....................................................................................... 103
2.3.27.7. Description .......................................................................................................... 103
2.3.27.8. Usage .................................................................................................................. 103
2.3.27.9. Example .............................................................................................................. 104
2.3.27.10. Hooking a Prandtl Number UDF to ANSYS Fluent ................................................ 105
2.3.27.11. DEFINE_PRANDTL_O ..................................................................................... 105
2.3.27.12. Description ........................................................................................................ 105
2.3.27.13. Usage ................................................................................................................ 105
2.3.27.14. Example ............................................................................................................ 106
2.3.27.15. Hooking a Prandtl Number UDF to ANSYS Fluent ................................................ 106
2.3.27.16. DEFINE_PRANDTL_T ..................................................................................... 106
2.3.27.17. Description ........................................................................................................ 106
2.3.27.18. Usage ................................................................................................................ 106
2.3.27.19. Example ............................................................................................................ 106
2.3.27.20. Hooking a Prandtl Number UDF to ANSYS Fluent ................................................ 107
2.3.27.21. DEFINE_PRANDTL_T_WALL .......................................................................... 107
2.3.27.22. Description ........................................................................................................ 107
2.3.27.23. Usage ................................................................................................................ 107
2.3.27.24. Example ............................................................................................................ 107
2.3.27.25. Hooking a Prandtl Number UDF to ANSYS Fluent ................................................ 108
2.3.28. DEFINE_PROFILE .................................................................................................... 108
2.3.28.1. Description .......................................................................................................... 108
2.3.28.2. Usage .................................................................................................................. 109
2.3.28.3. Example 1 - Pressure Profile .................................................................................. 110
vii
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.28.4. Example 2 - Velocity,Turbulent Kinetic Energy, and Turbulent Dissipation Rate Profiles .................................................................................................................................. 110
2.3.28.5. Example 3 - Fixed Velocity UDF ............................................................................. 113
2.3.28.6. Example 4 - Wall Heat Generation Rate Profile ....................................................... 114
2.3.28.7. Example 5 - Beam Direction Profile at Semi-Transparent Walls ............................... 115
2.3.28.8. Example 6 - Viscous Resistance Profile in a Porous Zone ........................................ 115
2.3.28.9. Example 7 - Porous Resistance Direction Vector .................................................... 116
2.3.28.10. Example 8 -Target Mass Flow Rate UDF as a Function of Physical Flow Time ......... 117
2.3.28.11. Example 9 - Mass Flow Rate UDF for a Mass-Flow Inlet or Mass-Flow Outlet ......... 117
2.3.28.12. Hooking a Boundary Profile UDF to ANSYS Fluent ............................................... 118
2.3.29. DEFINE_PROPERTY UDFs .......................................................................................... 118
2.3.29.1. Description .......................................................................................................... 118
2.3.29.2. Usage .................................................................................................................. 120
2.3.29.3. Auxiliary Utilities .................................................................................................. 120
2.3.29.4. Example 1 - Temperature-dependent Viscosity Property ....................................... 122
2.3.29.5. Example 2 - User-defined Mixing Law for Thermal Conductivity ............................ 123
2.3.29.6. Example 3 - Surface Tension Coefficient UDF ........................................................ 123
2.3.29.7. Example 4 - Density Function for Compressible Liquids ......................................... 123
2.3.29.8. Hooking a Property UDF to ANSYS Fluent ............................................................. 124
2.3.30. DEFINE_REACTING_CHANNEL_BC .......................................................................... 124
2.3.30.1. Description .......................................................................................................... 124
2.3.30.2. Usage .................................................................................................................. 124
2.3.30.3. Example .............................................................................................................. 125
2.3.30.4. Hooking a Reacting Channel Solver UDF to ANSYS Fluent ..................................... 126
2.3.31. DEFINE_REACTING_CHANNEL_SOLVER ................................................................. 127
2.3.31.1. Description .......................................................................................................... 127
2.3.31.2. Usage .................................................................................................................. 127
2.3.31.3. Example .............................................................................................................. 128
2.3.31.4. Hooking a Reacting Channel Solver UDF to ANSYS Fluent ..................................... 130
2.3.32. DEFINE_RELAX_TO_EQUILIBRIUM ........................................................................ 130
2.3.32.1. Description .......................................................................................................... 130
2.3.32.2. Usage .................................................................................................................. 130
2.3.32.3. Example .............................................................................................................. 131
2.3.32.4. Hooking a DEFINE_RELAX_TO_EQUILIBRIUM UDF to ANSYS Fluent ............... 131
2.3.33. DEFINE_SBES_BF .................................................................................................... 131
2.3.33.1. Description .......................................................................................................... 131
2.3.33.2. Usage .................................................................................................................. 131
2.3.33.3. Example .............................................................................................................. 132
2.3.33.4. Hooking an SBES Blending Function UDF to ANSYS Fluent .................................... 132
2.3.34. DEFINE_SCAT_PHASE_FUNC ................................................................................... 132
2.3.34.1. Description .......................................................................................................... 132
2.3.34.2. Usage .................................................................................................................. 132
2.3.34.3. Example .............................................................................................................. 133
2.3.34.4. Hooking a Scattering Phase UDF to ANSYS Fluent ................................................. 134
2.3.35. DEFINE_SOLAR_INTENSITY ................................................................................... 134
2.3.35.1. Description .......................................................................................................... 134
2.3.35.2. Usage .................................................................................................................. 134
2.3.35.3. Example .............................................................................................................. 135
2.3.35.4. Hooking a Solar Intensity UDF to ANSYS Fluent .................................................... 135
2.3.36.DEFINE_SOLIDIFICATION_PARAMS ...................................................................... 135
2.3.36.1. Description .......................................................................................................... 135
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
viii of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.36.2. Usage .................................................................................................................. 135
2.3.36.3. Example .............................................................................................................. 136
2.3.36.4. Hooking a Solidification Parameter UDF in ANSYS Fluent ...................................... 136
2.3.37. DEFINE_SOOT_MASS_RATES ................................................................................... 136
2.3.37.1. Description .......................................................................................................... 136
2.3.37.2. Usage .................................................................................................................. 136
2.3.37.3. Example: Soot Mass Rate ...................................................................................... 137
2.3.37.4. Hooking a Soot Mass Rate UDF to ANSYS Fluent ................................................... 138
2.3.38. DEFINE_SOOT_MOM_RATES ..................................................................................... 139
2.3.38.1. Description .......................................................................................................... 139
2.3.38.2. Usage .................................................................................................................. 139
2.3.38.3. Example: Soot MOM Rates .................................................................................... 140
2.3.38.4. Hooking a Soot MOM Rates UDF to ANSYS Fluent ................................................. 141
2.3.39.DEFINE_SOOT_NUCLEATION_RATES ...................................................................... 141
2.3.39.1. Description .......................................................................................................... 141
2.3.39.2. Usage .................................................................................................................. 141
2.3.39.3. Example: Soot Nucleation and Coagulation Rates ................................................. 142
2.3.39.4. Hooking a Nucleation and Coagulation Rates UDF to ANSYS Fluent ...................... 144
2.3.40. DEFINE_SOOT_OXIDATION_RATE .......................................................................... 144
2.3.40.1. Description .......................................................................................................... 144
2.3.40.2. Usage .................................................................................................................. 144
2.3.40.3. Example: Soot Oxidation Rate ............................................................................... 145
2.3.40.4. Hooking a Soot Oxidation Rate UDF to ANSYS Fluent ............................................ 146
2.3.41. DEFINE_SOOT_PRECURSOR ..................................................................................... 146
2.3.41.1. Description .......................................................................................................... 146
2.3.41.1.1. Usage ......................................................................................................... 146
2.3.41.1.2. Example: Soot Precursor .............................................................................. 146
2.3.41.1.3. Hooking a SOOT_PRECURSOR UDF to ANSYS Fluent ..................................... 147
2.3.42.DEFINE_SOURCE ....................................................................................................... 147
2.3.42.1. Description .......................................................................................................... 147
2.3.42.2. Usage .................................................................................................................. 147
2.3.42.3. Example 1 - Source Term Addition ........................................................................ 148
2.3.42.4. Example 2 - Degassing Boundary Condition ......................................................... 149
2.3.42.5. Hooking a Source UDF to ANSYS Fluent ................................................................ 151
2.3.43. DEFINE_SOX_RATE .................................................................................................. 151
2.3.43.1. Description .......................................................................................................... 151
2.3.43.2. Usage .................................................................................................................. 151
2.3.43.3. Example 1 ............................................................................................................ 152
2.3.43.4. Example 2 ............................................................................................................ 154
2.3.43.5. Hooking a SOx Rate UDF to ANSYS Fluent ............................................................. 155
2.3.44. DEFINE_SPARK_GEOM (R14.5 spark model) .................................................. 156
2.3.44.1. Description .......................................................................................................... 156
2.3.44.2. Usage .................................................................................................................. 156
2.3.44.3. Example .............................................................................................................. 156
2.3.44.4. Hooking a Spark Geometry UDF to ANSYS Fluent ................................................. 158
2.3.45. DEFINE_SPECIFIC_HEAT ....................................................................................... 158
2.3.45.1. Description .......................................................................................................... 158
2.3.45.2. Usage .................................................................................................................. 158
2.3.45.3. Example .............................................................................................................. 159
2.3.45.4. Hooking a Specific Heat UDF to ANSYS Fluent ...................................................... 159
2.3.46. DEFINE_SR_RATE .................................................................................................... 159
ix
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.46.1. Description .......................................................................................................... 159
2.3.46.2. Usage .................................................................................................................. 160
2.3.46.3. Example 1 - Surface Reaction Rate Using Species Mass Fractions ........................... 160
2.3.46.4. Example 2 - Surface Reaction Rate Using Site Species ........................................... 161
2.3.46.5. Hooking a Surface Reaction Rate UDF to ANSYS Fluent ......................................... 162
2.3.47.DEFINE_THICKENED_FLAME_MODEL ...................................................................... 162
2.3.47.1. Description .......................................................................................................... 162
2.3.47.2. Usage .................................................................................................................. 162
2.3.47.3. Example - Thickened Flame Model ....................................................................... 163
2.3.47.4. Hooking a Thickened Flame Model UDF to ANSYS Fluent ...................................... 163
2.3.48. DEFINE_TRANS UDFs ................................................................................................. 163
2.3.48.1.DEFINE_TRANS_FLENGTH ............................................................................... 163
2.3.48.2. Description .......................................................................................................... 163
2.3.48.3. Usage .................................................................................................................. 163
2.3.48.4. Example .............................................................................................................. 164
2.3.48.5. Hooking a Transition Correlation UDF to ANSYS Fluent ......................................... 164
2.3.48.6.DEFINE_TRANS_GEOMRGH ............................................................................... 164
2.3.48.7. Description .......................................................................................................... 164
2.3.48.8. Usage .................................................................................................................. 164
2.3.48.9. Example .............................................................................................................. 165
2.3.48.10. Hooking a Transition Correlation UDF to ANSYS Fluent ....................................... 165
2.3.48.11. DEFINE_TRANS_RETHETA_C ........................................................................ 165
2.3.48.12. Description ........................................................................................................ 165
2.3.48.13. Usage ................................................................................................................ 165
2.3.48.14. Example ............................................................................................................ 165
2.3.48.15. Hooking a Transition Correlation UDF to ANSYS Fluent ....................................... 166
2.3.48.16. DEFINE_TRANS_RETHETA_T ........................................................................ 166
2.3.48.17. Description ........................................................................................................ 166
2.3.48.18. Usage ................................................................................................................ 166
2.3.48.19. Example ............................................................................................................ 166
2.3.48.20. Hooking a Transition Correlation UDF to ANSYS Fluent ....................................... 167
2.3.49. DEFINE_TRANSIENT_PROFILE .............................................................................. 167
2.3.49.1. Description .......................................................................................................... 167
2.3.49.2. Usage .................................................................................................................. 167
2.3.49.3. Example .............................................................................................................. 167
2.3.49.4. Hooking a Transient Profile UDF to ANSYS Fluent .................................................. 168
2.3.50. DEFINE_TURB_PREMIX_SOURCE ............................................................................ 168
2.3.50.1. Description .......................................................................................................... 168
2.3.50.2. Usage .................................................................................................................. 168
2.3.50.3. Example .............................................................................................................. 169
2.3.50.4. Hooking a Turbulent Premixed Source UDF to ANSYS Fluent ................................. 169
2.3.51. DEFINE_TURB_SCHMIDT UDF ................................................................................... 170
2.3.51.1. Description .......................................................................................................... 170
2.3.51.2. Usage .................................................................................................................. 170
2.3.51.3. Example .............................................................................................................. 170
2.3.51.4. Hooking a Turbulent Schmidt Number UDF to ANSYS Fluent ................................ 170
2.3.52. DEFINE_TURBULENT_VISCOSITY .......................................................................... 171
2.3.52.1. Description .......................................................................................................... 171
2.3.52.2. Usage .................................................................................................................. 171
2.3.52.3. Example 1 - Single Phase Turbulent Viscosity UDF ................................................. 171
2.3.52.4. Example 2 - Multiphase Turbulent Viscosity UDF ................................................... 172
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
x of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.3.52.5. Hooking a Turbulent Viscosity UDF to ANSYS Fluent ............................................. 172
2.3.53. DEFINE_VR_RATE .................................................................................................... 173
2.3.53.1. Description .......................................................................................................... 173
2.3.53.2. Usage .................................................................................................................. 173
2.3.53.3. Example 1 ............................................................................................................ 173
2.3.53.4. Example 2 ............................................................................................................ 174
2.3.53.5. Hooking a Volumetric Reaction Rate UDF to ANSYS Fluent .................................... 175
2.3.54. DEFINE_WALL_FUNCTIONS ..................................................................................... 175
2.3.54.1. Description .......................................................................................................... 175
2.3.54.2. Usage .................................................................................................................. 175
2.3.54.3. Example .............................................................................................................. 176
2.3.54.4. Hooking a Wall Function UDF to ANSYS Fluent ..................................................... 176
2.3.55. DEFINE_WALL_NODAL_DISP ................................................................................... 177
2.3.55.1. Description .......................................................................................................... 177
2.3.55.2. Usage .................................................................................................................. 177
2.3.55.3. Example .............................................................................................................. 177
2.3.55.4. Hooking a Wall Nodal Displacement UDF to ANSYS Fluent .................................... 178
2.3.56.DEFINE_WALL_NODAL_FORCE ................................................................................. 178
2.3.56.1. Description .......................................................................................................... 178
2.3.56.2. Usage .................................................................................................................. 178
2.3.56.3. Example .............................................................................................................. 178
2.3.56.4. Hooking a Wall Nodal Force UDF to ANSYS Fluent ................................................. 179
2.3.57. DEFINE_WSGGM_ABS_COEFF ................................................................................... 179
2.3.57.1. Description .......................................................................................................... 179
2.3.57.2. Usage .................................................................................................................. 179
2.3.57.3. Example .............................................................................................................. 180
2.3.57.4. Hooking a Wall Function UDF to ANSYS Fluent ..................................................... 181
2.4. Multiphase DEFINE Macros .................................................................................................... 181
2.4.1. DEFINE_BOILING_PROPERTY .................................................................................. 183
2.4.1.1. Description ............................................................................................................ 183
2.4.1.2. Usage .................................................................................................................... 183
2.4.1.3. Example ................................................................................................................ 184
2.4.1.4. Hooking a Boiling Property UDF to ANSYS Fluent ................................................... 184
2.4.2. DEFINE_CAVITATION_RATE ..................................................................................... 185
2.4.2.1. Description ............................................................................................................ 185
2.4.2.2. Usage .................................................................................................................... 185
2.4.2.3. Example ................................................................................................................ 186
2.4.2.4. Hooking a Cavitation Rate UDF to ANSYS Fluent ..................................................... 186
2.4.3. DEFINE_EXCHANGE_PROPERTY ................................................................................ 187
2.4.3.1. Description ............................................................................................................ 187
2.4.3.2. Usage .................................................................................................................... 188
2.4.3.3. Example 1 - Custom Drag Law ................................................................................ 188
2.4.3.4. Example 2 - Custom Lift Law .................................................................................. 189
2.4.3.5. Example 3- Heat Transfer ........................................................................................ 190
2.4.3.6. Example 4- Custom Interfacial Area ........................................................................ 191
2.4.3.7. Hooking an Exchange Property UDF to ANSYS Fluent ............................................. 191
2.4.4. DEFINE_HET_RXN_RATE ........................................................................................... 191
2.4.4.1. Description ............................................................................................................ 191
2.4.4.2. Usage .................................................................................................................... 192
2.4.4.3. Example ................................................................................................................ 192
2.4.4.4. Hooking a Heterogeneous Reaction Rate UDF to ANSYS Fluent ............................... 194
xi
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.4.5. DEFINE_LINEARIZED_MASS_TRANSFER ................................................................. 194
2.4.5.1. Description ............................................................................................................ 194
2.4.5.2. Usage .................................................................................................................... 195
2.4.5.3. Example ................................................................................................................ 196
2.4.5.4. Hooking a Linearized Mass Transfer UDF to ANSYS Fluent ....................................... 197
2.4.6. DEFINE_MASS_TRANSFER ......................................................................................... 198
2.4.6.1. Description ............................................................................................................ 198
2.4.6.2. Usage .................................................................................................................... 198
2.4.6.3. Example ................................................................................................................ 199
2.4.6.4. Hooking a Mass Transfer UDF to ANSYS Fluent ........................................................ 200
2.4.7. DEFINE_VECTOR_EXCHANGE_PROPERTY ................................................................. 200
2.4.7.1. Description ............................................................................................................ 200
2.4.7.2. Usage .................................................................................................................... 200
2.4.7.3. Example 1 — Custom Slip Velocity ......................................................................... 201
2.4.7.4. Example 2 — Custom Turbulent Dispersion ............................................................ 202
2.4.7.5. Hooking a Vector Exchange Property UDF to ANSYS Fluent ..................................... 202
2.5. Discrete Phase Model (DPM) DEFINE Macros .......................................................................... 202
2.5.1. DEFINE_DPM_BC ........................................................................................................ 204
2.5.1.1. Description ............................................................................................................ 204
2.5.1.2. Usage .................................................................................................................... 204
2.5.1.3. Example 1 ............................................................................................................. 205
2.5.1.4. Example 2 ............................................................................................................. 206
2.5.1.5. Example 3 ............................................................................................................. 209
2.5.1.6. Example 4 ............................................................................................................. 209
2.5.1.7. Hooking a DPM Boundary Condition UDF to ANSYS Fluent ..................................... 210
2.5.2. DEFINE_DPM_BODY_FORCE ....................................................................................... 210
2.5.2.1. Description ............................................................................................................ 210
2.5.2.2. Usage .................................................................................................................... 210
2.5.2.3. Example ................................................................................................................ 211
2.5.2.4. Hooking a DPM Body Force UDF to ANSYS Fluent ................................................... 212
2.5.3. DEFINE_DPM_DRAG .................................................................................................... 212
2.5.3.1. Description ............................................................................................................ 212
2.5.3.2. Usage .................................................................................................................... 212
2.5.3.3. Example ................................................................................................................ 213
2.5.3.4. Hooking a DPM Drag Coefficient UDF to ANSYS Fluent ........................................... 213
2.5.4. DEFINE_DPM_EROSION ............................................................................................. 214
2.5.4.1. Description ............................................................................................................ 214
2.5.4.2. Usage .................................................................................................................... 214
2.5.4.3. Example ................................................................................................................ 215
2.5.4.4. Hooking an Erosion/Accretion UDF to ANSYS Fluent ............................................... 217
2.5.5. DEFINE_DPM_HEAT_MASS ......................................................................................... 218
2.5.5.1. Description ............................................................................................................ 218
2.5.5.2. Usage .................................................................................................................... 218
2.5.5.3. Example ................................................................................................................ 219
2.5.5.4. Hooking a DPM Particle Heat and Mass Transfer UDF to ANSYS Fluent ..................... 220
2.5.6. DEFINE_DPM_INJECTION_INIT .............................................................................. 220
2.5.6.1. Description ............................................................................................................ 220
2.5.6.2. Usage .................................................................................................................... 221
2.5.6.3. Example ................................................................................................................ 221
2.5.6.4. Using DEFINE_DPM_INJECTION_INIT with an unsteady injection file .............. 223
2.5.6.5. Hooking a DPM Initialization UDF to ANSYS Fluent ................................................. 226
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xii of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.5.7. DEFINE_DPM_LAW ...................................................................................................... 226
2.5.7.1. Description ............................................................................................................ 226
2.5.7.2. Usage .................................................................................................................... 226
2.5.7.3. Example ................................................................................................................ 227
2.5.7.4. Hooking a Custom DPM Law to ANSYS Fluent ........................................................ 227
2.5.8. DEFINE_DPM_OUTPUT ................................................................................................ 228
2.5.8.1. Description ............................................................................................................ 228
2.5.8.2. Usage .................................................................................................................... 228
2.5.8.3. Example 1 - Sampling and Removing Particles ........................................................ 229
2.5.8.4. Example 2 - Source Code Template ......................................................................... 230
2.5.8.5. Using DEFINE_DPM_OUTPUT in VOF-to-DPM Simulations .................................... 232
2.5.8.5.1. Example ....................................................................................................... 234
2.5.8.6. Hooking a DPM Output UDF to ANSYS Fluent ......................................................... 237
2.5.9. DEFINE_DPM_PROPERTY ........................................................................................... 237
2.5.9.1. Description ............................................................................................................ 237
2.5.9.2. Usage .................................................................................................................... 238
2.5.9.3. Example ................................................................................................................ 239
2.5.9.4. Hooking a DPM Material Property UDF to ANSYS Fluent ......................................... 241
2.5.10. DEFINE_DPM_SCALAR_UPDATE .............................................................................. 242
2.5.10.1. Description .......................................................................................................... 242
2.5.10.2. Usage .................................................................................................................. 242
2.5.10.3. Example .............................................................................................................. 243
2.5.10.4. Hooking a DPM Scalar Update UDF to ANSYS Fluent ............................................. 244
2.5.11. DEFINE_DPM_SOURCE .............................................................................................. 244
2.5.11.1. Description .......................................................................................................... 244
2.5.11.2. Usage .................................................................................................................. 244
2.5.11.3. Example .............................................................................................................. 245
2.5.11.4. Hooking a DPM Source Term UDF to ANSYS Fluent ............................................... 245
2.5.12. DEFINE_DPM_SPRAY_COLLIDE .............................................................................. 245
2.5.12.1. Description .......................................................................................................... 245
2.5.12.2. Usage .................................................................................................................. 246
2.5.12.3. Example .............................................................................................................. 246
2.5.12.4. Hooking a DPM Spray Collide UDF to ANSYS Fluent .............................................. 247
2.5.13. DEFINE_DPM_SWITCH .............................................................................................. 247
2.5.13.1. Description .......................................................................................................... 247
2.5.13.2. Usage .................................................................................................................. 247
2.5.13.3. Example .............................................................................................................. 248
2.5.13.4. Hooking a DPM Switching UDF to ANSYS Fluent ................................................... 250
2.5.14. DEFINE_DPM_TIMESTEP ......................................................................................... 251
2.5.14.1. Description .......................................................................................................... 251
2.5.14.2. Usage .................................................................................................................. 251
2.5.14.3. Example 1 ............................................................................................................ 251
2.5.14.4. Example 2 ............................................................................................................ 251
2.5.14.5. Hooking a DPM Timestep UDF to ANSYS Fluent .................................................... 252
2.5.15. DEFINE_DPM_VP_EQUILIB ..................................................................................... 252
2.5.15.1. Description .......................................................................................................... 252
2.5.15.2. Usage .................................................................................................................. 252
2.5.15.3. Example .............................................................................................................. 253
2.5.15.4. Hooking a DPM Vapor Equilibrium UDF to ANSYS Fluent ....................................... 254
2.5.16.DEFINE_IMPINGEMENT ............................................................................................ 254
2.5.16.1. Description .......................................................................................................... 254
xiii
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.5.16.2. Usage .................................................................................................................. 254
2.5.16.3. Example .............................................................................................................. 256
2.5.16.4. Hooking an Impingement UDF to ANSYS Fluent ................................................... 257
2.5.17.DEFINE_FILM_REGIME ............................................................................................ 257
2.5.17.1. Description .......................................................................................................... 257
2.5.17.2. Usage .................................................................................................................. 257
2.5.17.3. Example .............................................................................................................. 258
2.5.17.4. Hooking a Film Regime UDF to ANSYS Fluent ....................................................... 259
2.5.18. DEFINE_SPLASHING_DISTRIBUTION ................................................................... 259
2.5.18.1. Description .......................................................................................................... 259
2.5.18.2. Usage .................................................................................................................. 259
2.5.18.3. Example .............................................................................................................. 260
2.5.18.4. Hooking a Splashing Distribution UDF to ANSYS Fluent ........................................ 263
2.6. Dynamic Mesh DEFINE Macros .............................................................................................. 263
2.6.1. DEFINE_CG_MOTION .................................................................................................. 264
2.6.1.1. Description ............................................................................................................ 264
2.6.1.2. Usage .................................................................................................................... 264
2.6.1.3. Example ................................................................................................................ 265
2.6.1.4. Hooking a Center of Gravity Motion UDF to ANSYS Fluent ...................................... 266
2.6.2. DEFINE_DYNAMIC_ZONE_PROPERTY ....................................................................... 266
2.6.2.1. Description ............................................................................................................ 266
2.6.2.2. Swirl Center Definition for In-Cylinder Applications ................................................. 266
2.6.2.2.1. Usage ........................................................................................................... 266
2.6.2.2.2. Example ....................................................................................................... 267
2.6.2.2.3. Hooking a Swirl Center UDF to ANSYS Fluent ................................................. 267
2.6.2.3.Variable Cell Layering Height .................................................................................. 268
2.6.2.3.1. Usage ........................................................................................................... 268
2.6.2.3.2. Example ....................................................................................................... 269
2.6.2.3.3. Hooking a Variable Cell Layering Height UDF to ANSYS Fluent ........................ 269
2.6.3. DEFINE_GEOM ............................................................................................................. 270
2.6.3.1. Description ............................................................................................................ 270
2.6.3.2. Usage .................................................................................................................... 270
2.6.3.3. Example ................................................................................................................ 270
2.6.3.4. Hooking a Dynamic Mesh Geometry UDF to ANSYS Fluent ..................................... 270
2.6.4. DEFINE_GRID_MOTION ............................................................................................. 271
2.6.4.1. Description ............................................................................................................ 271
2.6.4.2. Usage .................................................................................................................... 271
2.6.4.3. Example ................................................................................................................ 272
2.6.4.4. Hooking a DEFINE_GRID_MOTION to ANSYS Fluent ............................................ 273
2.6.5. DEFINE_SDOF_PROPERTIES ..................................................................................... 273
2.6.5.1. Description ............................................................................................................ 273
2.6.5.2. Usage .................................................................................................................... 273
2.6.5.3. Custom Transformation Variables ........................................................................... 274
2.6.5.4. Example 1 ............................................................................................................. 275
2.6.5.5. Example 2 ............................................................................................................. 275
2.6.5.6. Example 3 ............................................................................................................. 276
2.6.5.7. Hooking a DEFINE_SDOF_PROPERTIES UDF to ANSYS Fluent ............................ 276
2.6.6. DEFINE_CONTACT ...................................................................................................... 277
2.6.6.1. Description ............................................................................................................ 277
2.6.6.2. Usage .................................................................................................................... 277
2.6.6.3. Example 1 ............................................................................................................. 277
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xiv of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
2.6.6.4. Example 2 ............................................................................................................. 280
2.6.6.5. Hooking a DEFINE_CONTACT UDF to ANSYS Fluent ............................................. 281
2.7. User-Defined Scalar (UDS) Transport Equation DEFINE Macros ............................................... 281
2.7.1. Introduction ................................................................................................................... 282
2.7.1.1. Diffusion Coefficient UDFs ..................................................................................... 282
2.7.1.2. Flux UDFs .............................................................................................................. 282
2.7.1.3. Unsteady UDFs ...................................................................................................... 282
2.7.1.4. Source Term UDFs .................................................................................................. 282
2.7.1.5. Fixed Value Boundary Condition UDFs .................................................................... 283
2.7.1.6.Wall, Inflow, and Outflow Boundary Condition UDFs ............................................... 283
2.7.2. DEFINE_ANISOTROPIC_DIFFUSIVITY ................................................................... 283
2.7.2.1. Description ............................................................................................................ 283
2.7.2.2. Usage .................................................................................................................... 283
2.7.2.3. Example ................................................................................................................ 284
2.7.2.4. Hooking an Anisotropic Diffusivity UDF to ANSYS Fluent ........................................ 285
2.7.3. DEFINE_UDS_FLUX .................................................................................................... 285
2.7.3.1. Description ............................................................................................................ 285
2.7.3.2. Usage .................................................................................................................... 285
2.7.3.3. Example ................................................................................................................ 287
2.7.3.4. Hooking a UDS Flux Function to ANSYS Fluent ....................................................... 288
2.7.4. DEFINE_UDS_UNSTEADY ........................................................................................... 288
2.7.4.1. Description ............................................................................................................ 288
2.7.4.2. Usage .................................................................................................................... 288
2.7.4.3. Example ................................................................................................................ 289
2.7.4.4. Hooking a UDS Unsteady Function to ANSYS Fluent ............................................... 289
3. Additional Macros for Writing UDFs ............................................................................................. 291
3.1. Introduction ........................................................................................................................... 291
3.2. Data Access Macros ................................................................................................................. 293
3.2.1. Axisymmetric Considerations for Data Access Macros ...................................................... 293
3.2.2. Node Macros .................................................................................................................. 293
3.2.2.1. Node Position ........................................................................................................ 294
3.2.2.2. Number of Nodes in a Face (F_NNODES) ................................................................ 294
3.2.3. Cell Macros .................................................................................................................... 294
3.2.3.1. Cell Centroid (C_CENTROID) ................................................................................. 294
3.2.3.2. Cell Volume (C_VOLUME) ....................................................................................... 295
3.2.3.3. Number of Faces (C_NFACES) and Nodes (C_NNODES) in a Cell ............................. 295
3.2.3.4. Cell Face Index (C_FACE) ....................................................................................... 295
3.2.3.5. Cell Face Thread (C_FACE_THREAD) ..................................................................... 296
3.2.3.6. Flow Variable Macros for Cells ................................................................................ 296
3.2.3.6.1. Species Fractions Calculations with the Non- and Partially- Premixed Models .............................................................................................................................. 297
3.2.3.7. Gradient (G) and Reconstruction Gradient (RG) Vector Macros ................................ 298
3.2.3.8. Previous Time Step Macros ..................................................................................... 303
3.2.3.9. Derivative Macros .................................................................................................. 305
3.2.3.10. Material Property Macros ..................................................................................... 305
3.2.3.11. Reynolds Stress Model Macros ............................................................................. 307
3.2.3.12. VOF Multiphase Model Macro .............................................................................. 307
3.2.4. Face Macros ................................................................................................................... 308
3.2.4.1. Face Centroid (F_CENTROID) ............................................................................... 308
3.2.4.2. Face Area Vector (F_AREA) .................................................................................... 308
3.2.4.3. Flow Variable Macros for Boundary Faces ............................................................... 309
xv
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
3.2.4.4. Flow Variable Macros at Interior and Boundary Faces .............................................. 310
3.2.5. Connectivity Macros ....................................................................................................... 310
3.2.5.1. Adjacent Cell Index (F_C0, F_C1) .......................................................................... 311
3.2.5.2. Adjacent Cell Thread (THREAD_T0, THREAD_T1) .................................................. 312
3.2.5.3. Interior Face Geometry (INTERIOR_FACE_GEOMETRY) ....................................... 312
3.2.5.4. Boundary Face Geometry (BOUNDARY_FACE_GEOMETRY) ................................... 313
3.2.5.5. Boundary Face Thread (BOUNDARY_FACE_THREAD) ............................................. 313
3.2.5.6. Boundary Secondary Gradient Source (BOUNDARY_SECONDARY_GRADIENT_SOURCE) ................................................................................................................. 313
3.2.6. Special Macros ............................................................................................................... 314
3.2.6.1.Thread Pointer for Zone ID (Lookup_Thread) ...................................................... 314
3.2.6.2. Zone ID (THREAD_ID) ........................................................................................... 316
3.2.6.3. Domain Pointer (Get_Domain) ............................................................................ 316
3.2.6.4. Set Boundary Condition Value (F_PROFILE) ......................................................... 317
3.2.6.5. THREAD_SHADOW(t) ......................................................................................... 318
3.2.7.Time-Sampled Data ........................................................................................................ 319
3.2.8. Model-Specific Macros ................................................................................................... 321
3.2.8.1. DPM Macros .......................................................................................................... 321
3.2.8.2. NOx Macros ........................................................................................................... 327
3.2.8.3. SOx Macros ........................................................................................................... 329
3.2.8.4. Dynamic Mesh Macros ........................................................................................... 330
3.2.9. NIST Real Gas Saturation Properties ................................................................................ 331
3.2.9.1. Saturation Curves for Single-Species ...................................................................... 331
3.2.9.2. Saturation Curves for Multi-Species (UDF 1) ............................................................ 332
3.2.9.3. Saturation Curves for Multi-Species (UDF 2) ............................................................ 333
3.2.9.3.1. Using Multi-Species User-Defined Function (UDF2) ........................................ 333
3.2.9.3.2. Example Multi-Species User-Defined Function (UDF2) .................................... 334
3.2.10. NIST Real Gas UDF Access Macro for Multi-Species Mixtures .......................................... 335
3.2.10.1. Description .......................................................................................................... 335
3.2.10.2. Using get_prop_NIST_msp ............................................................................ 337
3.2.10.3. Error Handling ..................................................................................................... 338
3.2.10.4. Example .............................................................................................................. 338
3.2.11. User-Defined Scalar (UDS) Transport Equation Macros ................................................... 340
3.2.11.1.Set_User_Scalar_Name ............................................................................... 340
3.2.11.2. F_UDSI ............................................................................................................. 341
3.2.11.3. C_UDSI ............................................................................................................. 341
3.2.11.4. Reserving UDS Variables ...................................................................................... 341
3.2.11.5. Reserve_User_Scalar_Vars ...................................................................... 342
3.2.11.6. Unreserving UDS Variables ................................................................................... 342
3.2.11.7.N_UDS ................................................................................................................ 342
3.2.12. User-Defined Memory (UDM) Macros ............................................................................ 342
3.2.12.1.Set_User_Memory_Name ............................................................................... 343
3.2.12.2.Set_User_Node_Memory_Name .................................................................... 343
3.2.12.3. F_UDMI ............................................................................................................. 344
3.2.12.4. C_UDMI ............................................................................................................. 345
3.2.12.5. N_UDMI ............................................................................................................. 345
3.2.12.6. Example UDF that Utilizes UDM and UDS Variables ............................................... 346
3.2.12.7. Reserving UDM Variables Using Reserve_User_Memory_Vars ..................... 347
3.2.12.8. Example 1 ............................................................................................................ 348
3.2.12.9. Example 2 ............................................................................................................ 349
3.2.12.10. Unreserving UDM Variables ................................................................................ 350
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xvi of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
3.3. Looping Macros ...................................................................................................................... 350
3.3.1. Looping Over Cell Threads in a Domain (thread_loop_c) ........................................... 350
3.3.2. Looping Over Face Threads in a Domain (thread_loop_f) .......................................... 351
3.3.3. Looping Over Cells in a Cell Thread (begin...end_c_loop) ....................................... 351
3.3.4. Looping Over Faces in a Face Thread (begin...end_f_loop) .................................... 351
3.3.5. Looping Over Faces of a Cell (c_face_loop) ................................................................ 352
3.3.6. Looping Over Nodes of a Cell (c_node_loop) ............................................................... 352
3.3.7. Looping Over Nodes of a Face (f_node_loop) ............................................................. 353
3.3.8. Overset Mesh Looping Macros ........................................................................................ 353
3.3.8.1. Looping Over Overset Interface Cell Threads (thread_loop_overset_c) ......... 353
3.3.8.2. Looping Over Active Overset Cells in a Cell Thread (begin...end_c_loop_active,
begin…end_c_loop_solve) ....................................................................................... 354
3.3.8.2.1. Example 1 ..................................................................................................... 354
3.3.8.2.2. Example 2 ..................................................................................................... 355
3.3.8.3. Looping Over Faces in a Face Thread with Overset Mesh (begin...end_f_loop_active) ..................................................................................... 355
3.3.8.3.1. Example ....................................................................................................... 356
3.3.9. Multiphase Looping Macros ........................................................................................... 357
3.3.9.1. Looping Over Phase Domains in Mixture (sub_domain_loop) ............................ 357
3.3.9.2. Looping Over Phase Threads in Mixture (sub_thread_loop) .............................. 358
3.3.9.3. Looping Over Phase Cell Threads in Mixture (mp_thread_loop_c) ..................... 359
3.3.9.4. Looping Over Phase Face Threads in Mixture (mp_thread_loop_f) .................... 359
3.3.10. Advanced Multiphase Macros ....................................................................................... 360
3.3.10.1. Phase Domain Pointer (DOMAIN_SUB_DOMAIN) ................................................. 360
3.3.10.2. Phase-Level Thread Pointer (THREAD_SUB_THREAD) .......................................... 361
3.3.10.3. Phase Thread Pointer Array (THREAD_SUB_THREADS) ........................................ 362
3.3.10.4. Mixture Domain Pointer (DOMAIN_SUPER_DOMAIN) .......................................... 362
3.3.10.5. Mixture Thread Pointer (THREAD_SUPER_THREAD) ............................................ 362
3.3.10.6. Domain ID (DOMAIN_ID) .................................................................................... 363
3.3.10.7. Phase Domain Index (PHASE_DOMAIN_INDEX) .................................................. 363
3.4.Vector and Dimension Macros ................................................................................................. 363
3.4.1. Macros for Dealing with Two and Three Dimensions ........................................................ 364
3.4.1.1. RP_2D and RP_3D ............................................................................................... 364
3.4.2. The ND Macros ............................................................................................................... 364
3.4.2.1. ND_ND ................................................................................................................. 364
3.4.2.2. ND_SUM ............................................................................................................... 365
3.4.2.3. ND_SET ............................................................................................................... 365
3.4.3. The NV Macros ............................................................................................................... 365
3.4.3.1.NV_V .................................................................................................................... 365
3.4.3.2. NV_VV ................................................................................................................. 365
3.4.3.3. NV_V_VS ............................................................................................................. 365
3.4.3.4. NV_VS_VS ........................................................................................................... 366
3.4.4.Vector Operation Macros ................................................................................................ 366
3.4.4.1.Vector Magnitude Using NV_MAG and NV_MAG2 ................................................... 366
3.4.4.2. Dot Product ........................................................................................................... 366
3.4.4.3. Cross Product ........................................................................................................ 367
3.5.Time-Dependent Macros ......................................................................................................... 367
3.6. Scheme Macros ...................................................................................................................... 369
3.6.1. Defining a Scheme Variable in the Text Interface ............................................................. 369
3.6.2. Accessing a Scheme Variable in the Text Interface ........................................................... 370
3.6.3. Changing a Scheme Variable to Another Value in the Text Interface ................................. 370
xvii
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
3.6.4. Accessing a Scheme Variable in a UDF ............................................................................. 370
3.7. Input/Output Functions .......................................................................................................... 371
3.7.1. Message ...................................................................................................................... 372
3.7.2. Error .......................................................................................................................... 372
3.7.3.The par_fprintf_head and par_fprintf Functions ............................................. 373
3.7.3.1. par_fprintf_head ......................................................................................... 373
3.7.3.2. par_fprintf .................................................................................................... 373
3.8. Miscellaneous Macros ............................................................................................................. 374
3.8.1. Data_Valid_P() ...................................................................................................... 374
3.8.2. FLUID_THREAD_P() .................................................................................................. 374
3.8.3. Get_Report_Definition_Values ....................................................................... 375
3.8.4. M_PI ............................................................................................................................ 377
3.8.5. NULLP & NNULLP ...................................................................................................... 377
3.8.6. N_UDM .......................................................................................................................... 377
3.8.7. N_UDS .......................................................................................................................... 377
3.8.8. SQR(k) ........................................................................................................................ 378
3.8.9. UNIVERSAL_GAS_CONSTANT ..................................................................................... 378
4. Interpreting UDFs .......................................................................................................................... 379
4.1. Introduction ........................................................................................................................... 379
4.1.1. Location of the udf.h File ............................................................................................. 379
4.1.2. Limitations ..................................................................................................................... 380
4.2. Interpreting a UDF Source File Using the Interpreted UDFs Dialog Box ..................................... 381
4.3. Common Errors Made While Interpreting A Source File ............................................................ 383
5. Compiling UDFs ............................................................................................................................. 385
5.1. Introduction ........................................................................................................................... 386
5.1.1. Location of the udf.h File ............................................................................................. 387
5.1.2. Compilers ...................................................................................................................... 387
5.2. Compiling a UDF Using the GUI ............................................................................................... 389
5.3. Compile a UDF Using the TUI ................................................................................................... 394
5.3.1. Set Up the Directory Structure ........................................................................................ 394
5.3.1.1.Windows Systems .................................................................................................. 394
5.3.1.2. Linux Systems ........................................................................................................ 396
5.3.2. Build the UDF Library ..................................................................................................... 397
5.3.2.1.Windows Systems .................................................................................................. 397
5.3.2.2. Linux Systems ........................................................................................................ 399
5.3.3. Load the UDF Library ...................................................................................................... 400
5.4. Link Precompiled Object Files From Non-ANSYS Fluent Sources ............................................... 400
5.4.1.Windows Systems ........................................................................................................... 401
5.4.2. Linux Systems ................................................................................................................ 401
5.4.3. Example: Link Precompiled Objects to ANSYS Fluent ....................................................... 402
5.5. Load and Unload Libraries Using the UDF Library Manager Dialog Box ..................................... 405
5.5.1. Load the UDF Library ...................................................................................................... 405
5.5.2. Unload the UDF Library .................................................................................................. 406
5.6. Common Errors When Building and Loading a UDF Library ...................................................... 407
5.6.1.Windows Distributed Parallel .......................................................................................... 408
5.7. Special Considerations for Parallel ANSYS Fluent ...................................................................... 409
6. Hooking UDFs to ANSYS Fluent .................................................................................................... 411
6.1. Hooking General Purpose UDFs ............................................................................................... 411
6.1.1. Hooking DEFINE_ADJUST UDFs ................................................................................... 411
6.1.2. Hooking DEFINE_DELTAT UDFs ................................................................................... 413
6.1.3. Hooking DEFINE_EXECUTE_AT_END UDFs ................................................................. 414
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xviii of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
6.1.4. Hooking DEFINE_EXECUTE_AT_EXIT UDFs ............................................................... 415
6.1.5. Hooking DEFINE_INIT UDFs ....................................................................................... 417
6.1.6. Hooking DEFINE_ON_DEMAND UDFs ............................................................................ 418
6.1.7. Hooking DEFINE_RW_FILE and DEFINE_RW_HDF_FILE UDFs ................................. 419
6.1.8. User-Defined Memory Storage ....................................................................................... 420
6.2. Hooking Model-Specific UDFs ................................................................................................. 421
6.2.1. Hooking DEFINE_ANISOTROPIC_CONDUCTIVITY UDFs ........................................... 423
6.2.2. Hooking DEFINE_CHEM_STEP UDFs ............................................................................ 424
6.2.3. Hooking DEFINE_CPHI UDFs ....................................................................................... 425
6.2.4. Hooking DEFINE_DIFFUSIVITY UDFs ........................................................................ 426
6.2.5. Hooking DEFINE_DOM_DIFFUSE_REFLECTIVITY UDFs ........................................... 428
6.2.6. Hooking DEFINE_DOM_SOURCE UDFs .......................................................................... 430
6.2.7. Hooking DEFINE_DOM_SPECULAR_REFLECTIVITY UDFs ......................................... 431
6.2.8. Hooking DEFINE_ECFM_SOURCE UDFs ........................................................................ 432
6.2.9. Hooking DEFINE_ECFM_SPARK_SOURCE UDFs .......................................................... 433
6.2.10. Hooking DEFINE_EC_RATE UDFs .............................................................................. 434
6.2.11. Hooking DEFINE_EC_KINETICS_PARAMETER UDFs ................................................ 436
6.2.12. Hooking DEFINE_EDC_MDOT UDFs ............................................................................ 437
6.2.13. Hooking DEFINE_EDC_SCALES UDFs ........................................................................ 438
6.2.14. Hooking DEFINE_EMISSIVITY_WEIGHTING_FACTOR UDFs .................................. 440
6.2.15. Hooking DEFINE_FLAMELET_PARAMETERS UDFs .................................................... 441
6.2.16. Hooking DEFINE_ZONE_MOTION UDFs ...................................................................... 442
6.2.17. Hooking DEFINE_GRAY_BAND_ABS_COEFF UDFs .................................................... 444
6.2.18. Hooking DEFINE_HEAT_FLUX UDFs .......................................................................... 445
6.2.19. Hooking DEFINE_IGNITE_SOURCE UDFs ................................................................. 445
6.2.20. Hooking DEFINE_MASS_TR_PROPERTY UDFs ........................................................... 447
6.2.21. Hooking DEFINE_NET_REACTION_RATE UDFs ........................................................ 449
6.2.22. Hooking DEFINE_NOX_RATE UDFs ............................................................................ 450
6.2.23. Hooking DEFINE_PDF_TABLE UDFs .......................................................................... 452
6.2.24. Hooking DEFINE_PR_RATE UDFs .............................................................................. 453
6.2.25. Hooking DEFINE_PRANDTL UDFs .............................................................................. 454
6.2.26. Hooking DEFINE_PROFILE UDFs .............................................................................. 455
6.2.26.1. Hooking Profiles for UDS Equations ...................................................................... 456
6.2.27. Hooking DEFINE_PROPERTY UDFs ............................................................................ 459
6.2.28. Hooking DEFINE_REACTING_CHANNEL_BC UDFs .................................................... 460
6.2.29. Hooking DEFINE_REACTING_CHANNEL_SOLVER UDFs ........................................... 460
6.2.30. Hooking DEFINE_RELAX_TO_EQUILIBRIUM UDFs .................................................. 461
6.2.31. Hooking DEFINE_SBES_BF UDFs .............................................................................. 463
6.2.32. Hooking DEFINE_SCAT_PHASE_FUNC UDFs ............................................................. 465
6.2.33. Hooking DEFINE_SOLAR_INTENSITY UDFs ............................................................. 466
6.2.34. Hooking DEFINE_SOLIDIFICATION_PARAMS UDFs ................................................ 468
6.2.35. Hooking DEFINE_SOURCE UDFs ................................................................................. 469
6.2.36. Hooking DEFINE_SOOT_MASS_RATES UDFs ............................................................. 471
6.2.37. Hooking DEFINE_SOOT_MOM_RATES UDFs ............................................................... 472
6.2.38. Hooking DEFINE_SOOT_NUCLEATION_RATES UDFs ................................................ 474
6.2.39. Hooking DEFINE_SOOT_OXIDATION_RATE UDFs .................................................... 474
6.2.40. Hooking DEFINE_SOOT_PRECURSOR UDFs ............................................................... 475
6.2.41. Hooking DEFINE_SOX_RATE UDFs ............................................................................ 476
6.2.42. Hooking DEFINE_SPARK_GEOM UDFs ........................................................................ 478
6.2.43. Hooking DEFINE_SPECIFIC_HEAT UDFs ................................................................. 479
6.2.44. Hooking DEFINE_SR_RATE UDFs .............................................................................. 480
xix
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
6.2.45. Hooking DEFINE_THICKENED_FLAME_MODEL UDFs ................................................ 481
6.2.46. Hooking DEFINE_TRANS UDFs ................................................................................... 482
6.2.47. Hooking DEFINE_TRANSIENT_PROFILE UDFs ........................................................ 483
6.2.48. Hooking DEFINE_TURB_PREMIX_SOURCE UDFs ...................................................... 484
6.2.49. Hooking DEFINE_TURB_SCHMIDT UDFs ................................................................... 485
6.2.50. Hooking DEFINE_TURBULENT_VISCOSITY UDFs .................................................... 486
6.2.51. Hooking DEFINE_VR_RATE UDFs .............................................................................. 487
6.2.52. Hooking DEFINE_WALL_FUNCTIONS UDFs ............................................................... 488
6.2.53. Hooking DEFINE_WALL_NODAL_DISP UDFs ............................................................. 489
6.2.54. Hooking DEFINE_WALL_NODAL_FORCE UDFs ........................................................... 490
6.2.55. Hooking DEFINE_WSGGM_ABS_COEFF UDFs ............................................................. 491
6.3. Hooking Multiphase UDFs ....................................................................................................... 493
6.3.1. Hooking DEFINE_BOILING_PROPERTY UDFs ............................................................. 493
6.3.2. Hooking DEFINE_CAVITATION_RATE UDFs ............................................................... 494
6.3.3. Hooking DEFINE_EXCHANGE_PROPERTY UDFs .......................................................... 496
6.3.4. Hooking DEFINE_HET_RXN_RATE UDFs ..................................................................... 499
6.3.5. Hooking DEFINE_LINEARIZED_MASS_TRANSFER UDFs ........................................... 500
6.3.6. Hooking DEFINE_MASS_TRANSFER UDFs ................................................................... 501
6.3.7. Hooking DEFINE_VECTOR_EXCHANGE_PROPERTY UDFs ........................................... 503
6.4. Hooking Discrete Phase Model (DPM) UDFs ............................................................................. 505
6.4.1. Hooking DEFINE_DPM_BC UDFs ................................................................................... 506
6.4.2. Hooking DEFINE_DPM_BODY_FORCE UDFs ................................................................. 507
6.4.3. Hooking DEFINE_DPM_DRAG UDFs .............................................................................. 508
6.4.4. Hooking DEFINE_DPM_EROSION UDFs ........................................................................ 509
6.4.5. Hooking DEFINE_DPM_HEAT_MASS UDFs ................................................................... 510
6.4.6. Hooking DEFINE_DPM_INJECTION_INIT UDFs ........................................................ 511
6.4.7. Hooking DEFINE_DPM_LAW UDFs ................................................................................ 512
6.4.8. Hooking DEFINE_DPM_OUTPUT UDFs .......................................................................... 513
6.4.9. Hooking DEFINE_DPM_PROPERTY UDFs ..................................................................... 514
6.4.10. Hooking DEFINE_DPM_SCALAR_UPDATE UDFs ........................................................ 516
6.4.11. Hooking DEFINE_DPM_SOURCE UDFs ........................................................................ 517
6.4.12. Hooking DEFINE_DPM_SPRAY_COLLIDE UDFs ........................................................ 518
6.4.13. Hooking DEFINE_DPM_SWITCH UDFs ........................................................................ 519
6.4.14. Hooking DEFINE_DPM_TIMESTEP UDFs ................................................................... 520
6.4.15. Hooking DEFINE_DPM_VP_EQUILIB UDFs ............................................................... 521
6.4.16. Hooking DEFINE_IMPINGEMENT UDFs ...................................................................... 523
6.4.17. Hooking DEFINE_FILM_REGIME UDFs ...................................................................... 524
6.4.18. Hooking DEFINE_SPLASHING_DISTRIBUTION UDFs ............................................. 526
6.5. Hooking Dynamic Mesh UDFs ................................................................................................. 527
6.5.1. Hooking DEFINE_CG_MOTION UDFs ............................................................................ 528
6.5.2. Hooking DEFINE_DYNAMIC_ZONE_PROPERTY UDFs .................................................. 529
6.5.2.1. Hooking a Swirl Center UDF ................................................................................... 529
6.5.2.2. Hooking a Variable Cell Layering Height UDF .......................................................... 530
6.5.3. Hooking DEFINE_GEOM UDFs ....................................................................................... 531
6.5.4. Hooking DEFINE_GRID_MOTION UDFs ........................................................................ 532
6.5.5. Hooking DEFINE_SDOF_PROPERTIES UDFs ............................................................... 533
6.5.6. Hooking DEFINE_CONTACT UDFs ................................................................................ 535
6.6. Hooking User-Defined Scalar (UDS) Transport Equation UDFs .................................................. 536
6.6.1. Hooking DEFINE_ANISOTROPIC_DIFFUSIVITY UDFs ............................................. 536
6.6.2. Hooking DEFINE_UDS_FLUX UDFs .............................................................................. 538
6.6.3. Hooking DEFINE_UDS_UNSTEADY UDFs ..................................................................... 538
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xx of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
6.7. Common Errors While Hooking a UDF to ANSYS Fluent ............................................................ 539
7. Parallel Considerations ................................................................................................................. 541
7.1. Overview of Parallel ANSYS Fluent ........................................................................................... 541
7.1.1. Command Transfer and Communication ......................................................................... 543
7.2. Cells and Faces in a Partitioned Mesh ....................................................................................... 545
7.2.1. Cell Types in a Partitioned Mesh ...................................................................................... 545
7.2.2. Faces at Partition Boundaries .......................................................................................... 546
7.2.3. PRINCIPAL_FACE_P ................................................................................................... 547
7.2.4. Exterior Thread Storage .................................................................................................. 548
7.2.5. Extended Neighborhood ................................................................................................ 548
7.3. Parallelizing Your Serial UDF .................................................................................................... 549
7.3.1. Parallelization of Discrete Phase Model (DPM) UDFs ........................................................ 550
7.3.2. Macros for Parallel UDFs ................................................................................................. 551
7.3.2.1. Compiler Directives ............................................................................................... 551
7.3.2.2. Communicating Between the Host and Node Processes ......................................... 553
7.3.2.2.1. Host-to-Node Data Transfer ........................................................................... 553
7.3.2.2.2. Node-to-Host Data Transfer ........................................................................... 554
7.3.2.3. Predicates .............................................................................................................. 554
7.3.2.4. Global Reduction Macros ....................................................................................... 555
7.3.2.4.1. Global Summations ....................................................................................... 556
7.3.2.4.2. Global Maximums and Minimums ................................................................. 557
7.3.2.4.3. Global Logicals .............................................................................................. 558
7.3.2.4.4. Global Synchronization ................................................................................. 558
7.3.2.5. Looping Macros ..................................................................................................... 558
7.3.2.5.1. Looping Over Cells ........................................................................................ 559
7.3.2.5.2. Interior Cell Looping Macro ........................................................................... 559
7.3.2.5.3. Exterior Cell Looping Macro .......................................................................... 559
7.3.2.5.4. Interior and Exterior Cell Looping Macro ........................................................ 560
7.3.2.5.5. Looping Over Faces ....................................................................................... 561
7.3.2.6. Cell and Face Partition ID Macros ............................................................................ 562
7.3.2.6.1. Cell Partition IDs ............................................................................................ 562
7.3.2.6.2. Face Partition IDs .......................................................................................... 563
7.3.2.7. Message Displaying Macros ................................................................................... 563
7.3.2.8. Message Passing Macros ........................................................................................ 564
7.3.2.9. Macros for Exchanging Data Between Compute Nodes ........................................... 567
7.3.3. Limitations of Parallel UDFs ............................................................................................ 567
7.3.4. Process Identification ..................................................................................................... 569
7.3.5. Parallel UDF Example ...................................................................................................... 569
7.4. Reading and Writing Files in Parallel ........................................................................................ 571
7.4.1. Reading Files in Parallel .................................................................................................. 572
7.4.2.Writing Files in Parallel .................................................................................................... 572
7.5. Enabling Fluent UDFs to Execute on General Purpose Graphics Processing Units (GPGPUs) ....... 574
8. Examples ....................................................................................................................................... 575
8.1. Step-By-Step UDF Example ..................................................................................................... 575
8.1.1. Process Overview ........................................................................................................... 575
8.1.2. Step 1: Define Your Problem ............................................................................................ 576
8.1.3. Step 2: Create a C Source File .......................................................................................... 578
8.1.4. Step 3: Start ANSYS Fluent and Read (or Set Up) the Case File .......................................... 578
8.1.5. Step 4: Interpret or Compile the Source File ..................................................................... 579
8.1.5.1. Interpret the Source File ......................................................................................... 579
8.1.5.2. Compile the Source File ......................................................................................... 581
xxi
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
8.1.6. Step 5: Hook the UDF to ANSYS Fluent ............................................................................ 583
8.1.7. Step 6: Run the Calculation ............................................................................................. 584
8.1.8. Step 7: Analyze the Numerical Solution and Compare to Expected Results ....................... 584
8.2. Detailed UDF Examples ........................................................................................................... 585
8.2.1. Boundary Conditions ...................................................................................................... 585
8.2.1.1. Parabolic Velocity Inlet Profile in an Elbow Duct ...................................................... 585
8.2.1.2.Transient Pressure Outlet Profile for Flow in a Tube ................................................. 590
8.2.2. Source Terms .................................................................................................................. 595
8.2.2.1. Adding a Momentum Source to a Duct Flow .......................................................... 596
8.2.3. Physical Properties ......................................................................................................... 600
8.2.3.1. Solidification via a Temperature-Dependent Viscosity ............................................. 600
8.2.4. Reaction Rates ............................................................................................................... 604
8.2.4.1.Volume Reaction Rate ............................................................................................ 604
8.2.5. User-Defined Scalars ...................................................................................................... 609
8.2.5.1. Postprocessing Using User-Defined Scalars ............................................................ 609
8.2.5.2. Implementing ANSYS Fluent’s P-1 Radiation Model Using User-Defined Scalars ....... 611
8.2.6. User-Defined Real Gas Models (UDRGM) ......................................................................... 614
8.2.6.1. UDRGM Example: Redlich-Kwong Equation of State ................................................ 614
8.2.6.2. Specific Volume and Density .................................................................................. 615
8.2.6.3. Derivatives of Specific Volume and Density ............................................................ 616
8.2.6.4. Specific Heat and Enthalpy ..................................................................................... 617
8.2.6.5. Entropy ................................................................................................................. 617
8.2.6.6. Speed of Sound ..................................................................................................... 618
8.2.6.7.Viscosity and Thermal Conductivity ........................................................................ 618
8.2.6.8. Using the Redlich-Kwong Real Gas UDRGM ............................................................ 619
8.2.6.9. Redlich-Kwong Real Gas UDRGM Code Listing ........................................................ 620
8.2.6.9.1. UDRGM Example: Multiple-Species Real Gas Model ........................................ 625
8.2.6.9.2. UDRGM Example: Real Gas Model with Volumetric Reactions ......................... 631
A. C Programming Basics ..................................................................................................................... 643
A.1. Introduction ........................................................................................................................... 643
A.2. Commenting Your C Code ....................................................................................................... 643
A.3. C Data Types in ANSYS Fluent .................................................................................................. 644
A.4. Constants ............................................................................................................................... 644
A.5.Variables ................................................................................................................................. 644
A.5.1. Declaring Variables ........................................................................................................ 645
A.5.2. External Variables ........................................................................................................... 645
A.5.2.1. Example ................................................................................................................ 646
A.5.3. Static Variables ............................................................................................................... 646
A.5.3.1. Example - Static Global Variable ............................................................................. 647
A.6. User-Defined Data Types ......................................................................................................... 647
A.6.1. Example ........................................................................................................................ 647
A.7. Casting ................................................................................................................................... 648
A.8. Functions ............................................................................................................................... 648
A.9. Arrays ..................................................................................................................................... 648
A.9.1. Examples ....................................................................................................................... 648
A.10. Pointers ................................................................................................................................ 648
A.10.1. Pointers as Function Arguments ................................................................................... 649
A.11. Control Statements ............................................................................................................... 650
A.11.1.if Statement ............................................................................................................... 650
A.11.1.1. Example .............................................................................................................. 650
A.11.2.if-else Statement .................................................................................................... 650
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xxii of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
A.11.2.1. Example .............................................................................................................. 650
A.11.3. for Loops ................................................................................................................... 651
A.11.3.1. Example .............................................................................................................. 651
A.12. Common C Operators ........................................................................................................... 651
A.12.1. Arithmetic Operators ................................................................................................... 651
A.12.2. Logical Operators ......................................................................................................... 652
A.13. C Library Functions ............................................................................................................... 652
A.13.1. Trigonometric Functions .............................................................................................. 652
A.13.2. Miscellaneous Mathematical Functions ......................................................................... 652
A.13.3. Standard I/O Functions ................................................................................................. 653
A.13.3.1. fopen ............................................................................................................... 653
A.13.3.2. fclose ............................................................................................................. 654
A.13.3.3. printf ............................................................................................................. 654
A.13.3.4. fprintf ........................................................................................................... 654
A.13.3.5. fscanf ............................................................................................................. 655
A.14. Preprocessor Directives ......................................................................................................... 655
A.14.1. Macro Substitution Directive Using #define .............................................................. 655
A.14.2. File Inclusion Directive Using #include ..................................................................... 656
A.15. Comparison with FORTRAN ................................................................................................... 656
B. DEFINE Macro Definitions .............................................................................................................. 659
B.1. General Solver DEFINE Macros ............................................................................................... 659
B.2. Model-Specific DEFINE Macro Definitions .............................................................................. 659
B.3. Multiphase DEFINE Macros .................................................................................................... 661
B.4. Dynamic Mesh Model DEFINE Macros ................................................................................... 662
B.5. Discrete Phase Model DEFINE Macros .................................................................................... 662
B.6. User-Defined Scalar (UDS) DEFINE Macros ............................................................................. 663
C. Quick Reference Guide for Multiphase DEFINE Macros .................................................................... 665
C.1.VOF Model .............................................................................................................................. 665
C.2. Mixture Model ........................................................................................................................ 667
C.3. Eulerian Model - Laminar Flow ................................................................................................ 669
C.4. Eulerian Model - Mixture Turbulence Flow ............................................................................... 671
C.5. Eulerian Model - Dispersed Turbulence Flow ............................................................................ 674
C.6. Eulerian Model - Per Phase Turbulence Flow ............................................................................ 676
Bibliography ....................................................................................................................................... 679
2. Creating Custom User Interfaces in Fluent ......................................................................................... 681
1. Introduction to Fluent User Interface Concepts ........................................................................... 683
1.1. Introduction ........................................................................................................................... 683
1.2. Limitations ............................................................................................................................. 683
1.2.1. Menu Items Read Into Fluent Cannot Be Removed Or Overwritten .................................. 683
1.2.2. Help Button Unusable .................................................................................................... 684
1.3. Scheme Basics ........................................................................................................................ 684
1.3.1. Data Types ..................................................................................................................... 684
1.3.1.1. Boolean ................................................................................................................. 685
1.3.1.2. Integers ................................................................................................................. 685
1.3.1.3. Reals ..................................................................................................................... 685
1.3.1.4. Characters ............................................................................................................. 686
1.3.1.5. Strings ................................................................................................................... 686
1.3.1.6. Symbols ................................................................................................................ 687
1.3.1.7. Pairs and Lists ........................................................................................................ 687
1.3.2. Important Concepts ....................................................................................................... 688
1.3.2.1. Define ................................................................................................................... 688
xxiii
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
1.3.2.2. Set! ........................................................................................................................ 688
1.3.2.3. Let ......................................................................................................................... 689
1.3.2.4. Lambda ................................................................................................................. 689
1.3.2.5. If ........................................................................................................................... 690
1.3.2.6. Map ...................................................................................................................... 690
1.4. RP Variables ............................................................................................................................ 691
1.4.1. Creating an RP Variable ................................................................................................... 691
1.4.2. Changing an RP Variable ................................................................................................. 691
1.4.3. Accessing the Value of an RP Variable In Your GUI ............................................................ 692
1.4.4. Accessing the Value of an RP Variable In Your UDF ........................................................... 692
1.4.5. Saving and Loading RP Variables ..................................................................................... 692
1.5. The .fluent File ........................................................................................................................ 693
2. How to Create an Interface ............................................................................................................ 695
2.1. Dialog Boxes (cx-create-panel) ................................................................................................ 695
2.1.1. Description .................................................................................................................... 695
2.1.2. Usage ............................................................................................................................ 695
2.1.2.1. cx-create-panel ...................................................................................................... 695
2.1.2.2. cx-show-panel ....................................................................................................... 696
2.1.3. Examples ....................................................................................................................... 696
2.1.3.1. Example One ......................................................................................................... 696
2.1.3.2. Example Two ......................................................................................................... 697
2.1.3.3. Additional Examples .............................................................................................. 697
2.2. Tables (cx-create-table) ........................................................................................................... 698
2.2.1. Description .................................................................................................................... 698
2.2.2. Usage ............................................................................................................................ 698
2.2.3. Examples ....................................................................................................................... 698
3. Interface Elements ........................................................................................................................ 699
3.1. Integer Entry (cx-create-integer-entry) ..................................................................................... 699
3.1.1. Description .................................................................................................................... 699
3.1.2. Usage ............................................................................................................................ 699
3.1.2.1. cx-create-integer-entry .......................................................................................... 699
3.1.2.2. cx-set-integer-entry ............................................................................................... 700
3.1.2.3. cx-show-integer-entry ........................................................................................... 700
3.1.3. Integer Entry Example .................................................................................................... 700
3.2. Real Number Entry (cx-create-real-entry) ................................................................................. 701
3.2.1. Description .................................................................................................................... 701
3.2.2. Usage ............................................................................................................................ 701
3.2.2.1. cx-create-real-entry ............................................................................................... 702
3.2.2.2. cx-set-real-entry .................................................................................................... 702
3.2.2.3. cx-show-real-entry ................................................................................................. 702
3.2.3. Real Number Entry Example ........................................................................................... 702
3.3. Text Entry (cx-create-text-entry) .............................................................................................. 703
3.3.1. Description .................................................................................................................... 703
3.3.2. Usage ............................................................................................................................ 703
3.3.2.1. cx-create-text-entry ............................................................................................... 704
3.3.2.2. cx-set-text-entry .................................................................................................... 704
3.3.2.3. cx-show-text-entry ................................................................................................ 704
3.3.3.Text Entry Example ......................................................................................................... 704
3.4. Check Boxes & Radio Buttons (cx-create-toggle-button) ........................................................... 705
3.4.1. Description .................................................................................................................... 706
3.4.2. Usage ............................................................................................................................ 706
Release 2020 R2 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
xxiv of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
3.4.2.1. cx-create-button-box ............................................................................................. 706
3.4.2.2. cx-create-toggle-button ......................................................................................... 706
3.4.2.3. cx-set-toggle-button ............................................................................................. 706
3.4.2.4. cx-show-toggle-button .......................................................................................... 707
3.4.3. Check Box Example ........................................................................................................ 707
3.4.4. Option Button Example .................................................................................................. 708
3.5. Buttons (cx-create-button) ...................................................................................................... 709
3.5.1. Description .................................................................................................................... 709
3.5.2. Usage ............................................................................................................................ 709
3.5.3. Button Example .............................................................................................................. 709
3.6. Lists & Drop-down Lists (cx-create-list) & (cx-create-drop-down-list) ......................................... 710
3.6.1. Description .................................................................................................................... 711
3.6.2. Usage ............................................................................................................................ 711
3.6.2.1. cx-create-list .......................................................................................................... 711
3.6.2.2. cx-create-drop-down-list ....................................................................................... 712
3.6.2.3. cx-set-list-items ..................................................................................................... 712
3.6.2.4. cx-set-list-selections .............................................................................................. 712
3.6.2.5. cx-show-list-selections ........................................................................................... 712
3.6.3. List Example ................................................................................................................... 713
3.6.4. Drop Down List Example ................................................................................................ 714
4. Adding Menus to the Right of the Ribbon .................................................................................... 717
4.1. Adding a New Menu ............................................................................................................... 717
4.1.1. Description .................................................................................................................... 717
4.1.2. Usage ............................................................................................................................ 717
4.1.3. Examples ....................................................................................................................... 718
4.2. Adding a New Submenu ......................................................................................................... 718
4.2.1. Description .................................................................................................................... 718
4.2.2. Usage ............................................................................................................................ 718
4.2.3. Examples ....................................................................................................................... 719
4.3. Adding a New Menu Item ........................................................................................................ 719
4.3.1. Description .................................................................................................................... 719
4.3.2. Usage ............................................................................................................................ 720
4.3.3. Examples ....................................................................................................................... 720
5. Comprehensive Examples ............................................................................................................. 721
5.1. Dialog Box Example ................................................................................................................ 721
5.2. Example Menu Added to the Right of the Ribbon Tabs ............................................................. 724
5.3. UDF Example .......................................................................................................................... 725
A. Avoiding Common Mistakes ............................................................................................................ 727
A.1. Keeping Track Of Parentheses ................................................................................................. 727
A.2. Knowing The Type Of Each Variable ......................................................................................... 727
A.3. Overwriting Interface Elements ............................................................................................... 727
A.3.1. Example One ................................................................................................................. 727
A.3.2. Example Two ................................................................................................................. 728
B. Reference Table For Fluent Macros ................................................................................................... 731

标签: Fluent UDF 手册

实例下载地址

Fluent udf手册

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警