登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
一段一维FDTD程序的问题
发帖
回复
1542
阅读
8
回复
一段一维FDTD程序的问题
离线
learnerlcy
UID :43237
注册:
2009-10-07
登录:
2014-01-15
发帖:
55
等级:
仿真一级
0楼
发表于: 2009-11-14 22:09:41
这是一个叫DENIS的人写的一本书上面的例子,但是我在我的机子运行的结果就是不对,不知道哪里出了错,我是新手,望多多指教。
k1~nd=p
HYa$EE2
/*1D FDTD simulation in free space*/
Pf^Ly97
#include<math.h>
\@iOnRuHn9
#include<stdlib.h>
f(@"[-[
#include<stdio.h>
7]<F>97
#dxJ#
#define KE 200
*!wO:<-
i-K"9z|)
main()
j\jL[hG_
{
mjkw&2
float ex[KE], hy[KE];
I_jM-/3b
int n, k, kc, ke, NSTEPS;
+=,4@I%
float T;
=:ya;k&
float t0, spread, pulse;
KoxGxHz^Y3
FILE *fp; //, *fopen();
ba1$kU
l,^i5t'
/*Initialize*/
K%aPl~e
for (k=1; k<KE; k++)
vUodp#s
{
zx_O"0{5
ex[k] = 0;
i+qLc6|S=2
hy[k] = 0;
$9 &Q.Kpq>
}
/: \V wH
8VAYIxRv
kc = KE/2; //Center of the problem space
#buV;!_!E?
t0 = 40.0; //Center of the incident pulse
&?5{z\;1"
spread = 12; //Width of the incident pulse
8f6;y1!;
T = 0;
R|Q_W X
NSTEPS = 1;
` + n
Zh fD`@>&
while(NSTEPS > 0)
:+?W
{
BC$;b>IUA
printf("NSTEPS -->"); //NSTEPS is the number of times the main loop has executed
Ma*dIwEp
scanf("%d", &NSTEPS);
SCt=OdP=
printf("%d\n", NSTEPS);
HqnKpZ
n = 0;
Vm,f3~
for (n=1; n<=NSTEPS; n++)
HIWmh4o/.
{
n'&`9M['%d
T = T+1;
bVAgul=__
//Main FDTD Loop
DS,FVh".|
/*Calculate the Ex field*/
H-\{w
for ( k=1; k < KE; k++)
>`rNT|rg
{
5E oWyy
ex[k] = ex[k]+ 0.5*( hy[k-1] - hy[k] );
5M\=+5wB
}
~y-vKCp|
//Put a Gaussian pulse in the middle
057G;u/
pulse = exp(-0.5*(pow((t0-T)/spread, 2.0 )));
8.;';[
ex[kc] = pulse;
@7[.>I(
printf( " %5.1f %6.2f \n", t0 - T, ex[kc] );
VM V]TPks>
//Calculate the Hy field
Jq+$_Uqd
for (k=0; k<KE-1; k++)
&Lt$a_y>
{
[K4+G]6
hy[k] = hy[k] +0.5* (ex[k] - ex[k+1] );
u6S0t?Udap
}
" jQe\
}
|q.:hWYFpM
//End of the Main loop
?3"D| cS1
//At the end of the calculation ,print out the Ex and Hy fields
r~D~7MNl
for (k=1; k<=KE; k++)
%Dr4~7=7a
{
sY;gh`4h
printf("%3d %6f %6.2f\n", k, ex[k], hy[k]);
!$KhL.4P
}
gHh.|PysW
c!u}KVH
//Write the E field out to a file "Ex"
vo( j@+dz
fp = fopen("Ex.dat","w");
:2UC{_
for (k=1; k<=KE; k++)
4xpWO6Q
{
Uh|__DUkh
fprintf(fp, "%d %6.2f \n",k, ex[k]);
o"ah\"#el
}
M6hvi(!X2
fclose(fp);
>eG&gc@$1$
4{pemqS*
//Write the H field out to a file "Hy"
.dKRIFo
&nb ..
>K|G LP
nwZr3r
未注册仅能浏览
部分内容
,查看
全部内容及附件
请先
登录
或
注册
共
条评分
离线
learnerlcy
UID :43237
注册:
2009-10-07
登录:
2014-01-15
发帖:
55
等级:
仿真一级
1楼
发表于: 2009-11-14 22:12:12
这是计算结果画的图
图片:untitled.jpg
共
条评分
离线
learnerlcy
UID :43237
注册:
2009-10-07
登录:
2014-01-15
发帖:
55
等级:
仿真一级
2楼
发表于: 2009-11-15 00:04:48
这个结果似乎是发散的啊~~不知道怎么弄才对啊?
共
条评分
离线
learnerlcy
UID :43237
注册:
2009-10-07
登录:
2014-01-15
发帖:
55
等级:
仿真一级
3楼
发表于: 2009-11-15 12:08:58
怎么没人回答我,急呀~这次我把C语言的代码文件给附上~希望哪位高手指教一二啊!
附件:
fdtd_1.1a.rar
(1 K) 下载次数:10
共
条评分
离线
kerving16
UID :48824
注册:
2009-12-14
登录:
2009-12-14
发帖:
3
等级:
旁观者
4楼
发表于: 2009-12-14 21:07:46
研究研究~~~~~~~~~~~
共
条评分
离线
gwzhao
方恨少
UID :17098
注册:
2008-08-24
登录:
2019-01-09
发帖:
1374
等级:
荣誉管理员
5楼
发表于: 2009-12-14 22:16:01
for ( k=1; k < KE; k++)
&3rh{" ^9
{
0/c4%+ Ln
ex[k] = ex[k]+ 0.5*( hy[k] - hy[k-1] );
- 0zo>[c/p
}
tZJKB1#WbP
m{~r6@
for (k=0; k<KE-1; k++)
&f[[@EF7
{
fI6F};I5}T
hy[k] = hy[k] +0.5* (ex[k+1] - ex[k] );
1z)+P1nH]
}
共
条评分
逆流而上
离线
gwzhao
方恨少
UID :17098
注册:
2008-08-24
登录:
2019-01-09
发帖:
1374
等级:
荣誉管理员
6楼
发表于: 2009-12-14 22:16:26
你改一下,试试看行不行。
共
条评分
逆流而上
离线
alang
UID :41410
注册:
2009-09-11
登录:
2010-03-02
发帖:
77
等级:
仿真一级
7楼
发表于: 2010-02-07 10:49:17
xiexielouzhufenxianga
共
条评分
离线
learnerlcy
UID :43237
注册:
2009-10-07
登录:
2014-01-15
发帖:
55
等级:
仿真一级
8楼
发表于: 2010-03-17 23:22:43
回 5楼(gwzhao) 的帖子
谢谢啊,最近在忙别的事情,好久没来了~这个程序我已经解决掉了!谢谢你!
vWc =^tT
/*1D FDTD simulation in free space*/
4cDjf~n
#include<math.h>
_SY4Qs`d
#include<stdlib.h>
[LbUlNq^B@
#include<stdio.h>
1^jGSB.%A
!RN(/ &%y
#define KE 200
mr&nB
x4Q*~,n
main()
KEEHb2q
{
A\X?Aq-^'
double ex[KE], hy[KE];
UiO%y
int n, k, kc, ke, NSTEPS;
Wxx?iW ,
double T;
h\k@7wgu
double t0, spread, pulse;
kr[p4X4
double ex_low_m1, ex_low_m2, ex_high_m1, ex_high_m2;
V i V3Y
FILE *fp;
Iy% fg',%
wylbs@
//Initialize
tJ;<=.n
for (k=0; k<KE; k++)
..'k+0u^
{
YMb\v4
ex[k] = 0;
',$Uw|N
hy[k] = 0;
/}t>o* x
}
CY"&@v1
'B>fRN
kc = KE/2; //Center of the problem space
yhxen
t0 = 40.0; //Center of the incident pulse
>+Z BQ]~
spread = 25; //Width of the incident pulse
K Rs e
T = 0;
+uZ,}J
NSTEPS = 50;
?NkweT(
//Initialize boundary conditions' variable
>$Sc}a3
ex_low_m1 = 0;
ra2sYH1wr
ex_low_m2 = 0;
R9bsl.e
ex_high_m1 = 0;
?tx%KU\3
ex_high_m2 = 0;
u_ou,RF
//Initialization finished
S{wR Z|8U
q% *-4GP
while(NSTEPS > 0)
<?yf<G'$
{
$De1 4
printf("NSTEPS -->"); //NSTEPS is the number of times the main loop has executed
B /q/6Pp
scanf("%d", &NSTEPS);
RrB)u?
printf("%d\n", NSTEPS);
PxE 0b0eo
n = 0;
P5-1z&9O
for (n=1; n<=NSTEPS; n++)
_sLSl;/t
{
-hL 0}Wy$N
T = T+1;
#y;TSHx/
//Main FDTD Loop
!'scOWWn
/*Calculate the Ex field*/
YD>5zV%!D
for ( k=1; k < KE; k++)
7m='-_w)?w
{
RI.6.f1dy
ex[k] = ex[k]+ 0.5*( hy[k-1] - hy[k] );
D_kz'0^|
}
f"i(+:la
//Put a Gaussian pulse in the middle
uzG{jc^
pulse = exp(-3.0*(pow((t0-T)/spread, 2.0 ))); //exp()函数前面的系数决定了振幅的大小
d^b(Uo=$
ex[kc] = pulse;
" ,k(*
printf( " %5.1f %6.2f \n", t0 - T, ex[kc] );
|W $epOLg
D#"BY; J
//Absorbing Boundary Conditions
CWKN0HB
//第一次改变:加入边界条件。
V;}kgWc1
//这里使用的是Toflove吸收边界条件
RgTm^?Ex
ex[0] = ex_low_m2;
Y%$@ZYW
ex_low_m2 = ex_low_m1;
f+3ico]f@
ex_low_m1 = ex[1];
}#'I,?_k
[=/Yo1:v
ex[KE-1] = ex_high_m2;
SUGB)vEa
ex_high_m2 = ex_high_m1;
rF n%e
ex_high_m1 = ex[KE-2];
' b?' u
//Absorbing Boundary Conditions is finished
$r> $ u
^<u9I5?
//Calculate the Hy field
uT1xvXfqP
for (k=0; k<KE-1; k++)
$U. >]i
{
}7Lo}}
hy[k] = hy[k] + 0.5*( ex[k] - ex[k+1] );
q-? k=RX`
}
< 7
}
j:k}6]p}
//End of the Main loop
'DLgOUvh
//At the end of the calculation ,print out the Ex and Hy fields
kD"BsL*6!
for (k=0; k<KE; k++)
'OEh'\d+x
{
B"; >zF
printf("%3d %6f %6.2f\n", k, ex[k], hy[k]);
`eZ +Pf".
}
[k<"@[8)
!W\Zq+^^J3
//Write the E field out to a file "Ex"
"&9L
fp = fopen("Ex.dat","w");
"!w$7|%T
for (k=0; k<KE; k++)
F"I{_yleq'
{
%3SBs*?
fprintf(fp, "%d %6.2f \n",k, ex[k]);
Ebk9[=
}
^v2-"mX<
fclose(fp);
`3wzOMgJ
Jeb"t1.$
//Write the H field out to a file "Hy"
Dqxtc|vo
fp = fopen("Hy.dat","w");
oY NIJXln
for (k=0; k<KE; k++)
sWtT"7>x
{
MawWgd*
fprintf(fp, "%d %6.2f \n", k, hy[k]);
s<#["K*_
}
SK][UxoHm
fclose(fp);
_Fc :<Ym?
printf("T= %5.0f\n",T);
WF#3'"I
}
[l`_2{:
}
共
条评分
发帖
回复