Advanced User Defined Function (UDF) Tutorials
Advanced User Defined Function (UDF) Tutorials
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
The problem considered in this tutorial is shown schematically in Figure 1: Problem Schematic (p. 1)
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Position Dependent Porous Media
The domain is divided into two fluid zones. In the fluid-2 cell zone, an X-momentum source term is in-
cluded for each cell using UDF. This source term models the effect of a porous plug on the flow in the
X-direction and is given by:
The finite-volume solver of ANSYS Fluent expects the source term to be linearized according to the
following convention:
where the superscript * represents the value at the previous iteration. B (called dS[eqn]} in the UDF
macro) can be coded explicitly by using currently known value of φ, and the entire S is returned by
DEFINE_SOURCE. For the simple source of X-momentum equation in this problem,
For more details, examine the source code (porous plug.c) as shown in the Appendix (p. 9).
4. Preparation
1. Copy the files (porous_plug.msh.gz and porous_plug.c) to the working folder.
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
General
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Position Dependent Porous Media
5.3. Models
• Select the k-epsilon turbulence model.
Note
You will use the default fluid properties of air for this problem. Hence, you need not
make any changes to the material properties.
Note
The UDF can be compiled as well as interpreted. In this tutorial, use the compiled option.
Compile the UDF (porous plug.c).
1. Click the Add... button in the Source Files section to open the Select File dialog.
3. Click Build.
Note
A Warning dialog box will appear, warning you to make sure that the UDF source files
are in the same folder that contains the case and data files. Click OK to close the
Warning dialog box.
You can view the compilation history in the log file that is saved in your working folder.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
1. Enable Source Terms and then click the Source Terms tab.
2. Click Edit... for X Momentum to open the X Momentum sources dialog box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Position Dependent Porous Media
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
b. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list in the
Turbulence group box.
b. Retain the selection of Intensity and Viscosity Ratio from the Specification Method drop-down
list in the Turbulence group box.
c. Retain 5 % for Backflow Turbulent Intensity and 10 for Backflow Turbulent Viscosity Ratio.
5.7. Solution
1. Initialize the solution.
Note
Hybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the
section 28.11 Hybrid Initialization, in the ANSYS Fluent User's Guide.
Note
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Position Dependent Porous Media
5.8. Postprocessing
1. Display the pressure contours.
c. Click Display (Figure 4: Pressure Contours (p. 9)) and close the Contours dialog box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
5.9. Appendix
The contents of the UDF source code are as follows:
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Position Dependent Porous Media
/*******************************************************************/
/* */
/* Position-Dependent Porous Media */
/* */
/*******************************************************************/
#include "udf.h"
return source;
}
5.10. Results
Figure 4: Pressure Contours (p. 9) shows that fluid-2 is causing pressure drop in the system and thus
acting as a porous plug. Figure 5: Velocity Vectors (p. 9) shows that the fluid flows preferentially near
the bottom of the channel due to the effect of the source term on the axial momentum of the fluid.
5.11. Summary
This tutorial demonstrated the use of UDF for specifying source terms. User-defined source terms can
be useful for introducing additional physics into the simulation, and can usually be modeled as sources
or sinks of mass, momentum, energy, species etc.
Note
When you are comfortable with the present exercise, you can try modifying the UDF to
specify momentum sources for both the X and Y momentum equations. The present UDF
can be copied and suitably modified for the Y momentum equation. Both functions will then
reside in the UDF file, and be accessible to the solver upon compilation.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Sinusoidal Wall Temperature Variation
1. Introduction
This tutorial examines fluid flow through a two dimensional channel, where one wall of the channel
has user-defined temperature profile applied to it. The purpose of this tutorial is to demonstrate the
ability of ANSYS Fluent to use user-defined functions (UDFs) to specify a position-dependent variable
on the wall boundary condition.
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
The problem considered in this tutorial is shown schematically in Figure 1: Problem Schematic (p. 2).
Air at 300 K enters a 2D channel which has an insulated upper wall and a heated lower wall. The tem-
perature on the lower wall varies sinusoidally with x-position according to:
The calculation will be performed assuming steady state, incompressible, and laminar flow in the
channel.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Sinusoidal Wall Temperature Variation
4. Preparation
1. Copy the files (channel.msh.gz and wallprof.c) to the working folder.
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
General
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
5.3. Models
Enable energy equation.
Note
You will use the default fluid properties of air for this problem. Hence, you need not make
any changes to the material properties.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Sinusoidal Wall Temperature Variation
Note
The UDF can be compiled as well as interpreted. In this tutorial, you will use the interpreted
option.
2. Select the source file (wallprof.c) in the Select File dialog box.
Note
If you want to use the C preprocessor that ANSYS Fluent. has supplied, you can enable
the Use Contributed CPP option.
Note
The Stack Size should be 10000 unless the number of local variables in your function
causes the stack to overflow. Its value should be set to a number that is greater than
the number of local variables used.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
a. Click the Thermal tab and select Temperature from the Thermal Conditions list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Sinusoidal Wall Temperature Variation
5.6. Solution
1. Change the Absolute Criteria for continuity to 0.0001.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
Hybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the
section 28.11 Hybrid Initialization, in the ANSYS Fluent User's Guide.
Note
5.7. Postprocessing
Display the filled contours of static temperature.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Sinusoidal Wall Temperature Variation
3. Click Display (Figure 4: Contours of Static Temperature (p. 8)) and close the Contours dialog box.
5.8. Appendix
The contents of the UDF source code are as follows:
/*******************************************************************/
/* */
/* User-Defined Functions for sinusoidal temperature profile */
/* */
/*******************************************************************/
include "udf.h"
#define PI 3.141592654
if (!Data_Valid_P()) return;
begin_f_loop(f, thread)
{
F_CENTROID(r,f,thread);
x = r[0];
F_PROFILE(f, thread, position) = 300.+100.*sin(PI*x/0.005);
}
end_f_loop(f, thread)
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
5.9. Results
The contour plot in Figure 4: Contours of Static Temperature (p. 8) shows that the temperature on
the wall and in the fluid reaches a peak at the center of the channel due to the peak in the prescribed
wall temperature.
5.10. Summary
This tutorial demonstrated the use of UDF for specifying profiles on boundaries. You can apply this
approach to the other boundary condition types such as pressure and velocity inlets, and pressure
outlets.
When you are comfortable with this problem, try modifying the UDF to specify heat flux rather than
temperature.
• Replace the following line in the udf code with the specified heat flux expression.
• Hook the new profile to the wall boundary before running the new case.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Temperature Dependent Viscosity
1. Introduction
This tutorial examines the flow of liquid metal through a two dimensional channel. The viscosity of the
liquid metal is modeled as a function of the temperature using a user-defined function (UDF).
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
The problem considered in this tutorial is shown schematically in Figure 1: Problem Schematic (p. 1).
As the symmetry condition is imposed at the centerline, only half the channel is modeled. The wall of
the channel is split into two parts: wall-2, which has a temperature of 280 K and wall-3, which has a
temperature of 290 K. The temperature-dependent viscosity of the liquid metal will respond to this
change in wall temperature.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Temperature Dependent Viscosity
Strategy
The function cell_viscosity is defined on a cell using DEFINE_PROPERTY. Two real variables are
introduced:
The value of the temperature is checked and based upon its range, the appropriate value of mu is
computed. At the end of the function, the computed value for mu is returned to the solver.
The molecular viscosity of the liquid metal will be defined as a function of temperature which is given
as follows:
where,
4. Preparation
1. Copy the files (user-vis.msh.gz and viscosity.c) to the working folder.
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
General
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
5.3. Models
Enable energy equation.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Temperature Dependent Viscosity
2. Select the source file (viscosity.c) in the Select File dialog box.
Note
If you want to use the C preprocessor that ANSYS Fluent has supplied, you can enable
Note
The Stack Size should be 10000 unless the number of local variables in your function
causes the stack to overflow. Its value should be set to a number that is greater than
the number of local variables used.
5.5. Materials
Modify the fluid material.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
5. Select user-defined from the Viscosity drop-down list and click OK to close User-Defined Functions
dialog box.
Note
A Question dialog box opens, asking whether to overwrite air. Click Yes.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Temperature Dependent Viscosity
a. Click the Thermal tab and select Temperature from the Thermal Conditions list.
a. Click the Thermal tab and select Temperature from the Thermal Conditions list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Temperature Dependent Viscosity
5.7. Solution
1. Initialize the flow field from velocity-inlet-6.
Solution Initialization
c. Click Initialize.
Note
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
5.8. Postprocessing
Display the filled contours of molecular viscosity..
3. Click Display (Figure 4: Contours of Molecular Viscosity (p. 9)) and close the Contours dialog box.
5.9. Appendix
The UDF (viscosity.c) is used to specify the temperature-dependent molecular viscosity in each
cell. You can open the UDF in a separate editor and view its contents to understand the structure and
function.
#include "udf.h"
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Temperature Dependent Viscosity
else
mu = 1.0;
}
return mu;
}
The above equations are applied to each and every cell which is associated to the thread (in this case
a fluid zone). This UDF will be called from the Create/Edit Materials dialog box where the user-defined
is specified for Viscosity.
5.10. Results
Figure 4: Contours of Molecular Viscosity (p. 9) shows that when the warmer fluid enters the channel
from the left and encounters the cooler wall further on, its viscosity increases according to the user-
defined viscosity relation.
5.11. Summary
This tutorial demonstrated the use of UDFs for specifying a user-defined property.
Important
This capability is available only for viscosity and thermal conductivity (density and specific
heat cannot be specified through UDFs).
Note
When you are comfortable with this exercise, you can try modifying the UDF to specify
temperature-dependent thermal conductivity. You can copy the source code for the viscosity
UDF and change the appropriate lines to calculate thermal conductivity. You need to access
the thermal conductivity UDF in the Create/Edit Materials dialog box in the same way as
viscosity.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
UDFs for a User-Defined Scalar
1. Introduction
ANSYS Fluent solves the transport equation for a user-defined scalar (UDS) in the same way as it solves
the transport equation for a scalar in the core equations, such as a species mass fraction. The UDS
capability can be used to implement a wide range of physical models in magneto-hydrodynamics,
electromagnetics, and more.
In this tutorial you will learn to solve a general scalar diffusion equation with the possible types of
boundary condition (BC) at the boundary (or a part of the boundary) of the domain.
• Dirichlet BC: Φ = D0
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
As shown in the problem illustration, the problem is a 2D rectangle, with constant flux, constant value,
and mixed boundary conditions along the boundary edges.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
UDFs for a User-Defined Scalar
Γ = 0.162 W/(m K)
Φ∞ = 550oC
hC = 20 W/(m2K)
4. Preparation
1. Copy the files (laplace.msh.gz, mixedbc.c, and transientMixedBC.c) to the working folder.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
General
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
UDFs for a User-Defined Scalar
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
Note
Click OK in the Information dialog box that appears informing you of the change in
the material properties or methods.
1. Click the Add... button in the Source Files section to open the Select File dialog.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
3. Click Build.
Note
A Warning dialog box will appear, warning you to make sure that the UDF source files
are in the same folder that contains the case and data files. Click OK to close the
Warning dialog box.
You can view the compilation history in the log file that is saved in your working folder.
5.4. Materials
2. Click Edit... for UDS Diffusivity and enter 0.162 for the Coefficient and close the UDS Diffusion
Coefficients dialog box..
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
UDFs for a User-Defined Scalar
4. Click Change/Create.
Note
A Question dialog box appears, asking you whether to overwrite air. Click Yes.
b. Select Specified Value from the User Scalar 0 drop-down list in the User-Defined Scalar
Boundary Condition group box.
c. Enter 80 for UDS Scalar 0 in the User-Defined Scalar Boundary Value group box.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
b. Ensure that Specified Value is selected from the User Scalar 0 drop-down list in the User-Defined
Scalar Boundary Condition group box.
c. Retain 0 for UDS Scalar 0 in the User-Defined Scalar Boundary Value group box.
a. Click the UDS tab and select Specified Value from the User Scalar 0 drop-down list in the User-
Defined Scalar Boundary Condition group box.
b. Select udf scalarMixedBC::libudf from the User Scalar 0 drop-down list in the User-Defined
Scalar Boundary Value group box.
4. Set the similar boundary conditions for bottomwall as set for rightwall.
Note
The following equation gives mixed boundary condition for rightwall and bottomwall.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
UDFs for a User-Defined Scalar
where,
hC = 20
Φ∞ = 550
Surface → Point...
b. Retain the selection of Iteration from the X Axis and Get Data Every drop-down lists.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
d. Select User Defined Scalars... and Scalar-0 from the Field Variable drop-down lists.
Note
Hybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the
section 28.11 Hybrid Initialization, in the ANSYS Fluent User's Guide.
Note
As the value of Φ remains constant after 40 iterations (Figure 3: Scaled Residuals (p. 9)
and Figure 4: Monitor Plot (p. 10)), you can consider that the solution is converged.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
UDFs for a User-Defined Scalar
5.7. Postprocessing
• Display the contours of Φ.
a. Select User Defined Scalars... and Scalar-0 from the Contours of drop-down lists.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Figure 5: Contours of Φ
Since the problem is partially set up in the steady case, here only the unique steps for the setup
of the unsteady solver are mentioned.
General → Transient
Note
A Warning dialog box opens, asking you to ensure that the UDF source files are
in the same folder that contains the case and data files. Click OK.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 11
UDFs for a User-Defined Scalar
Calculation Activities
Run Calculation
d. Click Calculate.
b. Select User Defined Scalars... and Scalar-0 from the Contours of drop-down lists.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
12 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Figure 6: Contours of Φ at t = 1 s
Note
The diffusion of Φ into the domain due to high Φ∞ in the ambient is clearly visible via
the mixed (convective) boundary condition.
Figure 7: Contours of Φ at t = 3 s
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 13
UDFs for a User-Defined Scalar
Figure 8: Contours of Φ at t = 4 s
Figure 9: Contours of Φ at t = 5s
— ∇ . (Γ∇Φ) = 0
This is the Laplace's equation. Solving the Laplaces's equation using the ANSYS Fluent UDS solver does
not necessarily require user-defined functions (UDFs). You can activate the UDS from the graphical user
interface. ANSYS Fluent UDS provides only Dirichlet and Neumann conditions for the boundaries. Hence,
you need to use the UDF to apply the mixed boundary condition for the UDS equation.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
14 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix A: Steady-State Solver
For a generic cell c0 adjacent to the boundary, the diffusive flux across the boundary face f of the cell
is expressed as follows:
Using the mid-point rule of surface integral, the diffusive flux can be approximated as:
1. The primary gradient is evaluated implicitly along the line connecting the cell centroid c0 to the centroid
face f.
2. It is corrected by a secondary gradient (or cross diffusion) term evaluated explicitly by the gradient obtained
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 15
UDFs for a User-Defined Scalar
If you designate the secondary gradient term in the above equation as β0, and as
Abe, equations can be written as:
The mixed boundary condition for the UDS is ready to be specified by boundary profile Φf in the
equation above through the UDF macro DEFINED_PROFILE().
UDF Code
The UDF code for steady state is as follows:
/***************************************************************************************/
/* Implementation of the mixed boundary condition for a UDS (or multiple): */
/* q = hC ( phi - PHI_inf) */
/***************************************************************************************/
#include "udf.h"
#include "sg.h" /* needed for the boundary and secondary gradient macros */
/*=====================================================================================*/
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
16 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix B: Unsteady Solver
/* ====================== */
face_t f;
hC=HTC;
PHI1_inf=TINF;
begin_f_loop(f, thread)
{
if (NULLP(T_STORAGE_R_NV(t0, SV_UDST_G(phi1))))
beta0=0; /*if gradient is not allocated and stored yet,
bypass the following macro (it happens
when case/data files are being read */
else
BOUNDARY_SECONDARY_GRADIENT_SOURCE(beta0, SV_UDSI_G(phi1), dG,
es, A_by_es, gamma);
It has to be solved with the same boundary conditions and given initial condition. When the transient
term is ∂(ρΦ)/∂t, ANSYS Fluent can readily handle this unsteady UDS term when you enable the unsteady
solver (either first or second-order). But if the transient term of the user's equation is not the same as
the given form, you must supply the unsteady term through the DEFINE_UDS_UNSTEADY() macro.
For example, in the above equation, c is a variable. For an unsteady heat conduction problem in dimen-
sional form it represents ρcp of the solid material.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 17
UDFs for a User-Defined Scalar
where,
Hence,
where,
Su = the explicit part (because it is expressed by known values at the previous time-step)
You can rewrite the volume integral of the unsteady term as:
UDF Code
The UDF code for unsteady solver is as follows:
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
18 of ANSYS, Inc. and its subsidiaries and affiliates.
Further Improvements
/**************************************************************************************/
/* Implementation of */
/* */
/* the unsteady term for the user-defined scalar (1st-order) */
/* */
/**************************************************************************************/
volume=C_VOLUME(c, t);
/* the transient term is moved to the RHS of the equation and is split
into two parts---check the FVM algorithm for detail. First-order
backward differencing is implemented below: */
*apu = -cp*volume/deltaTime;
*su = cp*volume*C_UDSI_M1(c, t, i)/deltaTile;
Note
Before compiling the source code, add the program fragment to the code given in
8. Further Improvements
It can be shown that the following finite-difference backward differencing approximation to ∂Φ/∂t is
second-order accurate in time:
It involves the values of Φ at three different time levels: Φn,Φn-1, and Φn-2.
You can use the first-order implicit UDF code in the appendix as a useful guide to come up with your
own second-order implicit unsteady UDF code. A few hints for the exercise:
• In the first step of unsteady simulation (n = 1), Φn–2 is not available yet (Φn-1 condition). Therefore you
can use the first-order formulation in this step in order to advance to the second time step (n = 2).
• The transient term is moved to the right hand side of the equation as a source term. Hence, remember
to get the signs right.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 19
UDFs for a User-Defined Scalar
where,
A = source
B = dS[eqn]
A and B can be coded explicitly by using currently known value of Φ. The general UDF for all variables
is DEFINE_SOURCE(). To use it for a UDS (Φ), you need to hook it up in the boundary condition dialog
box to the cell zone where Φ is be solved.
There are various ways to linearize a source term, but the general requirement is that B (the slope)
should be non-positive to enhance convergence of the iterative solution process. The convergence is
better with more negative slope.
9. Summary
In this tutorial, you modeled the UDS scalar diffusion equation by using UDFs in ANSYS Fluent. Some
details of the finite-volume method used by the solver were carefully discussed when implementing
terms in the governing equation and BC. However, treatment of the advective term∇. Φ( is the
general flux vector), is not covered here.
Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
20 of ANSYS, Inc. and its subsidiaries and affiliates.
Modeling Uniform Fluidization in 2D Fluidized Bed
1. Introduction
The prediction of pressure drop in a uniformly fluidized bed is a problem of long standing interest in
the process industry. The Eulerian models in ANSYS Fluent provide an important modeling tool for
studying dense phase particulate flow involving complex inter-phase momentum transfer.
Despite rigorous mathematical modeling of the associated physics, the drag laws used in the model
continue to be semi-empirical in nature. Therefore, it is crucial to use a drag law that correctly predicts
the incipient or minimum fluidization conditions where the bed of particles is essentially in a state of
suspension as a result of the balance between interfacial drag and body forces.
The purpose of this tutorial is to study the hydrodynamics and bubble formation in a fluidized bed over
a period of time. It also demonstrates how to customize a drag law for granular gas-solid flow.
• Use the Eulerian models to predict the pressure drop in an uniformly fluidized bed.
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
This tutorial will not cover the mechanics of using the Eulerian models. It will focus on the application
of these models. For more information refer to Section 25.5 Setting Up the Eulerian Model in the ANSYS
Fluent User's Guide. For information about user-defined functions (UDF) refer to the ANSYS Fluent UDF
Manual.
3. Problem Description
One of the drag laws in ANSYS Fluent is the Syamlal-O'Brien drag law. This law works for a large variety
of problems, but has to be tuned properly for predicting the minimum fluidization conditions accurately.
The default Syamlal-O'brien drag law is as follows: The fluid-solid exchange coefficient is
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Modeling Uniform Fluidization in 2D Fluidized Bed
where υr,s is the terminal velocity coefficient for the solid phase.
with A = αl4.14 and B = 0.8 αl1.28 for α ≤ 0:85 and with B = αl2.65 2 for α ≥ 0:85
The default constants of 0.8 and 2.65 predict a minimum fluidization of 21 cm/s. The experimentally
observed minimum fluidization for this particular case is 8 cm/s. Therefore, by changing the constants
we can tune the drag law to predict minimum fluidization at 8 cm/s. After some mathematical manipu-
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
lation, these constants come out to be 0.281632 and 9.07696 respectively. Therefore, these values have
to be used to predict the correct bed behavior and are passed to the code through user-defined functions.
The problem considered is a 1m x 0.15m fluidized bed as shown in Figure 1: Problem Schematic (p. 2).
The inlet air enters in at 0.25 m/s and the top is modeled as a outflow. The bed is packed with granular
solids at 0.55 volume fraction (close to packing).
4. Preparation
1. Copy the files (bp.msh.gz and bp_drag.c) to the working folder.
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Note
All entries in setting up this case are in SI units, unless otherwise specified.
5.1. Mesh
Read the mesh file (bp.msh.gz).
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Modeling Uniform Fluidization in 2D Fluidized Bed
General → Transient
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
5.3. Models
Select the Eulerian multiphase model.
2. Retain the default settings and click OK to close the Multiphase Model dialog box.
5.4. Materials
1. Modify the properties for air.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
c. Click Change/Create.
b. Enter 2600 kg/m3 for Density and 1.7894e-05 kg/m-s for Viscosity.
c. Click Change/Create.
Note
A Question dialog box will appear asking if you want to overwrite air. Click No.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Modeling Uniform Fluidization in 2D Fluidized Bed
Note
The UDF contains two arguments s_col and f_col. These refer to the indices of the phases
appearing in the second and first columns of the table in the interaction dialog box respect-
ively. Therefore in this case s_col refers to the index of gas phase which is 0 and f_col
refers to the index for solids which is equal to 1.
1. Click the Add... button in the Source Files section to open the Select File dialog.
4. Click Build.
Note
A Warning dialog box will appear, warning you to make sure that the UDF source files
are in the same folder that contains the case and data files. Click OK to close the
Warning dialog box.
You can view the compilation history in the log file that is saved in your working folder.
5.6. Phases
1. Define primary phase.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Modeling Uniform Fluidization in 2D Fluidized Bed
c. Enable Granular.
d. Enter 0.0003 m for Diameter, and select syamlal-obrien from the Granular Viscosity drop-
down list.
Note
Check the column numbers where the two phases appear in the Phase Interaction
dialog box. In this case solid and gas appear in the first and second columns respectively.
These columns are used to specify the phase indices in the argument list for the UDF.
Phases → Interaction...
Click the Interaction... button to open the Phase Interaction dialog box.
a. In the Drag tab, select user-defined from the drop-down list in the Drag Coefficient group box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
1. Select gas from the Phase drop-down list and click Edit....
2. Select solid from the Phase drop-down list and click the Edit... button to open the Velocity Inlet dialog
box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Modeling Uniform Fluidization in 2D Fluidized Bed
1. Enable Gravity and enter -9.81 m/s2 for Gravitational Acceleration in the Y direction.
2. Enable Specified Operating Density, and enter 1.2 kg/m3 for Operating Density.
5.9. Solution
1. Mark a region for adaption.
Adapt → Region...
a. Enter 0.15 m for X Max and Y Max in the Input Coordinates group box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
You can display and manipulate the generated adaption registers using the Man-
age... button in the Region Adaption dialog box.
Solution Controls
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 11
Modeling Uniform Fluidization in 2D Fluidized Bed
Note
If you wish to patch a constant value, enter that value in the Value field. If you
want to patch a previously-defined field function, enable the Use Field Function
option and select the appropriate function in the Field Function list.
e. Click Patch.
5. Enable autosaving of the data files for every 100 time steps.
Calculation Activities
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
12 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
d. Select Time Step from the When drop-down list for all.
b. Select Phases... and Volume Fraction from the Contours of drop-down lists.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 13
Modeling Uniform Fluidization in 2D Fluidized Bed
Run Calculation
d. Click Calculate.
5.10. Postprocessing
1. Display contours of volume fraction.
a. Read the data file for the 200th time step (bp-1-00200.dat).
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
14 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
b. Display filled contours of volume fraction for solid, at 0.2 sec (Figure 3: Contours of Volume Fraction
of solid (t = 0.2 s) (p. 15)).
c. Similarly display contours at 0.9 sec (Figure 4: Contours of Volume Fraction of solid (t = 0.9 s) (p. 15)),
and 1.4 sec (Figure 5: Contours of Volume Fraction of solid (t = 1.4 s) (p. 16)).
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 15
Modeling Uniform Fluidization in 2D Fluidized Bed
2. View the animation for the fluidization process using the .tiff files.
5.11. Results
Typically, the constants set to 0.8 and 2.65 in the default Syamlal-O'Brien drag law have to be modified
to balance the interfacial drag with the weight of the bed at minimum fluidization. If this is not done,
the correct bubbling pattern will not be predicted, leading to incorrect predictions of pressure drop
which is the most important objective of such simulations.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
16 of ANSYS, Inc. and its subsidiaries and affiliates.
Calculation of Flow Uniformity
1. Introduction
The purpose of this tutorial is to provide guidelines and recommendations for setting up and solving
a flow uniformity problem with the help of a user-defined function (UDF).
• Use the UDF to calculate the flow uniformity indexes for steady-state flow.
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
The problem considers a 3D flow passage. A schematic of the problem is shown in Figure 1: Problem
Schematic (p. 2). There are two flow inlets and an outlet. The postprocessing planes (post-01, post-
02, post-03, and post-04) have already been created with the mesh.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Calculation of Flow Uniformity
4. Preparation
1. Copy the files (flow-uniformity.msh.gz, cat-general.c, and input.txt) to the working
folder.
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
General
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
General → Scale...
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Calculation of Flow Uniformity
5.3. Models
Select the k-epsilon turbulence model.
Note
You will use the default fluid properties of air for this problem. Hence, you need not make
any changes to the material properties.
a. Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method
drop-down list.
c. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
a. Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method
drop-down list.
c. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.
a. Retain selection of Normal to Boundary from the Backflow Direction Specification Method
drop-down list.
b. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.
5.5. Solution
1. Initialize the flow field from vel-in-large.
Solution Initialization
c. Click Initialize.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Calculation of Flow Uniformity
Note
5.6. Postprocessing
1. Display the filled contours of velocity magnitude.
c. Select post-01, post-02, post-03, and post-04 from the Surfaces list.
Note
ii. Select all the surfaces except the default-interior ones from the Surfaces list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
a. Select the surfaces wall, press-out, vel-in-large, vel-in-small, wall:014, wall:016, wall:017, under
the list of Names in the Scene Description dialog box.
b. Click Display... in the Geometry Attributes group box to open the Display Properties dialog
box.
ii. Disable Edges, Lines, and Nodes in the Visibility group box.
iv. Set the sliders for Red, Green, and Blue to 255 in the Colors group box.
vi. Click Apply and close the Display Properties dialog box (Figure 3: Contours of Velocity Mag-
nitude (p. 8)).
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Calculation of Flow Uniformity
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
The input file (input.txt) has to be processed before executing the UDF. For the
details about the input file, see Appendix A: Details of the Input File (p. 10).
i. Click the Add... button in the Source Files section to open the Select File dialog.
Note
For details about the UDF file (cat-general.c), refer to Appendix B: Contents
of UDF (p. 11).
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Calculation of Flow Uniformity
Note
A Warning dialog box will appear, warning you to make sure that the UDF
source files are in the same folder that contains the case and data files. Click
OK to close the Warning dialog box.
You can view the compilation history in the log file that is saved in your working folder.
f. The output on the screen and in the file are shown in Appendix C: Output of UDF (p. 15). The UDF
reads the input file (input.txt) and generates the output file (output.txt) automatically in
each simulation. The parameters of the output are explained in Appendix D: General Structure of
UDF (p. 16). If you want to preserve the old results, rename the output.txt file. Otherwise the
data for the next run will be appended to the old file.
• Each line after the first line has the parameters of a face-zone. They are defined in the following order:
– POST_BOUNDARY_ZONE_ID
– POST_CELL_ZONE_ ID_1
– POST_CELL_ZONE_ ID_2
– L_XX
– L_YX
– L_ZX
– L_XY
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix B: Contents of UDF
– L_YY
– L_ZY
2. POST_CELL_ZONE_ ID_1 and POST_CELL_ZONE_ ID_2 are the IDs of two adjacent cell zones of the
postprocessing face zone. They are the same if the face zone is inside a cell zone.
3. L_XX, L_YX, L_ZX are the direction cosines of the x-axis of the local coordinate. The UDF uses a local
coordinate for each face zone to compute the flow uniformity. The local x-axis will be the major axis,
and local y-axis will be the minor axis. You should define the direction of longer length as x-axis, and
the other direction in the same plane as y-axis.
4. L_XY, L_YY, L_ZY are the direction cosines of the y-axis of the local coordinate. The UDF uses a local
coordinate for each face zone to compute the flow uniformity. The local x-axis will be the major axis,
and local y-axis will be the minor axis. You should define the direction of longer length as x-axis, and
the other direction in the same plane as y-axis.
• The definition of the direction cosines may affect the eccentricity because it reflects the local flow distri-
bution on the plane. The gamma does not depend on the direction cosines.
int ncount;
int npost;
float L_XX[50];
float L_YX[50];
float L_ZX[50];
float L_XY[50];
float L_YY[50];
float L_ZY[50];
float L_XZ[50];
float L_YZ[50];
float L_ZZ[50];
if((fpin=fopen("input.txt","r"))==NULL)
{
printf("Input file does not exist!");
}
fscanf(fpin, "%d",&npost);
for(i=0;i<npost;i++)
{
fscanf(fpin,"%d %d %d %f %f %f %f %f %f", &POST_BOUNDARY_ZONE_ID[i], &POST_CELL_ZONE_ID_1[i],
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 11
Calculation of Flow Uniformity
L_XZ[i]=L_YX[i]*L_ZY[i]-L_ZX[i]*L_YY[i];
L_YZ[i]=L_ZX[i]*L_XY[i]-L_XX[i]*L_ZY[i];
L_ZZ[i]=L_XX[i]*L_YY[i]-L_XY[i]*L_YX[i];
}
fclose(fpin);
}
static void init_udm()
{
Thread *tc;
cell_t c;
Domain *domain;
domain = Get_Domain(1);
thread_loop_c(tc,domain)
{
begin_c_loop(c,tc)
{
C_UDMI(c,tc,0)=0;
C_UDMI(c,tc,1)=0;
C_UDMI(c,tc,2)=0;
C_UDMI(c,tc,3)=0;
}
end_c_loop(c,tc)
}
ncount=0;
}
face_t f, f_vmax;
cell_t c0, c1;
Thread *tf, *tc0, *tc1;
FILE *fp;
Domain *domain;
domain = Get_Domain(1);
if((fp=fopen("output.txt", "r"))==NULL)
{
fp=fopen("output.txt","w+");
fprintf(fp, "post-face eccent gamma unif_35 unif_65 vratio vmax \n");
fclose(fp);
}
fp=fopen("output.txt", "a");
x_min=BIGNUM;
y_min=BIGNUM;
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
12 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix B: Contents of UDF
x_max=-BIGNUM;
y_max=-BIGNUM;
tf=Lookup_Thread(domain, POST_BOUNDARY_ZONE_ID[flag]);
begin_f_loop(f,tf)
{
f_node_loop(f,tf,k)
{
xn[0]=NODE_X(F_NODE(f,tf,k));
xn[1]=NODE_Y(F_NODE(f,tf,k));
xn[2]=NODE_Z(F_NODE(f,tf,k));
x_node_local = NVD_DOT(xn,L_XX[flag],L_YX[flag],L_ZX[flag]);
y_node_local = NVD_DOT(xn,L_XY[flag],L_YY[flag],L_ZY[flag]);
x_min=MIN(x_node_local,x_min);
x_max=MAX(x_node_local,x_max);
y_min=MIN(y_node_local,y_min);
y_max=MAX(y_node_local,y_max);
}
}
end_f_loop(f,tf)
x_mid=0.5*(x_min + x_max);
y_mid=0.5*(y_min + y_max);
L_major = x_max - x_min;
L_minor = y_max - y_min;
Message("================================================================\n");
Message("post-%d\n",flag);
Message("================================================================\n");
Message("Geometry information:\n");
Message("(x_min, x_mid, x_max) = (%f, %f, %f) [m]\n", x_min, x_mid, x_max);
Message("(y_min, y_mid, y_max) = (%f, %f, %f) [m]\n", y_min, y_mid, y_max);
Message("(L_major, L_minor) = (%f, %f) [m]\n\n", L_major, L_minor);
eccent_x=2.0*(x_vmax-x_mid)/L_major;
eccent_y=2.0*(y_vmax-y_mid)/L_minor;
eccent=sqrt(eccent_x*eccent_x+eccent_y*eccent_y);
Message("Eccentricity information:\n");
Message("(x_vmax, y_vmax) = (%f, %f) [m]\n", x_vmax, y_vmax);
Message("eccentricity = (%f, %f) -> %f \n\n",eccent_x, eccent_y, eccent);
Message("vmax = %f m/s occurs at face %d\n", vmax, f_vmax);
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 13
Calculation of Flow Uniformity
unif_35=a_35/A_tot*100;
unif_65=a_65/A_tot*100;
fprintf(fp, "post%d %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f \n", flag, eccent, gamma,
unif_35, unif_65, vratio, vmax);
fclose(fp);
}
static void set_udm(int flag)
{
/* NOTE: THIS ROUTINE REQUIRES ALLOCATION OF */
/* 4 USER DEFINED MEMORY LOCATIONS IN FLUENT */
#define X_PRIME 0
#define Y_PRIME 1
#define Z_PRIME 2
#define V_MAG 3
float xc[ND_ND];
Thread *tc1,*tc2;
cell_t c;
Domain *domain;
domain = Get_Domain(1);
tc1=Lookup_Thread(domain, POST_CELL_ZONE_ID_1[flag]);
tc2=Lookup_Thread(domain, POST_CELL_ZONE_ID_2[flag]);
begin_c_loop(c,tc1)
{
C_CENTROID(xc,c,tc1);
C_UDMI(c,tc1,X_PRIME)=NVD_DOT(xc,L_XX[flag],L_YX[flag],L_ZX[flag]);
C_UDMI(c,tc1,Y_PRIME)=NVD_DOT(xc,L_XY[flag],L_YY[flag],L_ZY[flag]);
C_UDMI(c,tc1,Z_PRIME)=NVD_DOT(xc,L_XZ[flag],L_YZ[flag],L_ZZ[flag]);
C_UDMI(c,tc1,V_MAG)=sqrt(C_VMAG2(c,tc1));
}
end_c_loop(c,tc1)
if(POST_CELL_ZONE_ID_1[flag] != POST_CELL_ZONE_ID_2[flag])
{
begin_c_loop(c,tc2)
{
C_CENTROID(xc,c,tc2);
C_UDMI(c,tc2,X_PRIME)=NVD_DOT(xc,L_XX[flag],L_YX[flag],L_ZX[flag]);
C_UDMI(c,tc2,Y_PRIME)=NVD_DOT(xc,L_XY[flag],L_YY[flag],L_ZY[flag]);
C_UDMI(c,tc2,Z_PRIME)=NVD_DOT(xc,L_XZ[flag],L_YZ[flag],L_ZZ[flag]);
C_UDMI(c,tc2,V_MAG)=sqrt(C_VMAG2(c,tc2));
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
14 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix C: Output of UDF
}
end_c_loop(c,tc2)
}
}
DEFINE_ON_DEMAND(Uniform_steady)
{
int i=0;
read_input();
init_udm();
for(i=0; i<npost;i++)
{
set_udm(i);
cat_post(i);
}
}
Note
• The postprocessing face must be a real face zone and should be created in preprocessing.
You can use the EXECUTE ON DEMAND macro for calculations which do not participate in the
solution iterations, such as postprocessing.
Eccentricity information:
(x_vmax, y_vmax) = (-0.000981, -0.003447) [m]
eccentricity = (-0.032702, -0.114892) -> 0.119455
Eccentricity information:
(x_vmax, y_vmax) = (-0.000981, -0.008046) [m]
eccentricity = (-0.032702, -0.268192) -> 0.270179
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 15
Calculation of Flow Uniformity
================================================================
Geometry information:
(x_min, x_mid, x_max) = (-0.044035, -0.029980, -0.015925) [m]
(y_min, y_mid, y_max) = (-0.010000, -0.000000, 0.009999) [m]
(L_major, L_minor) = (0.028110, 0.019999) [m]
Eccentricity information:
(x_vmax, y_vmax) = (-0.019842, -0.002659) [m]
eccentricity = (0.721307, -0.265830) -> 0.768732
Eccentricity information:
(x_vmax, y_vmax) = (-0.004882, 0.003414) [m]
eccentricity = (-0.162746, 0.113784) -> 0.198577
Output in a file:
post-face eccent gamma unif_35 unif_65 vratio vmax
post0 0.119 0.791 46.124 15.249 2.436 1.905
post1 0.270 0.795 58.618 20.263 2.209 1.718
post2 0.769 0.958 100.000 98.426 1.113 2.293
post3 0.199 0.787 36.440 13.180 2.652 2.079
• set_udm: It computes the local coordinate in the selected cell zones based on the directional cosines
provided by users. It stores the local coordinates in udm-0, udm-1, and udm-2, and velocity magnitude
of the selected cell zones in udm-3.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
16 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix D: General Structure of UDF
where,
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 17
Calculation of Flow Uniformity
Compute the location (x and y coordinates) of the maximum velocity and the distance between this
location and the center of the face. Find the maximum velocity and velocity ratio.
Velocity ratio ( ν_ratio) can be defined as the ratio of the maximum velocity to the average velocity.
3. Calculation of ow uniformity.
Compute the uniformity index (area based), gamma, and vel_space. The uniformity index is based
on these reference velocities: ν_65 (65% of the maximum velocity) and ν_35 (35% of the maximum
velocity).
where,
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
18 of ANSYS, Inc. and its subsidiaries and affiliates.
Summary
4. Output parameters.
a. On the screen:
• vratio = ν_ratio
• gamma = γ
• eccent = ε
• gamma = γ
• unif_35 = φ_35
• unif_65 = φ_65
10. Summary
In this tutorial, a flow uniformity problem was set up and solved for a steady state flow with the help
of UDF
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 19
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
20 of ANSYS, Inc. and its subsidiaries and affiliates.
Modeling Effect of Sedimentation Concentration in a Secondary
Clarifier using a UDF
1. Introduction
The purpose of this tutorial is to include a user-defined scalar equation (sediment concentration) in the
calculation process. With the help of the user-defined functions (UDFs), a Boussinesq-like approximation
is considered. The buoyancy effects due to density gradients are accounted for by a gravity source term
in the vertical (axial) momentum equation. The damping effect of stratification on turbulence is introduced
by means of source terms in the transport equations of turbulence kinetic energy (k) and its rate of
dissipation (e). A rheology function is also considered to account for the increased viscosity of highly
concentrated sludge mixtures.
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
Some knowledge of UDF structure, compilation and linking is desired. For more details about user-
defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
The problem considered is a circular, center-feed secondary clarifier with inclined bottom and central
sludge withdrawal. The central inlet includes two baffles: a vertical inlet baffle that forces the inflow to
enter the tank at a relatively low position; and a horizontal deflection plate that prevents short circuiting
from the inlet to the sludge withdrawal. Axisymmetry is assumed, and the flow and settling processes
are modelled in a radial section on a two-dimensional grid (References (p. 22)).
4. Preparation
1. Copy the files (clarifier.msh.gz and clarifier.c) to the working folder.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
Display → Views...
a. Click the Camera... button to open the Camera Parameters dialog box.
c. Set X, Y, Z to -1, 0, 0.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
General
1. Enable Transient.
Note
If you check in the Scale Mesh dialog box you will notice that Ymin value is negative.
For an axisymmetric problem this results in an error while checking the mesh. The axis
of rotation must be the X-axis and the mesh must lie on or above the y=0 line. .
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
5.3. Models
Select the k-epsilon turbulence model.
Retain the default selection of Standard Wall Functions from the Near-Wall Treatment list and close
the Viscous Model dialog box.
Note
Based on Reynolds number calculation at the inlet, the flow is expected to be turbulent, so
an appropriate turbulence model is required.
1. Click the Add... button in the Source Files section to open the Select File dialog.
2. Select the file clarifier.c and click OK in the Select File dialog box.
Note
A Warning dialog box will appear, warning you to make sure that the UDF source files
are in the same folder that contains the case and data files. Click OK to close the
Warning dialog box. All related files following the compilation will be stored in the
sedimentation folder.
You can view the compilation history in the log file that is saved in your working folder.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
5. Click Load so that all the macros are available in the graphical user interface.
For more details regarding the resolved system of equations, refer to Appendix B: Compiling the
UDF (p. 21).
Note
Besides the continuity, momentum, and turbulence transport equation, a new passive scalar
equation is defined to determine local particle concentration. Although the standard GUI
does not allow the direct activation of the concentration equation, you can introduce the
computation of a general transport equation, whose terms are adapted to yield the final
sediment concentration equation.
c. Retain the selection of default from the Unsteady Function drop-down list.
Note
ANSYS Fluent displays an Information dialog box informing that available material properties
or methods have changed. Click OK in the Information dialog box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
Note
A user-defined memory (UDM) is a customized variable defined within the UDF code. UDMs
can store any expression combining flow variables and user constants. They are easily accessed
and can be used for postprocessing (contours, vectors, XY plots, etc.).
In this tutorial, five UDMs have been defined to store quantities as shown in the following table:
Table 1:
UDM Description
0 Settling Velocity
1 UDS Diffusion Coefficient
2 Gravity Source Term
3 Turbulence Kinetic Rate Source Term
4 Turbulence Dissipation Rate Source Term
5.7. Materials
Materials → Edit...
Note
2. Select turbulent_diff::sedimentation and click OK to close the User-Defined Functions dialog box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
3. Click Change/Create.
6. Select user-defined from the Viscosity drop-down list and select viscosity::sedimentation in the User-
defined Functions dialog box.
7. Select user-defined from the UDS Diusivity drop-down list and select turbulent_diff::sedimentation
in the User-Defined Functions dialog box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
a. Click the Edit... button next to Axial Momentum to open the Axial Momentum sources dialog
box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
4. Similarly, enable the UDF source term udf turb_k_source::sedimentation for Turbulent Kinetic Energy.
a. Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method
drop-down list.
c. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.
f. Click the UDS tab and select Specified Value from the User Scalar 0 drop-down list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
a. Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method
drop-down list.
c. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
a. Retain selection of Normal to Boundary from the Backflow Direction Specification Method
drop-down list.
b. Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.
5.10. Solution
1. Define the solution control parameters.
Solution Methods
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 11
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
d. Select Second Order Implicit from the Transient Formulation drop-down list.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
12 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
e. Select User Defined Scalars... and Scalar-0 from the Field Variable drop-down lists.
Solution Initialization
c. Click Initialize.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 13
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
1. Enter 10 for Time Step Size and 7300 for Number of Time Steps.
2. Click Calculate.
Note
The hydraulic residence time (hrt = ratio of volume to flow rate) of the sedimentation
tank is approximately 7300 seconds. It is assumed that the steady-state solution is
achieved for 10 times the hrt (conservative estimation).
The size of the time step size is a compromise between numerical stability and compu-
tational time. A time step of 10 seconds is chosen which yields a total number of 7300
time steps to reach a steady-state solution.
The outcome of the simulation is the steady-state clarifier behavior and intermediate
time-dependent information will be neglected.
5.11. Postprocessing
1. Display contours of particle concentration, User Scalar 0.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
14 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 15
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
Surface → Iso-Surface...
a. Select Mesh... and Y-Coordinate from the Surface of Constant drop-down lists.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
16 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
b. Select Mesh... and X-Coordinate from the Field Functions drop-down lists.
c. Click the Select button and enter x-in in the New Function Name text entry box.
d. Click Define.
i. Select User Defined Scalars... and Scalar-0 from the Field Functions drop-down list and click
Select.
iv. Enter mgl-1 for the New Function Name and click Define.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 17
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
a. In the list of Options disable Position on X Axis and ensure that only Node Values is enabled.
b. Select Custom Field Functions.... and x-in0 from the Y Axis Function drop-down lists.
c. Select User Defined Scalars.... and Scalar-0 from the X Axis Function drop-down lists.
e. Click Plot.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
18 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Display → Colormap...
Note
Changing the number format (type and precision) eases results interpretation for a non-
technical audience.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 19
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
8. Display concentration contours in mg/l units (Custom Field Function and mgl-1).
6. Appendix A: Parameters
The loading conditions for this reference case can be found on the publication in References (p. 22).
For simplicity, some key parameters are summarized in the following table:
Table 2:
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
20 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix B: Compiling the UDF
1. Continuity Equation:
2. X-Momentum Equation:
where,
: DEFINE_SOURCE(X_mom_src,c,tc,ds,eqn)
3. Y-Momentum Equation:
where,
Gb =
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 21
Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF
where,
C3εGb: DEFINE_SOURCE(turb_e_source,c,tc,,ds,eqn)
where,
: DEFINE_UDS_FLUX(settling_flux,f,tf,i)
: DEFINE_DIFFUSIVITY(turbulent_diff,f,tf,i)
8. References
Computing Shear Flow and Sludge Blanket in Secondary Clariers Djamel Lakehal, Peter Krebs, Johan
Krijgsman, Wolfgang Rodi
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
22 of ANSYS, Inc. and its subsidiaries and affiliates.
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating
Membrane
1. Introduction
The purpose of this tutorial is to illustrate how to use a user-defined function (UDF) to control the dy-
namic mesh of a generic flow device with a rotating blade and a flexible oscillating membrane. The
motion of the rotating blade and the oscillating membrane have a large amplitude which requires the
use of local remeshing. The rotation of the blade, the oscillation of the membrane, and the sliding of
the nodes along the top wall of the housing are defined and controlled by means of a UDF that utilizes
the three macros specific to the dynamic mesh model.
• Use the three DM-specific macros in a UDF to control the dynamic mesh.
2. Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tu-
torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some
steps in the setup and solution procedure will not be shown explicitly.
Some knowledge of UDF structure, compilation and linking is desired. For more details about user-
defined functions (UDF) refer to the ANSYS Fluent UDF Manual.
3. Problem Description
A generic flow device with a flexible oscillating membrane beneath it is shown in Figure 1: Problem
Schematic (p. 2). The valve radius is 0.1 m.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane
4. Preparation
1. Copy the files (butterfly-flex.msh.gz and butterfly-flex.c) to the working folder.
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.
Note
The path to the .bat fie which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default,
click the Show More Options button to view the additional settings.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
As the mesh file is read, ANSYS Fluent will report the progress in the console.
General → Transient
General → Check
Note
ANSYS Fluent will perform various checks on the mesh and will report the progress in
the console. Ensure that the reported minimum volume is a positive number.
General → Display
a. Click Colors....
i. Select Color by ID from the Options list in the Mesh Colors dialog box.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane
a. Click the Add... button in the Source Files section to open the Select File dialog.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
d. Click Build.
Note
A Warning dialog box will appear, warning you to make sure that the UDF source
files are in the same folder that contains the case and data files. Click OK to close
the Warning dialog box.
You can view the compilation history in the log file that is saved in your working folder.
e. Click Load to load the newly created UDF library so that all the macros are available in the graph-
ical user interface.
Dynamic Mesh
Note
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane
i. Click Smoothing tab and enter 0.3 for the Spring Constant Factor.
iii. Click Remeshing tab and specify the parameters as given in the following table:
Table 1:
Parameter Value
Minimum Length Scale (m) 0.00236
Maximum Length Scale (m) 0.02
Maximum Cell Skewness 0.65
Size Remeshing Interval 1
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
6 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane
b. Retain the default selection of Rigid Body in the Type group box.
Note
The valve motion is defined about its center of gravity (CG) located at (0,0). This is
important in the case of rotation.
e. In the Meshing Options tab, specify a value of 0.002 m for Cell Height.
f. Click Create.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Setup and Solution
Note
The objective is to allow all nodes located on the top wall to slide along that wall as
the tip of the valve moves past it. Thus define a horizontal line and set wall-top zone
as a deforming zone.
c. In the Motion Attributes tab select moving_arc::libudf-flex from the Mesh Motion UDF drop-
down list.
Note
d. Click Create.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane
3. Click Preview.
Note
The valve will move through 90 degrees and assume the position shown in Figure 3: Mesh
Display After Mesh Motion (p. 10).
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Appendix
6. Appendix
/*********************************************************************/
/* UDF to compute the orientation of a rotating valve, based on a
specified rotational speed.
cg_omega[0] = 0.0;
cg_omega[1] = 0.0;
cg_omega[2] = omega;
}
/***********************************************************************/
/*
UDF to define a horizontal plane. One will thus be able to project
boundary nodes upon this plane.
*/
/***********************************************************************/
/***********************************************************************/
/*
UDF to define a wall that is initially a circular arc, but then
oscillates sinusoidally with time.
*/
/***********************************************************************/
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 11
Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane
x = NODE_X (node_p);
ymag = sqrt (R*R - x*x) + 0.03;
yfull = ymag - 0.1;
y = - 0.1 + yfull * sin(theta);
NODE_Y (node_p) = y;
}
}
}
end_f_loop (f, tf);
}
/*********************************************************************/
/* */
/* End of the UDF. */
/* */
/*********************************************************************/
Note
The first section (under DEFINE_CG_MOTION) prescribes a constant angular rotation about
the z-axis, and is used to spin the valve. The second section (under DEFINE_GEOM) defines
a line at y = R = 0.109 m; this line is coincident with the top wall of the housing and guides
the nodes as they slide along the top wall. The third section (under DEFINE_GRID_MOTION)
controls the motion of the nodes belonging to the membrane. The initial shape of the
membrane is that of a circular arc, and then it moves up and down harmonically.
7. Summary
In this tutorial you modeled an oscillating membrane in a generic flow device with a rotating blade
using the DM model in ANSYS Fluent. The local remeshing scheme was used to define the mesh motion.
DM specific macros of a UDF were used to govern the rotational motion of the blade, deformation of
the membrane, and the sliding of the nodes on the top wall of the housing.
Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
12 of ANSYS, Inc. and its subsidiaries and affiliates.