声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1991|回复: 8

[UDF专题] 编程出现的错误

[复制链接]
发表于 2008-5-7 21:37 | 显示全部楼层 |阅读模式

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

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  • parse error
刚开始编程,经常出现这个错误,我把对应的代码找到帖出来
face_t FaceInlet;
int IntIdInlet=16;
Thread *ThrdInlet=Lookup_Thread(DmnAir,IntIdInlet);
都是些声明变量时出现的错误,声明变量很简单啊,为什么说我错了呢?
  • ThrdInlet: undeclared variable
说我ThrdInlet变量没有声明,可是明明声明了啊,就如上边红色字体。明显声明了嘛
那位高手遇到类似问题,给我解答一下吧

我的QQ:332492456
email:appolm at 163.com

[ 本帖最后由 appolm 于 2008-5-7 21:48 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2008-5-7 21:50 | 显示全部楼层
所有的变量声明都有 parse error
 楼主| 发表于 2008-5-8 09:05 | 显示全部楼层
#include "math.h"
#include "udf.h"

/*使用DEFINE_ON_DEMAND 宏
可以定义一个按命令执行的UDF,这比让FLUENT 在计算过程中机械地调用UDF 优越的多。UDF 一旦被激活,可以立即被执行,不过,当求解器正在迭代的时候,函数是不可以调用的。
*/

DEFINE_ON_DEMAND(on_demand_energyuse)
{        
        //送风口
        Domain *DmnAir;        //流场的domain
        DmnAir=Get_Domain(1);
        face_t FaceInlet;
        int IntIdInlet=16; //每个送风口的温度相同,只读一个即可,16由case中查知
        Thread *ThrdInlet=Lookup_Thread(DmnAir,IntIdInlet);                //ThrdInlet的赋值
        real RealTempSnd;        //送风温度
        
        //回风口
        face_t FaceOtlt;        
        int IntIdOtlt=15;        //对应case确定
        Thread *ThrdOtlt=Lookup_Thread(DmnAir,IntIdOtlt);
        real RealTempEx;        //排风温度
        
        /*工作区
        主要测量的值有
        1.平均温度RealTempAvg
                平均温度积分(单元温度*单元质量)/总质量
        2.ADPI
                ET有效温差满足要求的体积/总体积        
        3.温度不均匀系数,速度不均匀系数                        
        */
        real RealEff;        //RealEff,能量利用系数               
        int IntIdAir=2;        //对应case,确定air的id
        Thread *ThrdAir=Lookup_Thread(DmnAir,IntIdAir);        //air的thread
        cell_t Cell;        //定义单元格标识符Cell
        real RealTempAvg;        //工作区平均温度        
        real RealTempCell;        //单元温度
        real RealMassCell;        //单元质量
        real RealDnstyCell;        //单元密度
        real RealVlmCell;        //单元体积
        real RealVlctyCell;        //单元的绝对速度
        real p[ND_ND];        //存储单元重心点坐标的向量
        real RealZmax=1.8;        //定义工作区的高度
        real RealMassTtl=0;        //总质量,初始为0
        real RealTempSum=0;        //积分(温度*质量)
        real RealVlctySum=0;        //积分(速度*质量)
        real RealET;        //有效温差
        real RealTempSet=299.15;        //温度设定值
        //real RealVlmTtl=0;        //总体积,初始为0
        real RealADPI;        //待求参数
        real RealMassSumADPI=0;        //满足ADPI要求的质量之和
        real RealVlctyAvg;        //工作区平均速度
        real RealTempDlta=0;        //均方根偏差
        real RealVlctyDlta=0;
        real RealKt;        //不均匀系数
        real RealKv;
        
        //送风温度
        begin_f_loop(FaceInlet,ThrdInlet)
        {
                RealTempSnd=F_T(FaceInlet,ThrdInlet);                                
        }
        end_f_loop(FaceInlet,ThrdInlet)
        //排风温度
        begin_f_loop(FaceOtlt,ThrdOtlt)
        {
                RealTempEx=F_T(FaceOtlt,ThrdOtlt);                                
        }        
        end_f_loop(FaceOtlt,ThrdOtlt)
        //工作区
        //第一次循环,计算ADPI,平均温度,平均速度,能量利用系数
        begin_c_loop(Cell,ThrdAir)
        {
                RealVlmCell=C_VOLUME(Cell,ThrdAir);
                RealDnstyCell=C_R(Cell,ThrdAir);
                RealTempCell=C_T(Cell,ThrdAir);
                RealVlctyCell=sqrt(pow(C_U(Cell,ThrdAir),2)+pow(C_V(Cell,ThrdAir),2)+pow(C_W(Cell,ThrdAir),2));
                C_CENTROID(p,Cell,ThrdAir);
                if(p[2]<RealZmax)
                        {
                                RealMassTtl=RealMassTtl+RealVlmCell*RealDnstyCell;
                                RealTempSum=RealTempSum+RealTempCell*RealVlmCell*RealDnstyCell;
                                RealVlctySum=RealVlctySum+RealVlctyCell*RealVlmCell*RealDnstyCell;
                                //有效温差
                                RealET=(RealTempCell-RealTempSet)-8.0*(RealVlctyCell-0.15);
                                if((RealET<=1.0)&&(RealET>=-1.5)&&(RealVlctyCell<0.35))
                                        {
                                                RealMassSumADPI=RealMassSumADPI+RealVlmCell*RealDnstyCell;
                                        }
                        }
        }
        end_c_loop(Cell,ThrdAir)
        RealADPI=RealMassSumADPI/RealMassTtl;
        RealTempAvg=RealTempSum/RealMassTtl;
        RealVlctyAvg=RealVlctySum/RealMassTtl;
        RealEff=(RealTempEx-RealTempSnd)/(RealTempAvg-RealTempSnd);
        //第二次循环,求速度、温度不均匀系数
        begin_c_loop(Cell,ThrdAir)
        {
                RealVlmCell=C_VOLUME(Cell,ThrdAir);
                RealDnstyCell=C_R(Cell,ThrdAir);
                RealTempCell=C_T(Cell,ThrdAir);
                RealVlctyCell=sqrt(pow(C_U(Cell,ThrdAir),2)+pow(C_V(Cell,ThrdAir),2)+pow(C_W(Cell,ThrdAir),2));
                C_CENTROID(p,Cell,ThrdAir)
                if(p[2]<RealZmax)
                        {                                
                                RealTempDlta=RealTempDlta+pow((RealTempCell-RealTempAvg),2)*RealVlmCell*RealDnstyCell/RealMassTtl;
                                RealVlctyDlta=RealVlctyDlta+pow((RealVlctyCell-RealVlctyAvg),2)*RealVlmCell*RealDnstyCell/RealMassTtl;
                        }
        }
        end_c_loop(Cell,ThrdAir)
        RealKt=sqrt(RealTempDlta)/RealTempAvg;
        RealKv=sqrt(RealVlctyDlta)/RealVlctyAvg;
        //输出结果
        printf("average temperature of workzone:%g\n",RealTempAvg);
        printf("average velocity of workzone:%g\n",RealVlctyAvg);
        printf("ADPI:%g\n",RealADPI);
        printf("kt:%g\n",RealKt);
        printf("kv:%g\n",RealKv);
        printf("energy efficiency:%g\n",RealEff);
}

[ 本帖最后由 appolm 于 2008-5-8 09:14 编辑 ]
 楼主| 发表于 2008-5-8 09:05 | 显示全部楼层
这是代码,请帮我看一下,很急的
 楼主| 发表于 2008-5-8 10:24 | 显示全部楼层

提示错误如下显示:

cpp -IC:\Fluent.Inc\fluent6.2.16/src -IC:\Fluent.Inc\fluent6.2.16/cortex/src -IC:\Fluent.Inc\fluent6.2.16/client/src -IC:\Fluent.Inc\fluent6.2.16/multiport/src -I. -DUDFCONFIG_H="<udfconfig.h>" f:\work\aircondion        est\myudf.C
Error: f:\work\aircondion\test\myudf.C: line 13: parse error.
Error: f:\work\aircondion\test\myudf.C: line 14: parse error.
Error: f:\work\aircondion\test\myudf.C: line 15: parse error.
Error: f:\work\aircondion\test\myudf.C: line 16: parse error.
Error: f:\work\aircondion\test\myudf.C: line 19: parse error.
Error: f:\work\aircondion\test\myudf.C: line 20: parse error.
Error: f:\work\aircondion\test\myudf.C: line 21: parse error.
Error: f:\work\aircondion\test\myudf.C: line 22: parse error.
Error: f:\work\aircondion\test\myudf.C: line 32: parse error.
Error: f:\work\aircondion\test\myudf.C: line 33: parse error.
Error: f:\work\aircondion\test\myudf.C: line 34: parse error.
Error: f:\work\aircondion\test\myudf.C: line 35: parse error.
Error: f:\work\aircondion\test\myudf.C: line 36: parse error.
Error: f:\work\aircondion\test\myudf.C: line 37: parse error.
Error: f:\work\aircondion\test\myudf.C: line 38: parse error.
Error: f:\work\aircondion\test\myudf.C: line 39: parse error.
Error: f:\work\aircondion\test\myudf.C: line 40: parse error.
Error: f:\work\aircondion\test\myudf.C: line 41: parse error.
Error: f:\work\aircondion\test\myudf.C: line 42: parse error.
Error: f:\work\aircondion\test\myudf.C: line 43: parse error.
Error: f:\work\aircondion\test\myudf.C: line 44: parse error.
Error: f:\work\aircondion\test\myudf.C: line 45: parse error.
Error: f:\work\aircondion\test\myudf.C: line 46: parse error.
Error: f:\work\aircondion\test\myudf.C: line 47: parse error.
Error: f:\work\aircondion\test\myudf.C: line 48: parse error.
Error: f:\work\aircondion\test\myudf.C: line 50: parse error.
Error: f:\work\aircondion\test\myudf.C: line 51: parse error.
Error: f:\work\aircondion\test\myudf.C: line 52: parse error.
Error: f:\work\aircondion\test\myudf.C: line 53: parse error.
Error: f:\work\aircondion\test\myudf.C: line 54: parse error.
Error: f:\work\aircondion\test\myudf.C: line 55: parse error.
Error: f:\work\aircondion\test\myudf.C: line 56: parse error.
Error: f:\work\aircondion\test\myudf.C: line 59: ThrdInlet: undeclared variable
发表于 2008-5-8 13:50 | 显示全部楼层
不断调试吧,感觉UDF的bug很多,听起来似乎很好,用户自定义函数,其实约束很多。

我不用FLuent很多年了,以前就觉得UDF的问题比较多,而且说实话这方面的技术支持也很烂(不知道现在是否好了些),大部分时候出了问题我都是慢慢调试。比如楼主的问题,可以先不要声明那么多的变量,先声明一个变量,如果不行再把声明放到函数外面试试看,再不行就要看这个函数的详细介绍了。别仅仅就是把帮助文件中的一段程序就拿来改写,一般都不行。

可惜没有装Fluent,否则帮你试试看。你再调试一下吧,其他用Fluent的人呢?别都光顾问问题,也帮人解决问题啊,呵呵。要是StarCD也有Fluent讨论区这么热闹就好了。
 楼主| 发表于 2008-5-8 14:59 | 显示全部楼层

回复 6楼 的帖子

谢谢,好的,我试试看看
 楼主| 发表于 2008-6-17 22:29 | 显示全部楼层
很郁闷

Domain *DmnAir;        //流场的domain
        DmnAir=Get_Domain(1);
改为
Domain *DmnAir=Get_Domain(1);
就可以了
不知道为什么
发表于 2009-9-30 08:55 | 显示全部楼层
楼主你好,我也出现了你相似的问题。
也是照你那个样子把Domain *d; d=Get_Domain(ID)改成Domain *d=Get_Domain(ID);就通过。
不知道你是否清楚了为什么是这个样子?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-6 20:17 , Processed in 0.058508 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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