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ob1@
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