將udf直接compile,報(bào)錯(cuò),如下所示![fluent中的編譯型udf怎么生成?怎么用?為什么直接compile會(huì)出現(xiàn)不可思議的錯(cuò)誤?]()
我的udf源碼如下:
# include "udf.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#define M 50
#define K 70
#define PULSE 1
#define X_MIN 0
#define Y_MIN 0
#define Y_MAX 1.4
#define VESSEL 0.06
#define DX 0.02
#define DY 0.02
#define NN 10 //矩陣分塊后每塊的維數(shù)
DEFINE_SOURCE(heat_source,cell,thread,dS,eqn)
{
real time;
real source0[NN][NN];
real source;
int i,k;
int ln;
int ii,kk,temp_ii,temp_kk;
int file;
char str[25]={'\0'};
char filename[25]={'\0'};
real x[ND_ND];
time=RP_Get_Real("flow-time" ;
if(time<=PULSE)
{
C_CENTROID(x,cell,thread);
ii=floor((x[0]-X_MIN)/DX);
kk=floor((x[1]-Y_MIN)/DY);//找到當(dāng)前cell的編號(hào)
temp_ii=floor(ii/10.0)+1;
temp_kk=floor(kk/10.0)+1;
//此時(shí)需要讀取第x個(gè)文件,x=(temp_ii-1)*int(M/10)+temp_kk
file=(temp_kk-1)*(M/NN)+temp_ii;
//convert the int to char
for(ln=0,i=file;i;i/=10,ln++);
for(ln--,i=file;i;str[ln--]=i%10+'0',i/=10);
strcpy(filename,"S2D_20(" ;
strcat(filename,str);
strcat(filename," .txt" ;
/*讀入熱源文件*/
FILE *fd;
fd = fopen(filename,"r" ;
for(k=0;k<NN;k++)
for(i=0;i<NN;i++)
fscanf(fd, "%lf", &source0[k]);
fclose(fd);/*此時(shí),將外部數(shù)據(jù)讀入到數(shù)組source0中*/
ii=ii%NN; kk=kk%NN;
source=source0[kk][ii];//當(dāng)前cell的熱源等于對(duì)應(yīng)編號(hào)下的外部數(shù)據(jù)
dS[eqn]=0;//熱源的導(dǎo)數(shù)為0
}
else
source=0.0;
return source;
}
請(qǐng)大俠指點(diǎn)啊! |