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
- v e.g., trigonometric, exponential, control blocks, do-loops, file i/o, etc.
- Pre-Defined Macros
- v 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).
- v 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.
Using UDFs in the Solvers
The basic steps for using UDFs in FLUENT are as follows:
STEP 1: Create a file containing the UDF source code
STEP 2: Start the solver and read in your case/data files
STEP 3: Interpret or Compile the UDF
STEP 4: Assign the UDF to the appropriate variable and zone in BC panel.
STEP 5: Set the UDF update frequency in the Iterate panel
STEP 6: Run the calculation
Example: Non-Uniform Inlet Velocity
A non-uniform inlet velocity is to be imposed on the 2D turbine vane shown below. The x-velocity variation is to be specified as:
u(y) = 20 [ 1 - (y/0.0745)2]
y = 0
Example: Source Code
The DEFINE_PROFILE macro allows the function inlet_x_velocity to be defined.
- All UDFs begin with a DEFINE_ macro.
- inlet_x_velocity will be identifiable in solver GUI.
thread and nv are dynamic references, input to the UDF to identify the zone and variable being defined, respectively.
The macro begin_f_loop loops over all faces, f, on thread.
The F_CENTROID macro assigns cell position vector to x[ ].
The F_PROFILE macro applies the velocity component to face f.
#include "udf.h"
DEFINE_PROFILE(inlet_x_velocity, thread, nv)
{
float x[3]; /* this will hold the position vector*/
float y;
face_t f;
begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f, thread, nv)=20. *(1. - y*y/(.0745*.0745));
}
end_f_loop(f, thread)
}
Example: Interpreting the UDF
The UDF is saved as velprof.c
Define ¡User Defined
¡Functions ¡Interpreted…
Click Compile
The assembly language code will
scroll past window.
به زودي تكميل خواهند شد
«پروژه های دانشگاهی و صنعتی خود را به ما بسپارید»
می توانید از طریق پست الکترونیک با ما در تماس باشید...
Email: eng_s_sadeghi@yahoo.com
















