Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Dynamic Mesh DEFINE_GRID_MOTION UDF Errors

    • jdch232
      Subscriber

      Hello,

      I'm attempting to model a flexible flat plate using using a UDF with the DEFINE_GRID_MOTION macro in Fluent 2025 R1 student through Workbench. I'm new to using UDFs, though I have gotten some working. I'm defining a flexible plate as one that alternates between flat and bulging outwards in several peaks over time.

      I'm using the following equation for y-velocity: Vy = (5pi/33) * (sin{2pi * t - 1.5} + 1) * sin{10000pi * x}

      This results in a plate alternating between flat at 0s, 1s, 2s, ... and a flexed at 0.5s, 1.5, 2.5s, ..., as shown below.

      I'm using the following c code:

      #include "udf.h"

      DEFINE_GRID_MOTION(flexible_wall_velocity, domain, dt, time, dtime)
      {
        Thread *t;
        face_t f;
        Node *v;
        real NV_VEC(velocity);

        thread_loop_c(t, domain)
        {
            // Loop across faces in wall
            begin_f_loop(f, t)
            {
              // Loop across nodes of face
              f_node_loop(f, t, v)
              {
                // Current node's coordinates
                real x_coord = NODE_X(v);
                real y_coord = NODE_Y(v);

                // Calculate velocity based on x_coord and time
                velocity[0] = 0;
                velocity[1] = (5 * 3.14159 / 33) * (sin(2 * 3.14159 * time - 1.5) + 1) * (sin(1000 * 3.14159 * x_coord));

                // Update node's position from calculated velocity
                NODE_X(v) += velocity[0] * dtime;
                NODE_Y(v) += velocity[1] * dtime;
              }
            }
            end_f_loop(f, t)
          }
        }

      When I compile the code in Fluent I get this warning: 

      "warning: ordered comparison between pointer and integer ('Node *' (aka 'struct _tg_node_struct *') and 'int')

                  f_node_loop(f, t, v)

                  ^~~~~~~~~~~~~~~~~~~~"

      I've looked into this and found it's saying I'm comparing a pointer variable and an integer. Though I'm having trouble seeing where.

      Then when I create the dynamic mesh on the plate, I get this warning:

      "Warning: incorrect cg motion UDF flexible_wall_velocity::libudf on zone 10 (assuming no motion)"

      This confuses me as I'm not using the CG Motion macro. Does anyone have any advice or direction I could take?

    • Mark O
      Ansys Employee

      Please see the example for DEFINE_GRID_MOTION in the Fluent Customization manual. It is not f_node_loop(f, t, v). It is

      int n;

      f_node_loop(f,t,n)

      {

        v = F_NODE(f,t,n);

      }

       

    • jdch232
      Subscriber

      Yes I was able to get it working. For anyone who might find it helpful, this is the code that ended up working:

       

      #include "udf.h"
      #include "math.h"

      #define PI 3.14159

      DEFINE_GRID_MOTION(dynamic_wall_motion, domain, dt, time, dtime)
      {
          Thread *thread = DT_THREAD(dt);
          face_t f;
          Node *v;
          int n;

          real x, y, dy;

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

                  if (NODE_POS_NEED_UPDATE(v))
                  {
                      x = NODE_X(v);
                      y = NODE_Y(v);

                      dy = (1.0 / 80000.0) * (sin((20000000.0 / 3.0) * PI * time - 1.5) + 1) * -cos(10000.0 * PI * x);

                      NODE_Y(v) = dy;
                      NODE_POS_UPDATED(v);
                  }
              }
          }
          end_f_loop(f, thread)
      }
      Just plug that into the dynamic mesh and apply it to whatever boundary you're moving
Viewing 2 reply threads
  • You must be logged in to reply to this topic.
[bingo_chatbox]