Udf

download Udf

of 6

description

udf

Transcript of Udf

1

See section 10 of fluent user manual for user-defined functions and examples

1. Steady velocity function

A UDF is used to introduce this parabolic profile at the inlet. The C source code ( vprofile.c) is shown below. The function makes use of Fluent-provided solver

functions that are described in Section 5.3.

/***********************************************************************/

/* vprofile.c */

/* UDF for specifying steady-state velocity profile boundary condition */

/***********************************************************************/

#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)

{

real x[ND_ND]; /* this will hold the position vector */

real y;

face_t f;

begin_f_loop(f, thread)

{

F_CENTROID(x,f,thread);

y = x[1];

F_PROFILE(f, thread, position) = 20. - y*y/(.0745*.0745)*20.;

}

end_f_loop(f, thread)

}

The function, named inlet_x_velocity, is defined using DEFINE_PROFILE and has two arguments: thread and position. Thread is a pointer to the face's

thread, and position is an integer that is a numerical label for the variable being set within each loop.

The function begins by declaring variable f as a face_t data type. A one-dimensional array x and variable y are declared as real data types. A looping macro is

then used to loop over each face in the zone to create a profile, or an array of data. Within each loop, F_CENTROID outputs the value of the face centroid (array x)

for the face with index f that is on the thread pointed to by thread. The y coordinate stored in x[1] is assigned to variable y, and is then used to calculate the x

velocity. This value is then assigned to F_PROFILE, which uses the integer position (passed to it by the solver based on your selection of the UDF as the

boundary condition for x velocity in the Velocity Inlet panel) to set the x velocity face value in memory.

To make use of this interpreted UDF in FLUENT, you must first compile it.

Define User-Defined Functions Interpreted...

In the Interpreted UDFs panel, name your function in the Source File Name field. If necessary, enter your C preprocessor type in the CPP Command Name

field and the size of the stack under Stack Size. Turn on Display Assembly Listing to see an assembly listing in your console window as the function compiles.

Click on Compile and then Close the panel.

To select this user-defined function as the velocity boundary condition for the zone of choice, open the Velocity Inlet panel.

In the X-Velocity drop-down list, select udf inlet_x_velocity, the name that was given to the function above. This function will now be used, rather than the value

of (in this example) 0 that appears in the X-Velocity field. Click on OK to accept the new boundary condition and close the panel.

In this example, a temporally periodic velocity boundary condition will be applied to the inlet of a tube using a UDF. The velocity has the form

(10.1.1)

The tube is 1 m long with a radius of 0.2 m. It is assumed to be filled with air with a density of 1 kg/m 3and a viscosity of 2 kg/m-s. The velocity of the air

fluctuates about an equilibrium value, v 0, of 20 m/s, with an amplitude of 5 m/s and at a frequency of 10 rad/s.

2. Unsteady Velocity specification :

The source code for the velocity profile UDF ( unsteady.c) is shown below.

/**********************************************************************/

/* unsteady.c */

/* UDF for specifying a transient velocity profile boundary condition */

/**********************************************************************/

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity, thread, position)

{

face_t f;

begin_f_loop(f, thread)

{

real t = RP_Get_Real("flow-time");

F_PROFILE(f, thread, position) = 20. + 5.0*sin(10.*t);

}

end_f_loop(f, thread)

}

The function, named unsteady_velocity, is defined using the DEFINE_PROFILE macro. The utility RP_Get_Real("flow-time") is used to look up the real

flow time, which is assigned to the variable t. (See Section 6.9 for details on RP_Get_Real.)

Before you can compile this UDF, you must specify an unsteady flow calculation in the Solver panel.

Define Models Solver...

Next you can open the Interpreted UDFs panel. Enter the name of the function in the text entry box under Source File Name and, if necessary, the name of your

C preprocessor. Turn on Display Assembly Listing. Click on Compile and then Close the panel.

Define User-Defined Functions Interpreted...

The sinusoidal velocity boundary condition defined by the UDF can now be selected for the X-Velocity in the inlet zone. In the Velocity Inlet panel, simply select

udf unsteady_velocity in the drop-down list to the right of the X-Velocity field, and click on OK.

3. Momentum Source :

/******************************************************************/

/* UDF that adds momentum source term and derivative to duct flow */

/******************************************************************/

#include "udf.h"

#define CON 20.0

DEFINE_SOURCE(cell_x_source, cell, thread, dS, eqn)

{

real source;

if (C_T(cell,thread) 288 K) fluid has a molecular value for the liquid (5.5 kg/m-s), while the viscosity for the cooler region ( T < 286 K) has a

much larger value (1.0 kg/m-s). In the intermediate temperature range (286 K 288 K), the viscosity follows a linear profile that extends between the two

values given above:

(10.3.1)

This model is based on the assumption that as the liquid cools and rapidly becomes more viscous, its velocity will decrease, thereby simulating solidification. Here,

no correction is made for the energy field to include the latent heat of freezing. The C source code for the UDF is shown below.

/*********************************************************************/

/* UDF for specifying a temperature-dependent viscosity property */

/*********************************************************************/

#include "udf.h"

DEFINE_PROPERTY(cell_viscosity, cell, thread)

{

real mu_lam;

real temp = C_T(cell, thread);

if (temp > 288.)

mu_lam = 5.5e-3;

else if (temp > 286.)

mu_lam = 143.2135 - 0.49725 * temp;

else

mu_lam = 1.;

return mu_lam;

}

The function, named cell_viscosity, is defined on a cell using DEFINE_PROPERTY. Two real variables are introduced: temp, the value of

C_T(cell,thread), and mu_lam, the laminar viscosity computed by the function. The value of the temperature is checked, and based upon the range into which it

falls, the appropriate value of mu_lam is computed. At the end of the function, the computed value for mu_lam is returned to the solver.

To make use of a user-defined property, you will use the Materials panel. In the drop-down list for Viscosity, select the user-defined option.

Once you select this option, the User-Defined Functions panel opens, from which you can select the appropriate function name. In this example, only one is

available, but in another example, you might have several functions from which to choose. (Recall that if you need to compile more than one interpreted UDF, the

functions can be concatenated prior to compiling. See Section 7.2.1 for details.)

5. Wall Heat Flux

The wall heat flux function ( DEFINE_HEAT_FLUX) can be used to modify

the way that the solver computes the heat flux between

a wall and the neighboring fluid cells. For example, you can customize

the heat transfer coefficient or the law-of-the-wall for

temperature. The UDF presented below uses an internal heat transfer

coefficient to specify the wall heat flux. It is another example

of a UDF that utilizes the ADJUST function to adjust a computed value,

and it is executed as a compiled UDF.

The diffusive heat flux coefficients ( cid) are specified in this UDF.

The diffusive heat flux ( qid) will then be computed by

FLUENT using the following equation:

qid = cid[0] + cid[1]*C_T(c0,t0) - cid[2]*F_T(f,t) -

cid[3]*pow(F_T(f,t),4)

/***********************************************************************/

/* UDF for specifying the diffusive heat flux between a wall and

*/

/* neighboring cells

*/

/***********************************************************************/

#include "udf.h"

static real h = 0.; /* heat transfer coefficient (W/m^2 C)

*/

DEFINE_ADJUST(htc_adjust, domain)

{

/* Define the heat transfer coefficient. */

h = 120;

}

DEFINE_HEAT_FLUX(heat_flux, f, t, c0, t0, cid, cir)

{

cid[0] = 0.;

cid[1] = h;

cid[2] = h;

cid[3] = 0.;

}