Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
peter-gr said:A simple 1-D FDTD code in matlab with ABC is given below.
% 1-D FDTD code
KE=200 ;%KE is he number of cells to be used
ex=zeros(1,KE);
hy=zeros(1,KE);
ex_low_m1=0;
ex_low_m2=0;
ex_high_m1=0;
ex_high_m2=0;
kc=KE/2;
%Gaussian pulse
t0=40;
spread=12;
n=input('T=?');
for T=1:n
%Main FDTD Loop
%Ex field
for k=2:KE
ex(k)=ex(k) + 0.5*(hy(k-1)-hy(k));
end
%Gaussian pulse in the middle
pulse=exp(-0.5*((t0-T)^2/spread^2));
ex(kc)=pulse;
%Absorbing Boundary Conditions
ex(1)=ex_low_m2;
ex_low_m2=ex_low_m1;
ex_low_m1=ex(2);
ex(KE)=ex_high_m2;
ex_high_m2=ex_high_m1;
ex_high_m1=ex(KE-1);
%Hy field
for k=1:KE-1
hy(k)=hy(k)+ 0.5*(ex(k)-ex(k+1));
end
end
%End of FDTD Loop
plot(ex)
Absorbing Boundary ... So in one time step of the FDTD algorithm,it travels:
distance=c*dt=c*(dx/2c)=dx/2
The above equation explains that it takes two time steps for a wave to cross one cell.So a common sense approach tells as that a common boundary condition would be Ex(0)=Ex(n-2)(1)
It is relativeley easy to implement this.Store a value of Ex(1) for two time steps and then put it in Ex(0).