CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   using DEFINE_GEOM to change 2D geometry- shear constant area (https://www.cfd-online.com/Forums/fluent/226672-using-define_geom-change-2d-geometry-shear-constant-area.html)

ystein May 4, 2020 15:11

using DEFINE_GEOM to change 2D geometry- shear constant area
 
5 Attachment(s)
Hi All,

I have been trying to deform a square into a rhombic shape such as the attached pure strain image and have been testing out a few UDFs to deform the boundaries.
Attachment 77223


I start out with a simple mesh geometry like this:
Attachment 77225
and use DEFINE_GEOM to deform all four walls (labeling is wall12 top right wall and then going clockwise).
This is my dynamic mesh setup page:
Attachment 77229


Current issues with my UDF:
(1) Something that I am worried about is CURRENT_TIME, so I tried to output it as a message, but it always shows like 21 times? Should i put it outside the function? such as in my TUI:

"Updating mesh to time 3.00000e-02 (step = 00003)... time = 0.020000
time = 0.020000
time = 0.020000
time = 0.020000
time = 0.020000
time = 0.020000
time = 0.020000
time = 0.020000
time = 0.020000
"


(2) my mesh is only moving in the y direction, but I know I need to be stretching all four "corners" so it should update x and y.
Attachment 77230

Any help is appreciated. I have also tried to use DEFINE_GRID_MOTION to move the walls at an angle, but to no avail.

I have attached my full UDF, but a snippet of it is as follows:

#include "udf.h"
#include "unsteady.h"

#define W 64 /* side wall of trough, mm */
#define gamma 0.2 /* desired strain */
#define vel_exp 5e-2 /* expansion velocity mm/s */
#define vel_comp 4.52267e-2 /* compression velocity mm/s */

DEFINE_GEOM(wall_12geom, domain, dt, position)
{ Message("time = %f\n ", CURRENT_TIME , '\n');
real D,R,L,l;
real hD,hL,hl;
real dlength_L, dlength_l;
real update_length_L, update_length_l;

/*constants */
D = sqrt(2)*W; /*diagnol of square, intial*/
R = sqrt((2+gamma)/(2-gamma));
L = R*D; /*expansion axis diagnol, final*/
l = pow(D,2)/L; /* compression axis diagnol, final*/
hD=D/2; /* use these variables to calculte angle*/

real t = CURRENT_TIME;
real slope12, intercept12; /* geometry line */

dlength_L = vel_exp*t; /*delta change in expansion axis from ORIGIN, lengthening x axis*/
dlength_l = -1*vel_comp*t; /*delta change in compression axis from ORIGIN, shortening y axis*/

update_length_L = hD + dlength_L; /* every time step length, L from ORIGIN to sharp corner*/
update_length_l = hD + dlength_l; /* every time step length,l from ORIGIN to sharp corner*/

/* set variables */
slope12 = dlength_l/dlength_L; /*neg */
intercept12 = update_length_l; /*pos*/

/* set y = mx + b dependent on time*/
position[0] = position[0] + dlength_L; /* START HERE */

position[1] = slope12*position[0] + intercept12;


}

vinerm May 5, 2020 07:20

Shape Deformation
 
Instead of using DEFINE_GEOM, use DEFINE_GRID_MOTION. This way you can control motion of each individual node instead of a boundary. If you want to use DEFINE_GEOM, then you have to define four different functions, one for each edge.

ystein May 5, 2020 08:27

Quote:

Originally Posted by vinerm (Post 768790)
Instead of using DEFINE_GEOM, use DEFINE_GRID_MOTION. This way you can control motion of each individual node instead of a boundary. If you want to use DEFINE_GEOM, then you have to define four different functions, one for each edge.

Hi Vinerm,

Thank you for your reply. I had originally used DEFINE_GRID_MOTION to control the edge boundaries ( one function for each edge), but did not get it to work properly. With DEFINE_GRID_MOTION, I moved each node of the boundaries based on the angle of the two corners that were moving. My code for one of the wall boundaries is below.

However, I think you are saying I should use DEFINE_GRID_MOTION on the interior surface body too? I'm a little confused how you would avoid cell skew using that? Could you expound on that? Thanks!

I wonder if this has to do with constraining a mesh that resists the movement of the boundary walls to turn " inward."


Code:

/*expansion*/
DEFINE_CG_MOTION(corner2cg, dt, cg_vel, cg_omega, time, dtime)
{
  cg_vel[0] = vel_exp;
  cg_vel[1] = 0.0;
  cg_vel[2] = 0.0;


}

/*compression*/
DEFINE_CG_MOTION(corner3cg, dt, cg_vel, cg_omega, time, dtime)
{
  cg_vel[0] = 0.0;
  cg_vel[1] = vel_comp;
  cg_vel[2] = 0.0;


}

/*expansion*/
DEFINE_CG_MOTION(corner4cg, dt, cg_vel, cg_omega, time, dtime)
{
  cg_vel[0] = -1*vel_exp;
  cg_vel[1] = 0.0;
  cg_vel[2] = 0.0;


}

/* PROGRESS */
DEFINE_GRID_MOTION(wall_12grid, domain, dt, time, dtime)
{
  Thread *tf = DT_THREAD (dt);
  face_t f;
  Node *v;
  real D,R,L,l;
  real hD,hL,hl;
  real dlength_L, dlength_l;
  real update_length_L, update_length_l;
  real alpha_new,d_alpha;
  real NV_VEC(centroid), NV_VEC(rvec), NV_VEC(dvel), NV_VEC(dx);
  real NV_VEC(d_omega);
  int n;
 
  /* !!!! update here !!!!*/
  /* initialize the vectors */
  NV_D(centroid, =, 0, 0.0, 0.000); /* meters CONSTANTLY MOVING! */
  NV_S(d_omega,=,0.0); /* cycles per second */
 
  /*constants */
        D = sqrt(2)*W; /*diagnol of square, intial*/
        R = sqrt((2+gamma)/(2-gamma));
        L = R*D; /*expansion axis diagnol, final*/
        l = pow(D,2)/L; /* compression axis diagnol, final*/
       
        hD=D/2; /* use these variables to calculte angle*/
        hL=L/2;
        hl=l/2;

       
        dlength_L = vel_exp*time; /*delta change in expansion axis from ORIGIN, lengthening*/
        dlength_l = -1*vel_comp*time; /*delta change in compression axis from ORIGIN, shortening*/
       
        update_length_L = hD + dlength_L; /* every time step length, L from ORIGIN*/
        update_length_l = hD + dlength_l; /* every time step length,l from ORIGIN*/
       
        alpha_new = atan2(update_length_l,update_length_L); /* change in angle of wall,rad */
        d_alpha = alpha_prev - alpha_new; /* change in angle from prior timestep to now, rad */
        alpha_prev = alpha_new; /* store change in angle (rad) per time step */
       
        d_omega[2] = d_alpha/dtime/(2*M_PI); /* cycles per second [Hz] every time step update*/
       
        /* change the reference vector */
        centroid[0] = update_length_L;

        Message("centroid_x = %f,dlength_L = %f, dlength_l = %f, alpha_new = %f, alpha_prev = %f", centroid[0],dlength_L, dlength_l, alpha_new,alpha_prev );
 
/* Set/activate the deforming flag on adjacent cell zone, which      */
/* means that the cells adjacent to the deforming wall will also be  */
/* deformed, in order to avoid skewness.                            */
  SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));

/* Loop over the deforming boundary zone's faces;                    */
/* inner loop loops over all nodes of a given face;                  */
/* Thus, since one node can belong to several faces, one must guard  */
/* against operating on a given node more than once:                */

  begin_f_loop (f, tf)
    {
      f_node_loop (f, tf, n)
        {
          v = F_NODE(f, tf, n);

          /* Update the current node only if it has not been        */
                  /* previously visited:                                    */
          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 during a future pass through the loop:      */
              NODE_POS_UPDATED (v);
                         
                          NV_VV(rvec, =, NODE_COORD(v),-,centroid); /* setting vector distance*/
                          NV_CROSS(dx, d_omega, rvec); /* velocity vector, m/s = (1/s * m )*/
                          NV_S(dx,*=,dtime); /* distance vector*/
                          NV_V(NODE_COORD(v),+=,dx); /* updating current nodes to new position) */
               
            }
        }
    }
  end_f_loop (f, tf);
 
  b++;
}



All times are GMT -4. The time now is 05:57.