找回密码
 注册
查看: 2469|回复: 5

DEFINE_ADJUST宏

[复制链接]
发表于 2012-12-2 09:57:42 | 显示全部楼层 |阅读模式

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

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

x
想用ADJUST宏求取某一个面上的温度平均值,实现这个平均值的实时更新,因为其他宏要用到。但是编译时会出错,程序及错误信息如下:
#include "udf.h"
#include "mem.h"

real avg=0.;

DEDINE_ADJUST(adjust_avg,d)
{
        real sum=0.;
        int n=0;

        CX_Message("Computing the avg :\n");

        Thread *t=Lookup_Thread(d,6);
        cell_t c;

        begin_c_loop(c,t)
        {
                sum+=C_T(c,t);
                n++;
        }
        end_c_loop(c,t)

        avg=sum/n;

}

..\..\src\try.c(13) : error C2275: 'Thread' : illegal use of this type as an expression
        ..\..\src\mem.h(653) : see declaration of 'Thread'
..\..\src\try.c(13) : error C2065: 't' : undeclared identifier
..\..\src\try.c(13) : warning C4047: 'function' : 'struct domain_struct *' differs in levels of indirection from 'int '
..\..\src\try.c(13) : warning C4024: 'Lookup_Thread' : different types for formal and actual parameter 1
..\..\src\try.c(14) : error C2275: 'cell_t' : illegal use of this type as an expression
        ..\..\src\mem.h(173) : see declaration of 'cell_t'
..\..\src\try.c(14) : error C2146: syntax error : missing ';' before identifier 'c'
..\..\src\try.c(14) : error C2065: 'c' : undeclared identifier
..\..\src\try.c(16) : error C2223: left of '->nelements' must point to struct/union
..\..\src\try.c(18) : error C2223: left of '->storage' must point to struct/union
尼玛错误信息都快比程序长了……求指教,到底咋回事?ADJUST宏里不能用Lookup_Thread吗??
发表于 2012-12-4 14:30:10 | 显示全部楼层
变量声明全部放在执行语句之前,例如Message。
#include "udf.h"
#include "mem.h"

real avg=0.;

DEDINE_ADJUST(adjust_avg,d)
{
        real sum=0.;
        int n=0;
         Thread *t=Lookup_Thread(d,6);
        cell_t c;

  CX_Message("Computing the avg :\n");


        begin_c_loop(c,t)
        {
                sum+=C_T(c,t);
                n++;
        }
        end_c_loop(c,t)

        avg=sum/n;

}
发表于 2012-12-4 19:12:26 | 显示全部楼层
数据结构就不对,应该这样:
thread_loop_c(t,d)
{
begin_c_loop(cell,t)
{
......
}
end_c_loop(cell,t)
}
发表于 2012-12-5 09:01:28 | 显示全部楼层
别误导人家好不好,人家就是针对ID为6的zone区域的cell进行循环,写得挺好,没错。

 楼主| 发表于 2012-12-5 21:16:46 | 显示全部楼层

回复 3# thermfluidtml 的帖子

嘿嘿,还是谢谢你
 楼主| 发表于 2012-12-5 21:19:14 | 显示全部楼层

回复 2# gearboy78 的帖子

谢谢大神,你一来就能解决问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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