You are on page 1of 17

Tutorial: Using a UDF to Control the Dynamic Mesh

Introduction
The purpose of this tutorial is to illustrate how to use a user defined function (UDF) to
control the dynamic 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.
In this tutorial you will learn how to:

• Set up the dynamic mesh (DM) model for this problem.

• Use the three DM-specific macros in a UDF to control the dynamic mesh.

• Preview the dynamic mesh before starting the flow computation.

Prerequisites
This tutorial assumes that you are familiar with the FLUENT interface and have completed
Tutorial 1 from the FLUENT 6.2 Tutorial Guide. Some of the basic steps in the setup and
solution procedures will not be shown explicitly. You should be familiar with the dynamic
mesh model. If you are not, you can refer Section 10.6: Dynamic Meshes in the FLUENT
6.2 User’s Guide.

Problem Description
A generic flow device with a flexible oscillating membrane beneath it is shown in Figure 1.
The valve radius is 0.1 m.


c Fluent Inc. April 1, 2005 1
Tutorial: Using a UDF to Control the Dynamic Mesh

Figure 1: Problem Schematic

Preparation

1. Copy the mesh file, butterfly-flex.msh and the source file, butterfly-flex.c to
your working directory.

2. Start the 2D version of FLUENT.

Setup and Solution


Step 1: Grid

1. Read the mesh file, butterfly-flex.msh.


File −→ Read −→Case...
FLUENT will read the mesh file and report the progress in the console window.

2. Check the grid.


Grid −→Check
FLUENT will perform various checks on the mesh and will report the progress in the
console window. Pay attention to the reported minimum volume and make sure this
is a positive number.

2
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

3. Display the grid (Figure 2).


Display −→Grid...

(a) Click Colors....


The Grid Colors panel opens.

(b) Under Options, enable Color by ID.


(c) Click Close.
(d) In the Grid Display panel, click Display.


c Fluent Inc. April 1, 2005 3
Tutorial: Using a UDF to Control the Dynamic Mesh

Grid
FLUENT 6.2 (2d, segregated, lam)

Figure 2: Grid Display – Colored by ID

4
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

Step 2: Models

1. Select the unsteady solver.


Define −→ Models −→Solver...

(a) Under Time, enable Unsteady.


(b) Retain the default settings for other parameters.
(c) Click OK.


c Fluent Inc. April 1, 2005 5
Tutorial: Using a UDF to Control the Dynamic Mesh

Step 3: Compile the UDF


Define −→ User-Defined −→ Functions −→Compiled...

1. In the Compiled UDFs panel, click Add... under Source Files.


The Select File panel opens.
(a) Select the file, butterfly-flex.c and click OK.

2. Enter the Library Name as libudf-flex.

3. Click Build.

4. Click OK on the Information Panel that opens.

5. Click Load.

6
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

The contents of the UDF are listed for your reference:

#include "udf.h"

#define omega 1.0 /* rotational speed, rad/sec */


#define R 0.109 /* radius of the arc, meters */

DEFINE_CG_MOTION(butterfly_flex_UDF, dt, cg_vel, cg_omega, time, dtime)


{
cg_vel[0] = 0.0;
cg_vel[1] = 0.0;
cg_vel[2] = 0.0;

cg_omega[0] = 0.0;
cg_omega[1] = 0.0;
cg_omega[2] = omega;
}

DEFINE_GEOM(plane, domain, dt, position)


{
position[1] = R;
}

DEFINE_GRID_MOTION(moving_arc, domain, dt, time, dtime)


{
Thread *tf = DT_THREAD (dt);
face_t f;
Node *node_p;
real alpha, theta, x, ymag, yfull, y;
int n;

/* Set/activate the deforming flag on adjacent cell zone, which */


/* means that the cells adjacent to the deforming wall will also be */
/* deformed, in order to avoid skewness. */
SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));

alpha = omega * CURRENT_TIME;


theta = 2.0 * alpha + 3.0 * M_PI / 2.0;

begin_f_loop (f, tf)


{
f_node_loop (f, tf, n)
{
node_p = F_NODE (f, tf, n);
/* Update the current node only if it has not been */
/* previously visited: */
if (NODE_POS_NEED_UPDATE (node_p))


c Fluent Inc. April 1, 2005 7
Tutorial: Using a UDF to Control the Dynamic Mesh

{
/* Set flag to indicate that the current node’s */
/* position has been updated, so that it will not be */
/* updated during a future pass through the loop: */

NODE_POS_UPDATED (node_p);

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);
}

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) con-
trols 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.
Step 4: Dynamic Mesh Setup
The mesh is controlled using a combination of local remeshing with sizing functions and
spring smoothing.

1. Set up the controls for spring smoothing.


Define −→ Dynamic Mesh −→Parameters...

8
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

(a) Under Models, enable Dynamic Mesh.


The panel expands to show relevant inputs.

(b) Under Mesh Methods, enable Remeshing.


(c) In the Smoothing tab, set the Spring Constant Factor to 0.3.


c Fluent Inc. April 1, 2005 9
Tutorial: Using a UDF to Control the Dynamic Mesh

(d) In the Remeshing tab, enable Size Function and specify the parameters as follows:
Parameter Value
Minimum Length Scale (m) 0.00236
Maximum Length Scale (m) 0.02
Maximum Cell Skewness 0.65
Size Remesh Interval 1
Size Function Resolution 3
Size Function Variation 0.5
Size Function Rate 0.99

10
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

2. Specify the zone, wall-butterfly as a rigid body.


Define −→ Dynamic Mesh −→Zones...

(a) In the Zone Names drop-down list, select wall-butterfly.


(b) Under Type, enable Rigid Body.
(c) In the Motion Attributes tab, under Motion UDF/Profile, select butterfly flex UDF::libudf-
flex.
(d) Retain the Center of Gravity Location as (0,0).
The valve motion is defined about its center of gravity (CG) located at (0,0).
This is important in the case of rotation.


c Fluent Inc. April 1, 2005 11
Tutorial: Using a UDF to Control the Dynamic Mesh

(e) In the Meshing Options tab, specify a value of 0.002 for Cell Height.

(f) Click Create.

12
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

3. Specify the zone wall-top as a deforming zone.


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.
(a) Select wall-top from the Zone Names drop-down list.
(b) Under Type, select Deforming.
(c) Click the Geometry Definition tab.
i. Under Definition, select user-defined.
ii. Under Geometry UDF, select plane::libudf-flex.


c Fluent Inc. April 1, 2005 13
Tutorial: Using a UDF to Control the Dynamic Mesh

(d) Click the Meshing Options tab.


i. Under Methods, enable Smoothing and Remeshing.
ii. Set the following parameters:
Parameter Value
Minimum Length Scale (m) 0.002
Maximum Length Scale (m) 0.02
Maximum Skewness 0.65

(e) Click Create.

14
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

4. Specify the zone membrane as dynamic zone.


The motion of the membrane and its shadow wall is governed by the function mov-
ing arc from the UDF.
(a) Select membrane from the Zone Names drop-down list.
(b) Under Type, select User-Defined.
(c) Under Mesh Motion UDF, select moving arc::libudf-flex.

5. Repeat the procedure (a) through (c) for the zone, membrane-shadow.

6. Save the case file, membrane-moving-init.cas.gz.


c Fluent Inc. April 1, 2005 15
Tutorial: Using a UDF to Control the Dynamic Mesh

Step 5: Mesh Motion Preview

1. Specify the parameters for the mesh motion.


Solve −→Mesh Motion...

(a) Specify a value of 0.005 for Time Step Size.


(b) Increase the Number of Time Steps to 313.
(c) Click Preview.
The valve will move through 90 degrees and assume the position shown in Fig-
ure 3.

Grid (Time=1.5650e+00)
FLUENT 6.2 (2d, segregated, dynamesh, lam, unsteady)

Figure 3: Grid Display After Mesh Motion

16
c Fluent Inc. April 1, 2005
Tutorial: Using a UDF to Control the Dynamic Mesh

Summary
In this tutorial you modeled an oscillating membrane in a generic flow device with a rotating
blade using the DM model in 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.


c Fluent Inc. April 1, 2005 17

You might also like