登 录
註 冊
论坛
微波仿真网
注册
登录论坛可查看更多信息
微波仿真论坛
>
时域有限差分法 FDTD
>
PML吸收边界的二维FDTD代码
发帖
回复
4539
阅读
4
回复
[
讨论
]
PML吸收边界的二维FDTD代码
离线
lv19860312
UID :28549
注册:
2009-03-27
登录:
2009-06-08
发帖:
17
等级:
仿真新人
0楼
发表于: 2009-06-07 19:59:17
我在网上找的这个程序,有些地方看不同,请各位给解释一下。代码如下:
Sigu p#.p
%***********************************************************************
bE2{^5iG
% 2-D FDTD TE code with PML absorbing boundary conditions
Q&?B^[N*Q
%***********************************************************************
txy'7t
%
{fu[&@XV
% Program author: Susan C. Hagness
:w:ql/?X
% Department of Electrical and Computer Engineering
()yOK$"
% University of Wisconsin-Madison
~)]n67Or~
% 1415 Engineering Drive
/{nZI_v#
% Madison, WI 53706-1691
r8[Ywn<u
% 608-265-5739
+!<{80w
%
hagness@engr.wisc.edu
P!~B07y
%
<`*v/D7\02
% Date of this version: February 2000
3H,>[&d
%
*AA78G|
% This MATLAB M-file implements the finite-difference time-domain
l ?gh7m_ej
% solution of Maxwell's curl equations over a two-dimensional
+(vL~
% Cartesian space lattice comprised of uniform square grid cells.
KPI[{T\`ZM
%
hVu~[ 'Me
% To illustrate the algorithm, a 6-cm-diameter metal cylindrical
&A~(9IV
% scatterer in free space is modeled. The source excitation is
Y~I6ee,\
% a Gaussian pulse with a carrier frequency of 5 GHz.
`-<m#HF:)d
%
|~YhN'OJ
% The grid resolution (dx = 3 mm) was chosen to provide 20 samples
+)*aS+
% per wavelength at the center frequency of the pulse (which in turn
0coRar?+b
% provides approximately 10 samples per wavelength at the high end
" {Nw K
% of the excitation spectrum, around 10 GHz).
juBzpQYj
%
@RLlkWGc
% The computational domain is truncated using the perfectly matched
q@iZo,Yk
% layer (PML) absorbing boundary conditions. The formulation used
)LE#SGJP
% in this code is based on the original split-field Berenger PML. The
mW @Z1Plxs
% PML regions are labeled as shown in the following diagram:
4I3)eS%2
%
\h7XdmA]~
% ----------------------------------------------
I}1<epd ,
% | | BACK PML | |
vmT6^G
% ----------------------------------------------
Axx{G~n! [
% |L | /| R|
t[x[X4
% |E | (ib,jb) | I|
a: [m;
% |F | | G|
0p!N'7N
% |T | | H|
pt8#cU\
% | | MAIN GRID | T|
BG2Z'WOH
% |P | | |
)\,hc$<=m
% |M | | P|
u3_AZ2-;
% |L | (1,1) | M|
D[CEg2$y
% | |/ | L|
\DRYqLT`
% ----------------------------------------------
Fj0h-7L
% | | FRONT PML | |
4L[-[{2
% ----------------------------------------------
?iNihE
%
R=s^bYdoy
% To execute this M-file, type "fdtd2D" at the MATLAB prompt.
~n!7 ?4%U
% This M-file displays the FDTD-computed Ex, Ey, and Hz fields at
C'CdVDmX
% every 4th time step, and records those frames in a movie matrix,
>)S'`e4Gu
% M, which is played at the end of the simulation using the "movie"
k0!D9tk
% command.
CiC@Z,ud`
%
%~YQlN
%***********************************************************************
"AMsBvzgo
LQ=Fck~[r
clear
=/F\_/Xw
J|[`8 *8
%***********************************************************************
)J!=X`b
% Fundamental constants
R3} Z"
%***********************************************************************
QzA/HP a
aFwfF^\(|,
cc=2.99792458e8; %speed of light in free space
?c#v'c^=h
muz=4.0*pi*1.0e-7; %permeability of free space
t^@4n&Dg
epsz=1.0/(cc*cc*muz); %permittivity of free space
b. oA}XP
*saO~.-;4
freq=5.0e+9; %center frequency of source excitation
p4I6oS`/.
lambda=cc/freq; %center wavelength of source excitation
"Kt[jV;6
omega=2.0*pi*freq;
6'vt '9
)ia$pes
%***********************************************************************
kR|(hA,$N
% Grid parameters
DSx D531[A
%***********************************************************************
T1pMe{
?u /i8
ie=100; %number of grid cells in x-direction
v0S7 ]?_
je=50; %number of grid cells in y-direction
KoO\<_@";
>,%7bq=T!
ib=ie+1;
a+{95"4
jb=je+1;
0P6< 4
'8bT9
is=15; %location of z-directed hard source
OX/}j_8E^(
js=je/2; %location of z-directed hard source
CF+:9PG
OgBZoTT
dx=3.0e-3; %space increment of square lattice
t"Djh^=y
dt=dx/(2.0*cc); %time step
LjA>H>8%[
L~xzfO
nmax=300; %total number of time steps
Z )dz
B|n<{g[-cM
iebc=8; %thickness of left and right PML region
~`x<;Ts
jebc=8; %thickness of front and back PML region
}9ZcO\M
rmax=0.00001;
=8)q-{p3
orderbc=2;
@Xe[5T
ibbc=iebc+1;
\m;"KyP+
jbbc=jebc+1;
*FEY"W+bY
iefbc=ie+2*iebc;
Z]Iyj 97
jefbc=je+2*jebc;
6sp?'GO`~
ibfbc=iefbc+1;
#3act)m
jbfbc=jefbc+1;
.]W A/}
!t92_y3
%***********************************************************************
_fQBXG2
% Material parameters
rnCu=n
%***********************************************************************
rC!~4xj-
l<#*[TJ
media=2;
XDi[Iyj
d ;W(Vm6
eps=[1.0 1.0];
Bn_@R`
sig=[0.0 1.0e+7];
,zY!EHpx
mur=[1.0 1.0];
Nm]\0m0p-
sim=[0.0 0.0];
(J^2|9r
SH5G
%***********************************************************************
[{!5{k!
% Wave excitation
a7UfRG
%***********************************************************************
O%(k$fvM
#.n%$r
rtau=160.0e-12;
sd~T
tau=rtau/dt;
b bO1`b-
delay=3*tau;
*S@0o6v
y~\K~qjd
source=zeros(1,nmax);
Z*(lg$A9M
for n=1:7.0*tau
sw715"L
source(n)=sin(omega*(n-delay)*dt)*exp(-((n-delay)^2/tau^2));
" |l-NUe
end
_GK3]F0
y}bE'Od
%***********************************************************************
+e%U6&l{
% Field arrays
lj!f\C}d
%***********************************************************************
L'Fy\K\
mMEa*9P
ex=zeros(ie,jb); %fields in main grid
4aQb+t,
ey=zeros(ib,je);
*"D8E^9
hz=zeros(ie,je);
c0%%X!!$
"m:4e`_dz
exbcf=zeros(iefbc,jebc); %fields in front PML region
#7A_p8
eybcf=zeros(ibfbc,jebc);
m*S[oy&
hzxbcf=zeros(iefbc,jebc);
W} U-u{Z
hzybcf=zeros(iefbc,jebc);
X%b.]A
' Z}/3 dp
exbcb=zeros(iefbc,jbbc); %fields in back PML region
Y SE6PG
eybcb=zeros(ibfbc,jebc);
7}<057Xn'
hzxbcb=zeros(iefbc,jebc);
uR7\uvibUO
hzybcb=zeros(iefbc,jebc);
8?rRLM4
Qm X(s
exbcl=zeros(iebc,jb); %fields in left PML region
/hMD Me
eybcl=zeros(iebc,je);
,@Izx
hzxbcl=zeros(iebc,je);
z2QZ;ZjvRS
hzybcl=zeros(iebc,je);
^#4?v^QNh
P]G`Y>#$r
exbcr=zeros(iebc,jb); %fields in right PML region
Q7 Clr{&
eybcr=zeros(ibbc,je);
bNG;`VZ%
hzxbcr=zeros(iebc,je);
Ge>%?\
hzybcr=zeros(iebc,je);
$(6 .K-D
x`vIY-DS
%***********************************************************************
r%g?.4o*b
% Updating coefficients
kMHupROj
%***********************************************************************
+89s+4Jn
w8Mi:;6
for i=1:media
N@>,gm@UU
eaf =dt*sig(i)/(2.0*epsz*eps(i));
j:9kJq>mv
ca(i)=(1.0-eaf)/(1.0+eaf);
89@e &h*
cb(i)=dt/epsz/eps(i)/dx/(1.0+eaf);
jyt#C7mj-A
haf =dt*sim(i)/(2.0*muz*mur(i));
R;_U BQ)
da(i)=(1.0-haf)/(1.0+haf);
{zc<:^r^
db(i)=dt/muz/mur(i)/dx/(1.0+haf);
|6pNe T[
end
eswsxJ/!
0UmK S\P
%***********************************************************************
]r{-K63P{!
% Geometry specification (main grid)
>k?/'R
%***********************************************************************
XACbDKyS
MhNDf[W>
% Initialize entire main grid to free space
;y7V-sf
0omg%1vt<A
caex(1:ie,1:jb)=ca(1);
n#G I& U
cbex(1:ie,1:jb)=cb(1);
JxP=[>I
\1[I(u
caey(1:ib,1:je)=ca(1);
e%'$Vx0kA
cbey(1:ib,1:je)=cb(1);
zOpl#%"
3 G?^/nB
dahz(1:ie,1:je)=da(1);
(c<Krc h
dbhz(1:ie,1:je)=db(1);
$GyO+xF
uLsGb=m%b
% Add metal cylinder
oOhm`7iy
/]Fs3uf
diam=20; % diameter of cylinder: 6 cm
lMX 2O2 o
rad=diam/2.0; % radius of cylinder: 3 cm
bqXCe\#
icenter=4*ie/5; % i-coordinate of cylinder's center
d))(hk:
jcenter=je/2; % j-coordinate of cylinder's center
|yi3y `f
y#AwuC K
for i=1:ie
6s833Tmb&r
for j=1:je
rdsm /^,s
dist2=(i+0.5-icenter)^2 + (j-jcenter)^2;
q9RCXo>Y+1
if dist2 <= rad^2
N;A#3Ter
caex(i,j)=ca(2);
D@yg)$;z
cbex(i,j)=cb(2);
pHFh7-vj
end
}TZ5/zn.Dw
dist2=(i-icenter)^2 + (j+0.5-jcenter)^2;
g<