Introductory FLUENT Training: User-Defined Functions
Introductory FLUENT Training: User-Defined Functions
User-Defined Functions
Introductory FLUENT
Training
• Two Examples
• UDF Support
User-
Initialize Begin Loop defined Solver? Solve U-Momentum Source terms
ADJUST
Solve Mass,
Source terms Solve V-Momentum Momentum,
User Defined Solve Mass Source terms
& Momentum Energy,
INITIALIZE Species
Solve W-Momentum
Repeat
Solve Mass Continuity;
Update Velocity
The cell zones and face zones of a model (in the finite-volume
scheme) are accessed in UDFs as Thread data types
Thread is a FLUENT-defined data type
Domain
Domain
Cell
Cell face
face
Thread Thread
Thread
Boundary (face thread or zone) Fluid (cell
thread or
zone)
Cells Faces
• The DEFINE_PROFILE macro allows the Header file “udf.h” must be included at the top
function x_velocity to of the program by the #include command
be defined. #include "udf.h"
– All UDFs begin with a DEFINE_ DEFINE_PROFILE(x_velocity,thread,nv)
macro {
– x_velocity will appear in the float x[3]; /* an array for the
solver GUI coordinates */
– thread and nv are arguments of float y;
the DEFINE_PROFILE macro, face_t f; /* f is a face
which are used to identify the
zone and variable being defined, thread index */
respectively
– The macro begin_f_loop loops begin_f_loop(f, thread)
over all faces f, pointed by thread {
F_CENTROID(x,f,thread);
• The F_CENTROID macro assigns
y = x[1];
cell position vector to x[] F_PROFILE(f, thread, nv)
• The F_PROFILE macro applies the = 20.*(1.-
velocity component to face f y*y/(.0745*.0745));
• The code is store as a text file }
inlet_bc.c end_f_loop(f, thread)
}
• Add the UDF source code to the Source • Add the UDF source code to the Source
Files list File Name list.
• Click Build to compile and link the code • Click Interpret
• If no errors, click Load to load the library • The assembly language code will display
• You can also unload a library if needed. in the FLUENT console
/define/user-defined/functions/manage • Click Close if there is no error
• Open the boundary condition panel for the surface to which you
would like to apply the UDF
• You can change the Profile Update Interval in the Run Calculation
panel (default value is 1).
– This setting controls how often (either iterations or time steps if
unsteady) the UDF profile is updated.
• The figure on the left shows the velocity field through the 2D elbow.
• The figure on the right shows the velocity vectors at the inlet. Notice
the imposed parabolic velocity profile.
– Flux Function
• DEFINE_UDS_FLUX(name,face,thread,index)
– Unsteady function
• DEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su)
• If statements are required in order to associate multiple flux and transient
functions with each UDS
• Example
– Can be used to solve the electromagnetic field equations.
ANSYS, Inc. Proprietary April 28, 2009
© 2009 ANSYS, Inc. All rights reserved. 8-22 Inventory #002600
User-Defined Functions
Additional Macros Training Manual
• Still many more macros are available in the following categories and
are documented in UDF Manual:
– Turbulence Models
– Multiphase models
– Reacting flows
– Dynamic mesh
– Input/Output
• Start your own UDF program by modifying an existing UDF program which is
close to what you want to do, then step by step add your own code to the
program.