fdtd1d_2

Upload: tiffany-campbell

Post on 02-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 fdtd1d_2

    1/3

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Scott Hudson, WSU Tri-Cities%1D electromagnetic finite-difference time-domain (FDTD) program.%Assumes Ey and Hz field components propagating in the x direction.%Fields, permittivity, permeability, and conductivity%are functions of x. Try changing the value of "profile".%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    close all;clear all;

    L = 5; %domain length in metersN = 505; %# spatial samples in domainNiter = 800; %# of iterations to performfs = 300e6; %source frequency in Hzds = L/N; %spatial step in metersdt = ds/300e6; %"magic time step"eps0 = 8.854e-12; %permittivity of free spacemu0 = pi*4e-7; %permeability of free space

    x = linspace(0,L,N); %x coordinate of spatial samplesshowWKB=0; %if =1 then show WKB appromination at end

    %scale factors for E and Hae = ones(N,1)*dt/(ds*eps0);am = ones(N,1)*dt/(ds*mu0);as = ones(N,1);epsr = ones(N,1);mur= ones(N,1);sigma = zeros(N,1);

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

    %Here we specify the epsilon, sigma, and mu profiles. I've%predefined some interesting examples. Try profile = 1,2,3,4,5,6 in sequence.%You can define epsr(i), mur(i) (relative permittivity and permeability)%and sigma(i) (conductivity) to be anything you want.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%profile = 1;for i=1:N epsr(i) = 1; mur(i) = 1; w1 = 0.5; w2 = 1.5; if (profile==1) %dielectric window

    if (abs(x(i)-L/2)L/2) epsr(i) = 9; end

    end if (profile==5) %conducting half space if (x(i)>L/2) sigma(i) = 0.005; end

  • 8/10/2019 fdtd1d_2

    2/3

    end if (profile==6) %sinusoidal dielectric epsr(i) = 1+sin(2*pi*x(i)/L)^2; endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    ae = ae./epsr;am = am./mur;ae = ae./(1+dt*(sigma./epsr)/(2*eps0));as = (1-dt*(sigma./epsr)/(2*eps0))./(1+dt*(sigma./epsr)/(2*eps0));

    %plot the permittivity, permeability, and conductivity profilesfigure(1)subplot(3,1,1);plot(x,epsr);grid on;axis([3*ds L min(epsr)*0.9 max(epsr)*1.1]);

    title('relative permittivity');subplot(3,1,2);plot(x,mur);grid on;axis([3*ds L min(mur)*0.9 max(mur)*1.1]);title('relative permeabiliity');subplot(3,1,3);plot(x,sigma);grid on;axis([3*ds L min(sigma)*0.9-0.001 max(sigma)*1.1+0.001]);title('conductivity');

    %initialize fields to zero

    Hz = zeros(N,1);Ey = zeros(N,1);figure(2);set(gcf,'doublebuffer','on'); %set double buffering on for smoother graphicsplot(Ey);grid on;

    for iter=1:Niter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %The next 10 or so lines of code are where we actually integrate Maxwell's %equations. All the rest of the program is basically bookkeeping and plotting. %"smooth turn on" sinusoidal source

    Ey(3) = Ey(3)+2*(1-exp(-((iter-1)/50)^2))*sin(2*pi*fs*dt*iter);Hz(1) = Hz(2); %absorbing boundary conditions for left-propagating waves

    for i=2:N-1 %update H field Hz(i) = Hz(i)-am(i)*(Ey(i+1)-Ey(i)); end Ey(N) = Ey(N-1); %absorbing boundary conditions for right propagating waves for i=2:N-1 %update E field Ey(i) = as(i)*Ey(i)-ae(i)*(Hz(i)-Hz(i-1)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure(2) hold off

    plot(x,Ey,'b'); axis([3*ds L -2 2]); grid on;

  • 8/10/2019 fdtd1d_2

    3/3

    title('E (blue) and 377*H (red)'); hold on plot(x,377*Hz,'r'); xlabel('x (m)'); pause(0); iterend

    %WKB prediction for the fieldsif (showWKB==1)

    phase = cumsum((epsr).^0.5)*ds;beta0 = 2*pi*fs/(300e6);

    theory = sin(2*pi*fs*(Niter+4)*dt-beta0*phase)./(epsr.^0.25); input('press enter to show WKB theory'); plot(x,theory,'b.'); theory = sin(2*pi*fs*(Niter+4)*dt-beta0*phase).*(epsr.^0.25); plot(x,theory,'r.'); title('E (blue), 377*H (red), WKB theory (points)');end