Professional Documents
Culture Documents
Fluent 13.0 Lecture08-Udf PDF
Fluent 13.0 Lecture08-Udf PDF
L t
Lecture
8
User Defined Functions
(UDFs)
Introduction to
ANSYS FLUENT
ANSYS, Inc. Proprietary
2010 ANSYS, Inc. All rights reserved.
L8-1
Release 13.0
December 2010
Outline
L8-2
Release 13.0
December 2010
Introduction
Pre-Defined Macros
Allows access to field variable, material property, and cell geometry data and many utilities
L8-3
Release 13.0
December 2010
Compiled
L8-4
Release 13.0
December 2010
Initialize
Begin
g Loop
p
Userdefined
ADJUST
Solver?
Source terms
User Defined
INITIALIZE
Segregated
PBCS
Solve U-Momentum
Source terms
Solve V-Momentum
Solve Mass
& Momentum
Solve W-Momentum
Repeat
Exit Loop
DBCS
Solve Mass,
Momentum,
Energy,
Species
Source terms
Check Convergence
Solve Energy
Update Properties
User-Defined Properties
Solve Species
Source
t
terms
User-Defined BCs
Solve Other Transport Equations as required
L8-5
Release 13.0
December 2010
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
B
Boundary
d
(f
(face th
thread
d or zone))
Fluid
Fl
id (cell
( ll
thread or
zone)
Cell
Thread
Face
Thread
Cells
Faces
L8-6
Release 13.0
December 2010
Variable
Domain
Thread
cell t
cell_t
face_t
Node
*d;
*t;
c;
f;
*node;
Fluid cell-thread
(control-volume ensemble)
Boundary face-thread
(boundary-face ensemble)
Nodes
Internal face-thread
(internal-face ensemble)
associated with cell-threads
L8-7
Release 13.0
December 2010
d: a domain pointer
ct, t: a cell thread pointer
ft,f_thread: a face thread
pointer
c: a cell thread variable
f: a face thread variable
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)
L8-8
Release 13.0
December 2010
L8-9
Release 13.0
December 2010
#include "udf.h"
DEFINE PROFILE(x velocity thread nv)
DEFINE_PROFILE(x_velocity,thread,nv)
{
float x[3]; /* an array for the
coordinates */
float y;
face_t f;
/* f is a face
thread index */
begin_f_loop(f,
begin
f loop(f thread)
{
F_CENTROID(x,f,thread);
y = x[1];
F PROFILE(f, thread, nv)
F_PROFILE(f,
= 20.*(1.y*y/(.0745*.0745));
}
end f loop(f, thread)
end_f_loop(f,
L8-10
Release 13.0
December 2010
User-Defined
Interpreted UDF
Functions
Define
Compiled
L8-11
User-Defined
Functions
Interpreted
Open the boundary condition panel for the surface to which you would like to
apply the UDF
Switch from Constant to udf x_velocity in the drop-down list.
DEFINE PROFILE in the UDF code
The macro name is the first argument of DEFINE_PROFILE
L8-12
Release 13.0
December 2010
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.
L8-13
Release 13.0
December 2010
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.
L8-14
Release 13.0
December 2010
Solution adjustment
Executes every iteration.
User-defined
User defined surface and volumetric
reactions
Read/write to/from case and data files
Read order and write order must be same.
Execute-on-Demand
E
t
D
d capability
bilit
Does not participate in the solver iterations
L8-15
Release 13.0
December 2010
#include "udf.h
DEFINE_INIT(my_init_function, domain)
{
cell t c;
cell_t
Thread *ct;
real xc[ND_ND];
thread_loop_c(ct,domain)
{
begin_c_loop (c,ct)
{
C_CENTROID(xc,c,ct);
if (sqrt(ND_SUM(pow(xc[0]-0.5,2.),
pow(xc[1] - 0.5,2.),
0 5 2 )
pow(xc[2] - 0.5,2.))) < 0.25)
C_T(c,ct) = 600.;
else
C_T(c,ct)
( , ) = 300.;
;
}
end_c_loop (c,ct)
}
}
L8-16
Release 13.0
December 2010
DEFINE Macros
L8-17
Release 13.0
December 2010
Returns nodes/cell
Returns faces/cell
Returns nodes/face
Returns coordinates of cell centroid in array x[]
[]
Returns coordinates of face centroid in array x[]
Returns area vector in array A[]
Returns cell volume
Returns cell volume (axisymmetric domain)
real current flow time (in seconds)
real current physical time step size (in seconds)
real previous flow time (in seconds)
real flow time two steps back in time (in seconds)
real previous physical time step size (in seconds)
integer number of time steps
integer number of iterations
L8-18
Release 13.0
December 2010
C_R(c,t); Density
C_P(c,t); Pressure
C_U(c,t); U-velocity
C_V(c,t); V-velocity
C_W(c,t); W-velocity
C_T(c,t); Temperature
(c,t); Enthalpy
py
C_H(c,t);
C_K(c,t); Turbulent kinetic energy (k)
C_D(c,t); Turbulent dissipation rate ()
C_O(c,t); Specific dissipation of k ()
C YI(c t i)
C_YI(c,t,i);
Species mass fraction
C_UDSI(c,t,i); UDS scalars
C_UDMI(c,t,i); UDM scalars
C_DUDX(c,t);
C_DUDY(c,t);
C_DUDZ(c,t);
C_DVDX(c,t);
C_DVDY(c,t);
C_DVDZ(c,t);
C_DWDX(c,t);
C_DWDY(c,t);
C_DWDZ(c,t);
Velocity derivative
Velocity derivative
Velocity derivative
V l it derivative
Velocity
d i ti
Velocity derivative
Velocity derivative
C_MU_L(c,t);
C_MU_T(c,t);
C_MU_EFF(c,t);
C K L(c t);
C_K_L(c,t);
Laminar viscosity
Turbulent viscosity
Effective viscosity
Laminar thermal
conductivity
Turbulent thermal
conductivity
Effective thermal
conductivity
Specific heat
Gas constant
C_K_T(c,t);
C K EFF(c t);
C_K_EFF(c,t);
Velocity derivative
Velocity derivative
Velocity derivative
C_CP(c,t);
C_RGAS(c,t);
L8-19
Release 13.0
December 2010
Define
User-Defined
Memory
L8-20
Release 13.0
December 2010
Define
User-Defined
Scalars
Unsteady function
DEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su)
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
p
Can be used to solve the electromagnetic field equations.
ANSYS, Inc. Proprietary
2010 ANSYS, Inc. All rights reserved.
L8-21
Release 13.0
December 2010
Additional Macros
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
L8-22
Release 13.0
December 2010
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.
Attend the Advanced UDF Training course
Beca
Because
se 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.
Support will be generally be limited to guidance related to communication between
UDFs and the FLUENT solver, we cannot help debug clients UDFs.
L8-23
Release 13.0
December 2010