Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

After importing the UDF, it crashes as soon as the calculation is made

    • 智敏 徐
      Subscriber

      We currently use porous media to make capillary cores, and UDFs to add capillary force to porous media so that they can be aspirated, but the code we write can be imported normally but crashes as soon as we calculate it

      #include "udf.h"
      #define PARAMETER_P 1.0 // 替换为实际的参数值
      #define UDS_INDEX 0
      #define UDM_INDEX 0
      #define USR_SOURCE_INDEX 0
       
      DEFINE_ADJUST(adjust_and_store_gradient, domain)
      {
          Thread *t;
          cell_t c;
          face_t f;
          real grad[ND_ND]; // 存储梯度的数组
          domain = Get_Domain(2); // 假设domain_ID为2
          thread_loop_c(t, domain)
          {
              begin_c_loop(c, t)
              {
                  C_UDMI(c, t, UDM_INDEX) = 0.0; // 初始化UDM
                  C_UDSI(c, t, UDS_INDEX) = C_VOF(c, t); // 设置UDS为当前体积分数
                  if (C_UDSI(c, t, UDS_INDEX) > 0.0 && C_UDSI(c, t, UDS_INDEX) < 1.0)
                  {
                      F_GRAD_CELL_THREAD(c, t, &C_UDSI(c, t, UDS_INDEX), grad);
                      C_UDMI(c, t, UDM_INDEX) = NV_MAG(grad); // 计算梯度的模并存储到UDM
                  }
              }
              end_c_loop(c, t)
          }
      }
       
      DEFINE_SOURCE(apply_momentum_source, c, t_cell, dS, eqn)
      {
          real p = PARAMETER_P; // 给定的参数p
          real vol_frac = C_UDSI(c, t_cell, UDS_INDEX); // 体积分数
          real grad_mag = C_UDMI(c, t_cell, UDM_INDEX); // 体积分数梯度的模
          real F = 2.0 * p * vol_frac * grad_mag; // 根据公式 F = 2 * p * vol_frac * grad_mag 计算动量源项
          if (vol_frac > 0.0 && vol_frac < 1.0)
          {
              dS[2] += F; // 在所有方向上添加动量源项
          }
          return 0;
      }

      This is our UDF,The following issues occur

      Here's the model we use

    • Rob
      Forum Moderator

      There may be a more useful error at the top of the list. Check all macros are valid - where did  F_GRAD_CELL_THREAD come from?

    • ALEXANDRE COSTA
      Subscriber

      Hi,

      I am also interested in this type of "crash".

    • 智敏 徐
      Subscriber

      我该如何修改它?

    • 智敏 徐
      Subscriber

      How can I modify this?

    • 智敏 徐
      Subscriber

      How do you change this UDF?

    • Rob
      Forum Moderator

      Maybe start by answering my previous question?

Viewing 6 reply threads
  • You must be logged in to reply to this topic.