一维等离子体FDTD的Matlab源代码.docx

上传人:b****5 文档编号:4761122 上传时间:2022-12-08 格式:DOCX 页数:22 大小:23.36KB
下载 相关 举报
一维等离子体FDTD的Matlab源代码.docx_第1页
第1页 / 共22页
一维等离子体FDTD的Matlab源代码.docx_第2页
第2页 / 共22页
一维等离子体FDTD的Matlab源代码.docx_第3页
第3页 / 共22页
一维等离子体FDTD的Matlab源代码.docx_第4页
第4页 / 共22页
一维等离子体FDTD的Matlab源代码.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

一维等离子体FDTD的Matlab源代码.docx

《一维等离子体FDTD的Matlab源代码.docx》由会员分享,可在线阅读,更多相关《一维等离子体FDTD的Matlab源代码.docx(22页珍藏版)》请在冰豆网上搜索。

一维等离子体FDTD的Matlab源代码.docx

一维等离子体FDTD的Matlab源代码

一维等离子体FDTD的Matlab源代码(两种方法)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*$g-:

ILRuZ 

%%%%%%%%%%%%%%%%%%%%        1D              %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%oCz/HQoBk 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%k9L;!

TH~1K 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'D1xh~ 

%%%%%%%%%初始化Q\Vgl(;lX 

clear;3^yK!

-Wp( 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%utV_W& 

%%%%%%%%%%%%%%%%系统参数uwGc@xOgg, 

TimeT=3000;%迭代次数qIT@g"%}t 

KE=2000;%网格树木p4Z(^+Aa 

kc=450;%源的位置f3y=Wxk[ 

kpstart=500;%等离子体开始位置|2A:

eI8^ 

kpstop=1000;%等离子体终止位置'LDQgC*% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%A@#E@;lm 

%%%%%%%%%%%%%物理参数V!

~wj 

c0=3e8;%真空中波速3Jn;} 

zdelta=1e-9;%网格大小#GFr`o0$^ 

dt=zdelta/(2*c0);%时间间隔))Za&S*< 

f=900e12;%Gause脉冲的载频

d=3e-15%脉冲底座宽度

.e-#yET 

t0=f;%脉冲中心时间uXiN~j&Be 

u0=57e12%碰撞频率m]&SNz= 

fpe=2000e12;%等离子体频率K(|}dl:

 

wpe=2*pi*fpe;%等离子体圆频率m4Zk\,1m.| 

epsz=1/(4*pi*9*10^9);%真空介电常数$/],tSm 

mu=1/(c0^2*epsz);%磁常数;9#KeA_ 

ex_low_m1=0;yt2PU_), 

ex_low_m2=0;CvdN"k 

ex_high_m1=0;8FhdN 

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=wpe^2+2*u0/dt+(2/dt)^2;*lb<$E]="!

 

b1=2*wpe^2-8/(dt)^2;F:

ELPs4"

 

b2=wpe^2-2*u0/dt+(2/dt)^2;

Vw"\{` 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&mvSiyKX 

%%%%%%%%%%%%%初始化电磁场X;RLpEc|A 

Ex=zeros(1,KE);%XTI-B/K 

Ex_Pre=zeros(1,KE);rM"l@3hP 

Hy=zeros(1,KE);i6N',&jFU 

Hy_Pre=zeros(1,KE);E}.^kc[(4 

Dx=zeros(1,KE);{XHh8_^& 

Dx_Pre=zeros(1,KE);K+iP6B 

Sx1=zeros(1,KE);(iGTACoF 

Sx2=zeros(1,KE);Wez5N 

Sx3=zeros(1,KE);U;I9bK8 

Sx=zeros(1,KE);-.3w^D"l 

Dx=Ex;nF/OPd 

Dx1=Ex;Qci]i)s$js 

Dx2=Ex;3N:

D6w-R 

Dx3=Ex;:

i7;w%B 

Ex1=Ex;cS+>

J@L 

Ex2=Ex;WjjB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ljNo 

%%%%%%%%%%%%%%%%%%开始计算M@ZI\ 

forT=1:

TimeTL_s:

l9!

    %%%保存前一时间的电磁场#o2[hibq 

    Ex_Pre=Ex;o$.fhD 

    Hy_Pre=Hy;bYPKh 

    %%%%中间差分计算Dx8sCv]|cn 

    fori=2:

KEO|hp

XkV 

        Dx(i)=Dx(i)-(dt/zdelta)*(Hy(i)-Hy(i-1));cFWc<55aX6 

    endI`p;F!

    %%%%%%%%加入源!

Rt>xD 

    Dx(kc)=cos(2*pi*f*T*dt)*exp(-4*pi*((T*dt-t0)/d)^2);1!

gbTeVlY 

    >dG[G> 

    %%%计算电场Exw+{LAS 

    fori=1:

kpstart-109Cez\0 

        Ex(i)=Dx(i)/epsz;tNX

|U:

Y* 

    endDDH:

)=;z 

    fori=kpstop+1:

KEU`m54f@U 

        Ex(i)=Dx(i)/epsz;_f:

W$\ho 

    endJ9[r|`gJ( 

    Dx3=Dx2;C6AUNRpl 

Dx2=Dx1;w*JGUk 

Dx1=Dx;>"=>3 

    fori=kpstart:

kpstopFG*r'tC~r 

                  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;'CkIz"Wd 

Ex1=Ex;vOpKNp 

    Sx3=Sx2;kq,ucU%>p 

    Sx2=Sx1;}d}Ke_Q0 

    Ex

(1)=ex_low_m2;^ 

    ex_low_m2=ex_low_m1;4u5-7[TZ 

    ex_low_m1=Ex

(2);HqT#$}rv 

DG:

Z=LuJr 

    Ex(KE)=ex_high_m2;76h,]xi 

    ex_high_m2=ex_high_m1;SmSH2m- 

    ex_high_m1=Ex(KE-1);X=fYWj[H, 

    %%%%%%%%%%%%%%%%%%计算磁场O*

)Vhw'pK 

    fori=1:

KE-1XBu"-( 

        Hy(i)=Hy(i)-(dt/(mu*zdelta))*(Ex(i+1)-Ex(i));GMf`A,> 

    end*kDCliL 

    plot(Ex);)g#T9tx2D 

    gridon;CxOob1@ 

    pause;:

hk5.

end

%FDTDMainFunctionJobstoWorkers%

%***********************************************************************

%3-DFDTDcodewithPECboundaries

%***********************************************************************

%

%ThisMATLABM-fileimplementsthefinite-differencetime-domain

%solutionofMaxwell'scurlequationsoverathree-dimensional

%Cartesianspacelatticecomprisedofuniformcubicgridcells.

%

%Toillustratethealgorithm,anair-filledrectangularcavity

%resonatorismodeled.Thelength,width,andheightofthe

%cavityareXcm(x-direction),Ycm(y-direction),and

%Zcm(z-direction),respectively.

%

%ThecomputationaldomainistruncatedusingPECboundary

%conditions:

%ex(i,j,k)=0onthej=1,j=jb,k=1,andk=kbplanes

%ey(i,j,k)=0onthei=1,i=ib,k=1,andk=kbplanes

%ez(i,j,k)=0onthei=1,i=ib,j=1,andj=jbplanes

%ThesePECboundariesformtheouterlosslesswallsofthecavity.

%

%Thecavityisexcitedbyanadditivecurrentsourceoriented

%alongthez-direction.Thesourcewaveformisadifferentiated

%Gaussianpulsegivenby

%J(t)=-J0*(t-t0)*exp(-(t-t0)^2/tau^2),

%wheretau=50ps.TheFWHMspectralbandwidthofthiszero-dc-

%contentpulseisapproximately7GHz.Thegridresolution

%(dx=2mm)waschosentoprovideatleast10samplesper

%wavelengthupthrough15GHz.

%

%ToexecutethisM-file,type"fdtd3D"attheMATLABprompt.

%ThisM-filedisplaystheFDTD-computedEzfieldsateveryother

%timestep,andrecordsthoseframesinamoviematrix,M,which

%isplayedattheendofthesimulationusingthe"movie"command.

%

%***********************************************************************

function[Ex,Ey,Ez]=FDTD3D_Main(handles)

globalSimRunStop

%if~isdir('C:

\MATLAB7\work\cavity\figures')

%mkdir'C:

\MATLAB7\work\cavity\figures'

%end

%***********************************************************************

%GridPartition

%***********************************************************************

=get,'Value');

=get,'Value');

=get,'Value');

%***********************************************************************

%GridDimensons

%***********************************************************************

ie=get,'Value');%numberofgridcellsinx-direction

je=get,'Value');%numberofgridcellsiny-direction

ke=get,'Value');%numberofgridcellsinz-direction

ib=ie+1;

jb=je+1;

kb=ke+1;

%***********************************************************************

%AllDomainsFieldsIni.

%***********************************************************************

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);

%***********************************************************************

%Fundamentalconstants

%***********************************************************************

=;%speedoflightinfreespace

=*pi*;%permeabilityoffreespace

=**;%permittivityoffreespace

%***********************************************************************

%Gridparameters

%***********************************************************************

=get,'Value');%locationofz-directedcurrentsource

=get,'Value');%locationofz-directedcurrentsource

=floor(ke/2);%Surfaceofobservation

=get,'Value');;%spaceincrementofcubiclattice

=*;%timestep

=get,'Value');;%totalnumberoftimesteps

%***********************************************************************

%DifferentiatedGaussianpulseexcitation

%***********************************************************************

=get,'Value')*100e-12;

=;

=3*;

=get,'Value')*10e11;

=*;

%***********************************************************************

%Materialparameters

%***********************************************************************

=get,'Value');

=get,'Value');

%***********************************************************************

%Updatingcoefficients

%***********************************************************************

=*/**)/+*/**);

=/+*/**);

=;

=;

%***********************************************************************

%CallingFDTDAlgorithm

%***********************************************************************

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);%Gridcoordinates

Psim=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;

forn=1:

1:

form1=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

[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;

forn=1:

1:

form2=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

[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;

end

elseif(==1)&==1))

x=ceil(ie/;

=[1:

x-1:

ie-x];

=[x+1:

x-1:

ie];

y=ceil(je/;

=[1:

y-1:

je-y];

=[y+1:

y-1:

je];

forn=1:

1:

form2=1:

1:

form1=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(param,handles,ex,ey,ez,X,Y,Z,n,Psim,Panl,p);

pause;

end

else

=1;

=ie;

=1;

=je;

m1=1;m2=1;

forn=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');

ifSimRunStop==1

h=warndlg('SimulationRunisStoppedbyUser!

','!

!

Warning!

!

');

waitfor(h);

break;

end

[Psim(n),Panl(n)]=Cavity_Power(param,handles,ex,ey,ez,n

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1