Data Loading...

FLU_MDM_2019R3_EN_LE06-UDF Flipbook PDF

FLU_MDM_2019R3_EN_LE06-UDF


508 Views
188 Downloads
FLIP PDF 1.71MB

DOWNLOAD FLIP

REPORT DMCA

Lecture 06: User-defined functions ANSYS Fluent Dynamic Mesh Release 2019 R3

11

© 2019 ANSYS, Inc.

Course content 01: Introduction

06: User-defined functions

02: Layering

07: Events

‒ General overview MDM process ‒ Remeshing by adding/removing cell layers

03: Smoothing

‒ Mesh deformation by moving nodes

04: Remeshing

‒ Remeshing by splitting/collapsing individual cells/(2.5D remeshing)

05: Six degrees of freedom

‒ Calculate movement as reaction to forces acting on walls

2

© 2019 ANSYS, Inc.

‒ Definition of complex motion ‒ Condition-based modification of boundary conditions

08: Convergence and stability ‒ Methods to improve stability

09: Overset mesh interfaces

‒ Introduction to overset method

Introduction • A user-defined function (UDF) is a custom sub-program which extends Fluent capabilities ‒ 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 • Strongly recommended: get familiar with UDFs before starting with MDM UDFs ‒ Focused UDF training course available

3

© 2019 ANSYS, Inc.

Introduction • Dynamic Mesh makes use of 3 types of macros

Rigid Body motion Deformation Property

4

© 2019 ANSYS, Inc.

• DEFINE_CG_MOTION • DEFINE_SDOF_PROPERTIES (lecture 6DOF) • DEFINE_GEOM • DEFINE_GRID_MOTION • DEFINE_DYNAMIC_ZONE_PROPERTY • DEFINE_CONTACT

DEFINE_CG_MOTION Macro

55

© 2019 ANSYS, Inc.

DEFINE_CG_MOTION UDF macro • This macro allows object motion as a function of time

‒ Translational ‒ Rotational ‒ In each case with respect to the CG (Center of Gravity) of the body  CG is specified by the user (not calculated by Fluent)  CG is continually updated as the body moves

• This macro defines a prescribed motion • The object moves as a rigid body

‒ Can be used with boundary and cell zones ‒ In both cases all nodes associated with it move as one without any relative motion (deformation)

6

© 2019 ANSYS, Inc.

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

• Input parameters ‒ ‒ ‒ ‒

name: dt: time: dtime:

name of the UDF to identify and hook it in the dynamic mesh panel dynamic thread, pointer to structure that stores the dynamic mesh attributes current time current time step size

• Output parameters ‒ vel: ‒ omega:

7

© 2019 ANSYS, Inc.

translational velocity as 2D or 3D vector rotational velocity as 2D or 3D vector

Profile vs. UDF Profile

((pod transient 3 0) (time 0.0 3.0 10.0) (v_y 0.0 -1.0 -1.0) (omega_z 0.15 0.15 0.15))

Translational velocity

UDF CG

8

© 2019 ANSYS, Inc.

Time (s)

Angular velocity

#include "udf.h” DEFINE_CG_MOTION(object, dt, cg_vel, cg_omega,time, dtime) { NV_S(cg_vel, =, 0.0); /* Initial translational velocity */ NV_S(cg_omega, =, 0.0); /* Initial angular velocity */ if (time Zones > Profiles…) ‒ Compile & load the UDF

With profile 11

© 2019 ANSYS, Inc.

Hook the motion

With UDF

Example 1 – 2D store separation

12

© 2019 ANSYS, Inc.

DEFINE_CG_MOTION & steady state • Rigid body motion can also be used with the steady state solver ‒ Define different 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 ‒ “dtime” passed to the DEFINE_CG_MOTION UDF is 1 s ‒ Mesh update must be triggered manually in GUI or TUI  /solve/mesh-motion yes

13

© 2019 ANSYS, Inc.

DEFINE_CG_MOTION & steady state

CG MOTION STEADY

#include "udf.h" DEFINE_CG_MOTION(object, dt, vel, omega, time, dtime) { /* reset velocities */ NV_S(vel, =, 0.0); NV_S(omega, =, 0.0);

Initial velocity values

/* compute angular position */ omega[2] = 5.0; }

Angular velocity of 5 radians/sec This leads to a displacement of 5 radians as DTIME = 1

14

© 2019 ANSYS, Inc.

DEFINE_GEOM Macro

15 15

© 2019 ANSYS, Inc.

DEFINE_GEOM UDF macro • Remember: Fluent does not know the underlying geometry. Fluent only knows the node locations of the mesh ‒ For nodes to slide along a surface, the shape needs to be defined ‒ Only applicable to boundaries

• 2 predefined basic geometry shapes already exist under deforming type ‒ Dynamic mesh Zone  Plane projection  Cylinder projection

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

16

© 2019 ANSYS, Inc.

DEFINE_GEOM description DEFINE_GEOM(name, domain, dt, position)

• Input parameters

‒ name: name of the UDF to hook it up ‒ domain: pointer to domain ‒ dt: dynamic thread, pointer to structure that stores the dynamic mesh attributes

• Output parameters

‒ position: pointer to array that stores the node positions

17

© 2019 ANSYS, Inc.

Example 2 – parabola shape • Geom UDF: parabola shape

‒ parabola equation - revolve around Z axis: DEFINE GEOM

#include "udf.h" #include "dynamesh_tools.h"

𝒚𝒚 = −𝟎𝟎. 𝟒𝟒 ∗ 𝒛𝒛2 + 𝟎𝟎. 𝟓𝟓 ∗ 𝒛𝒛 + 𝟎𝟎. 𝟑𝟑

DEFINE_GEOM(parabola, domain, dt, position) { real radius; real norm; real x,y,z; x = position[0]; y = position[1]; z = position[2]; radius = -0.4 * z * z + 0.5 * z + 0.3; norm = sqrt(x*x+y*y); position[0] = position[0]*radius/norm; position[1] = position[1]*radius/norm; }

18

© 2019 ANSYS, Inc.

Variable declarations Definition of variables Parabola equation as a function of z X position Y position

Example II – Parabola shape • Simple predefined shape ‒ Deforming type condition

• More complex shape(s) ‒ User defined

Hook the DEFINE_GEOM UDF

Predefined shape 19

© 2019 ANSYS, Inc.

Geom UDF

DEFINE_GRID_MOTION Macro

20 20

© 2019 ANSYS, Inc.

DEFINE_GRID_MOTION UDF Macro • Control the motion of each node independently ‒ Applicable to boundary and cell zones

• Offers the maximum level of control over the deforming mesh ‒ No connectivity change is allowed, though ‒ 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)

21

© 2019 ANSYS, Inc.

DEFINE_GRID_MOTION Description DEFINE_GRID_MOTION(name, domain, dt, time, dtime)

• Input parameters ‒ ‒ ‒ ‒ ‒

name: domain: dt: time: dtime:

name of the UDF to hook it up pointer to domain dynamic thread, pointer to structure that stores the dynamic mesh attributes current time time step size

• Output parameters

22

© 2019 ANSYS, Inc.

Example 3 – 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

© 2019 ANSYS, Inc.

Example 3 – sinusoidal wave Value definition

Grid

#include"udf.h" #define D 2e-3 #define l 2e-2 #define freq 1

Macro

/* Pipe diameter */ /* Pipe length */ /* frequency */

DEFINE_GRID_MOTION(grid_both, domain, dt, time, dtime) { face_t f; Thread *tf = DT_THREAD(dt); int n; Node *v; real x; real y; SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));

24

© 2019 ANSYS, Inc.

Defintion of variables

Example 3 – sinusoidal wave

begin_f_loop(f, tf) { f_node_loop(f, tf, n) { v = F_NODE(f, tf, n); if (NODE_POS_NEED_UPDATE(v)) { /* 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. */ 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; } else { NODE_Y(v) = -y; } Setting of the new node } position on the lower wall } Update_Face_Metrics(f, tf); } end_f_loop(f,tf)

Loop of faces

X position of the node

calculate the new node position on Y

} 25

© 2019 ANSYS, Inc.

Loop on nodes of a face

Flag to mark nodes after they have moved Setting of the new node position on the upper wall

Example 3 – 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

© 2019 ANSYS, Inc.

Example 3 – 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

© 2019 ANSYS, Inc.

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

© 2019 ANSYS, Inc.

DEFINE_DYNAMIC_ZONE_ PROPERTY Macro

35 35

© 2019 ANSYS, Inc.

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)

 sc is the position vector of the swirl center  Has to be calculated by the UDF

36

© 2019 ANSYS, Inc.

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

 Function of time  Function of crank angle (with In-Cylinder option)

37

© 2019 ANSYS, Inc.

Example 8 – 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) *lh = 0.065; else *lh=(*lh - CURRENT_TIMESTEP); }

Cell height remains constant till the current time reaches this target time

Cell height will change from one cell layer to another resulting from this function 38

© 2019 ANSYS, Inc.

Example 8 • Workflow to set a case with non constant cell height

‒ Activate dynamic mesh ‒ Choose the layering mesh method  Keep default parameters ‒ Use in-cylinder option to create the motion ‒ Write, compile & load the cell height UDF

39

© 2019 ANSYS, Inc.

Example 8 • 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

© 2019 ANSYS, Inc.

DEFINE_CONTACT Macro

41 41

© 2019 ANSYS, Inc.

DEFINE_CONTACT UDF macro • This macro allows 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

© 2019 ANSYS, Inc.

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  The physical properties specified in the respective flow control zone are copied to the newly separated cell zone DEFINE_CONTACT (contact_props, dt, contacts)

43

© 2019 ANSYS, Inc.

A reversed velocity can be imposed for a falling ball when contact is detected with the floor

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

© 2019 ANSYS, Inc.

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

© 2019 ANSYS, Inc.

Contact detection – example • In this example one ball moves towards the bottom wall, it will not bounce up after contact

- This is not the same as the animation on the earlier slide in which a DEFINE_CONTACT UDF causes the balls to bounce  The code for the UDF used in the bouncing balls animation on the earlier slide can be found in the ANSYS help https://ansyshelp.ansys.com/account/secured?returnurl=/Vi ews/Secured/corp/v201/en/flu_udf/flu_udf_sec_define_con tact.html ‒ In the example on this slide, 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 “fluid16:contact” 46

© 2019 ANSYS, Inc.

Contours of velocity

Velocity Inlet

Example - Contact and Flow Control #include"udf.h" static static static static

Value definitions

real ball_mass = 500.0; real ball_radius = 0.5; real alter = 1.0; int touching = 0;

DEFINE_CONTACT(contact_props, dt, contacts) { int nid = THREAD_ID(DT_THREAD(dt)); real x; real y;

Macro Code to be executed when contact has been detected

/* following lines are a trick needed because contact detection stops detecting if velocity = 0 for DOF zones. It sets a rotational velocity of +/ 1e-6 radians/second. Since the radius is 0.5 m, the tangential velocity of the surface is 5-e7 m/s, effectively 0 */ SDOF_Get_Motion(dt, vel0, omega0, theta0); omega0[2] = alter * 1e-6; /* reverses direction of rotation each time step */ SDOF_Overwrite_Motion (dt, vel0, omega0, theta0); alter *= -1; / /* "touching" is used for other DEFINE macros to know that contact has occured */ touching = 1; } 47

© 2019 ANSYS, Inc.

Example - Contact and Flow Control DEFINE_SDOF_PROPERTIES(secondball_props, prop, dt, time, dtime) { Thread *thread; thread = DT_THREAD (dt); prop[SDOF_MASS] prop[SDOF_IXX] prop[SDOF_IYY] prop[SDOF_IZZ]

= = = =

ball_mass; (2.0 / 5.0) * ball_mass * ball_radius * ball_radius; (2.0 / 5.0) * ball_mass * ball_radius * ball_radius; (2.0 / 5.0) * ball_mass * ball_radius * ball_radius;

prop[SDOF_ZERO_ROT_X] = TRUE; prop[SDOF_ZERO_ROT_Y] = TRUE;

} 48

if(touching) { Message("Contact detected prop[SDOF_ZERO_TRANS_X] = prop[SDOF_ZERO_TRANS_Y] = #if RP_3D prop[SDOF_ZERO_TRANS_Z] = #endif }

© 2019 ANSYS, Inc.

Set mass, moments of inertia

Disable rotation Once contact occurs, touching is set to 1 by the DEFINE_CONTACT macro

... motion stopped\n"); TRUE; If contact detected, TRUE; TRUE;

Macro

these commands set translational motion to zero Object effectively sticks to the wall

Summary • This chapter has covered some extended capabilities of deforming mesh ‒ 3 types of macros  Rigid body motion

 DEFINE_CG_MOTION

 Deformation

 DEFINE_GEOM  DEFINE_GRID_MOTION

 Property

 DEFINE_DYNAMIC_ZONE_PROPERTY  DEFINE_CONTACT

49

© 2019 ANSYS, Inc.

Workshops • Workshop 06.1: Use of UDF for moving/deforming mesh ‒ Rigid body motion with DEFINE_CG_MOTION ‒ Define topological shape with DEFINE_GEOM ‒ Deform a boundary with DEFINE_GRID_MOTION

50

© 2019 ANSYS, Inc.