1、一维等离子体FDTD的Matlab源代码一维等离子体FDTD的Matlab源代码(两种方法)% *$g-:ILRuZ %1D% oCz/HQoBk % k9L;!TH1K % D1xh %初始化 QVgl(;lX clear; 3yK!-Wp( % utV_ W& %系统参数 uwGcxOgg, TimeT=3000;%迭代次数 qITg%t KE=2000;%网格树木 p4Z(+Aa kc=450;%源的位置 f3y=Wxk kpstart=500;%等离子体开始位置 |2A:eI8 kpstop=1000;%等离子体终止位置 LDQgC*% % A#E ;lm %物理参数 V !wj c0
2、=3e8;%真空中波速 3Jn ; zdelta=1e-9;%网格大小 #GFro0$ dt=zdelta/(2*c0);%时间间隔 ) )Za&S* f=900e12;%Gause脉冲的载频 C*hokqqP d=3e-15%脉冲底座宽度 .e-#yET t0=f;%脉冲中心时间 uXiNj &Be u0=57e12%碰撞频率 m&SNz= fpe=2000e12;%等离子体频率 K (|dl: wpe=2*pi*fpe;%等离子体圆频率 m4Zk,1m.| epsz=1/(4*pi*9*109); % 真空介电常数 $/ ,tSm mu=1/(c02*epsz);%磁常数 ;9#KeA _
3、 ex_low_m1=0; yt2PU_), ex_low_m2=0; CvdNk ex_high_m1=0; 8 FhdN ex_high_m2=0; v r:=K a0=2*u0/dt+(2/dt)2; hf8ZEW9 a1=-8/(dt)2; +H2Qk4XFB a2=-2*u0/dt+(2/dt)2; 2t,zLwBdnJ b0=wpe2+2*u0/dt+(2/dt)2; *lbJL Ex2=Ex; WjjBYKzF % ljNo %开始计算 MZI for T=1:TimeT L_s:l9!r %保存前一时间的电磁场 #o2hibq Ex_Pre=Ex; o $.fhD Hy_Pre
4、=Hy; bYPKh %中间差分计算Dx 8sCv|cn for i=2:KE O| hpXkV Dx(i)=Dx(i)-(dt/zdelta)*(Hy(i)-Hy(i-1); cFWcxD Dx(kc)=cos(2*pi*f*T*dt)*exp(-4*pi*(T*dt-t0)/d)2); 1!gbTeVlY dGG %计算电场Ex w+ LAS for i=1:kpstart-1 09Cez0 Ex(i)=Dx(i)/epsz; tNX|U:Y* end DDH:)=;z for i=kpstop+1:KE Um54fU Ex(i)=Dx(i)/epsz; _f:W$ho end J9r|g
5、J( Dx3=Dx2; C 6AUNRpl Dx2=Dx1; w*JGUk Dx1=Dx; =3 for i=kpstart:kpstop FG*rtCr Ex(i)=(1/b0)*(a0*Dx1(i)+a1*Dx2(i)+a2*Dx3(i)-b1*Ex1(i)-b2*Ex2(i); )TH# 1 end Em&6! Ex2=Ex1; CkIzWd Ex1=Ex; vOpK Np Sx3=Sx2; kq,ucU%p Sx2=Sx1; dKe_Q0 Ex(1)=ex_low_m2; ex_low_m2=ex_low_m1; 4u5-7TZ ex_low_m1=Ex(2); HqT#$rv DG:
6、Z=LuJr Ex(KE)=ex_high_m2; 76h ,xi ex_high_m2=ex_high_m1; SmSH2m- ex_high_m1=Ex(KE-1); X=fYWjH, %计算磁场 O*)VhwpK for i=1:KE-1 XBu-( Hy(i)=Hy(i)-(dt/(mu*zdelta)*(Ex(i+1)-Ex(i); GM f A, end *kDCliL plot(Ex); )g#T9tx2D grid on; CxOob1 pause; :hk5 . end% FDTD Main Function Jobs to Workers %*% 3-D FDTD code
7、 with PEC boundaries%*% This MATLAB M-file implements the finite-difference time-domain% solution of Maxwells curl equations over a three-dimensional% Cartesian space lattice comprised of uniform cubic grid cells.% % To illustrate the algorithm, an air-filled rectangular cavity % resonator is modele
8、d. The length, width, and height of the % cavity are X cm (x-direction), Y cm (y-direction), and % Z cm (z-direction), respectively.% The computational domain is truncated using PEC boundary % conditions:% ex(i,j,k)=0 on the j=1, j=jb, k=1, and k=kb planes% ey(i,j,k)=0 on the i=1, i=ib, k=1, and k=k
9、b planes% ez(i,j,k)=0 on the i=1, i=ib, j=1, and j=jb planes% These PEC boundaries form the outer lossless walls of the cavity.% The cavity is excited by an additive current source oriented% along the z-direction. The source waveform is a differentiated % Gaussian pulse given by % J(t)=-J0*(t-t0)*ex
10、p(-(t-t0)2/tau2), % where tau=50 ps. The FWHM spectral bandwidth of this zero-dc-% content pulse is approximately 7 GHz. The grid resolution % (dx = 2 mm) was chosen to provide at least 10 samples per % wavelength up through 15 GHz.% To execute this M-file, type fdtd3D at the MATLAB prompt.% This M-
11、file displays the FDTD-computed Ez fields at every other% time step, and records those frames in a movie matrix, M, which % is played at the end of the simulation using the movie command.%*function Ex,Ey,Ez=FDTD3D_Main(handles)global SimRunStop% if isdir(C:MATLAB7workcavityfigures)% mkdir C:MATLAB7w
12、orkcavityfigures% end%*% Grid Partition%* = get,Value); = get,Value); = get,Value);%*% Grid Dimensons%*ie = get,Value); %number of grid cells in x-directionje = get,Value); %number of grid cells in y-directionke = get,Value); %number of grid cells in z-directionib=ie+1; jb=je+1; kb=ke+1;%*% All Doma
13、ins Fields Ini.%*Ex=zeros(ie,jb,kb);Ey=zeros(ib,je,kb);Ez=zeros(ib,jb,ke);Hx=zeros(ib,je,ke);Hy=zeros(ie,jb,ke);Hz=zeros(ie,je,kb);%*% Fundamental constants%*=; %speed of light in free space=*pi*; %permeability of free space = *; %permittivity of free space%*% Grid parameters%* = get,Value); %locati
14、on of z-directed current source = get,Value); %location of z-directed current source = floor(ke/2); %Surface of observation = get,Value); %space increment of cubic lattice = *; %time step = get,Value); %total number of time steps%*% Differentiated Gaussian pulse excitation%*=get,Value)*100e-12;=;=3*
15、; = get,Value)*10e11;=*;%*% Material parameters%*= get,Value);= get,Value); %*% Updating coefficients%*=*/*)/+*/*);=/+*/*);=;=;%*% Calling FDTD Algorithm%*ex=zeros(ib,jb,kb);ey=zeros(ib,jb,kb);ez=zeros(ib,jb,kb);hx=zeros(ib,jb,kb);hy=zeros(ib,jb,kb);hz=zeros(ib,jb,kb);X,Y,Z = meshgrid(1:ib,1:jb,1:kb
16、); % Grid coordinatesPsim = zeros,1);Panl = zeros,1); if ( = 1)& = 0) x = ceil(ie/ = 1:x-1:ie-x; = x+1:x-1:ie; = 1,1; = je,je; m2 = 1; for n=1:1: for m1=1:1: ex,ey,ez=Efields(param,handles,ex,ey,ez,hx,hy,hz,ie,je,ke,ib,jb,kb,n,m1,m2,p); hx,hy,hz = Hfields(param,hx,hy,hz,ex,ey,ez,ie,je,ke,ib,jb,kb,n,
17、m1,m2,p); end Psim(n),Panl(n) = Cavity_Power(param,handles,ex,ey,ez,n); field_viz(param,handles,ex,ey,ez,X,Y,Z,n,Psim,Panl,p); Dyn_FFT pause; end elseif ( = 0)& = 1) y = ceil(je/; = 1:y-1:je-y; = y+1:y-1:je; = 1,1; = ie,ie; m1 = 1; for n=1:1: for m2=1:1: ex,ey,ez=Efields(param,handles,ex,ey,ez,hx,hy
18、,hz,ie,je,ke,ib,jb,kb,n,m1,m2,p); hx,hy,hz = Hfields(param,hx,hy,hz,ex,ey,ez,ie,je,ke,ib,jb,kb,n,m1,m2,p); end Psim(n),Panl(n) = Cavity_Power(param,handles,ex,ey,ez,n); field_viz(param,handles,ex,ey,ez,X,Y,Z,n,Psim,Panl,p); pause; endelseif ( = 1)& = 1) x = ceil(ie/; = 1:x-1:ie-x; = x+1:x-1:ie; y =
19、ceil(je/; = 1:y-1:je-y; = y+1:y-1:je; for n=1:1: for m2=1:1: for m1=1:1: ex,ey,ez=Efields(param,handles,ex,ey,ez,hx,hy,hz,ie,je,ke,ib,jb,kb,n,m1,m2,p); hx,hy,hz = Hfields(param,hx,hy,hz,ex,ey,ez,ie,je,ke,ib,jb,kb,n,m1,m2,p); end end Psim(n),Panl(n) = Cavity_Power(param,handles,ex,ey,ez,n); field_viz
20、(param,handles,ex,ey,ez,X,Y,Z,n,Psim,Panl,p); pause; end else = 1; = ie; = 1; = je; m1 = 1;m2=1; for n=1:1: ex,ey,ez=Efields(param,handles,ex,ey,ez,hx,hy,hz,ie,je,ke,ib,jb,kb,n,m1,m2,p); hx,hy,hz = Hfields(param,hx,hy,hz,ex,ey,ez,ie,je,ke,ib,jb,kb,n,m1,m2,p); SimRunStop = get,value); if SimRunStop = 1 h = warndlg(Simulation Run is Stopped by User !,! Warning !); waitfor(h); break; end Psim(n),Panl(n) = Cavity_Power(param,handles,ex,ey,ez,n
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1