Contents
About This Document
1. Overview
1.1 What is a User-Defined Function (UDF)?
1.2 Why Use UDFs?
1.3 Limitations
1.4 Defining Your UDF Using
DEFINE
Macros
1.4.1 Including the
udf.h
Header File in Your Source File
1.5 Interpreting and Compiling UDFs
1.5.1 Differences Between Interpreted and Compiled UDFs
1.6 Hooking UDFs to Your
ANSYS FLUENT
Model
1.7 Mesh Terminology
1.8 Data Types in
ANSYS FLUENT
1.9 UDF Calling Sequence in the Solution Process
1.10 Special Considerations for Multiphase UDFs
1.10.1 Multiphase-specific Data Types
2.
DEFINE
Macros
2.1 Introduction
2.2 General Purpose
DEFINE
Macros
2.2.1
DEFINE_ADJUST
2.2.2
DEFINE_DELTAT
2.2.3
DEFINE_EXECUTE_AT_END
2.2.4
DEFINE_EXECUTE_AT_EXIT
2.2.5
DEFINE_EXECUTE_FROM_GUI
2.2.6
DEFINE_EXECUTE_ON_LOADING
2.2.7
DEFINE_EXECUTE_AFTER_CASE/DATA
2.2.8
DEFINE_INIT
2.2.9
DEFINE_ON_DEMAND
2.2.10
DEFINE_RW_FILE
2.3 Model-Specific
DEFINE
Macros
2.3.1
DEFINE_CHEM_STEP
2.3.2
DEFINE_CPHI
2.3.3
DEFINE_DIFFUSIVITY
2.3.4
DEFINE_DOM_DIFFUSE_REFLECTIVITY
2.3.5
DEFINE_DOM_SOURCE
2.3.6
DEFINE_DOM_SPECULAR_REFLECTIVITY
2.3.7
DEFINE_EMISSIVITY_WEIGHTING_FACTOR
2.3.8
DEFINE_GRAY_BAND_ABS_COEFF
2.3.9
DEFINE_HEAT_FLUX
2.3.10
DEFINE_IGNITE_SOURCE
2.3.11
DEFINE_NET_REACTION_RATE
2.3.12
DEFINE_NOX_RATE
2.3.13
DEFINE_PR_RATE
2.3.14
DEFINE_PRANDTL
UDFs
2.3.15
DEFINE_PROFILE
2.3.16
DEFINE_PROPERTY
UDFs
2.3.17
DEFINE_SCAT_PHASE_FUNC
2.3.18
DEFINE_SOLAR_INTENSITY
2.3.19
DEFINE_SOURCE
2.3.20
DEFINE_SOX_RATE
2.3.21
DEFINE_SPECIFIC_HEAT
2.3.22
DEFINE_SR_RATE
2.3.23
DEFINE_TRANS
UDFs
2.3.24
DEFINE_TURB_PREMIX_SOURCE
2.3.25
DEFINE_TURB_SCHMIDT
UDF
2.3.26
DEFINE_TURBULENT_VISCOSITY
2.3.27
DEFINE_VR_RATE
2.3.28
DEFINE_WALL_FUNCTIONS
2.4 Multiphase
DEFINE
Macros
2.4.1
DEFINE_CAVITATION_RATE
2.4.2
DEFINE_EXCHANGE_PROPERTY
2.4.3
DEFINE_HET_RXN_RATE
2.4.4
DEFINE_MASS_TRANSFER
2.4.5
DEFINE_VECTOR_EXCHANGE_PROPERTY
2.5 Discrete Phase Model (DPM)
DEFINE
Macros
2.5.1
DEFINE_DPM_BC
2.5.2
DEFINE_DPM_BODY_FORCE
2.5.3
DEFINE_DPM_DRAG
2.5.4
DEFINE_DPM_EROSION
2.5.5
DEFINE_DPM_HEAT_MASS
2.5.6
DEFINE_DPM_INJECTION_INIT
2.5.7
DEFINE_DPM_LAW
2.5.8
DEFINE_DPM_OUTPUT
2.5.9
DEFINE_DPM_PROPERTY
2.5.10
DEFINE_DPM_SCALAR_UPDATE
2.5.11
DEFINE_DPM_SOURCE
2.5.12
DEFINE_DPM_SPRAY_COLLIDE
2.5.13
DEFINE_DPM_SWITCH
2.5.14
DEFINE_DPM_TIMESTEP
2.5.15
DEFINE_DPM_VP_EQUILIB
2.6 Dynamic Mesh
DEFINE
Macros
2.6.1
DEFINE_CG_MOTION
2.6.2
DEFINE_DYNAMIC_ZONE_PROPERTY
2.6.3
DEFINE_GEOM
2.6.4
DEFINE_GRID_MOTION
2.6.5
DEFINE_SDOF_PROPERTIES
2.7 User-Defined Scalar (UDS) Transport Equation
DEFINE
Macros
2.7.1 Introduction
2.7.2
DEFINE_ANISOTROPIC_DIFFUSIVITY
2.7.3
DEFINE_UDS_FLUX
2.7.4
DEFINE_UDS_UNSTEADY
3. Additional Macros for Writing UDFs
3.1 Introduction
3.2 Data Access Macros
3.2.1 Axisymmetric Considerations for Data Access Macros
3.2.2 Node Macros
3.2.3 Cell Macros
3.2.4 Face Macros
3.2.5 Connectivity Macros
3.2.6 Special Macros
3.2.7 Model-Specific Macros
3.2.8 User-Defined Scalar (UDS) Transport Equation Macros
3.2.9 User-Defined Memory (UDM) Macros
3.3 Looping Macros
3.3.1 Multiphase Looping Macros
3.3.2 Advanced Multiphase Macros
3.4 Vector and Dimension Macros
3.4.1 Macros for Dealing with Two and Three Dimensions
3.4.2 The
ND
Macros
3.4.3 The
NV
Macros
3.4.4 Vector Operation Macros
3.5 Time-Dependent Macros
3.6 Scheme Macros
3.6.1 Defining a Scheme Variable in the Text Interface
3.6.2 Accessing a Scheme Variable in the Text Interface
3.6.3 Changing a Scheme Variable to Another Value in the Text Interface
3.6.4 Accessing a Scheme Variable in a UDF
3.7 Input/Output Macros
3.8 Miscellaneous Macros
4. Interpreting UDFs
4.1 Introduction
4.1.1 Location of the
udf.h
File
4.1.2 Limitations
4.2 Interpreting a UDF Source File Using the
Interpreted UDFs
Dialog Box
4.3 Common Errors Made While Interpreting A Source File
5. Compiling UDFs
5.1 Introduction
5.1.1 Location of the
udf.h
File
5.1.2 Compilers
5.2 Compiling a UDF Using the GUI
5.3 Compile a UDF Using the TUI
5.3.1 Set Up the Directory Structure
5.3.2 Build the UDF Library
5.3.3 Load the UDF Library
5.4 Link Precompiled Object Files From Non-
ANSYS FLUENT
Sources
5.4.1 Example - Link Precompiled Objects to
ANSYS FLUENT
5.5 Load and Unload Libraries Using the
UDF Library Manager
Dialog Box
5.6 Common Errors When Building and Loading a UDF Library
5.7 Special Considerations for Parallel
ANSYS FLUENT
6. Hooking UDFs to
ANSYS FLUENT
6.1 Hooking General Purpose UDFs
6.1.1 Hooking
DEFINE_ADJUST
UDFs
6.1.2 Hooking
DEFINE_DELTAT
UDFs
6.1.3 Hooking
DEFINE_EXECUTE_AT_END
UDFs
6.1.4 Hooking
DEFINE_EXECUTE_AT_EXIT
UDFs
6.1.5 Hooking
DEFINE_INIT
UDFs
6.1.6 Hooking
DEFINE_ON_DEMAND
UDFs
6.1.7 Hooking
DEFINE_RW_FILE
UDFs
6.1.8 User-Defined Memory Storage
6.2 Hooking Model-Specific UDFs
6.2.1 Hooking
DEFINE_CHEM_STEP
UDFs
6.2.2 Hooking
DEFINE_CPHI
UDFs
6.2.3 Hooking
DEFINE_DIFFUSIVITY
UDFs
6.2.4 Hooking
DEFINE_DOM_DIFFUSE_REFLECTIVITY
UDFs
6.2.5 Hooking
DEFINE_DOM_SOURCE
UDFs
6.2.6 Hooking
DEFINE_DOM_SPECULAR_REFLECTIVITY
UDFs
6.2.7 Hooking
DEFINE_EMISSIVITY_WEIGHTING_FACTOR
UDFs
6.2.8 Hooking
DEFINE_GRAY_BAND_ABS_COEFF
UDFs
6.2.9 Hooking
DEFINE_HEAT_FLUX
UDFs
6.2.10 Hooking
DEFINE_IGNITE_SOURCE
UDFs
6.2.11 Hooking
DEFINE_NET_REACTION_RATE
UDFs
6.2.12 Hooking
DEFINE_NOX_RATE
UDFs
6.2.13 Hooking
DEFINE_PR_RATE
UDFs
6.2.14 Hooking
DEFINE_PRANDTL
UDFs
6.2.15 Hooking
DEFINE_PROFILE
UDFs
6.2.16 Hooking
DEFINE_PROPERTY
UDFs
6.2.17 Hooking
DEFINE_SCAT_PHASE_FUNC
UDFs
6.2.18 Hooking
DEFINE_SOLAR_INTENSITY
UDFs
6.2.19 Hooking
DEFINE_SOURCE
UDFs
6.2.20 Hooking
DEFINE_SOX_RATE
UDFs
6.2.21 Hooking
DEFINE_SPECIFIC_HEAT
UDFs
6.2.22 Hooking
DEFINE_SR_RATE
UDFs
6.2.23 Hooking
DEFINE_TRANS
UDFs
6.2.24 Hooking
DEFINE_TURB_PREMIX_SOURCE
UDFs
6.2.25 Hooking
DEFINE_TURB_SCHMIDT
UDFs
6.2.26 Hooking
DEFINE_TURBULENT_VISCOSITY
UDFs
6.2.27 Hooking
DEFINE_VR_RATE
UDFs
6.2.28 Hooking
DEFINE_WALL_FUNCTIONS
UDFs
6.3 Hooking Multiphase UDFs
6.3.1 Hooking
DEFINE_CAVITATION_RATE
UDFs
6.3.2 Hooking
DEFINE_EXCHANGE_PROPERTY
UDFs
6.3.3 Hooking
DEFINE_HET_RXN_RATE
UDFs
6.3.4 Hooking
DEFINE_MASS_TRANSFER
UDFs
6.3.5 Hooking
DEFINE_VECTOR_EXCHANGE_PROPERTY
UDFs
6.4 Hooking Discrete Phase Model (DPM) UDFs
6.4.1 Hooking
DEFINE_DPM_BC
UDFs
6.4.2 Hooking
DEFINE_DPM_BODY_FORCE
UDFs
6.4.3 Hooking
DEFINE_DPM_DRAG
UDFs
6.4.4 Hooking
DEFINE_DPM_EROSION
UDFs
6.4.5 Hooking
DEFINE_DPM_HEAT_MASS
UDFs
6.4.6 Hooking
DEFINE_DPM_INJECTION_INIT
UDFs
6.4.7 Hooking
DEFINE_DPM_LAW
UDFs
6.4.8 Hooking
DEFINE_DPM_OUTPUT
UDFs
6.4.9 Hooking
DEFINE_DPM_PROPERTY
UDFs
6.4.10 Hooking
DEFINE_DPM_SCALAR_UPDATE
UDFs
6.4.11 Hooking
DEFINE_DPM_SOURCE
UDFs
6.4.12 Hooking
DEFINE_DPM_SPRAY_COLLIDE
UDFs
6.4.13 Hooking
DEFINE_DPM_SWITCH
UDFs
6.4.14 Hooking
DEFINE_DPM_TIMESTEP
UDFs
6.4.15 Hooking
DEFINE_DPM_VP_EQUILIB
UDFs
6.5 Hooking Dynamic Mesh UDFs
6.5.1 Hooking
DEFINE_CG_MOTION
UDFs
6.5.2 Hooking
DEFINE_DYNAMIC_ZONE_PROPERTY
UDFs
6.5.3 Hooking
DEFINE_GEOM
UDFs
6.5.4 Hooking
DEFINE_GRID_MOTION
UDFs
6.5.5 Hooking
DEFINE_SDOF_PROPERTIES
UDFs
6.6 Hooking User-Defined Scalar (UDS) Transport Equation UDFs
6.6.1 Hooking
DEFINE_ANISOTROPIC_DIFFUSIVITY
UDFs
6.6.2 Hooking
DEFINE_UDS_FLUX
UDFs
6.6.3 Hooking
DEFINE_UDS_UNSTEADY
UDFs
6.7 Common Errors While Hooking a UDF to
ANSYS FLUENT
7. Parallel Considerations
7.1 Overview of Parallel
ANSYS FLUENT
7.1.1 Command Transfer and Communication
7.2 Cells and Faces in a Partitioned Mesh
7.3 Parallelizing Your Serial UDF
7.4 Parallelization of Discrete Phase Model (DPM) UDFs
7.5 Macros for Parallel UDFs
7.5.1 Compiler Directives
7.5.2 Communicating Between the Host and Node Processes
7.5.3 Predicates
7.5.4 Global Reduction Macros
7.5.5 Looping Macros
7.5.6 Cell and Face Partition ID Macros
7.5.7 Message Displaying Macros
7.5.8 Message Passing Macros
7.5.9 Macros for Exchanging Data Between Compute Nodes
7.6 Limitations of Parallel UDFs
7.7 Process Identification
7.8 Parallel UDF Example
7.9 Writing Files in Parallel
8. Examples
8.1 Step-By-Step UDF Example
8.1.1 Process Overview
8.1.2 Step 1: Define Your Problem
8.1.3 Step 2: Create a C Source File
8.1.4 Step 3: Start
ANSYS FLUENT
and Read (or Set Up) the Case File
8.1.5 Step 4: Interpret or Compile the Source File
8.1.6 Step 5: Hook the UDF to
ANSYS FLUENT
8.1.7 Step 6: Run the Calculation
8.1.8 Step 7: Analyze the Numerical Solution and Compare to Expected Results
8.2 Detailed UDF Examples
8.2.1 Boundary Conditions
8.2.2 Source Terms
8.2.3 Physical Properties
8.2.4 Reaction Rates
8.2.5 User-Defined Scalars
8.2.6 User-Defined Real Gas Models
A. C Programming Basics
A.1 Introduction
A.2 Commenting Your C Code
A.3 C Data Types in
ANSYS FLUENT
A.4 Constants
A.5 Variables
A.5.1 Declaring Variables
A.5.2 External Variables
A.5.3 Static Variables
A.6 User-Defined Data Types
A.7 Casting
A.8 Functions
A.9 Arrays
A.10 Pointers
A.11 Control Statements
A.11.1
if
Statement
A.11.2
if-else
Statement
A.11.3
for
Loops
A.12 Common C Operators
A.12.1 Arithmetic Operators
A.12.2 Logical Operators
A.13 C Library Functions
A.13.1 Trigonometric Functions
A.13.2 Miscellaneous Mathematical Functions
A.13.3 Standard I/O Functions
A.14 Preprocessor Directives
A.15 Comparison with FORTRAN
B.
DEFINE
Macro Definitions
B.1 General Solver
DEFINE
Macros
B.2 Model-Specific
DEFINE
Macro Definitions
B.3 Multiphase
DEFINE
Macros
B.4 Dynamic Mesh Model
DEFINE
Macros
B.5 Discrete Phase Model
DEFINE
Macros
B.6 User-Defined Scalar (UDS)
DEFINE
Macros
C. Quick Reference Guide for Multiphase
DEFINE
Macros
C.1 VOF Model
C.2 Mixture Model
C.3 Eulerian Model - Laminar Flow
C.4 Eulerian Model - Mixture Turbulence Flow
C.5 Eulerian Model - Dispersed Turbulence Flow
C.6 Eulerian Model - Per Phase Turbulence Flow
Bibliography
Index
Previous:
ANSYS FLUENT 12.0 UDF Manual
Up:
ANSYS FLUENT 12.0 UDF Manual
Next:
About This Document
Release 12.0 ©
ANSYS, Inc.
2009-01-14