You are on page 1of 10

UDFs For Moving/Deforming Mesh

Main FLUENT Macros


Fluent provides the following macros for MDM calculations:
DEFINE_CG_MOTION DEFINE_GEOM DEFINE_GRID_MOTION

DEFINE_CG_MOTION Macro
Used to define the motion of the center of gravity for rigid body motion: Macro: DEFINE_CG_MOTION ( name, dt, vel, omega, time, dtime) Argument types: void *dt (dynamic thread pointer; common in all macros) real vel[] (array that returns the CG velocity) real omega[] (array that returns the of the CG) real time (time) real dtime (time step) Function returns: void

DEFINE_CG_MOTION Example
#include "udf.h" #include "dynamesh_tools.h" static real v_prev = 0.0; DEFINE_CG_MOTION(piston, dt, vel, omega, time, dtime) { Thread *t; face_t f; real NV_VEC (A); real force, dv; /* reset velocities */ NV_S (vel, =, 0.0); NV_S (omega, =, 0.0); if (!Data_Valid_P ()) return; /* get the thread pointer for which this motion is defined */ t = DT_THREAD ((Dynamic_Thread *)dt); } /* compute pressure force on body by looping through all faces */ force = 0.0; begin_f_loop (f, t) { F_AREA (A, f, t); force += F_P (f, t) * NV_MAG (A); } end_f_loop (f, t) /* compute change in velocity, i.e., dv = F * dt / mass velocity update using explicit euler formula */ dv = dtime * force / 50.0; v_prev += dv; Message ("time = %f, x_vel = %f, force = %f\n", time, v_prev, force); /* set x-component of velocity */ vel[0] = v_prev;

DEFINE_GEOM Macro
The DEFINE_GEOM macro is used to define geometry in a deforming zone (except for cylindrical geometries) Macro: DEFINE_GEOM ( name, d, dt, position) Argument types: char name Domain *d void *dt real *position (this matrix is overwritten with the node position on the boundary) Function returns: void

DEFINE_GEOM Example
/************************************************************* * defining parabola through points (0, 1), (1/2, 5/4), (1, 1) * ************************************************************/ #include "udf.h" DEFINE_GEOM(parabola, domain, dt, position) { /* set y = -x^2 + x + 1 */ position[1] = - position[0]*position[0] + position[0] + 1; } The new position (after projection to the geometry defining the zone) is returned to FLUENT by overwriting the position array

DEFINE_GRID_MOTION Macro
Useful when defining the position of the nodes individually, e.g. fluid-structure interaction. DEFINE_GRID_MOTION ( name, d, dt, time, dtime) Argument types: char name Domain *d void *dt real time real dtime Function returns: void

DEFINE_GRID_MOTION Example
Case: Specify the deflection of a beam based on local coordinate x and time t according to

( x, t ) = {

10 .4 x sin( 27 .178 t ), x > 0.02 0, x < 0.02

Node position is updated based on:

r n +1 = r n + r n t

DEFINE_GRID_MOTION Example
/********************************************************
* * node motion based on simple beam deflection equation * compiled UDF * *************************************************** *******/ #include "udf.h" DEFINE_GRID_MOTION(beam, domain, dt, time, dtime) { Thread *tf = DT_THREAD (dt); face_t f; Node *v; real NV_VEC (omega), NV_VEC (axis), NV_VEC (dx); real NV_VEC (origin), NV_VEC (rvec); real sign; int n;

/* set deforming flag on adjacent cell zone */ SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf)); sign = -5.0 * sin (26.178 * time); Message ("time = %f, omega = %f\n", time, sign); NV_S (omega, =, 0.0); NV_D (axis, =, 0.0, 1.0, 0.0); NV_D (origin, =, 0.0, 0.0, 0.152); begin_f_loop (f, tf) { f_node_loop (f, tf, n) { v = F_NODE (f, tf, n);

DEFINE_GRID_MOTION Example
/* update node if x position is greater than 0.02 and that the current node has not been previously visited when looping through previous faces */ if (NODE_X (v) > 0.020 && NODE_POS_NEED_UPDATE (v)) { /* indicate that node position has been update so that it's not updated more than once */ NODE_POS_UPDATED (v); omega[1] = sign * pow (NODE_X (v)/0.230, 0.5); NV_VV (rvec, =, NODE_COORD (v), -, origin); NV_CROSS (dx, omega, rvec); NV_S (dx, *=, dtime); NV_V (NODE_COORD (v), +=, dx); } } } end_f_loop (f, tf); }

You might also like