测试udf环境

#include "udf.h"
DEFINE_ON_DEMAND(test)
{
   Message0("hello, UDF!\n");
}

检查出错位置

规范并行udf写法

#include "udf.h"
DEFINE_ON_DEMAND (av_pres_in_thread)
{
    int thread id; 
    real vol_sum=0.0, pres sum=0.0 ;
#if !RP_HOST 
    ce11 t C; 
    Thread *t;
#endif 
#if !RP_NODE 
    thread_id = RP_Get_Integer("udf/av_thread_id");
#endif 
    host_to_node_int_1(thread id);
#if !RP_HOST 
    t = Lookup_Thread(Get_Domain(1), thread_id); 
    begin_C_1oop_int(c,t)
    {
        vol_sum += C_VOLUME(C,t); 
        pres_sum += C_P(C,t) * C_VOLUME(C,t); 
    }
    end_c_1oop_int(C, t)
#endif
#if RP_NODE 
Message("Sub totals on node %d: %f, %f\n", myid, pres_sum, vo1l_sum);
#endif 
    vol_sum = PRF_GRSUM1(vo1_sum); 
    pres_sum = PRF_GRSUM1(pres_sum); 
#if RP_NODE 
    Message("Reduced vals node %d: %f,%f\n", myid, pres_sum, vol_sum);
#endif 
    node_to_host_real_2(vo1_sum, pres_sum);
#if !RP_NODE 
    Message("\ nAvg. pressure over Thread %d is %f Pa\n", thread_id, pres_sum/vo1_sum);
#endif 
}
其中udf/av_thread_id使用TUI命令 (rp-var-define 'udf/av_thread_id 4' integer #f)定义,4为ID值,这样写udf可以避免当id值发生变化的时候需要改udf,省去重复编译的时间,直接在TUI中修改就行。

UDS对流项--实现通过判断thread为面还是区域内部来分配不同的uds质量流量值

/* UDF that implements a simplified advective term in the scalar transport equation */

 #include "udf.h"
 
 DEFINE_UDS_FLUX(my_uds_flux,f,t,i)
 {
    cell_t c0, c1 = -1;
    Thread *t0, *t1 = NULL;
    real NV_VEC(psi_vec), NV_VEC(A), flux = 0.0;
    c0 = F_C0(f,t);
    t0 = F_C0_THREAD(f,t);
    F_AREA(A, f, t);
    /* If face lies at domain boundary, use face values; */
    /* If face lies IN the domain, use average of adjacent cells. */
   if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/
    {
       real dens;
       /* Depending on its BC, density may not be set on face thread*/
       if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))
         dens = F_R(f,t);  /* Set dens to face value if available */
       else
         dens = C_R(c0,t0); /* else, set dens to cell value */
       NV_DS(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens);
       flux = NV_DOT(psi_vec, A); /* flux through Face */  }
    else
    {
     c1 = F_C1(f,t);   /* Get cell on other side of face */
     t1 = F_C1_THREAD(f,t);
     NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,C_R(c0,t0));
     NV_DS(psi_vec, +=, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1));
     flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */
    }
  /* ANSYS Fluent will multiply the returned value by phi_f (the scalar’s
  value at the face) to get the ‘‘complete’’ advective term. */
  return flux;
 } 

判断区域是不是多孔介质

if (FLUID_THREAD_P(t) && THREAD_VAR(t).fluid.porous)

udf编译小工具 by 硫酸亚铜

外置编译,能更清晰查看出错原因。

下载地址:https://lbj007.lanzoui.com/ins1Kt0oi8j
如果觉得我的文章对你有用,请随意赞赏