Академический Документы
Профессиональный Документы
Культура Документы
14. 5 Release
Lecture 8
User Defined Function (UDF)
1 © 2011 ANSYS, Inc. November 22,
2013
Introduction
• Allows the user to define their own specific problem, going beyond features
available in the Fluent GUI
• DEFINE_GEOM
Deformation • DEFINE_GRID_MOTION
• DEFINE_DYNAMIC_ZONE_PROPERTY
Property • DEFINE_CONTACT
DEFINE_CG_MOTION Macro
• Input parameters
– Name : Name of the UDF to hook it up
– dt : deformed thread
– time : current time
– dtime : current time step
• Output parameters
– vel : translational velocity
– omega : rotational velocity
0.2
Profile vs UDF 0 Time (s)
0 2 4 6 8 10
-0.2
Important : You must include the unsteady.h header file in your UDF source code when
using the PREVIOUS_TIME or PREVIOUS_2_TIME macros since it is not included in udf.h
Example: DT_CG (dt)[1] returns the current y coordinate of the body’s CG.
• The dynamic mesh can also be used with the steady state solver
– To define different vane positions for steady run
– Steady-state Fluid-Structure Interaction (FSI) simulation
CG #include "udf.h"
MOTION
STEADY DEFINE_CG_MOTION(object, dt, vel, omega, time, dtime)
{
/* reset velocities */
NV_S (vel, =, 0.0); Initial velocity values
NV_S (omega, =, 0.0);
omega[2] = 5;
}
DEFINE_GEOM Macro
• Remember Fluent does not know the underlying geometry. Fluent only
knows the node locations of the mesh.
– Therefore for nodes to slide along a surface, the shape needs to be
defined
– only applicable to Boundaries
• Input parameters
– parabola : Name of the UDF to hook it up
– domain : pointer to domain
– dt : pointer to structure that stores the dynamic mesh attributes
• Output parameters
– position : pointer to array that stores the node positions
#include "udf.h“
DEFINE #include "dynamesh_tools.h“
GEOM
DEFINE_GEOM(parabola, domain, dt, position) Variable
{
real radius; declarations
real norm;
real x,y,z;
Defintion of
x = position[0]; variables
y = position[1];
z = position[2];
Parabola
radius = -0.4 * z * z + 0.5 * z + 0.3; equation as a
norm = sqrt(x*x+y*y); function of z
position[0] = position[0]*radius/norm; X position
position[1] = position[1]*radius/norm;
Y position
18 © 2011 ANSYS, Inc. November 22,
2013
Example II – Parabola shape
DEFINE_GRID_MOTION Macro
• Input parameters
– udfname : Name of the UDF to hook it up
– domain *d : pointer to domain
– dt : pointer to structure that stores the dynamic mesh attributes
– time : current time
– dtime : time step
• Output parameters
SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));
/* Set flag to indicate that the current node's position
has been updated, so that it will not be updated in a
future pass through the loop. */
begin_f_loop(f, tf)
Loop of faces
24 © 2011 ANSYS, Inc. November 22, Flag to mark node after they have moved
2013
Example III – Sinusoidal wave
{ Loop on nodes of a
f_node_loop(f, tf, n) face
{
v = F_NODE(f, tf, n);
if (NODE_POS_NEED_UPDATE(v)) X position of a node
Grid {
NODE_POS_UPDATED(v);
x = NODE_X(v);
y = D/4.0*sin(x*M_PI/l*2)*
sin(2*M_PI*freq*CURRENT_TIME);
if (NODE_Y(v) > (D/2.0))
{
NODE_Y(v) = D+y;
calculate the new }
node position on Y else Setting of the new node
{ position on the upper wall
NODE_Y(v) = -y;
}
} Setting of the new node
} position on the lower wall
Update_Face_Metrics(f, tf);
}
end_f_loop(f,tf);
– Top wall :
• Repeat same settings than bottom
Limitations
• Application description
– The fluid moves from the inlet to the chamber
– The volume chamber is swept by the vane & pushed to the outlet
• The rotor of pump is not centered on the housing one
– The vanes have a linear motion as they rotate with the rotor
– The chambers change volume accross time
• The DEFINE_GRID_MOTION UDF
was used on the entire fluid zone
– On a pure Hexa mesh
• 100 000 cells
Rotor diameter : 6 cm
Angular speed : 1500 rpm
29 © 2011 ANSYS, Inc. November 22,
2013
Example IV – Volumetric fuel pump
DEFINE_DYNAMIC_ZONE_PROPERTY
Macro
35 © 2011 ANSYS, Inc. November 22,
2013
DEFINE_DYNAMIC_ZONE_PROPERTY UDF
Macro
• This macro can be used into 2 different ways
1. Swirl center definition for In-Cylinder application
DEFINE_DYNAMIC_ZONE_PROPERTY(swirl_udf, dt, sc)
• Will become
To be completed
Zone
Property
#include "udf.h"
#include "dynamesh_tools.h"
• Preview mesh
One Cycle
DEFINE_CONTACT Macro
• Contact detection can be used to automatically separate the cells that are
in the contact region (with or without using a UDF)
– Useful for specifying different flow conditions for this region
• E.g. porosity, to mimic a fully closed gap (see example on the next slide)
– Activate the “contact zone separation” by activate the flow control
• Create a new flow control zone and specify desired contact properties
• These properties will be copied to the automatically separated contact zone at contact
• In this example one ball moves towards the bottom wall, it will not bounce
up after contact
– A new zone (fluid-16:contact) will be created when the ball and the bottom wall
comes within the proximity threshold
• This automatically created zone will copy properties from the flow control zone
(fluid_contact)
– The “fluid contact” zone is an empty cell zone used to predefine properties that will be
copied to the automatically generated contact zone (fluid-16:contact)
– For this case, the predefined properties are porosity
• Note that the properties will be copied in the background, the properties will not be
visible in the GUI for “fluid-16:contact”
Contours of velocity
Velocity
Inlet