USER DEFINED FUNCTIONS and 

CUSTOM FIELD FUNCTIONS MANUAL

Fluent


User defined functions :

Custom field functions :


Boundary conditions :

  1. Create the user defined function.
  2. Use the user defined function.

Return


Source terms :

Return


Property definitions :

Return


Initialization :

  1. Create the initialization function.
  2. Use the initialization function.

Return


The patching of initial conditions :

  1. Create a patch.
  2. Use the patch.

Return



Create the user defined function :

First, you have to copy the '/logiciels-mfn/Fluent.Inc/uns4.2/lib/udf.h' file in your work directory; your boundary condition will be described using the C language, making use of the primitive functions that are available in the udf.h file.

Example : Parabolic x velocity inlet profile (user1.c)

# include "udf.h"

void inlet_x_velocity(Thread *t, int nv)

{

Face *f;

float y, xv;

for (f = thread_face(t); f ! = NULL; f = face_next(f) {

}

The function is named inlet_x_velocity. It is associated with a zone, or thread t, and will be used to describe a variable indexed by the integer nv. It will be applied at a face, f. The variables y and uv are introduced as floats or floating point variables. These variables represent the y coordinate of the centroid of the face, and the x component of the velocity to be computed at the face, respectively. A loop is performed on all the faces , using the defined function face_next. For each face, a new value of xv is computed, and it is set at the face using the set_face_var function.

To make use of this function in fluent/uns, it must first be compiled.

Define ->User Defined Functions.

Return

Use the user defined function :

When the compilation is complete, the new function can be selected in the Velocity inlet panel, instead of a constant value.

Define-> Boundary Conditions

-> Set...

Return


Create a patch :

First, you have to create a custom field function with :

-> Define -> Custom Field Functions

Example of a parabolic velocity inlet profile

The patch panel allows you to patch different values of flow variables into different cells.

Return


Use the patch :

  1. -> Solve -> Initilize -> Initilize
  2. -> Solve -> Patch

For example in fluid-6, we can define initial X Velocity with a parabolic profile defined in Define -> Custom Field Function.

The result is :

Return


Create the initialization function :

First, you have to copy the '/logiciels-mfn/Fluent.Inc/uns4.2/lib/udf.h' file in your work directory; your initialization will be described using the C language, making use of the primitive functions that are available in the udf.h file.

Example : Initialization with a parabolic velocity profile

#include "udf.h"

void initialize()

{

Thread *t;

Cell *c;

float y,u;

t = domain_cellthread(global_domain());

for (c=thread_cell(t) ; c != NULL; c=cell_next(c)) {

y=cell_centroid_y(c);

u=10.0 * y / 0.01* (1 - y / 0.02) ;

set_cell_x_velocity(c,u);

}

}

The function is named initialize. It is associated with the fluid zone, and will be used to describe the variable x-velocity. The variables y and u are introduced as floats or floating point variables. These variables represent the y coordinate of the centroid of the face of the cell c, and the x component of the velocity to be computed at the face of the cell c, respectively. A loop is performed on all the faces , using the defined function cell_next. For each cell, a new value of u is computed, and it is set at the face of cell c using the set_cell_x_velocity function.

To make use of this function in fluent/uns, it must first be compiled.

Define ->User Defined Functions.

Return


Use the initialization function :

When the compilation is complete, you have to write in the Fluent/Uns window the following command :

(%chip-exec 'initialize)

Return