2.6.6.  DEFINE_CONTACT

2.6.6.1. Description

You can use DEFINE_CONTACT to specify the response to a contact detection event in ANSYS Fluent. Note that UDFs that are defined using DEFINE_CONTACT can be executed only as compiled UDFs.

2.6.6.2. Usage

DEFINE_CONTACT (name, dt, contacts)

Argument Type

Description

symbol name

UDF name.

Dynamic_Thread *dt

Pointer to structure that stores the dynamic mesh attributes that you have specified (or that are calculated by ANSYS Fluent).

Objp *contacts

Pointer to a NULL-terminated linked list of elements involved in the contact detection event.

Function returns

void

There are three arguments to DEFINE_CONTACT: name, dt, and contacts. You supply name, the name of the UDF. The dt and contacts structure pointers are passed by the ANSYS Fluent solver to your UDF.

2.6.6.3. Example 1

/************************************************************\
 * 2-degree of freedom equation of motion compiled UDF      *
\************************************************************/

DEFINE_CONTACT(contact_props, dt, contacts)
{
  Objp *o;
  face_t face;
  Thread *thread;
  Domain *domain = NULL;
  Dynamic_Thread *ndt = NULL;

  int tid, nid, n_faces;

  real v0dotn1, v1dotn0;
  real nc_mag, norm0_mag, norm1_mag;

  real N3V_VEC (vel_rel);
  real N3V_VEC (nc), N3V_VEC (nctmp);
  real N3V_VEC (xc), N3V_VEC (xctmp);
  real N3V_VEC (vel0), N3V_VEC (omega0), N3V_VEC (theta0), N3V_VEC (norm0);
  real N3V_VEC (vel1), N3V_VEC (omega1), N3V_VEC (theta1), N3V_VEC (norm1);

  if (!Data_Valid_P())
    {
      return;
    }

  /* Define a common contact point / plane */
  N3V_S (nc, =, 0.0);
  N3V_S (xc, =, 0.0);

  /* Fetch current thread ID */
  tid = THREAD_ID (DT_THREAD (dt));

  nid = -1;
  n_faces = 0;

  loop (o, contacts)
    {
      face = O_F (o);
      thread = O_F_THREAD (o);

      /* Skip faces on current thread */
      if (THREAD_ID (thread) == tid)
        {
          continue;
        }

      /* Note ID for posterity */
      if (nid == -1)
        {
          nid = THREAD_ID (thread);
        }

      /* Initialize to zero */
      N3V_S (nctmp, =, 0.0);
      N3V_S (xctmp, =, 0.0);

      F_AREA (nctmp, face, thread);
      F_CENTROID (xctmp, face, thread);

#     if DEBUG
        {
          Message0
          (
            "\nFace:: %d (%d): Area: (%f %f %f) Centre: (%f %f %f)",
            face, THREAD_ID (thread),
            nctmp[0], nctmp[1], nctmp[2],
            xctmp[0], xctmp[1], xctmp[2]
          );
        }
#     endif

      /**
       * Negative sum because wall normals
       * point out of the fluid domain
       */
      N3V_V (nc, -=, nctmp);
      N3V_V (xc, +=, xctmp);

      n_faces++;
    }

# if RP_NODE
    {
      /* Reduce in parallel */
      nid = PRF_GIHIGH1 (nid);
      n_faces = PRF_GISUM1 (n_faces);

      PRF_GRSUM3 (nc[0], nc[1], nc[2]);
      PRF_GRSUM3 (xc[0], xc[1], xc[2]);
    }
# endif

  if (n_faces > 0)
    {
      nc_mag = N3V_MAG (nc) + REAL_MIN;

      N3V_S (nc, /=, nc_mag);
      N3V_S (xc, /=, n_faces);
    }
  else
    {
      return;
    }

  Message
  (
    "\nContact:: tid: %d nid: %d n_faces: %d "
    "Point: (%f %f %f) Normal: (%f %f %f)",
    tid, nid, n_faces,
    xc[0], xc[1], xc[2],
    nc[0], nc[1], nc[2]
  );

  /* Fetch thread for opposite body */
  domain = THREAD_DOMAIN (DT_THREAD (dt));
  thread = Lookup_Thread (domain, nid);

  if (NULLP (thread))
    {
      Message ("\nWarning: No thread for nid: %d ", nid);

      return;
    }
  else
    {
      ndt = THREAD_DT (thread);
    }

  /* Fetch body parameters */
  SDOF_Get_Motion (dt, vel0, omega0, theta0);

  /* Compute difference vectors and normalize */
  N3V_VV (norm0, =, xc, -, DT_CG (dt));
  norm0_mag = N3V_MAG (norm0) + REAL_MIN;
  N3V_S (norm0, /=, norm0_mag);

  if (NULLP (ndt))
    {
      /* Stationary body / wall. Use contact normal */
      N3V_V (norm1, =, nc);

      /* Compute relative velocity */
      N3V_S (vel1, =, 0.0);
      N3V_V (vel_rel, =, vel0);
    }
  else
    {
      /* Fetch body parameters */
      SDOF_Get_Motion (ndt, vel1, omega1, theta1);

      /* Compute relative velocity */
      N3V_VV (vel_rel, =, vel0, -, vel1);

      /* Compute difference vectors and normalize */
      N3V_VV (norm1, =, xc, -, DT_CG (ndt));
      norm1_mag = N3V_MAG (norm1) + REAL_MIN;
      N3V_S (norm1, /=, norm1_mag);

      /* Check if velocity needs to be reversed */
      if (N3V_DOT (vel_rel, nc) < 0.0)
        {
          /* Reflect velocity across the normal */
          v1dotn0 = 2.0 * N3V_DOT (vel1, norm0);

          N3V_S (norm0, *=, v1dotn0);
          N3V_V (vel1, -=, norm0);

          /* Override body velocity */
          SDOF_Overwrite_Motion (ndt, vel1, omega1, theta1);
        }
    }

  /* Check if velocity needs to be reversed */
  if (N3V_DOT (vel_rel, nc) < 0.0)
    {
      /* Reflect velocity across the normal */
      v0dotn1 = 2.0 * N3V_DOT (vel0, norm1);

      N3V_S (norm1, *=, v0dotn1);
      N3V_V (vel0, -=, norm1);

      /* Override body velocity */
      SDOF_Overwrite_Motion (dt, vel0, omega0, theta0);
    }

  Message
  (
    "\ncontact_props: Updated :: vel0 = (%f %f %f) vel1 = (%f %f %f)",
    vel0[0], vel0[1], vel0[2], vel1[0], vel1[1], vel1[2]
  );
}

2.6.6.4. Example 2

You can also use nodal contact information in a DEFINE_GRID_MOTION UDF that can be used to constrain grid motion in certain situations.

/*********************************************************************\
 * This UDF provides the moving-deforming mesh model with the        *
 * locations of the nodes on a deforming boundary. The UDF uses      *
 * nodal contact information to constrain motion.                    *
 * Compiled UDF, all metric units                                    *
\*********************************************************************/

#include "udf.h"

static real L = 2.5;
static real xoffset = 2.8;
static real amplitude = 1.0;
static real total_time = 15.0;

DEFINE_GRID_MOTION(wall_deform_top, domain, dt, time, dtime)
{
  int n;
  Node *node;
  face_t face;

  real A, factor, fraction;

  Thread *thread = DT_THREAD (dt);

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

  /**
   * Loop over the deforming boundary zone 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 (face, thread)
    {
      f_node_loop (face, thread, n)
        {
          node = F_NODE (face, thread, n);

          /* Compute the amplitude as a function of time */
          fraction = (time / total_time);

          factor = -1.0 * fabs (2.0 * (fraction - floor (fraction + 0.5)));

          A = factor * amplitude * sin (M_PI * (NODE_X (node) - xoffset) / L);

          /*
           * If node is in contact and motion is downward,
           * prevent further motion.
           */
          if (NODE_POS_CONTACT_P (node) && ((A + 1.0) < NODE_Y (node)))
            {
              NODE_POS_UPDATED (node);
              continue;
            }

          /*
           * Update the current node only if it has not been
           * previously visited:
           */
          if (NODE_POS_NEED_UPDATE (node))
            {
              /**
               * 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 (node);

              NODE_Y (node) = A + 1.0;
            }
        }
    }
  end_f_loop (face, thread);
}

2.6.6.5. Hooking a DEFINE_CONTACT UDF to ANSYS Fluent

After the UDF that you have defined using DEFINE_CONTACT is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible in the UDF drop-down list in the Contact Detection tab of the Options dialog box in ANSYS Fluent. See Hooking DEFINE_CONTACT UDFs for details on how to hook your DEFINE_CONTACT UDF to ANSYS Fluent.


Release 18.2 - © ANSYS, Inc. All rights reserved.