24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 1514  |  回复: 3

mgyao

新虫 (初入文坛)

[求助] 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;
}
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

坚若磐石
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xiegangmai: 金币-1, 专业版块交流贴,请勿灌水 2012-10-23 22:11:01
2楼2012-10-23 15:46:15
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sunbird04

银虫 (小有名气)

【答案】应助回帖

★ ★
感谢参与,应助指数 +1
xiegangmai: 金币+2, 谢谢参与 2012-10-24 19:51:46
先检查一下C_UDMI(c,t,UDM_SOURCE_FMAGX)及C_UDMI(c,t,UDM_SOURCE_FMAGY)看看他们的值是否为零。
如果不为零,那是不是你加的这个力对结果的影响不明显。
3楼2012-10-23 22:33:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

mgyao

新虫 (初入文坛)

引用回帖:
3楼: Originally posted by sunbird04 at 2012-10-23 22:33:24
先检查一下C_UDMI(c,t,UDM_SOURCE_FMAGX)及C_UDMI(c,t,UDM_SOURCE_FMAGY)看看他们的值是否为零。
如果不为零,那是不是你加的这个力对结果的影响不明显。

不是零,输出来看了的,试算一步的话也看不出来力有作用,估计还是哪里出问题没加上去
坚若磐石
4楼2012-10-24 11:05:17
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 mgyao 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 301求调剂 +6 细胞相关蛋白 2026-04-02 10/500 2026-04-06 08:34 by jp9609
[考研] 0855求调剂材料 +11 红桃灼灼 2026-04-04 11/550 2026-04-05 22:13 by 醉翁wl
[考研] 复试调剂 +13 呼呼?~+123456 2026-04-05 13/650 2026-04-05 22:07 by 醉翁wl
[考研] 359求调剂22408 +3 123456789qw 2026-03-31 3/150 2026-04-05 10:09 by zhq0425
[考研] 301求调剂 +18 骆驼男人 2026-04-02 18/900 2026-04-04 20:33 by 蓝云思雨
[考研] 324求调剂 +14 想上学求调 2026-04-02 15/750 2026-04-04 20:31 by 无际的草原
[考研] 085601,一志愿厦大334复试被刷求调剂 +13 曾仰之 2026-04-03 15/750 2026-04-04 20:13 by dongzh2009
[考研] 一志愿085404,总分291,四级已过,求调剂 +5 阿俊阿俊阿俊 2026-04-04 7/350 2026-04-04 13:23 by 莲菜就是藕吧
[考研] 278求调剂 +6 Yy7400 2026-04-03 6/300 2026-04-04 09:53 by zhangdingwa
[考研] 英一数一408,总分284,二战真诚求调剂 +13 12.27 2026-03-30 15/750 2026-04-03 14:41 by 氮气气气
[考研] 求调剂不挑专业 +3 xrh030412 2026-04-01 3/150 2026-04-03 14:40 by 氮气气气
[考研] 数一英一285求调剂 +7 AZMK 2026-04-03 9/450 2026-04-03 13:03 by ms629
[考研] 285求调剂 +6 FZAC123 2026-03-30 6/300 2026-04-03 12:22 by xingguangj
[基金申请] 请问共同通讯和共同一作的认可度问题 10+4 psa1234 2026-04-01 10/500 2026-04-03 11:08 by Kittylucky
[考研] 一志愿北京科技材料科学与工程288分,求调剂 +14 是辰啊 2026-04-02 14/700 2026-04-02 21:10 by dongzh2009
[考研] 求调剂推荐 +3 南山南@ 2026-04-01 3/150 2026-04-02 12:09 by xiaoranmu
[考研] 材料工程322分 +8 哈哈哈吼吼吼哈 2026-04-01 8/400 2026-04-02 11:53 by 3041
[考研] 271求调剂 +15 勒布朗@ 2026-03-31 20/1000 2026-04-02 11:24 by Sammy2
[考研] 土木304求调剂 +6 兔突突突, 2026-03-31 7/350 2026-04-02 09:06 by coolminer
[考研] 083000环境科学与工程调剂,总分281 +4 橙子(胜意) 2026-03-30 4/200 2026-03-31 00:44 by Linzejun
信息提示
请填处理意见