Fluent UDF 16.0 L01 Introduction PDF
Fluent UDF 16.0 L01 Introduction PDF
Introduction
16.0 Release
Programs written in C
Similar mechanism used to develop models in Fluent
– Powerful and efficient
Extends the functionality of ANSYS Fluent
– Initial and boundary conditions
– Material properties
– Material and energy transfer through source terms
– Modify solution variables
– Adding extra flow equations
– And many more …
Typically compiled to DLLs/shared object libraries
– Loaded only when required
Adiabatic wall
inlet outlet
𝝅𝒙
T(x) = 𝟑𝟎𝟎 + 𝟏𝟎𝟎 𝐬𝐢𝐧 𝟎.𝟎𝟎𝟓
16.0 Release
Programming practices
– Simplicity, Clarity and Generality
• Naming conventions
• Macros and comments
• Algorithms and data structures
• Design principles
• Testing
7 © 2015 ANSYS, Inc. June 7, 2015
User Access to the Fluent Solver
SOLVERS
Segregated PBCS DBCS
User-
Initialize Begin Loop defined Solver? Solve U-Momentum Source terms
ADJUST
Solve Mass,
Solve V-Momentum
User Defined Solve Mass Momentum,
Source terms Source terms
INITIALIZE & Energy,
Solve W-Momentum
Repeat Momentum Species
Solve Mass Continuity;
Update Velocity
Exit Loop Check Convergence
Solve Energy
Update Properties
Solve Species Source
User-Defined Properties terms
Solve Turbulence Equation(s)
User-Defined BCs
Solve Other Transport Equations as required
return-value-type function-name(parameter-list)
{
function body
}
• BUT: An array name cannot be set to a new value. It is fixed to the value
set when it is defined as an array.
ar = ip; /* This will cause a compilation error. */
• Arithmetic Operators
= (assignment)
+, -, *, /,
% (modulo reduction)
++ (increment) /* i++ is post-increment (i=i+1) */
-- (decrement) /* j–- is post-decrement (j=j-1) */
E.g.: x = 1;
y = x++; /* x is now 2, y is 1*/
• Logical Operators
<, >, >=, <= , ==, !=
• Assignments
E.g.: x += y; /* is equivalent
+=, *=, -=, /= to x = x + y */
E.g.:
real y = 2;
real x1 = (y < 0 ? 5 : 10);
real x2 = (y >= 0 ? 5 : 10);
Result: x1 = 10 and x2 = 5
It enables the linking of extra functionality using “shared objects” in Unix and Dynamic
Linked Libraries (DLLs) in windows systems.
This is a very convenient mechanism for linking in UDFs which allows a seamless
connection between the main program and the user functions
Users familiar with other “procedural” languages such as FORTRAN will be familiar with
most of the ideas and syntax used in C
• Each individual cell can be accessed by using a cell index of type cell_t and the cell thread
(the zone which contains the cell)
• Each individual face (boundary or internal) can be accessed by using a face index of type
face_t and the face thread (the zone which contains the face)
25 © 2015 ANSYS, Inc. June 7, 2015
Mesh Data Types (2)
• Some mesh or solver data types have a capital letter. These are actually data
structures in the C language and are usually passed between functions as pointers to
these structures.
• Examples of how these data types are defined are shown below:
Node Coordinates:
• NODE_X(nn) Node x–coord; (with Node *nn;)
Many more
• NODE_Y(nn) Node y–coord; macros available,
• NODE_Z(nn) Node z–coord; see UDF Manual.
• The cells on either side of a face (f,ft) can be accessed using the macros:
ct0 = THREAD_T0(ft); C0
ct1 = THREAD_T1(ft);
c0 = F_C0(f,ft); C1
c1 = F_C1(f,ft);
A face’s area vector
points from C0 to C1
• The macros THREAD_T0(ft) and THREAD_T1(ft)only need the
face thread, not the face index.
• Boundary zones such as inlets will connect to a cell zone on one side
with THREAD_T0(ft) but THREAD_T1(ft) will return NULL, a
special pointer which signifies there is no zone on the other side.
where F_AREA returns the face normal vector A and A face’s area vector
NV_MAG(A) the magnitude of the vector A. points from C0 to C1
• The faces that bound a cell can be accessed using this loop :
int nf;
for(nf = 0; nf < C_NFACES(c,ct); nf++)
{
f = C_FACE(c,ct,nf);
ft= C_FACE_THREAD(c,ct,nf);
}
33 © 2015 ANSYS, Inc. June 7, 2015
Macros used for Control
• Data_Valid_P() if (!Data_Valid_P())
return;
TRUE if data is available, FALSE if not.
• FLUID_THREAD_P(t0)
TRUE if threat t0 is a fluid thread, FALSE if not.
• NULLP(ct)
TRUE if a pointer is NULL, FALSE if not.
• NNULLP(ct) if(NNULLP(THREAD_T1(ft)))
{ ... Do things on neighbouring
TRUE if a pointer is NOT NULL, FALSE if not. cell thread.
}
path\ANSYS Inc\v160\fluent\fluent16.0.0\src\udf
directory.
• At the beginning of every UDF source code file, the header file MUST be included.
#include “udf.h”