找回密码
 注册
查看: 6929|回复: 7

求助:UDF对压力进行积分写入data

[复制链接]
发表于 2010-1-4 16:18:55 | 显示全部楼层 |阅读模式

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

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

x
初学UDF,参考帮助文件里的例子写了段程序,要对一部分网格上的压力进行积分,然后写入一个文件。程序如下
#include "udf.h"

DEFINE_ADJUST(my_adjust,d)
{
  Thread *t;
  real press=0.;                                                                  /*float型*/
  cell_t c;                                                  /*识别给定线索内单元的整数下标*/
  
  thread_loop_c (t,d)                                                    /*对压力的积分*/
  {
   begin_c_loop (c,t)
       press+= C_P(c,t)*                                                      /*C_P压力*/
       C_VOLUME(c,t);                                                  /*3D网格体积*/
   end_c_loop (c,t)
  }

  DEFINE_RW_FILE(writer, fp)
  {
  printf("Writing UDF data to data file...\n");
  fprintf(fp,"%d",press);                                     /* write out press to data file */
  }
  DEFINE_RW_FILE(reader, fp)
  {
  printf("Reading UDF data from data file...\n");
  fscanf(fp, "%d",&press);                                    /* read press from data file */
  }

}
Interpreted的结果是
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>" E:\UDF.c
Error: E:\UDF.c: line 17: parse error.
Error: E:\UDF.c: line 20: fp: undeclared variable
错在什么地方呢,要怎么改呢?请问各位高手指教。
发表于 2010-1-4 22:55:55 | 显示全部楼层
宏之间不能相互嵌套吧。
#include "udf.h"
real press=0.0;                                                              
DEFINE_ADJUST(my_adjust,d)
{
  Thread *t;
  cell_t c;                                                  /*识别给定线索内单元的整数下标*/  
  thread_loop_c (t,d)                                                    /*对压力的积分*/
  {
   begin_c_loop (c,t)
       press+= C_P(c,t)*                                                      /*C_P压力*/
       C_VOLUME(c,t);                                                  /*3D网格体积*/
   end_c_loop (c,t)
  }
}

  DEFINE_RW_FILE(writer, fp)
  {
  printf("Writing UDF data to data file...\n");
  fprintf(fp,"%d",press);                                     /* write out press to data file */
  }
  DEFINE_RW_FILE(reader, fp)
  {
  printf("Reading UDF data from data file...\n");
  fscanf(fp, "%d",&press);                                    /* read press from data file */
  }

[ 本帖最后由 swimming02 于 2010-1-4 22:57 编辑 ]
 楼主| 发表于 2010-1-5 12:19:32 | 显示全部楼层

回复 2# swimming02 的帖子

对,是这个问题,谢谢
改过之后的程序可以运行了,可是在屏幕上没有显示出press的值是为什么呢,在data里存的数据要怎么看到呢?
 楼主| 发表于 2010-1-6 15:06:13 | 显示全部楼层

改了之后

程序改过之后可以实现在屏幕上显示
Writing "E:\confirm\Jan40001.dat"...
Writing UDF data to data file...
press = 536870912
Done.
没有从data中读取Reading UDF data from data file...这一句,是什么原因呢?
另外又没有办法对一部分区域进行压力积分呢,现在好像是对整个网格进行积分的
发表于 2010-1-7 15:43:08 | 显示全部楼层
读写的操作我没怎么用过,你可自己调试下。
如果要限定积分的区域,就需要给出限定条件,如坐标范围,参数值范围等。
 楼主| 发表于 2010-1-8 15:26:49 | 显示全部楼层

回复 5# swimming02 的帖子

积分的这一部分已经调好了,谢谢
发表于 2012-7-12 14:41:27 | 显示全部楼层
初学者,标记一下!
发表于 2013-1-24 16:28:19 | 显示全部楼层

回复 6# dccat 的帖子

求问是如何输出的呢???急求
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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