CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   Help with DEFINE_GRID_MOTION (http://www.cfd-online.com/Forums/fluent-udf/74114-help-define_grid_motion.html)

 TDi March 24, 2010 15:31

Help with DEFINE_GRID_MOTION

I'm having trouble getting DEFINE_GRID_MOTION to work. The example for grid motion in section 2.6.3 of the manual includes some macros for which I cannot find documentation but are important:
NV_VEC()
NODE_POS_NEED_UPDATE()
NODE_POS_UPDATED()
I'm having trouble understanding how the node positions are updated. Where does the write occur? Is there are simple function for writing a new position to a node? Sample code from UDF manual 2.6.3 follows:

Code:

/**********************************************************
node motion based on simple beam deflection equation
compiled UDF
**********************************************************/
#include "udf.h"

DEFINE_GRID_MOTION(beam,domain,dt,time,dtime)
{
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 */

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

/* 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);
}

 TDi March 25, 2010 17:22

I'll answer my own question since I'm certain someone else will have the same question.
Operations on node geometry happen using vectors declared as real NV_VEC.
Values are assigned with NV_S for scalars and NV_D for three component lists.
Thus NV_S(omega, =, 0.0) gives the omega NV_VEC a scalar value of 0.0 and NV_D(axis, =, 0.0, 1.0, 0.0) makes axis = [0,1,0].
The node value is changed later with NV_V(NODE_COORD(v),+=,dx) which has the effect of adding dx to the coordinates of node v.

Maybe this is obvious to other people, but it took some time for me to figure out.

 enry July 7, 2010 14:04

Hi TDi !

Have you understand how can you move the domain?
I have to deform a flat-plate to a given geometry, where deformation is imposed by user.
Can you help me?
Thanks a lot.

 TDi July 12, 2010 10:40

I didn't find cyl3d.msh in my tutorial files.

 TDi July 12, 2010 10:58

Here's how I did this:
In my geometry, there are multiple zones on the surface to be moved, so I keep track of the last time each was moved with a static global variable.
I have changed some of the variable names due to IP concerns and have not tested this code as shown below, so I can't promise that it's free of syntax errors.
In my application, the zones are moved automatically at a specified interval, but you can easily adapt this to other uses.
Hope this helps.

Code:

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

/********************** UDF Explanation Starts ***************************
This udf is used to provide a moving boundary.

Written by : Tim Diller (UT Austin)
Last updated : 07/2010
********************** UDF Explanation Ends *****************************/

/*************************** User Input Starts *****************************/
# define INTERVAL 20      /* seconds - time between moves*/
# define START_TIME 20                /*time when the process starts*/
# define MOVE_THICKNESS 0.0005    /* meters */
# define ZONE1_ID 3                /*from Boundary Conditions panel*/
# define ZONE2_ID 6            /*from Boundary Conditions panel*/
# define NUM_ZONES 17    /*size array properly for tracking zone movement*/
/*************************** User Input Ends *******************************/

/*arrays initialized with a single value default to zero for all
unspecified values*/
static float previous_move_time[2] = {0}; /*time of the last face move*/
static float previous_time[2] = {0};      /*time of the last execution*/

/*DEFINE_GRID_MOTION(move_layer, udf name*/
/*                  domain,      domain pointer - face to be moved*/
/*                  time,          current simulation time (s)*/
/*                  dtime,        time step (s)*/

DEFINE_GRID_MOTION(move_layer,domain,dt,time,dtime){
real current_time = time;
real NV_VEC(layer); /*real vector for offsetting the nodes*/
face_t f;
Node *node;
int n;
int zi=0;

if (zone_ID == ZONE1_ID) {
zi=0;
}
else if (zone_ID == ZONE2_ID) {
zi=1;
}
else {
return;
}

/* Move the layer */
if((current_time >= START_TIME) & \
(current_time >= previous_move_time[zi]+INTERVAL)) {

printf("\n***** Adjusting grid for zone %d at time %.1f.",zone_ID,current_time);
/* write the layer offset direction to an NV_VEC variable 'layer'.*/
NV_D(layer, =, 0.0, 0.0, LAYER_THICKNESS);

begin_f_loop(f,tf) { /* loop over all the faces in the domain (zone) to move */
f_node_loop(f,tf,n) { /* loop over all the nodes of each face */
node = F_NODE(f,tf,n);
if(NODE_POS_NEED_UPDATE(node)){ /*add layer to the current node position*/
NV_V(NODE_COORD(node), +=, layer);
NODE_POS_UPDATED(node);
}/* end if node pos needs update loop */
}/* end_f_node_loop */
} end_f_loop(t,tf);
previous_move_time[zi] = current_time;
printf("\n **** Z-position=%f.",NODE_Z(node));
}/*end if - move layer*/

previous_time[zi] = current_time;
printf("\nDone with move_layer.");
}

 GeR July 20, 2010 01:11

Hi TDi,

I'm new to this area.
May I know this CG_MOTION is applicable for 3D problem ??
If I want to move a face, how should I proceed ?? Please advise !!

 jahan53 December 28, 2012 15:50

dynamic mesh

i want to write a udf that it can fluctuates a diaphragm but not as a piston(rigid body). two ends of diaphragm are fixed.