Professional Documents
Culture Documents
L t
Lecture 8
Introduction to
ANSYS FLUENT
• Two examples
• UDF support
– Compiled
• UDF code is translated once into machine language (object modules)
modules).
• Efficient way to run UDFs.
• Creates shared libraries which are linked with the rest of the solver.
• Does require a compilation step between creating/editing your UDF and using it.
User-
Initialize Begin
g Loop
p defined Solver? Solve U-Momentum Source terms
ADJUST
Solve Mass,
Source terms Solve V-Momentum Momentum,
Solve Mass Source terms
User Defined Energy,
INITIALIZE & Momentum
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
Thread Thread
B
Boundary
d (f
(face th
thread
d or zone)) Fluid
Fl id (cell
( ll
thread or
zone)
Cells Faces
– Loop
oop o
over
e faces
aces in a face
ace thread
ead f_t
thread:
ead
begin_f_loop(f, f_thread)
{ … }
end_f_loop(f, f_thread)
• The DEFINE_PROFILE macro allows the Header file “udf.h” must be included at the top
function x_velocity to be defined. of the program by the #include command
– All UDFs begin with a DEFINE_ #include "udf.h"
macro DEFINE PROFILE(x velocity thread nv)
DEFINE_PROFILE(x_velocity,thread,nv)
– x_velocity will appear in the {
solver GUI float x[3]; /* an array for the
– thread and nv are arguments of coordinates */
the DEFINE_PROFILE
_ macro, float y;
which are used to identify the
face_t f; /* f is a face
zone and variable being defined,
respectively thread index */
– The macro begin_f_loop loops
over allll ffaces f,
f pointed
i t dbby th
thread
d begin_f_loop(f,
begin f loop(f thread)
{
• The F_CENTROID macro assigns F_CENTROID(x,f,thread);
cell position vector to x[] y = x[1];
• The F_PROFILE macro appliespp the F PROFILE(f, thread, nv)
F_PROFILE(f,
velocity component to face f = 20.*(1.-
• The code is stored as a text file y*y/(.0745*.0745));
inlet_bc.c }
end f loop(f, thread)
end_f_loop(f,
}
• Add the UDF source code to the Source • Add the UDF source code to the Source
Files list File Name list
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 in
• You can also unload a library if needed. 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.
• 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.
• Beca
Becausese UDFs can be very
er complicated
complicated, ANSYS does not ass assume
me responsibilit
responsibility
for the accuracy or stability of solutions obtained using user-generated UDFs.