Вы находитесь на странице: 1из 47

Moving/Deforming Mesh

14. 5 Release

Lecture 8
User Defined Function (UDF)
1 © 2011 ANSYS, Inc. November 22,
2013
Introduction

• A UDF is a custom routine (or Macro) which extends Fluent capabilities


– UDFs are Written in ‘C’ language by the user
– Can be dynamically linked with Fluent solver

• Allows the user to define their own specific problem, going beyond features
available in the Fluent GUI

• Dynamic Mesh makes use of 3 types of macros

Rigid Body motion • DEFINE_CG_MOTION

• DEFINE_GEOM
Deformation • DEFINE_GRID_MOTION

• DEFINE_DYNAMIC_ZONE_PROPERTY
Property • DEFINE_CONTACT

2 © 2011 ANSYS, Inc. November 22,


2013
14. 5 Release

DEFINE_CG_MOTION Macro

3 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CG_MOTION UDF Macro

• This macro allows object motion as a function of time


 Translational
 Rotational
 Combination of Translation and Rotation
– In each case with respect to the CG (Center of Gravity) of the body
• CG is specified by the user (not calculated by the code)
• CG is continually updated as the body moves

• This macro defines a prescribed motion


• The object moves as a rigid body
– Boundary(ies)
– Fluid zone(s)
– In both cases all nodes associated with it move as one,
• without any relative motion (deformation)

DEFINE_CG_MOTION(name, dt, vel, omega, time, dtime)

4 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CG_MOTION Description

DEFINE_CG_MOTION(name, dt, vel, omega, time, dtime)

• 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

5 © 2011 ANSYS, Inc. November 22,


2013
Example I – 2D Store separation

0.2
Profile vs UDF 0 Time (s)
0 2 4 6 8 10
-0.2

((pod 3 point) -0.4


Profile (time 0.0 3.0 10.0) -0.6
v_y
omega
(v_y 0.0 -1.0 -1.0) -0.8
(omega_z 0.15 0.15 0.15)) -1
-1.2
Translational velocity
Angular velocity
#include "udf.h”
UDF CG DEFINE_CG_MOTION(object, dt, cg_vel,
cg_omega,time, dtime)
{ Initial velocity values
NV_S(cg_vel, =, 0.0);
NV_S(cg_omega, =, 0.0);
if (time <= 3.0)
{cg_vel[1] = - time/3.0;}
else Translational velocity
{cg_vel[1] = - 1.0;}
cg_omega[2] = 0.15;
}
Angular velocity
6 © 2011 ANSYS, Inc. November 22,
2013
Time-Dependent Variables

• Solver Macros for Time-Dependent Variables


Macro name Returns
CURRENT_TIME Real current flow time (in seconds)
CURRENT_TIMESTEP Real current physical time step size (in seconds)
PREVIOUS_TIME Real previous flow time (in seconds)
PREVIOUS_2_TIME Real flow time two time steps back in time(in seconds)
PREVIOUS_TIMESTEP Real previous physical time step size (in seconds)
N_TIME Integer number of time steps
N_ITER Integer number of iterations

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

7 © 2011 ANSYS, Inc. November 22,


2013
Dynamic Thread data access

• Macros for Dynamic-Mesh Variables defined in dynamesh_tools.h


Macro name Returns Argument types
DT_THREAD (dt) Pointer to a thread Dynamic_Thread *dt
DT_CG (dt) Center of gravity vector Dynamic_Thread *dt

DT_VEL_CG (dt) CG velocity vector Dynamic_Thread *dt

DT_OMEGA_CG (dt) Angular velocity vector Dynamic_Thread *dt


DT_THETA (dt) Orientation of body-fixed axis Dynamic_Thread *dt
vector
DYNAMESH_CURRENT_TIME Current dynamic mesh time N/A
TIME_TO_ABSOLUTE_CRANK Absolute value of the crank angle Real time
_ANGLE (time)

Example: DT_CG (dt)[1] returns the current y coordinate of the body’s CG.

8 © 2011 ANSYS, Inc. November 22,


2013
Example I – 2D Store separation

• Set up remains identical, the only differences


– Read a profile (define/profiles/…)
– Compile & load the UDF
Hook the motion

With profile With UDF


9 © 2011 ANSYS, Inc. November 22,
2013
Example I – 2D Store separation

10 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CG_MOTION & Steady state

DEFINE_CG_MOTION(name, dt, vel, omega, time, dtime)

• 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

• Setting a ‟steady moving” case


– Mostly similar to a transient one

– Keep the solver on steady


– Use the DEFINE_CG_MOTION UDF
• To specify the motion of the boundary
 The dtime passed to the DEFINE_CG_MOTION UDF is by default 1

11 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CG_MOTION & Steady state

DEFINE_CG_MOTION UDF for a steady state case

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

/* compute angular position */

omega[2] = 5;
}

Angular velocity of 5°/sec


This lead to a displacement of
5° as DTIME = 1
12 © 2011 ANSYS, Inc. November 22,
2013
DEFINE_CG_MOTION & Steady state

Workflow for a steady state


• Keep steady state solver
• Activate dynamic mesh
• Choose the right mesh method
– Settings
• Compile & load the UDF

13 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CG_MOTION & Steady state

• Dynamic Mesh Zones


– Define the right type
• & associated parameters
• Save Case
• Preview mesh motion
– Press : update
• Will rotate of 5° at each update

Initial position Updated position

14 © 2011 ANSYS, Inc. November 22,


2013
14. 5 Release

DEFINE_GEOM Macro

15 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_GEOM UDF 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

• 2 predefined simple Geometry shapes already exist under Deforming type


– Dynamic mesh Zone
• Plane projection
• Cylinder projection

• For more complex shapes, define shape using “DEFINE_GEOM” macro

DEFINE_GEOM(parabola, domain, dt, position)

16 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_GEOM Description

DEFINE_GEOM(parabola, domain, dt, position)

• 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

17 © 2011 ANSYS, Inc. November 22,


2013
Example II – Parabola shape

• Geom UDF : Parabola shape


– parabola equation - revolve around Z axis : 𝒚 = −𝟎. 𝟒 ∗ 𝒛2 + 𝟎. 𝟓 ∗ 𝒛 + 𝟎. 𝟑

#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

• Simple predefined shape • More complex shape(s)


– Deforming type condition – User defined

Hook the DEFINE_GEOM UDF

Predefined shape Geom UDF

19 © 2011 ANSYS, Inc. November 22,


2013
14. 5 Release

DEFINE_GRID_MOTION Macro

20 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_GRID_MOTION UDF Macro

• This macro allows to control the motion of each node independently


– Applicable to
• Boundary zone(s)
• Fluid zone(s)
• This macro offers the maximum level of control over the deforming mesh
– No connectivity change is allowed through
– It is called every time step

• Can be combined with rigid body motion, deformations, and relative


motions, or may use projection zones at the same time
– No Remeshing is allowed on boundary (that supports the DEFINE_GRID_MOTION)

DEFINE_GRID_MOTION(udfname, d, dt, time, dtime)

21 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_GRID_MOTION Description

DEFINE_GRID_MOTION(udfname, d, dt, time, dtime)

• 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

22 © 2011 ANSYS, Inc. November 22,


2013
Example III – Pulse in an Artery

• AIM : simulate the impact of a pressure pulse through an artery


• This problem could be coupled with a FEA code and treated as FSI
problem

• To simplify the problem a wave equation will be used to simulate the


pressure pulse

23 © 2011 ANSYS, Inc. November 22,


2013
Example III – Sinusoidal wave

Grid motion UDF : Sinusoidal wave Value definition


Macro
#include"udf.h"

Grid #define D 2e-3 /* Pipe diameter */


#define l 2e-2 /* Pipe length */
#define freq 1 /* frequency */

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


{
face_t f;
Thread *tf = DT_THREAD((Dynamic_Thread *)dt);
int n;
Node *v;
real x; Defintion of variables
real y;

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

25 © 2011 ANSYS, Inc. November 22,


2013
Example III – Pulse in an Artery

• Activate the dynamic mesh model


– Keep smoothing mesh method
– Settings : keep default value
• Switch element types
– All (because the mesh is made of quad elements)

26 © 2011 ANSYS, Inc. November 22,


2013
Example III – Pulse in an Artery

• Compile and Load the UDF


• Setting dynamic mesh zone
– Select bottom wall
– User-Defined
– Motion attributes
• Choose the correct libudf under
Mesh motion UDF
– Meshing options
• Cell height : 0
– There is no additional cell

– Top wall :
• Repeat same settings than bottom

27 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_GRID_MOTION

Limitations

• The motion of a given node is based on absolute (global) coordinates


– Not on relative coordinates
• The new position of a given node is based on its position at the previous
time step,
– not its initial (time = 0) position
28 © 2011 ANSYS, Inc. November 22,
2013
Example IV – Vane Pump

• 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

• The remaining part of the


domain is filled in of tets

Rotor diameter : 6 cm
Angular speed : 1500 rpm
29 © 2011 ANSYS, Inc. November 22,
2013
Example IV – Volumetric fuel pump

30 © 2011 ANSYS, Inc. November 22,


2013
Example IV – Volumetric fuel pump

31 © 2011 ANSYS, Inc. November 22,


2013
Example V – Gerotor with cavitation

Pressure distribution Vapor mass fraction

32 © 2011 ANSYS, Inc. November 22,


2013
Example VI – Fly with beating wings

33 © 2011 ANSYS, Inc. November 22,


2013
Example VII – Swimming Dolphin

34 © 2011 ANSYS, Inc. November 22,


2013
14. 5 Release

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

36 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_DYNAMIC_ZONE_PROPERTY UDF
Macro
• This macro can be used into 2 different ways
2. Variable cell layering height

DEFINE_DYNAMIC_ZONE_PROPERTY(nonconst_height, dt, lh)

• To be used with layering method


• Cell height can become
– A function of time
– Or function of crank angle (with In-Cylinder option)

37 © 2011 ANSYS, Inc. November 22,


2013
Example VIII – Cell layering height

• Simple example of a non constant cell layering height


– Based on one cycle piston motion

Zone
Property
#include "udf.h"
#include "dynamesh_tools.h"

DEFINE_DYNAMIC_ZONE_PROPERTY(nonconst_height, dt, lh)


{
if (CURRENT_TIME < 0.04166667) Cell height remains constant
*lh = 0.065; till the current time reaches
else this target time
*lh=(*lh - CURRENT_TIMESTEP);
}

Cell height will change from one


cell layer to another resulting
from this function
38 © 2011 ANSYS, Inc. November 22,
2013
Example VIII

Workflow to set a case with Non Cst Cell Height


• Activate dynamic mesh
• Choose the layering mesh method
– Settings
• Keep default parameters

• Use In-Cylinder option to create the motion

• Write, Compile & load the Cell Height UDF

39 © 2011 ANSYS, Inc. November 22,


2013
Example VIII

• Set Dynamic mesh zone


– Bottom wall
• Motion Attribute
– Piston-full (from the In-Cylinder definition)
• Meshing option
– Cell Height (libudf)

• Preview mesh

One Cycle

40 © 2011 ANSYS, Inc. November 22,


2013
14. 5 Release

DEFINE_CONTACT Macro

41 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CONTACT UDF Macro

• This macro allow to detect if the computed


mesh motion will result in contact between
a moving surface and surrounding surfaces
– To avoid Negative Cell Volume

• In case of contact within specified


tolerances (Proximity Threshold), mesh
motion of the moving zone can be modeled
according to the expected physics
– User defines how to treat contact region
and whether to restrict flow
• Default porous media zone treatment
– UDF hooks to define contact behavior

Contact detection in a case where the opposite


sides of a box deform in a sinusoidal wave pattern
42 © 2011 ANSYS, Inc. November 22,
2013
DEFINE_CONTACT UDF Macro

• Contact detection can be selected for


• Walls
• Dynamic zones of type Rigid Body & User Defined
– Dynamic zones of type System Coupling cannot be used
• Cells adjacent to face zones that fall below the Proximity
Threshold distance
• can be tagged and separated into new cell zones during
the contact detection process.
• different flow conditions in contact regions can be
specified
• During the simulation,
• once cells in the contact region have been separated into
new zones, A reversed velocity can be
imposed for a falling ball
• the physical properties specified in the respective flow when contact is detected
control zone are copied to the newly separated cell zone. with the floor

DEFINE_CONTACT (contact_props, dt, contacts)

43 © 2011 ANSYS, Inc. November 22,


2013
DEFINE_CONTACT UDF Macro

• Activate the dynamic mesh model


– Select the appropriate mesh method
• Set the parameters
– Set the dynamic mesh zone
• Rigid bodies
• deforming,
• …

– Activate contact detection option


• Click on settings
– Ensure the required boundaries are selected
– Enter a value for the Proximity Threshold
– Ensure that contact_props::libudf is selected in UDF
– Press OK

44 © 2011 ANSYS, Inc. November 22,


2013
Contact Detection
Example

• 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

45 © 2011 ANSYS, Inc. November 22,


2013
Contact Detection
Example

• 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

46 © 2011 ANSYS, Inc. November 22,


2013
Summary

• This chapter has covered some extended capabilities of Deforming Mesh


– in the use of UDF Macros
– 3 types of macros
• Rigid Body motion
– DEFINE_CG_MOTION
• Deformation
– DEFINE_GEOM
– DEFINE_GRID_MOTION
• Property
– DEFINE_DYNAMIC_ZONE_PROPERTY
– DEFINE_CONTACT

47 © 2011 ANSYS, Inc. November 22,


2013

Вам также может понравиться