|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
如何在udf中读取mat格式文件,并将其变量值设定为入口速度。
目前在做matlab和fluent联合仿真,期望在两软件之间做一接口,完成两者的通信。目前做法是建立了一共享文件,里面保存有入口速度和出口速度两个参数,其文件格式是mat。在VS中写好的程序,修改后搬到udf中老编译不过去,感觉缺少很多的头文件,具体程序如下所示:
#include "mat.h"
#include"udf.h"
#include"stdio.h"
#pragma comment(lib,"libmat.lib")
#pragma comment(lib,"libmx.lib")
DEFINE_PROFILE(inlet_x_velocity1, thread, index)
{
real Flag_mat;
real x[ND_ND];
real y;
face_t f;
MATFile *pmat;
const char **dir;
const char *file;
const char *name;
int ndir;
mxArray *pMxArray;
double *V_c=new double;
file="C:\\SharedData.mat"; //双反斜杠防止转义
pmat=matOpen(file, "a");//打开文件,返回指向文件指针
dir = (const char **)matGetDir(pmat, &ndir);
//ndir 表示mat文件中含有矩阵数目
pMxArray=(mxArray *)matGetVariable(pmat,"a");
//获取文件中的变量,返回axArray指针类型
V_c=(double*)mxGetData(pMxArray);
//获取文件中变量的值
if (*V_c == NULL)
{
printf("Error reading directory of file:");
}
else
{
begin_f_loop(f,thread)
{
F_CENTROID(x,f,thread);
y=x[1];
F_PROFILE(f,thread,index)=*V_c;
}
end_f_loop(f,thread)
}
}
出现如下错误:
..\..\src\TestProVel.c(23) : error C2065: 'new' : undeclared identifier
..\..\src\TestProVel.c(23) : warning C4047: 'initializing' : 'double *' differs in levels of indirection from 'int'
..\..\src\TestProVel.c(23) : error C2143: syntax error : missing ';' before 'type'
..\..\src\TestProVel.c(23) : error C2059: syntax error : 'empty declaration'
..\..\src\TestProVel.c(36) : error C2440: '==' : cannot convert from 'void *' to 'double'
其中表面很多变量未定义,有么有知道的大虾帮忙看看,不胜感谢! |
|