You are on page 1of 44

Workshop 06.

1:
Use of UDF in Moving
Deforming Mesh
ANSYS Fluent Dynamic Mesh
Release 2019 R3

11 © 2019 ANSYS, Inc.


Introduction
• 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 tree and ribbon structure. Some steps in the setup and solution procedure will
not be shown explicitly.
1. Preparation
2. UDF: DEFINE_CG_MOTION
3. UDF: DEFINE_GEOM
4. UDF: DEFINE_GRID_MOTION
5. Summary

2 © 2019 ANSYS, Inc.


Preparation
• 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.
• Launch Fluent.
• Select 2D under Dimension in the Fluent Launcher dialog box.
• 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.
• Retain the option of Serial under Processing Options.
• Make sure you have set the correct working directory in the
General Options tab.
• Click OK to start Fluent.
Note:
• Double Precision is recommended when moving deforming mesh is handling very thin cells (about the width of micron - μm).
• Use of Parallel Processing Options (associated with a number of processors) is recommended if you want to speed up your simulation.
3 © 2019 ANSYS, Inc.
UDF: DEFINE_CG_MOTION

44 © 2019 ANSYS, Inc.


Reading and Checking the Mesh
• Read the mesh file local-cell-remesh.msh.
File → Read → Mesh...
• Check the mesh.
Domain → Mesh → 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)

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.

5 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
Check the UDF by opening the file rotation.c, in a text editor
• 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 x-velocity.

6 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• Compile the UDF. User Defined → User Defined →
Functions → Compiled...
• Click Add... under Source Files dialog box to open
the Select File dialog box.
• Select the rotation.c file in the Select File dialog box
and click OK.
• Click Build.
• Click OK in the Question dialog box that appears.
Note: Check that there is no error reported in the console while
compiling.
• Click Load and then close the Compiled UDFs dialog
box.

7 © 2019 ANSYS, Inc.


Specifying Solver and Analysis Type
• Select Transient under General in the ribbon.
Physics → Solver → General → Time

8 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
Domain → Mesh Models → Dynamic Mesh...
• In the Dynamic Mesh task page enable
Dynamic Mesh.
• Enable Remeshing and retain Smoothing in
the Mesh Methods group box.

9 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• Click the Remeshing tab.
• Click Default.
• Enter 2 for Size Remeshing Interval
• Click OK to close the Mesh Method Settings dialog
box.

Note: Only Local Cell is enabled under Remeshing Methods. The object in
motion is in the middle of the domain and will not be in contact with the
external boundary. So none of the boundaries will change or deform.

10 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• 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.
• In the Dynamic Mesh Zones dialog box select
object from the Zone Names drop-down list.
• Retain the selection of Rigid Body in the Type
group box.
• Retain the selection of object::libudf from the
Motion UDF/Profile drop-down list.
• In the Meshing Options tab retain 0 for Cell
Height.
• Click Create.
• Close the Dynamic Mesh Zones dialog box.

11 © 2019 ANSYS, Inc.


Checking the Mesh Motion
• Click Preview Mesh Motion... in the Dynamic Mesh task page.
• Enter 0.002 for Time Step Size.
• Enter 100 for Number of Time Steps.
• Click Apply.
• Save the case file, local-cell-remesh-test.cas.gz.
File → Write → Case...
• 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.

• Close Fluent.
This concludes this first UDF workshop based on using a CG Motion UDF for
dynamic moving mesh.
12 © 2019 ANSYS, Inc.
UDF: DEFINE_GEOM

13
13 © 2019 ANSYS, Inc.
Preparation
Now you will check the effect of another UDF on moving
mesh.
• Launch Fluent.
• Select 3D under Dimension in the Fluent Launcher dialog
box.
• 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.
• Retain the option of Serial under Processing Options.
• Make sure you have set the correct working directory in
the General Options tab.
• Click OK to start Fluent.
14 © 2019 ANSYS, Inc.
Reading and Checking the Mesh
• Read the mesh file udf-def-geom.msh.
File → Read → Mesh...
• For a better display of the mesh click
Display....
Domain → Mesh → Display...
• Enable Faces and Edges in the Mesh
Display dialog box.

15 © 2019 ANSYS, Inc.


Reading and Checking the Mesh
• 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.

• Click Close to close the Mesh Colors


dialog box.

• Click Display and close the Mesh


Display dialog box.

16 © 2019 ANSYS, Inc.


Reading and Checking the Mesh
• In the mesh display visualize each
surface of the geometry to check the
name.
• Open the Mesh Display dialog box.
Domain → Mesh → Display...
• Deselect all from the list of Surfaces.
• 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.

17 © 2019 ANSYS, Inc.


Reading and Checking the Mesh
• Check the mesh. Domain → Mesh → Check
(ANSYS Fluent will perform various checks on the mesh and will
report the progress in the console. Ensure there are no error
messages)
• Check the scale of the mesh to understand the
dimensions of the mesh and the units used.
Domain → Mesh → Scale...

18 © 2019 ANSYS, Inc.


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

19 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• 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 arguments 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.
̶ 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.

20 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• 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 but only a vertical sinusoidal velocity.

21 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• Compile the UDF.
User Defined → User Defined → Functions → Compiled...
• Click Add... under Source Files dialog box to open the Select
File dialog box.
• Select the def_geom.c file in the Select File dialog box and
click OK.
• Click Build.
• Click OK in the Question dialog box that appears.
Note: Check that there is no error reported in the console while compiling.
• Click Load and then close the Compiled UDFs dialog box.

22 © 2019 ANSYS, Inc.


Specifying Solver and Analysis Type
• For moving deforming mesh you require the transient solver. Select Transient
under General in the ribbon.
Physics → Solver → General → Time

23 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• In the Dynamic Mesh task page enable Dynamic Mesh.
Disable Smoothing and enable Layering.
Domain → Mesh Models → Dynamic Mesh...
• 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.
• 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.
• Select fluid from the Zone Names drop-down list.
Note: This is the zone which will be moving up and down in the moving
mesh.
• Retain the selection of Rigid Body in the Type group box.
• Retain the selection of piston::libudf from the Motion
UDF/Profile drop-down list.
• Click Create.
24 © 2019 ANSYS, Inc.
Specifying Dynamic Mesh Settings
• Select top from the Zone Names drop-down
list.
Note: This zone will be stationary.
• Select Stationary in the Type group box.
• In the Meshing Options tab enter 0.05 for
Cell Height.
• Click Create.

25 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• Select parabola-wall from the Zone Names
drop-down list.
• Select Deforming in the Type group box.
• In the Meshing Options tab disable
Smoothing and Remeshing from the
Methods group box.
Note: The parabola-wall is not impacted by these.
• Retain the default values.
Note: They are not used as, the height is specified at the top
and bottom boundaries.

26 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• In the Geometry Definition tab select user-
defined from the Definition drop-down list.
• Select parabola::udf from the Geometry
UDF drop-down list. Ensure that the name
is same as that in the def_geom.c file.
• Click Create.
• Close the Dynamic Mesh Zones dialog box.

27 © 2019 ANSYS, Inc.


Checking the Mesh Motion
• Click Preview Mesh Motion... in the Dynamic Mesh task page.
• Enter 0.001 for Time Step Size and 30 for Number of Time Steps.
• Click Apply.
• Save the case file, udf-def-geom-test.cas.
File → Write → Case...

28 © 2019 ANSYS, Inc.


Checking the Mesh Motion
• Click Preview.

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 projected
on the radius, defined in the UDF file
def_geom.c.

• Close Fluent
29 © 2019 ANSYS, Inc.
UDF: DEFINE_GRID_MOTION

30
30 © 2019 ANSYS, Inc.
Preparation
Now you will study the effect of another UDF on a
different moving mesh.
• Launch Fluent.
• Select 2D under Dimension in the Fluent Launcher
dialog box.
• 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.
• Retain the option of Serial under Processing Options.
• Make sure you have set the correct working directory
in the General Options tab.
• Click OK to start Fluent.
31 © 2019 ANSYS, Inc.
Reading and Checking the Mesh
• Read the mesh file udf-grid-motion.msh.
File → Read → Mesh...
• In the mesh display check each surface
of the geometry to check the name and
which surface it corresponds to.
Domain → Mesh → Display...
• Open the Mesh Display dialog box.
Display → Mesh...
• Deselect all from the list of Surfaces Note: You can see that the mesh has 2 domains. One made of tri
elements and the other of quad. Among the Surfaces
• Select each surface one by one and click • wall consists of the sides of the quad elements.
• top-deforming is the top surface.
Display to check which displayed surface • right surface is the right wall of the tri elements.
represents which name. • 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.

32 © 2019 ANSYS, Inc.


Reading and Checking the Mesh
• Check the mesh. Domain → Mesh → Check
(ANSYS Fluent will perform various checks on the mesh and
will report the progress in the console. Ensure there are no
error messages)
• Check the scale of the mesh to understand
the dimensions of the mesh and the units
used. Domain → Mesh → Scale...

33 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• Check the UDF by opening the file
circular-punch.c, in a text editor.

34 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• 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.
̶ 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.

35 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• The macro SET_DEFORMING_THREAD_FLAG is then used to activate the deforming
flag on adjacent 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.

36 © 2019 ANSYS, Inc.


Checking and Compiling the UDF
• Compile the UDF.
User Defined → User Defined → Functions → Compiled...
• Click Add... under Source Files dialog box to open the
Select File dialog box.
• Select the circular-punch.c file in the Select File dialog
box and click OK.
• Click Build.
• Click OK in the Question dialog box that appears.
Note: Check that there is no error reported in the console while compiling.

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

37 © 2019 ANSYS, Inc.


Specifying Solver and Analysis Type
• For moving deforming mesh you require the transient solver. Select Transient
under General in the ribbon.
Physics → Solver → General → Time

38 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• In the Dynamic Mesh task page enable Dynamic Mesh.
Enable Remeshing and retain Smoothing.
Domain → Mesh Models → Dynamic Mesh...
• Click Settings... to open the Mesh Method Settings
dialog box.
• In the Smoothing tab, change the Method to
Spring/Laplace/Boundary Layer
– This change is required in order to allow deformation of the
boundary layer cells adjacent to the top surface
• Click the Remeshing tab.
• Click Default to fill in the parameters with values that
belong to the case.
• Enter 1 for Size Remeshing Interval.
• Click OK to close the Mesh Method Settings dialog box.

39 © 2019 ANSYS, Inc.


Specifying Dynamic Mesh Settings
• 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.
• In the Dynamic Mesh Zones dialog box select top-
deforming from the Zone Names drop-down list.
• Select User_Defined in the Type group box.
• Retain the selection of jk_punch::libudf from the Motion
UDF/Profile drop-down list.
• In the Meshing Options tab retain 0 for Cell Height.
• Enable Deform Adjacent Boundary Layer with Zone in the
Meshing Options tab.
Note: By enabling Deform Adjacent Boundary Layer with Zone you allow the
quad elements to remain 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.
• Click Create.
40 © 2019 ANSYS, Inc.
Specifying Dynamic Mesh Settings
• Select tri-zone from the Zone Names drop-
down list.
• Select Deforming in the Type group box.
• Click Zone Scale Info... to open the Zone Scale
Info dialog box.
• From the values in the Zone Scale Info dialog
box enter 0.06 for Minimum Length Scale.
• Enter 0.17 for Maximum Length Scale.
• Enter 0.6 for Maximum Skewness.
• Click Create.
• Close the Zone Scale Info and the Dynamic
Mesh Zones dialog boxes.

41 © 2019 ANSYS, Inc.


Checking the Mesh Motion
• Click Preview Mesh Motion... in the Dynamic Mesh task page.
• Enter 0.001 for Time Step Size and 10 for Number of Time Steps.
• Click Apply.
• Save the case file, udf-grid-motion-test.cas.
File → Write → Case...

42 © 2019 ANSYS, Inc.


Checking the Mesh Motion
• Click Preview.
Note:
• The deformation of the adjacent boundary layer
matches that of the top wall, and therefore is preserved
throughout the process.

• 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 larger way, where each node of the
concerned domain (from the front of the domain to the
inside) moves according to a predefined motion. When
using this UDF, no nodes can be deleted or added.

• Close Fluent.
43 © 2019 ANSYS, Inc.
Summary
• In this tutorial you have played with three different UDF macros. This was not a
detailed study in UDF process or programming, but just an introduction to what the
possibilities are in using these UDFs.
– DEFINE_CG_MOTION
‒ DEFINE_GEOM
‒ DEFINE_GRID_MOTION

44 © 2019 ANSYS, Inc.

You might also like