1D FDTD Solution For Mur
1D FDTD Solution For Mur
%
% Objective of the program is to solve for the Maxwell's equation for an
% x-directed z-polarized TEM wave containg the y-directed magnetic
% field Hy and z-directed electric field Ez. The fields are updated at every
% timestep, in a space, where all physical parameters of free space are
% not normalized to 1 (given real and known values), using standard update
% equations obtained from the difference form of Maxwell's curl equations
% with very low electric and magnetic conductivities of 4 x10^(-4) units
% incorporated in them. The field points are defined in a grid described
% by Yee's algorithm. The H fields are defined at every half coordinate of
% a spacestep and E field is defined at every coordinate point. Also,
% the time update is done using Leapfrog time-stepping. Here, the H fields
% are updated every half time-step and E fields are updated every full
% time-step. This is shown by two alternating vector updates spanning only
% a part of spatial grid where the wave, starting from source, has reached
% at that particular time instant avoiding field updates at all points in
% grid which is unnecessary at that time instant. These spatial updates are
% inside the main for-loop for time update, spanning the entire time grid.
% Also here, the space-step length is taken as 1 micron instead of 1 unit
% in unitless domain assumed in previous programs. Also, here, the vectors
% used as multiplication factors for update equations are initialized
% before the loop starts to avoid repeated calculation of the same in every
% loop iteration, a minor attempt at optimization. The boundary condition
% here is Mur's Absorbing Boundary Condition (ABC) where the fields at the
% grid points have electric field values formulated using Engquist Majda one
% way wave equations [1] where the boundaries give a sense of absorbing the
% total field incident on them and reflecting none back to the domain.
%
% A source of electric field is defined at the center of the spatial domain
% which is a hard source, in that it does not change its value due to
% interference from external fields i.e in other words, the source is a
% perfect electric conductor. The form of the source can be varied using
% the variables sine, gaussian and impulse. The source is available in four
% standard forms- Unit-time step, Impulse, Gausian and Sinusoidal forms.
% For the sinusoidal source, the user is allowed to give a frequency of
% his/her choice in Hz. The plot of Ez field v/s spacesteps is shown at
% every time step. The simulation can be ended by closing this plot
% window or by waiting till all the time step updates are completed.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Clearing variables in memory and Matlab command screen
clear all;
clc;
% Grid Dimension in x (xdim) direction
xdim=200;
%Total no of time steps
time_tot=350;
%Position of the source (center of the domain)
xsource=100;
%Courant stability factor
S=1;
% Parameters of free space (permittivity and permeability and speed of
% light) are all not 1 and are given real values
epsilon0=(1/(36*pi))*1e-9;
mu0=4*pi*1e-7;
c=3e+8;
% Spatial grid step length (spatial grid step = 1 micron)
delta=1e-6;
% Temporal gris step obtained using Courant condition
deltat=S*delta/c;
% Initialization of field vectors
Ez=zeros(1,xdim);
Hy=zeros(1,xdim);
% Initialization of permittivity and permeability vectors
epsilon=epsilon0*ones(1,xdim);
mu=mu0*ones(1,xdim);
% Initializing electric and magnetic field vectors
sigma=4e-4*ones(1,xdim);
sigma_star=4e-4*ones(1,xdim);
%Choice of natue of source
gaussian=0;
sine=0;
% The user can give a frequency of his choice for sinusoidal (if sine=1
above) waves in Hz
frequency=1.5e+13;
impulse=0;
%Choose any one as 1 and rest as 0. Default (when all are 0): Unit time step
%Multiplication factor vectors for H vector update to avoid being calculated
many times
%in the time update loop so as to increase computation speed
A=((mu-0.5*deltat*sigma_star)./(mu+0.5*deltat*sigma_star));
B=(deltat/delta)./(mu+0.5*deltat*sigma_star);
% Source conditions
if impulse==0
% If unit-time step
if gaussian==0 && sine==0
Ez(xsource)=1;
end
%if sine
if sine==1
tstart=1;
N_lambda=c/(frequency*delta);
Ez(xsource)=sin(((2*pi*(c/(delta*N_lambda))*(n-tstart)*deltat)));
end
%if gaussian
if gaussian==1
if n<=42
Ez(xsource)=(10-15*cos(n*pi/20)+6*cos(2*n*pi/20)-
cos(3*n*pi/20))/32;
end
end
else
%if impulse
Ez(xsource)=0;
end
plot((1:1:xdim)*delta,Ez,'color','k');
titlestring=['\fontsize{20}Plot of Ez vs x for 1D FDTD Mur Absorbing
Boundary Condition at time = ',num2str(round(n*deltat/10e-15)),' fs'];
title(titlestring,'color','k');
xlabel('x in m','FontSize',20);
ylabel('Ez in V/m','FontSize',20);
set(gca,'FontSize',20);
axis([0 xdim*delta -3 3]);
getframe;
end