找回密码
 注册
查看: 7481|回复: 8

请教gallongallon,关于源项DEFINE_SOURCE在流场中某一区域温度大于600度加质问题

[复制链接]
发表于 2009-4-17 23:12:44 | 显示全部楼层 |阅读模式

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

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

x
请教gallongallon高手,
  我现在想用DEFINE_SOURCE给流场中添加源项,添加位置是流场中靠近壁面一层网格中温度大于600度的网格加源项
  我用DEFINE_SOURCE循环流畅网格,再通过thread 循环得到靠近壁面的网格,如果温度大于600则加质,程序如下:
       DEFINE_SOURCE(mass,c,t,ds,eqn)
{
        face_tread=lookup_thread(domain,1);
   begin_f_loop(f,face_tread)
{
     T=F_T(f,face_tread);
     c0=F_C0(f,face_tread);
   if((c==c0)&&T>600)
    {
      source=10;
    }
}
end_f_loop(f,face_tread)
ds[eqn]=0;
return source;
}
如果通过解释法进行编译时可以使用,而通过compile法编译连接后
为什么加质时整个靠近壁面的网格全部加质呢?
发表于 2009-6-2 09:15:52 | 显示全部楼层
我也遇到相似的问题,有空可以探讨探讨。
我是将靠近壁面的一层流体单元单独作为一个流体域,然后再用源项法。也没算通。
好像DEFINE_SOURCE自动循环域中的所有单元的。
发表于 2009-6-24 17:09:28 | 显示全部楼层
DEFINE_SOURCE是针对整个计算域中的Cell来完成的。可以试试通过Cell的编号或者Cell中心的坐标来筛选。
发表于 2009-10-15 08:49:36 | 显示全部楼层
这个问题解决了吗?

我也正在困扰着
发表于 2009-10-15 12:59:18 | 显示全部楼层

网上一个例子(在指定单元坐标加入源项的UDF)

  1. /***************** UDF ***********************/
  2. /*
  3. * FLUENT User Defined Function
  4. *
  5. * version 4.0
  6. *
  7. *
  8. * Purpose
  9. * -------
  10. * Marks cells that contain coordinates in the a specified input file.
  11. *
  12. * Author
  13. * ------
  14. * William Wangard, Ph.D.
  15. * Fluent, Inc.
  16. * Feb 2003
  17. *
  18. * Note: Fluent, Inc. does not guarantee the rigor of this User-defined function
  19. *
  20. *
  21. * Usage
  22. * -----
  23. *
  24. * Data input format
  25. * -----------------
  26. * The format for the UDF input file (interp-input.dat) is the following:
  27. *
  28. * x0, y0, z0
  29. * x1, y1, z1
  30. * ...
  31. *
  32. *
  33. * Note, if you are using 2D, then you only enter the x- and y-coordinates.
  34. *
  35. *
  36. * Execution
  37. * ---------
  38. * There are 2 functions in this packages: mark, source.
  39. *
  40. *
  41. * Define on Demand function "mark" is used to read the data points from the inpute file
  42. * and locate the points in the domain. Upon finding each point, a UDM is set
  43. * to positive value in that cell.
  44. *
  45. * In FLUENT, you will separate the cell thread by UDM value. Then, you apply
  46. * the Mass source to the source-contatining cell thread.
  47. *
  48. *
  49. */


  50. #include "udf.h"
  51. #include "surf.h"
  52. #define MAXPOINTS 20000
  53. #define UDM_SOURCE 0

  54. boolean check(void);

  55. static int np = 0;
  56. real coordinates[MAXPOINTS][ND_ND] = {{0.}};


  57. struct interpolation_point{
  58. cell_t c;
  59. Thread* t;
  60. };

  61. struct interpolation_point point_list[MAXPOINTS];


  62. boolean check(void)
  63. {
  64. boolean ret = TRUE;
  65. if (sg_udm < 1)
  66. {
  67. ret = FALSE;
  68. Message("Error: You must define at least 1 UDM\n");
  69. }
  70. if (!Data_Valid_P())
  71. {
  72. ret = FALSE;
  73. Message("Error: You must initialize the data field\n");
  74. }
  75. return ret;
  76. }


  77. DEFINE_ON_DEMAND(mark_reset)
  78. {
  79. Domain*d = Get_Domain(1);
  80. Thread*t;
  81. cell_t c;

  82. if (!check()) return;

  83. thread_loop_c(t,d)
  84. {
  85. begin_c_loop(c,t)
  86. {
  87. C_UDMI(c,t,UDM_SOURCE) = 0.0;
  88. }
  89. end_c_loop(c,t);
  90. }
  91. }

  92. DEFINE_ON_DEMAND(mark)
  93. {

  94. #if !RP_HOST
  95. Domain *d = Get_Domain(1);
  96. cell_t c;
  97. CX_Cell_Id cx_cell;
  98. Thread* t;
  99. int points_found = 0, total_points_found=0;
  100. #endif

  101. #if !RP_NODE
  102. FILE* input;
  103. #endif
  104. int n;


  105. /* Check for UDM */
  106. if (!check()) return;

  107. /* READ COORDINATES */
  108. #if !RP_NODE

  109. /* Open input file */
  110. if (!(input = fopen("interp-input.dat","r")))
  111. {
  112. Message0("\nWarning: Could not open interpolation input file...\n");
  113. return;
  114. }

  115. /* Initialize */
  116. for(n=0; n<MAXPOINTS; n++)
  117. {
  118. point_list[n].c = 0;
  119. point_list[n].t = NULL;
  120. }

  121. /* Read points from input file */
  122. n = -1;
  123. while (!feof(input))
  124. {
  125. n++;
  126. #if RP_DOUBLE
  127. #if RP_3D
  128. fscanf(input,"%lg %lg %lg", &coordinates[n][0], &coordinates[n][1], &coordinates[n][2])
  129. ;
  130. #else
  131. fscanf(input,"%lg %lg", &coordinates[n][0], &coordinates[n][1]);
  132. #endif
  133. #else
  134. #if RP_3D
  135. fscanf(input,"%g %g %g", &coordinates[n][0], &coordinates[n][1], &coordinates[n][2])
  136. ;
  137. #else
  138. fscanf(input,"%g %g", &coordinates[n][0], &coordinates[n][1]);
  139. #endif
  140. #endif

  141. }
  142. np = n;


  143. /* Check np with MAXPOINTS */
  144. if (np > MAXPOINTS)
  145. {
  146. Message0("ERROR: You must recompile interpolate UDF with MAXPOINTS at least %i\n", np)
  147. ;
  148. return;
  149. }


  150. /* Close input file */
  151. fclose(input);



  152. #endif



  153. /* FIND COORDINATES IN CELLS */

  154. /* Pass coordinates and np to the compute nodes */
  155. host_to_node_real(&coordinates[0][0],ND_ND*MAXPOINTS);
  156. host_to_node_int_1(np);

  157. #if !RP_HOST

  158. /* Do computations */
  159. for(n=0;n<np;n++)
  160. {
  161. thread_loop_c(t,d)
  162. {
  163. begin_c_loop_int(c,t)
  164. {
  165. if (SV_is_point_in_cell(&cx_cell, c, t, coordinates[n]))
  166. {
  167. point_list[n].c = RP_CELL(&cx_cell);
  168. point_list[n].t = RP_THREAD(&cx_cell);

  169. /* SET UDM HERE */
  170. C_UDMI(point_list[n].c, point_list[n].t, UDM_SOURCE) = 1.0;

  171. points_found++;
  172. goto label;
  173. }
  174. }
  175. end_c_loop_int(c,t);
  176. }
  177. label: continue;
  178. }

  179. total_points_found += points_found;

  180. #if PARALLEL
  181. total_points_found = PRF_GISUM1(total_points_found);
  182. #endif


  183. /* PRINT MESSAGE */
  184. if (np != total_points_found)
  185. Message0("\n\n Warning.... %i points found in domain out of %i points in input file\n",
  186. total_points_found, np);
  187. else
  188. Message0("\n\n Interpolate... all %i points located!\n", np);

  189. #endif

  190. }



  191. DEFINE_SOURCE(mass_source,c,t,dS,eqn)
  192. {

  193. real source = 0.0;
  194. real mdot = 1.0;
  195. source = (C_UDMI(c,t,UDM_SOURCE) == 1.0) ? (mdot/C_VOLUME(c,t)) : 0.0;
  196. dS[eqn] = 0.0;
  197. return source;

  198. }


  199. /************************ END OF UDF *****************************/
复制代码
发表于 2010-3-16 16:14:53 | 显示全部楼层

跪谢!本人加一热源,编译通过,无法计算!

先将代码如帖,拜谢高手指点!
#include "udf.h"
DEFINE_SOURCE(energy_source1,c,t,ds,eqn)
{
real x[ND_ND];
real a,b,cwz;
real source;
cell_t c;
Thread *c_thread;
begin_c_loop(c,c_thread)
{
C_CENTROID(x,c,t);
a=x[0],b=x[1];
cwz=sqrt(a*a+b*b);
source=482252.4/cwz;
ds[eqn]=0;
return source;
}
end_c_loop(c,c_thread);
}
发表于 2012-4-11 14:39:34 | 显示全部楼层
写的不错 但是还是 有很多的疑惑的啊
发表于 2012-4-11 15:55:22 | 显示全部楼层

回复 7# 八怪 的帖子

你试过上面那段程序没?我试了下编译出错,boolean那块通不过,还有啊,您看懂了这段不,我怎么好多看不懂,查UDF帮助很多都没介绍
发表于 2013-1-15 15:07:19 | 显示全部楼层

回复 6# CAI 的帖子

#include "udf.h"
DEFINE_SOURCE(energy_source1,c,t,ds,eqn)
{
real x[ND_ND];
real source;
C_CENTROID(x,c,t);
source=482252.4/sqrt(x[0]*x[0]+x[1]*x[1])
ds[eqn]=0;
return source;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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