资源描述:
《一个二维的FDTD程序.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、一个二维的FDTD程序%本程序实现2维TM波FDTD仿真%此程序用PML设置吸收边界条件%FDTD_2D_kongqi_PML%仅含有Ez,Hx,Hy分量clear;clc;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1.初始化T=200;%迭代次数IE=100;%JE=100;npml=8;%PML的网格数量c0=3*10^8;%波速f=1.5*10^(9);%频率lambda=c0/f;%波长wl=10;dx=lambda/wl;dy=lambda/wl;pi=3.14159;dt=dx/(2*c0);%时间间
2、隔epsz=1/(4*pi*9*10^9);%真空介电常数epsilon=1;%相对介电常数sigma=0;%电导率spread=6;%脉冲宽度t0=20;%脉冲高度ic=IE/2;%源的X位置jc=JE/2;%源的Y位置fori=1E+1;forj=1:JE+1;dz(i,j)=0;%z方向电荷密度ez(i,j)=0;%z方向电场hx(i,j)=0;%x方向磁场hy(i,j)=0;%y方向磁场6ihx(i,j)=0;%ihy(i,j)=0;iz(i,j)=0;%z方向求和参量,频域卷积转化为时域求和end;end;fori=2E;%forj=2:JE;ga(i,j)
3、=1;end;end;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PML参数的设置fori=1E;gi2(i)=1;gi3(i)=1;fi1(i)=0;fi2(i)=1.0;fi3(i)=1.0;endforj=1:JE;gj2(j)=1;gj3(j)=1;fj1(j)=0;fj2(j)=1;fj3(j)=1;endfori=1:npml+1;%设置PML层中的参数xnum=npml+1-i;xn=0.33*(xnum/npml)^3;gi2(i)=1.0/(1+xn);g
4、i2(IE-1-i)=1/(1+xn);gi3(i)=(1-xn)/(1+xn);gi3(IE-1-i)=(1-xn)/(1+xn);xn=0.25*((xnum-0.5)/npml)^3;fi1(i)=xn;fi1(IE-2-i)=xn;fi2(i)=1.0/(1+xn);fi2(IE-2-i)=1/(1+xn);fi3(i)=(1-xn)/(1+xn);fi3(IE-2-i)=(1-xn)/(1+xn);end6fori=1:npml+1;xnum=npml+1-i;xn=0.33*(xnum/npml)^3;gj2(i)=1.0/(1+xn);gj2(JE-1-
5、i)=1/(1+xn);gj3(i)=(1-xn)/(1+xn);gj3(JE-1-i)=(1-xn)/(1+xn);xn=0.25*((xnum-0.5)/npml)^3;fj1(i)=xn;fj1(JE-2-i)=xn;fj2(i)=1.0/(1+xn);fj2(JE-2-i)=1/(1+xn);fj3(i)=(1-xn)/(1+xn);fj3(JE-2-i)=(1-xn)/(1+xn);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2.迭代求解电场和磁场fort
6、=1:T;fori=2E;%为了使每个电场周围都有磁场进行数组下标处理forj=2:JE;dz(i,j)=gi3(i)*gj3(j)*dz(i,j)+gi2(i)*gj2(j)*0.5*(hy(i,j)-hy(i-1,j)-hx(i,j)+hx(i,j-1));end;end;%电场循环结束pulse=sin(2*pi*f*t*dt);%正弦波源dz(ic,jc)=dz(ic,jc)+pulse;%软源fori=1E;%为了使每个电场周围都有磁场进行数组下标处理forj=1:JE;ez(i,j)=ga(i,j)*dz(i,j);%反映煤质的情况都是放到这里的%iz(i
7、,j)=iz(i,j)+gb(i,j)*ez(i,j);end;end;%电荷密度循环结束forj=1:JE;ez(1,j)=0;ez(IE,j)=0;endfori=1E;ez(i,1)=0;6ez(i,JE)=0;end;fori=1E;%为了使每个磁场周围都有电场进行数组下标处理forj=1:JE-1;curl_e=ez(i,j)-ez(i,j+1);ihx(i,j)=ihx(i,j)+fi1(i)*curl_e;hx(i,j)=fj3(j)*hx(i,j)+fj2(j)*0.5*(curl_e+ihx(i,j));end;end;%磁场HX循