CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

Help with DEFINE_GRID_MOTION

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree6Likes
  • 6 Post By TDi

Reply
 
LinkBack Thread Tools Display Modes
Old   March 24, 2010, 15:31
Default Help with DEFINE_GRID_MOTION
  #1
TDi
Member
 
Tim Diller
Join Date: Mar 2010
Location: Austin, TX
Posts: 32
Rep Power: 7
TDi is on a distinguished road
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()
SET_DEFORMING_THREAD_FLAG()
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)
{
  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);

          /* 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 is offline   Reply With Quote

Old   March 25, 2010, 17:22
Default
  #2
TDi
Member
 
Tim Diller
Join Date: Mar 2010
Location: Austin, TX
Posts: 32
Rep Power: 7
TDi is on a distinguished road
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.
dfeid, xisto, aerosjc and 3 others like this.
TDi is offline   Reply With Quote

Old   July 7, 2010, 14:04
Default
  #3
Senior Member
 
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 7
enry is on a distinguished road
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.
enry is offline   Reply With Quote

Old   July 12, 2010, 10:40
Default
  #4
TDi
Member
 
Tim Diller
Join Date: Mar 2010
Location: Austin, TX
Posts: 32
Rep Power: 7
TDi is on a distinguished road
I didn't find cyl3d.msh in my tutorial files.
TDi is offline   Reply With Quote

Old   July 12, 2010, 10:58
Default
  #5
TDi
Member
 
Tim Diller
Join Date: Mar 2010
Location: Austin, TX
Posts: 32
Rep Power: 7
TDi is on a distinguished road
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*/
/*		   dt,             dynamic thread pointer*/
/*		   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*/
  Thread *tf = DT_THREAD(dt);
  face_t f;
  Node *node;
  int n;
  int zone_ID = THREAD_ID(tf);
  int zi=0;
 
  if (zone_ID == ZONE1_ID) {
    zi=0;
  }
  else if (zone_ID == ZONE2_ID) {
    zi=1;
  }
  else {
    printf("\nmove_layer: zone_ID %d not found",zone_ID);
    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);
    SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));

    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.");
}
TDi is offline   Reply With Quote

Old   July 20, 2010, 01:11
Default
  #6
GeR
New Member
 
Wah Keng Sern
Join Date: Oct 2009
Posts: 6
Rep Power: 7
GeR is on a distinguished road
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 !!

Thanks in advance.
GeR is offline   Reply With Quote

Old   December 28, 2012, 15:50
Default dynamic mesh
  #7
New Member
 
Join Date: Nov 2011
Posts: 1
Rep Power: 0
jahan53 is on a distinguished road
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.
which of macros of dynamic mesh must be used? please advise.
jahan53 is offline   Reply With Quote

Reply

Tags
define macro, fluent, grid_motion, udf

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 22:29.