5 金钱
由于要做风场模拟,把脉动风引燃udf,因此采取的思路是,对于速度入口高度不同的点,施加不同的速度时程。速度时程已经事先用matlab生成了,保存为txt格式。因此代码中采用定义数组,然后读取txt赋值给数组的方法。高度上一共20个点,每个点读取一个txt文件,然后赋予A数组。但是用fluent读取这个代码,总是说real t = RP_Get_Real("flow-time");这一行语法错误,但是这个语句应该没有问题呀!附上截图:
代码如下,求指导!谢谢!
#include "udf.h"
#include "math.h"
DEFINE_PROFILE(unsteady_velocity, thread, position)
{
real x[ND_ND];
real y;
real z;
face_t f;
begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y=x[1];
z=x[2];
real t = RP_Get_Real("flow-time");
if(0<=z<20)
{int i;
double A1[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u1.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A1[i]);
printf("%lf",A1[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A1[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A1[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A1[i];}}
}
else if(20<=z<40)
{int i;
double A2[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u2.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A2[i]);
printf("%lf",A2[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A2[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A2[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A2[i];}}
}
else if(40<=z<60)
{int i;
double A3[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u3.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A3[i]);
printf("%lf",A3[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A3[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A3[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A3[i];}}
}
else if(60<=z<80)
{int i;
double A4[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u4.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A4[i]);
printf("%lf",A4[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A4[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A4[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A4[i];}}
}
else if(80<=z<100)
{int i;
double A5[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u5.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A5[i]);
printf("%lf",A5[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A5[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A5[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A5[i];}}
}
else if(100<z<120)
{int i;
double A6[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u6.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A6[i]);
printf("%lf",A6[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A6[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A6[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A6[i];}}
}
else if(120<=z<140)
{int i;
double A7[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u7.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A7[i]);
printf("%lf",A7[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A7[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A7[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A7[i];}}
}
else if(140<=z<160)
{int i;
double A8[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u8.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A8[i]);
printf("%lf",A8[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A8[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A8[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A8[i];}}
}
else if(160<=z<180)
{int i;
double A9[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u9.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A9[i]);
printf("%lf",A9[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A9[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A9[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A9[i];}}
}
else if(180<=z<200)
{int i;
double A10[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u10.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A10[i]);
printf("%lf",A10[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A10[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A10[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A10[i];}}
}
else if(200<=z<220)
{int i;
double A11[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u11.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A11[i]);
printf("%lf",A11[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A11[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A11[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A11[i];}}
}
else if(220<z<240)
{int i;
double A12[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u12.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A12[i]);
printf("%lf",A12[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A12[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A12[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A12[i];}}
}
else if(240<=z<260)
{int i;
double A13[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u13.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A13[i]);
printf("%lf",A13[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A13[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A13[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A13[i];}}
}
else if(260<=z<280)
{int i;
double A14[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u14.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A14[i]);
printf("%lf",A14[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A14[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A14[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A14[i];}}
}
else if(280<=z<300)
{int i;
double A15[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u15.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A15[i]);
printf("%lf",A15[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A15[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A15[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A15[i];}}
}
else if(300<=z<320)
{int i;
double A16[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u16.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A16[i]);
printf("%lf",A16[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A16[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A16[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A16[i];}}
}
else if(320<=z<340)
{int i;
double A17[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u17.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A17[i]);
printf("%lf",A17[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A17[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A17[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A17[i];}}
}
else if(340<=z<360)
{int i;
double A18[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u18.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A18[i]);
printf("%lf",A18[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A18[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A18[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A18[i];}}
}
else if(360<=z<380)
{int i;
double A19[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u19.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A19[i]);
printf("%lf",A19[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A19[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A19[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A19[i];}}
}
else
{int i;
double A20[1000];
{
FILE *fp;
if((fp=fopen("f:\\timehistory\\matlab\\windspeed\\u20.txt","r"))== NULL)
{
printf("cannot open this file\n");
}
for(i=0;i<1000;i++)
{ // 加上大括号
fscanf(fp,"%lf",&A20[i]);
printf("%lf",A20[i]); // 数组内改成变量 i
} // 加上大括号
fclose(fp);
}
if(0<=t<0.5)
{F_PROFILE(f, thread, position) =A20[0];}
else if(999.5<=t<=1000)
{F_PROFILE(f, thread, position) =A20[999];}
else{
for (int i=1;i<999;i++)
{if((i+0.5)<=t<(i+1+0.5))
F_PROFILE(f, thread, position) =A20[i];}}
}
}
end_f_loop(f, thread)
}
我来回答