| 查看: 1430 | 回复: 3 | ||
[求助]
udf 用source加源项总是失败,是什么原因?
|
|
我算一个二维的算例,用udf在空气域里面选了一些单元加上作用力 。 source源项可以做到吧?为什么加上去算出来的结果跟没有加力的时候相比总是没有变化呢 ? #include "udf.h" #include "surf.h" #define MAXPOINTS 9000 #define UDM_SOURCE_FMAGX 0 #define UDM_SOURCE_FMAGY 1 static int np = 0; real coordinates[MAXPOINTS][ND_ND] = {{0.}}; real area[MAXPOINTS]; real fx[MAXPOINTS]; real fy[MAXPOINTS]; real m; struct interpolation_point{ cell_t c; Thread* t; }; struct interpolation_point point_list[MAXPOINTS]; DEFINE_ON_DEMAND(mark_reset) { Domain*d = Get_Domain(1); Thread*t; cell_t c; thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDMI(c,t,UDM_SOURCE_FMAGX)=0.0; C_UDMI(c,t,UDM_SOURCE_FMAGY)=0.0; } end_c_loop(c,t); } } DEFINE_ON_DEMAND(mark) { #if !RP_HOST Domain *d=Get_Domain(1); cell_t c; CX_Cell_Id cx_cell; Thread* t; int points_found = 0, total_points_found=0; #endif #if !RP_NODE FILE *input; #endif int n; /*输入单元坐标*/ #if !RP_NODE /* Open input file */ if (!(input = fopen("coordinate.txt","r" )){ Message0("\nWarning: Could not open interpolation input file...\n" ;return; } /* Initialize */ for(n=0; n point_list[n].c = 0; point_list[n].t = NULL; } /* Read points from input file */ n = -1; while (!feof(input)) { n++; #if RP_DOUBLE #if RP_3D fscanf(input,"%lg %lg %lg", &coordinates[n][0], &coordinates[n][1], &coordinates[n][2]) ; #else fscanf(input,"%lg %lg", &coordinates[n][0], &coordinates[n][1]); #endif #else #if RP_3D fscanf(input,"%g %g %g", &coordinates[n][0], &coordinates[n][1], &coordinates[n][2]) ; #else fscanf(input,"%g %g", &coordinates[n][0], &coordinates[n][1]); #endif #endif } np = n; /* Check np with MAXPOINTS */ if (np > MAXPOINTS) { Message0("ERROR: You must recompile interpolate UDF with MAXPOINTS at least %i\n", np) ; return; } /* Close input file */ fclose(input); #endif /*输入需要加入的力fx,fy*/ #if !RP_NODE input=fopen("fx.txt","r" ;n = -1; while (!feof(input)) { n++; fscanf(input," %lg ",&fx[n]); } fclose(input); #endif #if !RP_NODE input=fopen("fy.txt","r" ;n = -1; while (!feof(input)) { n++; fscanf(input," %lg ",&fy[n]); } fclose(input); #endif /*输入单元面积*/ #if !RP_NODE input=fopen("area.txt","r" ;n = -1; while (!feof(input)) { n++; fscanf(input," %lg ",&area[n]); } fclose(input); #endif /* FIND COORDINATES IN CELLS */ /* Pass coordinates and np to the compute nodes */ host_to_node_real(&coordinates[0][0],ND_ND*MAXPOINTS); host_to_node_int_1(np); host_to_node_real(&area[0],MAXPOINTS); host_to_node_real(&fx[0],MAXPOINTS); host_to_node_real(&fy[0],MAXPOINTS); #if !RP_HOST /* Do computations */ for(n=0;n thread_loop_c(t,d) { begin_c_loop_int(c,t) { if (SV_is_point_in_cell(&cx_cell, c, t, coordinates[n],m)) { point_list[n].c = RP_CELL(&cx_cell); point_list[n].t = RP_THREAD(&cx_cell); /* SET UDM HERE */ C_UDMI(point_list[n].c, point_list[n].t, UDM_SOURCE_FMAGX)=fx[n]/area[n]; C_UDMI(point_list[n].c, point_list[n].t, UDM_SOURCE_FMAGY)=fy[n]/area[n]; points_found++; goto label; } } end_c_loop_int(c,t); } label: continue; } total_points_found += points_found; #if PARALLEL total_points_found = PRF_GISUM1(total_points_found); #endif /* PRINT MESSAGE */ if (np != total_points_found) Message0("\n\n Warning.... %i points found in domain out of %i points in input file\n", total_points_found, np); else Message0("\n\n Interpolate... all %i points located!\n", np); #endif } DEFINE_SOURCE(fmagx,c,t,dS,eqn) { real source=0.0; if(C_UDMI(c,t,UDM_SOURCE_FMAGX)!=0.0) { source=C_UDMI(c,t,UDM_SOURCE_FMAGX); } dS[eqn] = 0.0; return source; } DEFINE_SOURCE(fmagy,c,t,dS,eqn) { real source=0.0; if(C_UDMI(c,t,UDM_SOURCE_FMAGY)!=0.0) { source=C_UDMI(c,t,UDM_SOURCE_FMAGY); } dS[eqn] = 0.0; return source; } |
» 猜你喜欢
不自信的我
已经有8人回复
磺酰氟产物,毕不了业了!
已经有8人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有10人回复
26申博(荧光探针方向,有机合成)
已经有4人回复
要不要辞职读博?
已经有3人回复
论文终于录用啦!满足毕业条件了
已经有26人回复
2026年机械制造与材料应用国际会议 (ICMMMA 2026)
已经有4人回复
Cas 72-43-5需要30g,定制合成,能接单的留言
已经有8人回复
北京211副教授,35岁,想重新出发,去国外做博后,怎么样?
已经有8人回复
自荐读博
已经有3人回复
» 本主题相关价值贴推荐,对您同样有帮助:
vof模型算气液两相逆流 使用udf加动量源项 碰到问题 请高手解答
已经有14人回复
fluent能量源项中温度T对时间的t的偏导数,即dT/dt如何用udf编写能量源项
已经有6人回复
FLUENT源项UDF非稳态迭代的一个疑问请教
已经有8人回复
能量方程源项udf
已经有4人回复
UDF源项的一个疑问
已经有14人回复

★
xiegangmai: 金币-1, 专业版块交流贴,请勿灌水 2012-10-23 22:11:01
xiegangmai: 金币-1, 专业版块交流贴,请勿灌水 2012-10-23 22:11:01
|
2楼2012-10-23 15:46:15
3楼2012-10-23 22:33:24

4楼2012-10-24 11:05:17












))
回复此楼