You can use DEFINE_PROFILE to define
a custom boundary profile or cell zone condition that varies as a
function of spatial coordinates or time. Some of the variables you
can customize are:
velocity, pressure, temperature, turbulence kinetic energy, turbulence dissipation rate
mass flux
target mass flow rate as a function of physical flow time
species mass fraction (species transport)
volume fraction (multiphase models)
wall thermal conditions (temperature, heat flux, heat generation rate, heat transfer coefficients, and external emissivity, and so on)
shell layer heat generation rate
wall roughness conditions
wall shear and stress conditions
porosity
porous resistance direction vector
wall adhesion contact angle (VOF multiphase model)
source terms
fixed variables
Note that DEFINE_PROFILE allows you
to modify only a single value for wall heat flux. Single values are
used in the explicit source term which ANSYS Fluent does not linearize.
If you want to linearize your source term for wall heat flux and account
for conductive and radiative heat transfer separately, you will need
to use DEFINE_HEAT_FLUX to specify your UDF.
Some examples of boundary profile UDFs are provided below. For
an overview of the ANSYS Fluent solution process which shows when a DEFINE_PROFILE UDF is called, refer to Figure 1.2: Solution Procedure for the Pressure-Based Segregated Solver, Figure 1.3: Solution Procedure for the Pressure-Based Coupled Solver, and Figure 1.4: Solution Procedure for the Density-Based Solver.
DEFINE_PROFILE (name, t, i)
|
Argument Type |
Description |
|---|---|
|
|
UDF name. |
|
|
Pointer to thread on which boundary condition is to be applied. |
|
|
Index that identifies the variable that is to be defined. |
Function returns
void
There are three arguments to DEFINE_PROFILE: name, t, and
i. You supply name, the name of the UDF. t and i are variables that are passed by the ANSYS Fluent solver
to your UDF.
While DEFINE_PROFILE is usually used
to specify a profile condition on a boundary face zone, it can also
be used to specify, or fix, flow variables that are held constant
during computation in a cell zone. See Fixing the Values of Variables in the User's Guide for more information on fixing
values in a cell zone boundary condition. For these cases, the arguments
of the macro will change accordingly.
Note that unlike source term and property UDFs, profile UDFs
(defined using DEFINE_PROFILE) are not called by ANSYS Fluent from within a loop on threads in
the boundary zone. The solver passes only the pointer to the thread
associated with the boundary zone to the DEFINE_PROFILE macro. Your UDF will need to do the work of looping over all of
the faces in the thread, computing the face value for the boundary
variable, and then storing the value in memory. ANSYS Fluent has provided
you with a face looping macro to loop over all faces in a thread (begin_f_loop...). See Additional Macros for Writing UDFs for details.
F_PROFILE is typically used along with DEFINE_PROFILE and is a predefined macro supplied by ANSYS Fluent. F_PROFILE stores a boundary condition in memory for
a given face and thread and is nested within the face loop as shown
in the examples below. It is important to note that the index i that is an argument to DEFINE_PROFILE is the same argument to F_PROFILE. F_PROFILE uses the thread pointer t, face identifier f, and index i to set the appropriate boundary face value in memory.
See Set Boundary Condition Value (F_PROFILE) for a description of F_PROFILE. Note that in the case of porosity profiles,
you can also use C_PROFILE to define those
types of functions. See the example UDFs provided below.
In multiphase cases a DEFINE_PROFILE UDF may be called more than once (particularly if the profile is
used in a mixture domain thread). If this must be avoided, then add
the prefix MP_ to the UDF name. The function
will then be called only once even if it is used for more than one
profile.
The following UDF, named pressure_profile, generates a parabolic pressure profile according to the equation
Note that this UDF assumes that the mesh is generated such that
the origin is at the geometric center of the boundary zone to which
the UDF is to be applied. is 0.0 at the center of the inlet and extends to
at the top and bottom of the inlet. The source code
can be interpreted or compiled in ANSYS Fluent.
/***********************************************************************
UDF for specifying steady-state parabolic pressure profile boundary
profile for a turbine vane
************************************************************************/
#include "udf.h"
DEFINE_PROFILE(pressure_profile,t,i)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y = x[1];
F_PROFILE(f,t,i) = 1.1e5 - y*y/(.0745*.0745)*0.1e5;
}
end_f_loop(f,t)
}
The function named pressure_profile has two arguments: t and i. t is a pointer to the face’s thread,
and i is an integer that is a numerical label
for the variable being set within each loop.
Within the function body variable f is declared as a face. A one-dimensional array x and variable y are declared as real data types. Following the variable declarations,
a looping macro is used to loop over each face in the zone to create
a profile, or an array of data. Within each loop, F_CENTROID returns the value of the face centroid (array x) for the face with index f that is on the
thread pointed to by t. The coordinate stored in
x[1] is assigned to variable y, and is then used to calculate the pressure. This value is then
assigned to F_PROFILE which uses the integer i (passed to it by the solver, based on your selection
of the UDF as the boundary condition for pressure in the Pressure Inlet dialog box) to set the pressure face value
in memory.
In the following example, DEFINE_PROFILE is used to generate profiles for the velocity, turbulent kinetic energy,
and dissipation rate, respectively, for a 2D fully-developed duct
flow. Three separate UDFs named
x_velocity, k_profile, and dissip_profile are defined. These functions are concatenated in a single C source
file and can be interpreted or compiled in ANSYS Fluent.
The 1/7th power law is used to specify the velocity component:
A fully-developed profile occurs when is one-half the duct height.
In this example, the mean
velocity is prescribed and the peak (free-stream)
velocity is determined by averaging across the channel.
The turbulent kinetic energy is assumed to vary linearly from a near-wall value of
to a free-stream value of
The dissipation rate is given by
where the mixing length is the minimum of
and 0.085
. (
is the von Karman
constant = 0.41.)
The friction velocity and wall shear take the forms:
The friction factor is estimated from the Blasius equation:
/**********************************************************************
Concatenated UDFs for fully-developed turbulent inlet profiles
***********************************************************************/
#include "udf.h"
#define YMIN 0.0 /* constants */
#define YMAX 0.4064
#define UMEAN 1.0
#define B 1./7.
#define DELOVRH 0.5
#define VISC 1.7894e-05
#define CMU 0.09
#define VKC 0.41
/* profile for x-velocity */
DEFINE_PROFILE(x_velocity,t,i)
{
real y, del, h, x[ND_ND], ufree; /* variable declarations */
face_t f;
h = YMAX - YMIN;
del = DELOVRH*h;
ufree = UMEAN*(B+1.);
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y = x[1];
if (y <= del)
F_PROFILE(f,t,i) = ufree*pow(y/del,B);
else
F_PROFILE(f,t,i) = ufree*pow((h-y)/del,B);
}
end_f_loop(f,t)
}
/* profile for kinetic energy */
DEFINE_PROFILE(k_profile,t,i)
{
real y, del, h, ufree, x[ND_ND];
real ff, utau, knw, kinf;
face_t f;
h = YMAX - YMIN;
del = DELOVRH*h;
ufree = UMEAN*(B+1.);
ff = 0.045/pow(ufree*del/VISC,0.25);
utau=sqrt(ff*pow(ufree,2.)/2.0);
knw=pow(utau,2.)/sqrt(CMU);
kinf=0.002*pow(ufree,2.);
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y=x[1];
if (y <= del)
F_PROFILE(f,t,i)=knw+y/del*(kinf-knw);
else
F_PROFILE(f,t,i)=knw+(h-y)/del*(kinf-knw);
}
end_f_loop(f,t)
}
/* profile for dissipation rate */
DEFINE_PROFILE(dissip_profile,t,i)
{
real y, x[ND_ND], del, h, ufree;
real ff, utau, knw, kinf;
real mix, kay;
face_t f;
h = YMAX - YMIN;
del = DELOVRH*h;
ufree = UMEAN*(B+1.);
ff = 0.045/pow(ufree*del/VISC,0.25);
utau=sqrt(ff*pow(ufree,2.)/2.0);
knw=pow(utau,2.)/sqrt(CMU);
kinf=0.002*pow(ufree,2.);
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y=x[1];
if (y <= del)
kay=knw+y/del*(kinf-knw);
else
kay=knw+(h-y)/del*(kinf-knw);
if (VKC*y < 0.085*del)
mix = VKC*y;
else
mix = 0.085*del;
F_PROFILE(f,t,i)=pow(CMU,0.75)*pow(kay,1.5)/mix;
}
end_f_loop(f,t)
}
In the following example DEFINE_PROFILE is used to fix flow variables that are held constant during computation
in a cell zone. Three separate UDFs named fixed_u, fixed_v, and fixed_ke are defined in a single C source file. They specify fixed velocities
that simulate the transient startup of an impeller in an impeller-driven
mixing tank. The physical impeller is simulated by fixing the velocities
and turbulence quantities using the fix option in ANSYS Fluent. See Fixing the Values of Variables in the User’s
Guide for more information on fixing variables.
/***********************************************************************
Concatenated UDFs for simulating an impeller using fixed velocity
************************************************************************/
#include "udf.h"
#define FLUID_ID 1
#define ua1 -7.1357e-2
#define ua2 54.304
#define ua3 -3.1345e3
#define ua4 4.5578e4
#define ua5 -1.9664e5
#define va1 3.1131e-2
#define va2 -10.313
#define va3 9.5558e2
#define va4 -2.0051e4
#define va5 1.1856e5
#define ka1 2.2723e-2
#define ka2 6.7989
#define ka3 -424.18
#define ka4 9.4615e3
#define ka5 -7.7251e4
#define ka6 1.8410e5
#define da1 -6.5819e-2
#define da2 88.845
#define da3 -5.3731e3
#define da4 1.1643e5
#define da5 -9.1202e5
#define da6 1.9567e6
DEFINE_PROFILE(fixed_u,t,i)
{
cell_t c;
real x[ND_ND];
real r;
begin_c_loop(c,t)
{
/* centroid is defined to specify position dependent profiles */
C_CENTROID(x,c,t);
r =x[1];
F_PROFILE(c,t,i) =
ua1+(ua2*r)+(ua3*r*r)+(ua4*r*r*r)+(ua5*r*r*r*r);
}
end_c_loop(c,t)
}
DEFINE_PROFILE(fixed_v,t,i)
{
cell_t c;
real x[ND_ND];
real r;
begin_c_loop(c,t)
{
/* centroid is defined to specify position dependent profiles*/
C_CENTROID(x,c,t);
r =x[1];
F_PROFILE(c,t,i) =
va1+(va2*r)+(va3*r*r)+(va4*r*r*r)+(va5*r*r*r*r);
}
end_c_loop(c,t)
}
DEFINE_PROFILE(fixed_ke,t,i)
{
cell_t c;
real x[ND_ND];
real r;
begin_c_loop(c,t)
{
/* centroid is defined to specify position dependent profiles*/
C_CENTROID(x,c,t);
r =x[1];
F_PROFILE(c,t,i) =
ka1+(ka2*r)+(ka3*r*r)+(ka4*r*r*r)+(ka5*r*r*r*r)+(ka6*r*r*r*r*r);
}
end_c_loop(c,t)
}
The following UDF, named wallheatgenerate, generates a heat generation rate profile for a planar conduction
wall. After it has been interpreted or compiled, you can activate
this UDF in the Wall boundary conditions dialog
box in ANSYS Fluent.
/* Wall Heat Generation Rate Profile UDF */
#include "udf.h"
DEFINE_PROFILE(wallheatgenerate,thread,i)
{
real source = 0.001;
face_t f;
begin_f_loop(f,thread)
F_PROFILE(f,thread,i) = source;
end_f_loop(f,thread)
}
The following UDF, named q_nx, where
x is the direction vector i, j, k, specifies
the beam direction normal to every face on the cylinder. After it
has been interpreted or compiled, you can activate this UDF in the
Wall boundary conditions dialog box in ANSYS Fluent.
/* Beam Direction Profile UDF at Semi-Transparent Walls */
#include "udf.h"
DEFINE_PROFILE(q_ni, t, position)
{
real A[3], e_n[3];
face_t f;
real At;
begin_f_loop(f, t)
{
F_AREA(A, f, t);
At = NV_MAG(A);
NV_VS(e_n,=,A,/,At);
F_PROFILE(f, t, position) = -e_n[0];
}
end_f_loop(f, t)
}
DEFINE_PROFILE(q_nj, t, position)
{
real A[3], e_n[3];
face_t f;
real At;
begin_f_loop(f, t)
{
F_AREA(A, f, t);
At = NV_MAG(A);
NV_VS(e_n,=,A,/,At);
F_PROFILE(f, t, position) = -e_n[1];
}
end_f_loop(f, t)
}
DEFINE_PROFILE(q_nk, t, position)
{
real A[3], e_n[3];
face_t f;
real At;
begin_f_loop(f, t)
{
F_AREA(A, f, t);
At = NV_MAG(A);
NV_VS(e_n,=,A,/,At);
F_PROFILE(f, t, position) = -e_n[2];
}
end_f_loop(f, t)
}
You can either use F_PROFILE or C_PROFILE to define a viscous resistance profile in
a porous zone. Below are two sample UDFs that demonstrate the usage
of F_PROFILE and C_PROFILE, respectively. Note that porosity functions are hooked to ANSYS Fluent in
the Porous Zone tab in the appropriate Fluid cell zone conditions dialog box.
The following UDF, named vis_res, generates
a viscous resistance profile in a porous zone. After it has been interpreted
or compiled and loaded, you can activate this UDF in the Fluid cell zone condition dialog box in ANSYS Fluent.
/* Viscous Resistance Profile UDF in a Porous Zone that utilizes F_PROFILE*/
#include "udf.h"
DEFINE_PROFILE(vis_res,t,i)
{
real x[ND_ND];
real a;
cell_t c;
begin_c_loop(c,t)
{
C_CENTROID(x,c,t);
if(x[1] < (x[0]-0.01))
a = 1e9;
else
a = 1.0;
F_PROFILE(c,t,i) = a;
}
end_c_loop(c,t)
}
/* Viscous Resistance Profile UDF in a Porous Zone that utilizes C_PROFILE*/
#include "udf.h"
DEFINE_PROFILE(porosity_function, t, nv)
{
cell_t c;
begin_c_loop(c,t)
C_PROFILE(c,t,nv) = USER INPUT;
end_c_loop(c,t)
}
The following UDF contains profile functions for two porous
resistance direction vectors that use C_PROFILE. These profiles can be hooked to corresponding direction vectors
under Porous Zone in the Fluid cell zone condition dialog box.
/* Porous Resistance Direction Vector Profile that utilizes C_PROFILE*/
#include "udf.h"
DEFINE_PROFILE{dir1, t, nv}
{
cell_t c;
begin_c_loop(c,t)
C_PROFILE(c,t,nv) = USER INPUT1;
end_c_loop(c,t)
}
DEFINE_PROFILE{dir2, t, nv}
{
cell_t c;
begin_c_loop(c,t)
C_PROFILE(c,t,nv) = USER INPUT2;
end_c_loop(c,t)
}
For some unsteady problems, it is desirable that the target
mass flow rate be a function of the physical flow time. This boundary
condition can be applied using a DEFINE_PROFILE UDF. The following UDF, named tm_pout2,
adjusts the mass flow rate from to
when the
physical time step is greater than
seconds. After it has been interpreted or compiled,
you can activate this UDF in the Pressure Outlet boundary condition dialog box in ANSYS Fluent by selecting the Specify target mass-flow rate option, and then choosing
the UDF name from the corresponding drop-down list.
Important: Note that the mass flow rate profile is a function of time and only one constant value should be applied to all zone faces at a given time.
/* UDF for setting target mass flow rate in pressure-outlet */
/* at t0.2 sec the target mass flow rate set to 1.00 kg/s */
/* when t0.2 sec the target mass flow rate will change to 1.35 kg/s */
#include "udf.h"
DEFINE_PROFILE(tm_pout2, t, nv)
{
face_t f ;
real flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.2)
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 1.0 kg/s \n");
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 1.0 ;
}
end_f_loop(f,t)
}
else
{
printf("Time = %f sec. \n",flow_time);
printf("Targeted mass-flow rate set at 1.35 kg/s \n") ;
begin_f_loop(f,t)
{
F_PROFILE(f,t,nv) = 1.35 ;
}
end_f_loop(f,t)
} }
This UDF is used to provide a time-varying specification of the mass
flow rate. This boundary condition can be applied using a
DEFINE_PROFILE UDF. The following UDF, named
mass_flow, initially specifies a mass flow rate of 3.0 kg/s for
the first 10 milliseconds, then increases it to 4.0 kg/s for the next 10 milliseconds, and
after that specifies 5.0 kg/s. The macro CURRENT_TIME looks up the current flow time.
Since this is a built-in RP variable, it is available to all nodes. It is more efficient
to access it once and store the value in a local variable, rather than accessing it for
every face in the face loop.
After it has been interpreted or compiled, you can activate this UDF in the Mass-Flow Inlet or Mass-Flow Outlet boundary condition dialog box in ANSYS Fluent by selecting the UDF from the Mass Flow Rate drop-down list.
#include "udf.h"
DEFINE_PROFILE(mass_flow,th,i)
{
face_t f;
real flow_time = CURRENT_TIME;
begin_f_loop(f,th)
{
if(flow_time <= 0.01)
F_PROFILE(f,th,i) = 3.0;
else if(flow_time <=0.02)
F_PROFILE(f,th,i) = 4.0;
else
F_PROFILE(f,th,i) = 5.0;
}
end_f_loop(f,th);
}
After the UDF that you have defined using DEFINE_PROFILE is interpreted (Interpreting UDFs)
or compiled (Compiling UDFs), the name
of the argument that you supplied as the first DEFINE macro argument (for example, vis_res) will
become visible and selectable in the appropriate boundary condition
dialog box (for example, the Velocity Inlet dialog
box), cell zone condition dialog box, and Shell Conduction
Layers dialog box in ANSYS Fluent. See Hooking DEFINE_PROFILE UDFs for details.