Fluent UDF 调试之 Define_On_Demand

  • 原创
  • |
  • 浏览:4100
  • |
  • 更新:

用Fluent DUF编写时经常遇到不可预知的小错误,并且修改起来机器耗时,因此撰写次经验为自己,也为他人。

工具/原料

  • VS 2010
  • ANSYS 14.5
  • Ultraedtior

方法/步骤

  1. 1

    首先找个比较小的例子调试。将下列文本保存成udf.c

    /* This UDF is used to compute relative length scale in DES model*/

    #include "udf.h"

    #include "mem.h"

    #include "math.h"

    #include "stdio.h"

    DEFINE_ON_DEMAND(rls)

    {

    /*#if !RP_HOST*/

    Domain *domain=Get_Domain(1);

    Thread *c_thread;

    cell_t c;

    face_t f;

    Thread *tf;

    Node *node;

    int n,k,counter,i;

    real delx,dely,delz,deltamax,maxx=0,maxy=0,maxz=0;

    float x[8],y[8],z[8],temp;

    thread_loop_c(c_thread,domain) /*loops over all cell threads in domain*/

    {

    begin_c_loop(c,c_thread) /* loops over cells in a cell thread */

    {

    temp=C_K(c,c_thread);//1.0-pow((pow(C_K(c,c_thread)/deltamax,2.0/3.0)/(0.23+pow(C_K(c,c_thread)/deltamax,2.0/3.0))),4.5);

    C_UDMI(c,c_thread,0)=temp;

    Message("%E10.5",temp);

    }

    end_c_loop(c,c_thread)

    }

    }

  2. 2

    设置memory,全设置为1。define→define function→memory

  3. 3

    compile,知道保存的udf文件。define→define function→compile

  4. 4

    compile & load。define→define function→compile, 然后load

  5. 5

    初始化initializtion。因为里面有C_K,所以要获取cell的湍动能

  6. 6

    excute on demand。define→define function→excute on demand。

    就可以看到fluent的tui区域输出信息

    END
  7. 6
    相关内容未经授权抓取自百度经验

注意事项

  • get_domain(1)意味所有流体域
经验内容仅供参考,如果您需解决具体问题(尤其法律、医学等领域),建议您详细咨询相关领域专业人士。
作者声明:本篇经验系本人依照真实经历原创,未经许可,谢绝转载。
展开阅读全部