Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Chapter 4: Use of UDF in Moving Deforming Mesh

This tutorial illustrates the setup of a dynamic mesh using different kinds of UDF. You can open the
UDFs given and check how they are built.

This tutorial is written with the assumption 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.
4.1. Preparation
4.2. Reading and Checking the Mesh
4.3. Specifying Solver and Analysis Type
4.4. Specifying Dynamic Mesh Settings
4.5. Checking the Mesh Motion
4.6. Using a Geom UDF for motion in Dynamic Moving Mesh
4.7. Using Grid Motion UDF
4.8. Summary

4.1. Preparation
1. Copy the files (local-cell-remesh.msh, udf-def-geom.msh, udf-grid-motion.msh,
def_geom.c, rotation.c, and circular-punch.c) to your working folder.

2. Launch Fluent.

a. Select 2D under Dimension in the Fluent Launcher dialog box.

b. Ensure that Display Mesh After Reading is enabled under Display Options in the Fluent
Launcher dialog box. This will ensure that the mesh is displayed automatically after reading.

c. Disable the option Workbench Color Scheme under Display Options.

d. Retain the option of Serial under Processing Options.

e. Make sure you have set the correct working directory in the General Options tab.

f. Click OK to start Fluent.

Note

• Double Precision is recommended when moving deforming mesh is handling very


thin cells (ie: width of micron - µm).

• Use of Parallel Processing Options (associated with a number of processors) is re-


commended if you want to speed up your simulation.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 1
Use of UDF in Moving Deforming Mesh

4.2. Reading and Checking the Mesh


1. Read the mesh file local-cell-remesh.msh.

File → Read → Mesh...

Note

The mesh is a big domain with an object inside. This object is going to rotate around
the center line in the domain and also around itself.

2. Check the mesh.

General → Check

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.

3. Check the UDF by opening the file rotation.c, in a text editor.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
2 of ANSYS, Inc. and its subsidiaries and affiliates.
Reading and Checking the Mesh

The DEFINE_CG_MOTION macro is used to impose a defined motion on a rigid body. This macro
has six arguments that need to be defined.

• The first argument is object. This is the name with which the UDF will be known in Fluent.

• The second argument dt is a pointer on the dynamic thread which contains the deformations
applied to the zone to be deformed.

• The third and fourth arguments (vel and omega) are the translational and rotational velocities
respectively. The purpose of this UDF is to define these two arguments.

• Finally, The last two arguments (time and dtime) are the time and the timestep to be applied.

The first part of the UDF initializes both translational and rotational velocities.

The second part defines each component of the translational velocity (vel[0] for x_velocity and
vel[1] for y_velocity) as functions of time using a cosine function. The z_velocity is initialized to
zero from the beginning.

The third part, the definition of each component of the rotational velocity (omega[2]: z rotation)
as constant. Again, the two other components of rotational velocity are initialized to zero from the
beginning.

The last two lines of the UDF print the current longitudinal.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 3
Use of UDF in Moving Deforming Mesh

4. Compile the UDF.

Define → User-Defined → Functions → Compiled

a. Click Add... under Source Files dialog box to open the Select File dialog box.

b. Select the rotation.c file in the Select File dialog box and click OK.

c. Click Build.

Click OK in the Question dialog box that appears.

Note

Check that there are no errors reported in the console while compiling.

d. Click Load and then close the Compiled UDFs dialog box.

4.3. Specifying Solver and Analysis Type


For moving deforming mesh you require the transient solver. Select Transient under Time in the
Solver group box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
4 of ANSYS, Inc. and its subsidiaries and affiliates.
Specifying Dynamic Mesh Settings

4.4. Specifying Dynamic Mesh Settings

Dynamic Mesh

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 5
Use of UDF in Moving Deforming Mesh

1. In the Dynamic Mesh task page enable Dynamic Mesh.

2. Enable Remeshing and retain Smoothing in the Mesh Methods group box.

3. Click Settings... to open the Mesh Method Settings 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.
Specifying Dynamic Mesh Settings

a. Click the Remeshing tab.

b. Click Use Defaults.

c. Click OK to close the Mesh Method Settings dialog box.

4. To set the motion to the object you need to define the dynamic mesh zones. Click Create/Edit... under
the Dynamic Mesh Zones group box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 7
Use of UDF in Moving Deforming Mesh

a. In the Dynamic Mesh Zones dialog box select object from the Zone Names drop-down list.

b. Retain the selection of Rigid Body in the Type group box.

c. Retain the selection of object::libudf from the Motion UDF/Profile drop-down list.

d. In the Meshing Options tab retain 0 for Cell Height.

e. Click Create.

f. Close the Dynamic Mesh Zones dialog box.

4.5. Checking the Mesh Motion


Click Preview Mesh Motion... in the Dynamic Mesh task page.

1. Enter 0.005 for Time Step Size.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
8 of ANSYS, Inc. and its subsidiaries and affiliates.
Using a Geom UDF for motion in Dynamic Moving Mesh

2. Enter 100 for Number of Time Steps.

3. Click Apply.

4. Save the case file, local-cell-remesh-test.cas.gz.

File → Write → Case...

5. Click Preview. You can see how the inner object moves inside the outer object.

Note

At this point you can modify the function of the velocity component (translational and/or
rotational) or just set a constant value. If you do so, then save the UDF with another
name, compile and load it. Then run the case again.

6. This concludes this first UDF workshop based on using a CG Motion UDF for dynamic moving mesh.
Close Fluent.

4.6. Using a Geom UDF for motion in Dynamic Moving Mesh


Now you will check the effect of another UDF on moving mesh.

1. Launch Fluent.

a. Select 3D under Dimension in the Fluent Launcher dialog box.

b. Ensure that Display Mesh After Reading is enabled under Display Options in the Fluent
Launcher dialog box. This will ensure that the mesh is displayed automatically after reading.

c. Disable the option Workbench Color Scheme under Display Options.

d. Retain the option of Serial under Processing Options.

e. Make sure you have set the correct working directory in the General Options tab.

f. Click OK to start Fluent.

2. Read the mesh file udf-def-geom.msh.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 9
Use of UDF in Moving Deforming Mesh

File → Read → Mesh

3. For a better display of the mesh click Display....

General → Display...

a. Enable Faces and Edges in the Mesh Display dialog box.

b. Click Colors... in the Mesh Display dialog box to open the Mesh Colors dialog box and select
Color by ID in the Options group box.

c. Click Close to close the Mesh Colors dialog box.

d. Click Display and close the Mesh Display dialog box.

4. To improve the display lighting select Lights... from the Display menu.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
10 of ANSYS, Inc. and its subsidiaries and affiliates.
Using a Geom UDF for motion in Dynamic Moving Mesh

a. Select Flat from the Lighting Method drop-down list.

b. Enable Headlight On in the Lights dialog box.

c. Click Apply and close the Lights dialog box.

5. In the mesh display check each surface of the geometry to check the name and which surface it corres-
ponds to.

a. Open the Mesh Display dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 11
Use of UDF in Moving Deforming Mesh

Display → Mesh...

b. Deselect all from the list of Surfaces.

c. Select each surface one by one and click Display to check which displayed surface represents
which name.

Note

You have the top and bottom surfaces with a parabola-wall which has a clear
definition of shape.

6. Check the mesh.

General → Check

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.

7. Check the scale of the mesh to understand the dimensions of the mesh and the units used.

General → Scale...

8. Check the UDF by opening the file def_geom.c, in a text editor. Here you will study the macro
DEFINE_GEOM.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
12 of ANSYS, Inc. and its subsidiaries and affiliates.
Using a Geom UDF for motion in Dynamic Moving Mesh

The DEFINE_GEOM macro enables the user to define a topological shape on which a boundary
node will be when the boundary is deforming. Like in the previous workshop, this macro uses ar-
guments that need to be defined.

• The first argument, parabola, is the name with which the UDF will be known in Fluent.

• The second argument domain, is a pointer for the domain in which the deformation will take
place.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 13
Use of UDF in Moving Deforming Mesh

• The third argument dt is a pointer on the dynamic thread which contains the deformations
applied to the zone to be deformed.

• Finally, The last argument position is a vector containing the coordinate of the node to be
modified in order to be on the prescribed topological shape.

At the beginning the position vector contains the current coordinates of the node.

In the first part of the UDF, for simplification purpose, x, y, and z are defined as coordinates of
the node before modification.

The shape on which the node should be projected is a barrel shape. The radius of the barrel is
varying with the vertical coordinate z. Thus, in the second part of the UDF, the radius of the barrel
is defined using a parabolic equation with respect with z. The value of this radius is displayed when
debugging is needed.

The third part of the UDF is the projection of the node on the circle formed at the vertical coordinate
z and in the direction (x,y).

The last part of the UDF is a display of the new node coordinate when debugging is needed.

The DEFINE_CG_MOTION is setup as in the previous UDF but this time specifying no rotational
velocity and only a vertical sinusoidal velocity.

9. Compile the UDF.

Define → User-Defined → Functions → Compiled

a. Click Add... under Source Files dialog box to open the Select File dialog box.

b. Select the def_geom.c file in the Select File dialog box and click OK.

c. Click Build.

Click OK in the Question dialog box that appears.

Note

Check that there are no errors reported in the console while compiling.

d. Click Load and then close the Compiled UDFs dialog box.

10. Select Transient under Time in the Solver group box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
14 of ANSYS, Inc. and its subsidiaries and affiliates.
Using a Geom UDF for motion in Dynamic Moving Mesh

General

11. In the Dynamic Mesh task page enable Dynamic Mesh. Disable Smoothing and enable Layering.

Dynamic Mesh

12. Click Settings... to open the Mesh Method Settings dialog box.

• Retain the default settings in the Layering tab and click OK to close the Mesh Method Settings
dialog box.

13. To set the motion to the object you need to define the dynamic mesh zones. Click Create/Edit... under
the Dynamic Mesh Zones group box.

a. In the Dynamic Mesh Zones dialog box select bottom from the Zone Names drop-down list.

Note

This is the part which will be moving up and down in the moving mesh.

i. Retain the selection of Rigid Body in the Type group box.

ii. Retain the selection of piston::libudf from the Motion UDF/Profile drop-down list.

Note

The name of the function in the UDF file should be the same, piston.

iii. In the Meshing Options tab enter 0.05 for Cell Height.

iv. Click Create.

b. Select fluid from the Zone Names drop-down list.

Note

This zone will also be moving.

i. Retain the selection of Rigid Body in the Type group box.

ii. Retain the selection of piston::libudf from the Motion UDF/Profile drop-down list.

Note

The same motion is applied to this also similar to bottom.

iii. Click Create.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 15
Use of UDF in Moving Deforming Mesh

c. Select top from the Zone Names drop-down list.

Note

This zone will be stationary.

i. Select Stationary in the Type group box.

ii. Click Create.

iii. In the Meshing Options tab retain 0.05 for Cell Height.

iv. Click Create.

d. Select parabola-wall from the Zone Names drop-down list.

i. Select Deforming in the Type group box.

ii. In the Meshing Options tab enter 0.049 for Minimum Length Scale.

iii. Enter 0.051 for Maximum Length Scale.

iv. Enter 0.6 for Maximum Skewness.

v. In the Geometry Definition tab select user-defined from the Definition drop-down list.

vi. Ensure that parabola::udf is selected from the Geometry UDF drop-down list. Ensure that
the name is same as that in the def_geom.c file.

vii. Click Create.

e. Close the Dynamic Mesh Zones dialog box.

14. Click Preview Mesh Motion... in the Dynamic Mesh task page.

a. Enter 0.001 for Time Step Size and 30 for Number of Time Steps.

b. Click Apply.

c. Save the case file, udf-def-geom-test.cas.

File → Write → Case...

d. Click Preview.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
16 of ANSYS, Inc. and its subsidiaries and affiliates.
Using Grid Motion UDF

Note

The fluid is moving up as the bottom part is moving up. Cells are deleted and added
at the top wall, where a stationary condition is set. The parabola wall is deformed
due to the motion of the fluid and the bottom part. But the shape is preserved all
the way. All the nodes of the parabola wall are moving up and down and are pro-
jected on the radius, defined in the UDF file def_geom.c.

15. This concludes this second UDF workshop based on the use of a DEFINE_GEOM UDF for dynamic
moving mesh. Close Fluent.

4.7. Using Grid Motion UDF


Now you will study the effect of another UDF on a different moving mesh.

1. Launch Fluent.

a. Select 2D under Dimension in the Fluent Launcher dialog box.

b. Ensure that Display Mesh After Reading is enabled under Display Options in the Fluent
Launcher dialog box. This will ensure that the mesh is displayed automatically after reading.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 17
Use of UDF in Moving Deforming Mesh

c. Disable the option Workbench Color Scheme under Display Options.

d. Retain the option of Serial under Processing Options.

e. Make sure you have set the correct working directory in the General Options tab.

f. Click OK to start Fluent.

2. Read the mesh file udf-grid-motion.msh.

File → Read → Mesh

3. For a better display of the mesh click Display....

General → Display...

4. In the mesh display check each surface of the geometry to check the name and which surface it corres-
ponds to.

a. Open the Mesh Display dialog box.

Display → Mesh...

b. Deselect all from the list of Surfaces.

c. Select each surface one by one, and click Display to check which displayed surface represents
which name.

Note

You can see that the mesh has 2 domains. One made of tri elements and other of
quad. Amongst the Surfaces

• wall consists of the sides of the quad elements.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
18 of ANSYS, Inc. and its subsidiaries and affiliates.
Using Grid Motion UDF

• top-deforming is the top surface.

• right surface is the right wall of the tri elements.

• left surface is the left wall of the tri elements.

• quad-to-tri surface is the interior surface between the tri and quad elements.

• bottom surface is the bottom wall.

5. Check the mesh.

General → Check

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.

6. Check the scale of the mesh to understand the dimensions of the mesh and the units used.

General → Scale...

7. Select Transient under Time in the Solver group box.

General

8. Check the UDF by opening the file circular-punch.c, in a text editor.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 19
Use of UDF in Moving Deforming Mesh

The DEFINE_GRID_MOTION macro enables the user to specify the deformation of any zone (face
or cell) node by node. Here, the deformation (node by node) is applied on the upper face. Like in
the two first workshops, this macro uses arguments that need to be defined.

• The first argument jk_punch, is the name with which the UDF will be known in Fluent.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
20 of ANSYS, Inc. and its subsidiaries and affiliates.
Using Grid Motion UDF

• The second argument domain is a pointer to the domain in which the deformation will take place.

• The third argument dt is a pointer on the dynamic thread which contains the deformations applied
to the zone to be deformed.

• Finally, The last two arguments time and dtime are the time and the timestep to be applied.

A circle is used in this UDF as a deformation form. This circle center will go down at a constant
velocity.

In the first part of the UDF, the position of the circle center is both initialized and specified as a
function of time.

The macro SET_DEFORMING_THREAD_FLAG is then used to activate the deforming flag on adja-
cent cell zone in which the deformation will propagate: the cells adjacent to the deforming wall
will also be deformed, in order to avoid skewness. Then a loop is done over all the faces of the
face zone to be deformed. A loop on all the cells should be done for a cell zone. Then for all faces
a loop is done over all nodes which belong to this particular face.

Inside this double loop the position of each node is defined. A marker is used in order to verify
that the deformation of a node which is common to multiple faces is not provided a multiple times.
This marker is NODE_POS_NEED_UPDATE. Each time a node is visited the macro
NODE_POS_UPDATED is used to mark the node as visited. This method is always used inside a
DEFINE_GRID_MOTION.

The node position is then recalculated using a circle equation if the circle is in contact with the
face or is unchanged.

9. Compile the UDF.

Define → User-Defined → Functions → Compiled

a. Click Add... under Source Files dialog box to open the Select File dialog box.

b. Select the circular-punch.c file in the Select File dialog box and click OK.

c. Click Build.

Click OK in the Question dialog box that appears.

Note

Check that there are no errors reported in the console while compiling.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 21
Use of UDF in Moving Deforming Mesh

d. Click Load and then close the Compiled UDFs dialog box.

10. In the Dynamic Mesh task page enable Dynamic Mesh. Enable Remeshing and retain Smoothing.

Dynamic Mesh

11. Click Settings... to open the Mesh Method Settings dialog box.

a. Retain the default settings in the Smoothing tab.

b. Click the Remeshing tab.

i. Click Use Defaults to fill in the parameters with values that belong to the case.

ii. Enter 1 for Size Remeshing Interval.

c. Click OK to close the Mesh Method Settings dialog box.

12. To set the motion to the object you need to define the dynamic mesh zones. Click Create/Edit... under
the Dynamic Mesh Zones group box.

a. In the Dynamic Mesh Zones dialog box select top-deforming from the Zone Names drop-down
list.

i. Select User_Defined in the Type group box.

ii. Retain the selection of jk_punch::libudf from the Motion UDF/Profile drop-down list.

iii. In the Meshing Options tab retain 0 for Cell Height.

iv. Enable Deform Adjacent Boundary Layer with Zone in the Meshing Options tab.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
22 of ANSYS, Inc. and its subsidiaries and affiliates.
Using Grid Motion UDF

Note

By enabling Deform Adjacent Boundary Layer with Zone you allow the quads
elements to remains identical as the top is deforming. The total height of the
quads is preserved and only the tri elements are deformed. The quads are not
shrunk and therefore will not hang the process when the first quad layer will
meet the second.

v. Click Create.

b. Select tri-zone from the Zone Names drop-down list.

i. Select Deforming in the Type group box.

ii. Click Zone Scale Info... to open the Zone Scale Info dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 23
Use of UDF in Moving Deforming Mesh

A. From the values in the Zone Scale Info dialog box enter 0.06 for Minimum Length
Scale.

B. Enter 0.17 for Maximum Length Scale.

C. Enter 0.6 for Maximum Skewness.

D. Click Create.

c. Close the Dynamic Mesh Zones dialog box.

13. Click Preview Mesh Motion... in the Dynamic Mesh task page.

a. Enter 0.001 for Time Step Size and 10 for Number of Time Steps.

b. Click Apply.

c. Save the case file, udf-grid-motion-test.cas.

File → Write → Case...

d. Click Preview.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
24 of ANSYS, Inc. and its subsidiaries and affiliates.
Summary

Note

• The wall at the top is deforming due to the impact of a ball. As the time passes, the shape
of the ball can be perceived. The result of this deformation alters the inside of the domain
differently according to the zone. The adjacent boundary layers deforms pretty much the
same way than the top wall, so it remains preserved all through the process. This is due
to the enabling of Deform Adjacent Boundary Layer with Zone. On the other hand, the
tri elements, below the quad cells, are affected the most. This part of the mesh is smoothed
and remeshed when the deformation exceeds the limit (specified size or skewness).

• In this tutorial, only the top boundary is affected by the deformation which then impacts
and modifies the inner zones by doing some smoothing and remeshing operations. But
this is not the only way to use this UDF. This can be used in a more larger way, where
each node of the concerned domain (from the front of the domain to the inside) moves
according to a predefined motion. Thus, no nodes will be deleted or added.

14. This concludes this third and final UDF workshop based on the use of a DEFINE_GRID_MOTION UDF
for dynamic moving mesh. Close Fluent.

4.8. Summary
In this tutorial you have played with three different macro UDFs. This was not a detailed study in UDF
process or programming but just an introduction to what are the possibilities in using these UDFs.

You have learnt how to handle UDFS and understand what was the scope of use of the following UDFs:

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates. 25
Use of UDF in Moving Deforming Mesh

• DEFINE_CG_MOTION

• DEFINE_GEOM

• DEFINE_GRID_MOTION

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information
26 of ANSYS, Inc. and its subsidiaries and affiliates.

You might also like