找回密码
 注册
查看: 2437|回复: 1

fluent中udf函数调用问题

[复制链接]
发表于 2012-3-8 17:29:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
最近看了一个udf例子,在define_on_demand宏之前定义了一个函数,然后再在该宏里面调用此函数,
程序代码如下:
#include"udf.h"
FILE *fout;
Print_Thread_Face_Centroids(Domain *domain, int id)
{
  real FC[2];
  face_t f;
  Thread *t=Lookup_Thread(domain, id);
  fprintf(fout, "thread id %d\n",id);
  begin_f_loop(f,t)
    {
       F_CENTROID(FC,f,t);
       fprintf(fout, "f%d %g %g %g\n", f, FC[0], FC[1], FC[2]);
     }
  end_f_loop(f,t)
fprintf(fout, "\n");
}
DEFINE_ON_DEMAND(get_coords)
{
  Domain *domain;
  domain=Get_Domain(1);
  fout=fopen("faces.out","w");
  Print_Thread_Face_Centroids(domain,5);
  Print_Thread_Face_Centroids(domain ,6);
  fclose(fout);
}
其中的Print_Thread_Face_Centroids(Domain *domain, int id)即为定义的函数,然后在DEFINE_ON_DEMAND里调用(Print_Thread_Face_Centroids(domain,5); Print_Thread_Face_Centroids(domain ,6);)
现在的问题是,c里面定义函数时不应该首先对函数的返回类型进行声明吗?比如返回void或者real?为什么这里没有啊?
我仿照该udf编了一个程序,想实现进口速度是出口平均速度的50%,代码如下:
#include"udf.h"
real Print_Thread_Face_Centroids(Domain *domain, int id)
{
  real total_u, total_v, total_s;
  real flow;
  face_t f;
  real A[ND_ND];
  Thread *t = Lookup_Thread(domain, id);
  total_u=total_v=total_s=0.0;
  begin_f_loop(f,t)
  {
   F_AREA(A,f,t);
   total_u+=NV_MAG(A)*F_U(f,t);
   total_v+=NV_MAG(A)*F_V(f,t);
   total_s+=NV_MAG(A);
   }
  end_f_loop(f,t)
   flow=total_u/total_s;
  return flow;
}
DEFINE_PROFILE(inlet,t,i)
{
  real inflow=0.0;
  Domain *domain;
  face_t f;
  domain=Get_Domain(1);
  inflow=Print_Thread_Face_Centrodis(domain,6);
  begin_f_loop(f,t)
    {
       F_PROFILE(f,t,i)=inflow*0.5;
     }
   end_f_loop(f,t)
  }
现在的问题是,不论我是否对函数Print_Thread_Face_Centrodis返回类型进行定义,甚至去掉函数返回类型定义,同时去掉return语句,并在define_profile里面把inflow=Print_Thread_Face_Centrodis(domain,6)(这里的6是边界的ID)改为Print_Thread_Face_Centrodis(domain,6);,编译时均会提示“error LNK2001: unresolved external symbol _Print_Thread_Face_Centrodis”
搞不明白,忘高人指点一二。
 楼主| 发表于 2012-3-17 16:26:19 | 显示全部楼层
请版主删除该话题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表