登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
新手请教Traflove书中附带的2D程序
发帖
回复
1
2
3
3948
阅读
23
回复
[
求助
]
新手请教Traflove书中附带的2D程序
离线
wq_463
UID :20925
注册:
2008-11-06
登录:
2021-04-22
发帖:
227
等级:
仿真三级
0楼
发表于: 2008-12-20 19:45:32
— 本帖被 gwzhao 执行加亮操作(2008-12-21) —
这个程序有不少地方看不明啊,我把程序贴出来把不明白的地方打个问号,希望有人给解释一下
0k|/]zfb
我的qq243640120,希望做PML的朋友能加我,大家共同交流
(WS<6j[q
%***********************************************************************
'seuO!5
% 2-D FDTD TE code with PML absorbing boundary conditions
z;i4F.p
%***********************************************************************
rg+3pX\{
%
"}UYsXg
% Program author: Susan C. Hagness
&sPu3.p
% Department of Electrical and Computer Engineering
`JG7Pl/ih
% University of Wisconsin-Madison
EY!P"u;
% 1415 Engineering Drive
:&D$Q 4
% Madison, WI 53706-1691
),I7+rY
% 608-265-5739
{S5D~A*a+
% [url=mailto:hagness@engr.wisc.edu]hagness@engr.wisc.edu[/url]
[6Nzz]yy
%
>5]w\^QN9_
% Date of this version: February 2000
wsCT9&p
%
E{|n\|
% This MATLAB M-file implements the finite-difference time-domain
x6*.zo5e
% solution of Maxwell's curl equations over a two-dimensional
mZ t:
% Cartesian space lattice comprised of uniform square grid cells.
["?WVXCF8|
%
t+SLU6j,
% To illustrate the algorithm, a 6-cm-diameter metal cylindrical
rxI Ygh
% scatterer in free space is modeled. The source excitation is
V -9z{
% a Gaussian pulse with a carrier frequency of 5 GHz.
mc5$-}1V,
%
l_*:StyR+
% The grid resolution (dx = 3 mm) was chosen to provide 20 samples
/K#J63 ,
% per wavelength at the center frequency of the pulse (which in turn
4=n%<U`Z/
% provides approximately 10 samples per wavelength at the high end
qfEB VS(
% of the excitation spectrum, around 10 GHz).
s}Sxl0
%
e?b<-rL
% The computational domain is truncated using the perfectly matched
6I\mhw!pQ
% layer (PML) absorbing boundary conditions. The formulation used
- e"XEot~
% in this code is based on the original split-field Berenger PML. The
1HNX6
% PML regions are labeled as shown in the following diagram:
}=."X8zOI8
%
_^0)T@
% ----------------------------------------------
!' @
% | | BACK PML | |
8uhB&qxB
% ----------------------------------------------
SxCzI$SGu
% |L | /| R|
S{ !m})1?
% |E | (ib,jb) | I|
JYWc3o6
% |F | | G|
?GGh )";y
% |T | | H|
_N`pwxpsb
% | | MAIN GRID | T|
i0~L[v9l<
% |P | | |
[ w1"
% |M | | P|
su]ywVoRT
% |L | (1,1) | M|
/T2f~1R
% | |/ | L|
h!>NS ?X7
% ----------------------------------------------
gbRdng7(}
% | | FRONT PML | |
z'}?mE3i
% ----------------------------------------------
x@>^ c:-f
%
kOuQR$9s
% To execute this M-file, type "fdtd2D" at the MATLAB prompt.
-Qco4>Z 8
% This M-file displays the FDTD-computed Ex, Ey, and Hz fields at
> 'KQL?!F
% every 4th time step, and records those frames in a movie matrix,
}tZA7),L
% M, which is played at the end of the simulation using the "movie"
$JXQn
% command.
_`Sz}Yk
%
Ti9cN)lq&
%***********************************************************************
7dU7cc
clear
pNzGpCk
%***********************************************************************
gb0ZGnI
% Fundamental constants
;R?9|:7
%***********************************************************************
|tS~\_O/
cc=2.99792458e8; %speed of light in free space
cM'5m
muz=4.0*pi*1.0e-7; %permeability of free space
0#KB.2AP
epsz=1.0/(cc*cc*muz); %permittivity of free space
9^c"HyR
freq=5.0e+9; %center frequency of source excitation
pBu~($%d
lambda=cc/freq; %center wavelength of source excitation
ETVT.R8
omega=2.0*pi*freq;
KBFAV&
%***********************************************************************
}"?KHy
% Grid parameters
yo0?QRT
%***********************************************************************
Swz1RT
ie=100; %number of grid cells in x-direction
+nslS:(
je=50; %number of grid cells in y-direction
XUT\nN-N
ib=ie+1;
&hYjQ&n
jb=je+1;
QcQ|,lA.HI
is=15; %location of z-directed hard source
goT:\2
js=je/2; %location of z-directed hard source
JZ=a 3)x"
dx=3.0e-3; %space increment of square lattice
( Dl68]FX
dt=dx/(2.0*cc); %time step
dfq5P!'
nmax=300; %total number of time steps
{N,w5!cP
iebc=8; %thickness of left and right PML region
xX.Ox
jebc=8; %thickness of front and back PML region
$rC`)"t
rmax=0.00001;
"]`QQT-{0
orderbc=2;
W}1h~rNy
ibbc=iebc+1;
{#y HL
jbbc=jebc+1;
9? W38EF
iefbc=ie+2*iebc; %x方向的总网格数
fJC,ubP[5
jefbc=je+2*jebc;
DEC,oX!bI1
ibfbc=iefbc+1;
@]h#T4z'
jbfbc=jefbc+1;
;3_Q7;y
%***********************************************************************
ptuW}"F
% Material parameters
tgYIM`f
%***********************************************************************
:+,qvu!M7
media=2; %?
~dwl7Qc
eps=[1.0 1.0];
7iKbd
sig=[0.0 1.0e+7];
n1W}h@>8
mur=[1.0 1.0];
*WgP+"h
sim=[0.0 0.0];
0,;FiOp
%***********************************************************************
Ic/<jFZXM
% Wave excitation
Cst>'g-yB
%***********************************************************************
U-s6h;^O
rtau=160.0e-12;
Z@8amT;Y
tau=rtau/dt;
afc?a-~Z
delay=3*tau;
zj;y`ENj
source=zeros(1,nmax);
<`9:hPp0
for n=1:7.0*tau
(Qq$ql27
source(n)=sin(omega*(n-delay)*dt)*exp(-((n-delay)^2/tau^2)); %??????????
-}juj;IVv
end
vP'R7r2Yx
%***********************************************************************
Ve8`5
% Field arrays
V*'9yk"
%***********************************************************************
BWX&5""
ex=zeros(ie,jb); %fields in main grid
uyG4zV\h*
ey=zeros(ib,je);
L4;n$=e
hz=zeros(ie,je);
W:>RstbnMG
exbcf=zeros(iefbc,jebc); %fields in front PML region
|R*fw(=W
eybcf=zeros(ibfbc,jebc);
&/, BFx"
hzxbcf=zeros(iefbc,jebc);
Ahq^dx#o
hzybcf=zeros(iefbc,jebc);
(|5g`JDG
exbcb=zeros(iefbc,jbbc); %fields in back PML region
lv ^=g
eybcb=zeros(ibfbc,jebc);
Aq|LeH
hzxbcb=zeros(iefbc,jebc);
}%R6Su]y
hzybcb=zeros(iefbc,jebc);
TniZ!ud
exbcl=zeros(iebc,jb); %fields in left PML region
TCF[iE{
eybcl=zeros(iebc,je);
uYMW5k_,>
hzxbcl=zeros(iebc,je);
m x,X!}
hzybcl=zeros(iebc,je);
]3QQ"HLcp
exbcr=zeros(iebc,jb); %fields in right PML region
hoeTJ/;dm
eybcr=zeros(ibbc,je); %???????为什么跟LIFT的不一样呢
95wV+ q*
hzxbcr=zeros(iebc,je);
a}c(#ZLs
hzybcr=zeros(iebc,je);
Z9aDE@A
%***********************************************************************
t@v>eb
% Updating coefficients
=8dCk\/
%***********************************************************************
sinG $=
for i=1:media
\aUbBa%!
eaf =dt*sig(i)/(2.0*epsz*eps(i));
`u-VGd\
ca(i)=(1.0-eaf)/(1.0+eaf);
8a)EL*LH`
cb(i)=dt/epsz/eps(i)/dx/(1.0+eaf);
:WCUHQ+
haf =dt*sim(i)/(2.0*muz*mur(i));
]@?3,N
da(i)=(1.0-haf)/(1.0+haf);
(lPNMS|V
db(i)=dt/muz/mur(i)/dx/(1.0+haf);
=C\S6bF%
end
ccm <rZ7
%***********************************************************************
Qw5M\
% Geometry specification (main grid)
p-;]O~^
%***********************************************************************
~0 FqY&4
% Initialize entire main grid to free space
3nK'yC
caex(1:ie,1:jb)=ca(1);
Il;'s
cbex(1:ie,1:jb)=cb(1);
iQGoy@<R
caey(1:ib,1:je)=ca(1);
c*1x*'j.
cbey(1:ib,1:je)=cb(1);
0 q3<RX>M%
dahz(1:ie,1:je)=da(1);
FJL9x,%6
dbhz(1:ie,1:je)=db(1);
{fN_itn
% Add metal cylinder
@,aL'2G
diam=20; % diameter of cylinder: 6 cm
6OTxtk
rad=diam/2.0; % radius of cylinder: 3 cm
!Xj m h$F
icenter=4*ie/5; % i-coordinate of cylinder's center
\K?./*
jcenter=je/2; % j-coordinate of cylinder's center
d=4MqX r
for i=1:ie
uV 6f~cQ
for j=1:je
Z21XlbK
dist2=(i+0.5-icenter)^2 + (j-jcenter)^2;
(%fGS.TR
if dist2 <= rad^2
) L{Tn8
caex(i,j)=ca(2);
*,-YWx4
cbex(i,j)=cb(2);
kh,M'XbTo
end
$oua]8!
dist2=(i-icenter)^2 + (j+0.5-jcenter)^2;
(x$k\H
if dist2 <= rad^2
_1R`xbV
caey(i,j)=ca(2);
oC[wYUDg
cbey(i,j)=cb(2);
t583Q/1@
end
In;z\"NN4
end
\AK|~:\]
end
v}Aw!Dv/
%***********************************************************************
9wb$_j]F`#
% Fill the PML regions
iGU N$
%***********************************************************************
mifYk>J^9
delbc=iebc*dx;
wA~Nfn ^
sigmam=-log(rmax/100.0)*epsz*cc*(orderbc+1)/(2*delbc);%??????????
D@JHi'F
bcfactor=eps(1)*sigmam/(dx*(delbc^orderbc)*(orderbc+1));%???????????
_RmE+ Xg2
% FRONT region
<WbD4Q<3?
caexbcf(1:iefbc,1)=1.0;%???????我觉得Front和Back差不多,Rright和left差不多,大家能给我
MK[spV
解释一下F和R就是可以
UZAWh R
cbexbcf(1:iefbc,1)=0.0;
wFd*6%
for j=2:jebc
yauP j&^R
y1=(jebc-j+1.5)*dx;
F9+d7 Y$
y2=(jebc-j+0.5)*dx;
m9B3]H
sigmay=bcfactor*(y1^(orderbc+1)-y2^(orderbc+1));
l9L;Tjj
ca1=exp(-sigmay*dt/(epsz*eps(1)));
<m6I)}K
cb1=(1.0-ca1)/(sigmay*dx);
wRiP 5U,
caexbcf(1:iefbc,j)=ca1;
\qTNWA#'
cbexbcf(1:iefbc,j)=cb1;
9H)uTyuNi
end
ytC{E_
sigmay = bcfactor*(0.5*dx)^(orderbc+1);
r?+u}uH
ca1=exp(-sigmay*dt/(epsz*eps(1)));
TwhK>HN
cb1=(1-ca1)/(sigmay*dx);
J/=A f [
caex(1:ie,1)=ca1;
F'~/
cbex(1:ie,1)=cb1;
n `Xz<Q!
caexbcl(1:iebc,1)=ca1;
*nC,=2
cbexbcl(1:iebc,1)=cb1;
R{rV1j#@!a
caexbcr(1:iebc,1)=ca1;
Qom@-A
cbexbcr(1:iebc,1)=cb1;
q-3KF
for j=1:jebc
&S-& 'ZAY
y1=(jebc-j+1)*dx;
\S@A /t6pa
y2=(jebc-j)*dx;
bn(Scl#@K
sigmay=bcfactor*(y1^(orderbc+1)-y2^(orderbc+1));
IGqmH=-
sigmays=sigmay*(muz/(epsz*eps(1)));
x> q3w# B
da1=exp(-sigmays*dt/muz);
1aDDl-8,
db1=(1-da1)/(sigmays*dx);
OLR1/t`V
dahzybcf(1:iefbc,j)=da1;
C1do]1VH
dbhzybcf(1:iefbc,j)=db1;
}-Ma~/
caeybcf(1:ibfbc,j)=ca(1);
Vl z T
cbeybcf(1:ibfbc,j)=cb(1);
T8(wzs
dahzxbcf(1:iefbc,j)=da(1);
uHIWbF<0oo
dbhzxbcf(1:iefbc,j)=db(1);
-*Pt781
end
LK%B6-;~-
% BACK region
&Egn`QU
caexbcb(1:iefbc,jbbc)=1.0;
:hr@>Y~r
cbexbcb(1:iefbc,jbbc)=0.0;
X}=f{/\S
for j=2:jebc
gdZVc9_
y1=(j-0.5)*dx;
g`6wj|@ =W
y2=(j-1.5)*dx;
7w$R-Y/E
sigmay=bcfactor*(y1^(orderbc+1)-y2^(orderbc+1));
G7202(w <
ca1=exp(-sigmay*dt/(epsz*eps(1)));
s*X\%!l9
cb1=(1-ca1)/(sigmay*dx);
(hV"z; rI
caexbcb(1:iefbc,j)=ca1;
Rj&7|z
cbexbcb(1:iefbc,j)=cb1;
w+Z};C
end
E9:hK
sigmay = bcfactor*(0.5*dx)^(orderbc+1);
9M=K@a
ca1=exp(-sigmay*dt/(epsz*eps(1)));
0EB'!
cb1=(1-ca1)/(sigmay*dx);
"$'~=' [
caex(1:ie,jb)=ca1;
Iq=B]oE
cbex(1:ie,jb)=cb1;
&sgwY
caexbcl(1:iebc,jb)=ca1;
ykeUS zz2
cbexbcl(1:iebc,jb)=cb1;
^0 lPv!2
caexbcr(1:iebc,jb)=ca1;
4Qo1f5>N
cbexbcr(1:iebc,jb)=cb1;
S- \lN|
for j=1:jebc
:&-}S>pC
y1=j*dx;
3,5wWT] )
y2=(j-1)*dx;
&}$D[ 4N
sigmay=bcfactor*(y1^(orderbc+1)-y2^(orderbc+1));
c>!J@[,
sigmays=sigmay*(muz/(epsz*eps(1)));
9C 05
da1=exp(-sigmays*dt/muz);
M^f1D&A