Fluent 08 Udfs
Fluent 08 Udfs
Fluent 08 Udfs
TRN-99-003
Introduction
What is a User Defined Function?
A UDF is a routine (programmed by the user) written in C which can be
dynamically linked with the solver.
Standard C functions
e.g., trigonometric, exponential, control blocks, do-loops, file i/o, etc.
Pre-Defined Macros
Allows access to field variable, material property, and cell geometry data.
Why build UDF’s?
Standard interface cannot be programmed to anticipate all needs.
Customization of boundary conditions, source terms, reaction rates, material
properties, etc.
Adjust functions (once per iteration)
Execute on Demand functions
Solution Initialization
UDF Basics
UDF’s assigns values (e.g., boundary data,
source terms) to individual cells and cell faces
in fluid and boundary zones.
In a UDF, zones are referred to as threads.
A looping macro is used to access individual
cells belonging to a thread.
e.g., a face-loop macro visits 563 faces
on face zone 3 (velocity-inlet).
Position of each face is available
to calculate and assign spatially
varying properties.
Thread and variable references are
automatically passed to UDF when
assigned to boundary in GUI.
Values returned to the solver by UDFs must be in SI units.
u(y) = 20 [ 1 - (y/0.0745)2]
y=0
Macros
Macros are pre-defined (Fluent) functions:
Allows definition of UDF functionality and function name ( DEFINE_ macro)
Allows access to field variables, cell information, looping capabilities, etc.
Macros are defined in header files.
The udf.h header file must be included in your source code.
#include “udf.h”
The header files must be accessible in your path.
Typically stored in Fluent.Inc/src/ directory.
Other “.h” header files may need to be included.
Depends upon relevant variables and macros needed in your UDF, e.g.,
mem.h for field variable access
metric.h for cell geometry data
dpm.h for DPM variable access
DEFINE Macros
Any UDF you write must begin with a DEFINE macro:
14 general purpose macros and 10 DPM-related macros (not listed):
DEFINE_ADJUST(name,domain); general purpose UDF called every iteration
DEFINE_INIT(name,domain); UDF used to initialize field variables
DEFINE_ON_DEMAND(name); defines an ‘execute-on-demand’ function
DEFINE_RW_FILE(name,face,thread,index); customize reads/writes to case/data files
DEFINE_PROFILE(name,thread,index); defines boundary profiles
DEFINE_SOURCE(name,cell,thread,dS,index); defines source terms
DEFINE_HEAT_FLUX(name,face,thread,c0,t0,cid,cir); defines heat flux
DEFINE_PROPERTY(name,cell,thread); defines material properties
DEFINE_DIFFUSIVITY(name,cell,thread,index); defines UDS and species diffusivities
DEFINE_UDS_FLUX(name,face,thread,index); defines UDS flux terms
DEFINE_UDS_UNSTEADY(name,face,thread,index); defines UDS transient terms
DEFINE_SR_RATE(name,face,thread,r,mw,yi,rr); defines surface reaction rates
DEFINE_VR_RATE(name,cell,thread,r,mw,yi,rr,rr_t); defines vol. reaction rates
DEFINE_SCAT_PHASE_FUNC(name,cell,face); defines scattering phase function for DOM
Looping Macros
thread_loop_c(t, d){} loop that steps through all cell threads in domain
thread_loop_f(t, d){} loop that steps through all face threads in domain
begin_c_loop(c, t){} end_c_loop(c, t) loop that steps through all cells in a thread
begin_f_loop(f, t){} end_f_loop(f, t) loop that steps through all faces in a thread
Supporting UDF’s
Because UDF’s can be very complicated, Fluent Inc. does not
assume responsibility for the accuracy or stability of solutions
obtained using UDFs that are user-generated.
Support will be limited to guidance related to communication between a
UDF and the FLUENT solver.
Other aspects of the UDF development process that include conceptual
function design, implementation (writing C code), compilation and
debugging of C source code, execution of the UDF, and function design
verification will remain the responsibility of the UDF author.
Consulting option