在FDTD计算时出现反射是,应怎样调试程序: 在用UPML吸收边界条件,出现了反射应怎样调试程序?一般的方法是什么?
学习ing!!!
从简单的复杂,先检查FDTD程序有没有问题,可以选用简单的Mur吸收条件,调试程序;FDTD程序经调试正确后,吸收边界条件改为UPML边界,此时出问题自然是UPML处了,使用debug逐步调试,结合场分布分析检测出错位置。
非常感谢版主的指导,我会逐步调试的
江海客 发表于 2012-11-28 12:33
非常感谢版主的指导,我会逐步调试的
不客气,有问题欢迎在此版区讨论!
在学习用UPML作为吸收边界条件计算时,在微网上下了一段经典的程序(3D的UPML程序),此程序上是(绝缘介质——UPML的情况),我将程序改写成了导电介质——UPML的情况后,发现程序的迭代出现了问题。在调试的时候我将电导率(sigma取0),理论上应该和经典程序上的一样,但实际的程序上是无法迭代的
我将我改写的程序一并传上
三维UPML的FDTD公式:导电介质——UPML情形
我觉得是程序中电场的迭代下面的迭代出现了问题:
ex(:,2:je_tot,2:ke_tot)=C3ex(:,2:je_tot,2:ke_tot).*ex(:,2:je_tot,2:ke_tot)+...
C41ex(:,2:je_tot,2:ke_tot).*(C5ex(:,2:je_tot,2:ke_tot).*px(:,2:je_tot,2:ke_tot)-...
C6ex(:,2:je_tot,2:ke_tot).*pstore(:,2:je_tot,2:ke_tot));
但这个和葛老师书上的公式一致,我就不知道该如何处理这个问题
tingo 发表于 2012-12-4 22:09
不客气,有问题欢迎在此版区讨论!
在学习用UPML作为吸收边界条件计算时,在微网上下了一段经典的程序(3D的UPML程序),此程序上是(绝缘介质——UPML的情况),我将程序改写成了导电介质——UPML的情况后,发现程序的迭代出现了问题。在调试的时候我将电导率(sigma取0),理论上应该和经典程序上的一样,但实际的程序上是无法迭代的
tingo 发表于 2012-12-4 22:09
不客气,有问题欢迎在此版区讨论!
我将我改写的程序一并传上
tingo 发表于 2012-12-4 22:09
不客气,有问题欢迎在此版区讨论!
三维UPML的FDTD公式:导电介质——UPML情形
tingo 发表于 2012-12-4 22:09
不客气,有问题欢迎在此版区讨论!
- %--------------------------------------------------
- clear;
- clc;
- close all;
- %------------------------------------------------
- % Fundamental constants
- %-----------------------------------------------
- cc=3.0e8; %(cc 光波的传播速度)
- muz=4.0*pi*1.0e-7; %(muz 真空磁导率)
- epsz=1.0/(cc*cc*muz); %(真空介电常数)
- etaz=sqrt(muz/epsz);
- %----------------------------------------------
- % Material parameters
- %-----------------------------------------------
- mur(1)=1.0;
- epsr(1)=1.0;
- eta=etaz*sqrt(mur(1)/epsr(1));
- %-------------------------------------------------
- % Grid parameters
- %-------------------------------------------------
- ie=137; % x 方向的网格
- je=80; % y 方向的网格
- ke=20; % z 方向的网格
- ih=ie+1; % x 方向的边数(节点)
- jh=je+1;
- kh=ke+1;
- upml=10; % UPML层的厚度
- ih_bc=upml+1;
- jh_bc=upml+1;
- kh_bc=upml+1;
- ie_tot=ie+2*upml; % 总计算区域网格的数目
- je_tot=je+2*upml;
- ke_tot=ke+2*upml;
- ih_tot=ie_tot+1;
- jh_tot=je_tot+1;
- kh_tot=ke_tot+1;
- is=round(ie_tot/2);
- js=round(je_tot/2);
- ks=round(ke_tot/2);
-
- %---------------------------------------------
- % Fundamental grid parameters
- %----------------------------------------------
- delta=0.01;
- % dt=delta*sqrt(epsr*mur)/(2.0*cc);
- dt=delta/(2.0*cc);
- nmax=50;
- %-----------------------------------------------
- % Wave excitation
- %-----------------------------------------------
- rtau=50.0e-12;
- tau=rtau/dt;
- ndelay=3*tau;
- J0=-1.0*epsz.*10^20;
- %-----------------------------------------------
- % Initialize field arrays
- %------------------------------------------------
- ex=zeros(ie_tot, jh_tot, kh_tot); % the field in main grid
- ey=zeros(ih_tot, je_tot, kh_tot);
- ez=zeros(ih_tot, jh_tot, ke_tot);
- dx=zeros(ie_tot, jh_tot, kh_tot); % 绝缘介质——UPML中的中间变量D
- dy=zeros(ih_tot, je_tot, kh_tot);
- dz=zeros(ih_tot, jh_tot, ke_tot);
- px=zeros(ie_tot, jh_tot, kh_tot); % 导电介质——UPML中的中间变量P'和P,其中p'用表示 (这里是我加上去的)
- py=zeros(ih_tot, je_tot, kh_tot);
- pz=zeros(ih_tot, jh_tot, ke_tot);
- qx=zeros(ie_tot, jh_tot, kh_tot);
- qy=zeros(ih_tot, je_tot, kh_tot);
- qz=zeros(ih_tot, jh_tot, ke_tot);
- hx=zeros(ih_tot, je_tot, ke_tot); % to magnetic field
- hy=zeros(ie_tot, jh_tot, ke_tot);
- hz=zeros(ie_tot, je_tot, kh_tot);
- bx=zeros(ih_tot, je_tot, ke_tot);
- by=zeros(ie_tot, jh_tot, ke_tot);
- bz=zeros(ie_tot, je_tot, kh_tot);
- %------------------------------------------------
- % Initialize update coefficient arays
- %--------------------------------------------------
- C1ex=zeros(size(ex));
- C2ex=zeros(size(ex));
- C21ex=zeros(size(ex)); % 这是导电介质——UPML中的迭代系数(葛德彪老师书上P105页的迭代公式(4-9-16)中的系数)
- C3ex=zeros(size(ex));
- C4ex=zeros(size(ex));
- C41ex=zeros(size(ex)); % 这是导电介质——UPML中的迭代系数 (葛德彪老师书上P105页的迭代公式(4-9-16)中的系数)
- C5ex=zeros(size(ex));
- C6ex=zeros(size(ex));
- C7ex=zeros(size(ex)); % 这是导电介质——UPML中的迭代系数 (葛德彪老师书上P105页的迭代公式(4-9-13)中的系数)
- C8ex=zeros(size(ex));
- C1ey=zeros(size(ey));
- C2ey=zeros(size(ey));
- C21ey=zeros(size(ey));
- C3ey=zeros(size(ey));
- C4ey=zeros(size(ey));
- C41ey=zeros(size(ey));
- C5ey=zeros(size(ey));
- C6ey=zeros(size(ey));
- C7ey=zeros(size(ey));
- C8ey=zeros(size(ey));
- C1ez=zeros(size(ez));
- C2ez=zeros(size(ez));
- C21ez=zeros(size(ez));
- C3ez=zeros(size(ez));
- C4ez=zeros(size(ez));
- C41ez=zeros(size(ez));
- C5ez=zeros(size(ez));
- C6ez=zeros(size(ez));
- C7ez=zeros(size(ez));
- C8ez=zeros(size(ez));
- D1hx=zeros(size(hx));
- D2hx=zeros(size(hx));
- D3hx=zeros(size(hx));
- D4hx=zeros(size(hx));
- D5hx=zeros(size(hx));
- D6hx=zeros(size(hx));
- D1hy=zeros(size(hy));
- D2hy=zeros(size(hy));
- D3hy=zeros(size(hy));
- D4hy=zeros(size(hy));
- D5hy=zeros(size(hy));
- D6hy=zeros(size(hy));
- D1hz=zeros(size(hz));
- D2hz=zeros(size(hz));
- D3hz=zeros(size(hz));
- D4hz=zeros(size(hz));
- D5hz=zeros(size(hz));
- D6hz=zeros(size(hz));
- %--------------------------------------------------------
- % Update coefficients,as described in section 7.8.2 (have some questions)
- %--------------------------------------------------------
- C1=1.0;
- C2=dt;
- C21=1.0;
- C3=1.0;
- C4=1.0/2.0/epsr(1)/epsr(1)/epsz/epsz;
- C41=1.0/2.0/epsr(1)/epsz;
- C5=2.0*epsr(1)*epsz;
- C6=2.0*epsr(1)*epsz;
- C7=1.0;
- C8=dt/epsr(1)/epsz;
- D1=1.0;
- D2=dt;
- D3=1.0;
- D4=1.0/2.0/epsr(1)/epsz/mur(1)/muz;
- D5=2.0*epsr(1)*epsz;
- D6=2.0*epsr(1)*epsz;
- %-------------------------------------------------------
- % Initialize main grid update coefficients (considering the basic cell)
- %-------------------------------------------------------
- C1ex(:, jh_bc:jh_tot-upml, :)=C1;
- C2ex(:, jh_bc:jh_tot-upml, :)=C2;
- C21ex(:, jh_bc:jh_tot-upml, :)=C21;
- C3ex(:, :, kh_bc:kh_tot-upml)=C3;
- C4ex(:, :, kh_bc:kh_tot-upml)=C4;
- C41ex(:, :, kh_bc:kh_tot-upml)=C41;
- C5ex(ih_bc:ie_tot-upml, :, :)=C5;
- C6ex(ih_bc:ie_tot-upml, :, :)=C6;
- C7ex(1:ie_tot,1:jh_tot,1:kh_tot)=C7;
- C8ex(1:ie_tot,1:jh_tot,1:kh_tot)=C8;
- C1ey(:, :, kh_bc:kh_tot-upml)=C1;
- C2ey(:, :, kh_bc:kh_tot-upml)=C2;
- C21ey(:, :, kh_bc:kh_tot-upml)=C21;
- C3ey(ih_bc:ih_tot-upml, :, :)=C3;
- C4ey(ih_bc:ih_tot-upml, :, :)=C4;
- C41ey(ih_bc:ih_tot-upml, :, :)=C41;
- C5ey(:, jh_bc:je_tot-upml, :)=C5;
- C6ey(:, jh_bc:je_tot-upml, :)=C6;
- C7ey(1:ih_tot,1:je_tot,1:kh_tot)=C7;
- C8ey(1:ih_tot,1:je_tot,1:kh_tot)=C8;
- C1ez(ih_bc:ih_tot-upml, :, :)=C1;
- C2ez(ih_bc:ih_tot-upml, :, :)=C2;
- C21ez(ih_bc:ih_tot-upml, :, :)=C21;
- C3ez(:, jh_bc:jh_tot-upml, :)=C3;
- C4ez(:, jh_bc:jh_tot-upml, :)=C4;
- C41ez(:, jh_bc:jh_tot-upml, :)=C41;
- C5ez(:, :, kh_bc:ke_tot-upml)=C5;
- C6ez(:, :, kh_bc:ke_tot-upml)=C6;
- C7ez(1:ih_tot,1:jh_tot,1:ke_tot)=C7;
- C8ez(1:ih_tot,1:jh_tot,1:ke_tot)=C8;
- D1hx(:, jh_bc:je_tot-upml, :)=D1;
- D2hx(:, jh_bc:je_tot-upml, :)=D2;
- D3hx(:, :, kh_bc:ke_tot-upml)=D3;
- D4hx(:, :, kh_bc:ke_tot-upml)=D4;
- D5hx(ih_bc:ih_tot-upml, :, :)=D5;
- D6hx(ih_bc:ih_tot-upml, :, :)=D6;
- D1hy(:, :, kh_bc:ke_tot-upml)=D1;
- D2hy(:, :, kh_bc:ke_tot-upml)=D2;
- D3hy(ih_bc:ie_tot-upml, :, :)=D3;
- D4hy(ih_bc:ie_tot-upml, :, :)=D4;
- D5hy(:, jh_bc:jh_tot-upml, :)=D5;
- D6hy(:, jh_bc:jh_tot-upml, :)=D6;
- D1hz(ih_bc:ie_tot-upml, :, :)=D1;
- D2hz(ih_bc:ie_tot-upml, :, :)=D2;
- D3hz(:, jh_bc:je_tot-upml, :)=D3;
- D4hz(:, jh_bc:je_tot-upml, :)=D4;
- D5hz(:, :, kh_bc:kh_tot-upml)=D5;
- D6hz(:, :, kh_bc:kh_tot-upml)=D6;
- %--------------------------------------------
- % Fill in PML regions
- %---------------------------------------------
- rmax=exp(-16);
- orderbc=4;
- % x-varying material properties
- delbc=upml*delta;
- % sigmam=-log(rmax)*(orderbc+1.0)/(2.0*eta*delbc);
- sigmam=-log(rmax)*epsr*epsz*cc*(orderbc+1.0)/(2.0*delbc);
- sigfactor=sigmam/(delta*(delbc^orderbc)*(orderbc+1.0));
- kmax=1;
- kfactor=(kmax-1.0)/delta/(orderbc+1.0)/delbc^orderbc;
- for i=1:upml
- % Coefficients for field components in the center of the grid cell
- x1=(upml-i+1)*delta;
- x2=(upml-i)*delta;
- sigma=sigfactor*(x1^(orderbc+1)-x2^(orderbc+1));
- ki=1+kfactor*(x1^(orderbc+1)-x2^(orderbc+1));
- facm=(2*epsr(1)*epsz*ki-sigma*dt);
- facp=(2*epsr(1)*epsz*ki+sigma*dt);
-
- C5ex(i, :, :)=facp;
- C5ex(ie_tot-i+1, :, :)=facp;
- C6ex(i, :, :)=facm;
- C6ex(ie_tot-i+1, :, :)=facm;
- D1hz(i, :, :)=facm/facp;
- D1hz(ie_tot-i+1, :, :)=facm/facp;
- D2hz(i, :, :)=2.0*epsr(1)*epsz*dt/facp;
- D2hz(ie_tot-i+1, :, :)=2.0*epsr(1)*epsz*dt/facp;
- D3hy(i, :, :)=facm/facp;
- D3hy(ie_tot-i+1, :, :)=facm/facp;
- D4hy(i, :, :)=1.0/facp/mur(1)/muz;
- D4hy(ie_tot-i+1, :, :)=1.0/facp/mur(1)/muz;
-
- % Coefficients for field components on the grid cell boundary
- x1=(upml-i+1.5)*delta;
- x2=(upml-i+0.5)*delta;
- sigma=sigfactor*(x1^(orderbc+1)-x2^(orderbc+1));
- ki=1+kfactor*(x1^(orderbc+1)-x2^(orderbc+1));
- facm=(2.0*epsr(1)*epsz*ki-sigma*dt);
- facp=(2.0*epsr(1)*epsz*ki+sigma*dt);
-
- C1ez(i,:,:)=facm/facp;
- C1ez(ih_tot-i+1,:,:)=facm/facp;
- C2ez(i,:,:)=2.0*epsr(1)*epsz*dt/facp;
- C2ez(ih_tot-i+1,:,:)=2.0*epsr(1)*epsz*dt/facp;
- C21ez(i,:,:)=2.0*epsr(1)*epsz/facp;
- C21ez(ih_tot-i+1,:,:)=2.0*epsr(1)*epsz/facp;
- C3ey(i,:,:)=facm/facp;
- C3ey(ih_tot-i+1,:,:)=facm/facp;
- C4ey(i,:,:)=1.0/facp/epsr(1)/epsz;
- C4ey(ih_tot-i+1,:,:)=1.0/facp/epsr(1)/epsz;
- C41ey(i,:,:)=1.0/facp;
- C41ey(ih_tot-i+1,:,:)=1.0/facp;
- D5hx(i,:,:)=facp;
- D5hx(ih_tot-i+1,:,:)=facp;
- D6hx(i,:,:)=facm;
- D6hx(ih_tot-i+1,:,:)=facm;
- end
- % PEC walls
- C1ez(1,:,:)=-1.0;
- C1ez(ih_tot,:,:)=-1.0;
- C2ez(1,:,:)=0.0;
- C2ez(ih_tot,:,:)=0.0;
- C21ez(1,:,:)=0.0;
- C21ez(ih_tot,:,:)=0.0;
- C3ey(1,:,:)=-1.0;
- C3ey(ih_tot,:,:)=-1.0;
- C4ey(1,:,:)=0.0;
- C4ey(ih_tot,:,:)=0.0;
- C41ey(1,:,:)=0.0;
- C41ey(ih_tot,:,:)=0.0;
- % y-varying material properties
- delbc=upml*delta;
- sigmam=-log(rmax)*epsr*epsz*cc*(orderbc+1.0)/(2.0*delbc); %(some questions)
- sigfactor=sigmam/(delta*(delbc^orderbc)*(orderbc+1.0));
- kmax=1.0;
- kfactor=(kmax-1.0)/delta/(orderbc+1.0)/delbc^orderbc;
- for j=1:upml
- % Coefficients for field componments in the center of the grid cell
- y1=(upml-j+1)*delta;
- y2=(upml-j)*delta;
- sigma=sigfactor*(y1^(orderbc+1)-y2^(orderbc+1));
- ki=1+kfactor*(y1^(orderbc+1)-y2^(orderbc+1));
- facm=2*epsr(1)*epsz*ki-sigma*dt;
- facp=2*epsr(1)*epsz*ki+sigma*dt;
-
- C5ey(:,j,:)=facp;
- C5ey(:,je_tot-j+1,:)=facp;
- C6ey(:,j,:)=facm;
- C6ey(:,je_tot-j+1,:)=facm;
- D1hx(:,j,:)=facm/facp;
- D1hx(:,je_tot-j+1,:)=facm/facp;
- D2hx(:,j,:)=2*epsr(1)*epsz*dt/facp;
- D2hx(:,je_tot-j+1,:)=2*epsr(1)*epsz*dt/facp;
- D3hz(:,j,:)=facm/facp;
- D3hz(:,je_tot-j+1,:)=facm/facp;
- D4hz(:,j,:)=1/facp/mur(1)/muz;
- D4hz(:,je_tot-j+1,:)=1/facp/mur(1)/muz;
-
- % Coefficients for field components on the grid cell boundary
- y1=(upml-j+1.5)*delta;
- y2=(upml-j+0.5)*delta;
- sigma=sigfactor*(y1^(orderbc+1)-y2^(orderbc+1));
- ki=1+kfactor*(y1^(orderbc+1)-y2^(orderbc+1));
- facm=(2*epsr(1)*epsz*ki-sigma*dt);
- facp=(2*epsr(1)*epsz*ki+sigma*dt);
-
- C1ex(:,j,:)=facm/facp;
- C1ex(:,jh_tot-j+1,:)=facm/facp;
- C2ex(:,j,:)=2*epsr(1)*epsz*dt/facp;
- C2ex(:,jh_tot-j+1,:)=2*epsr(1)*epsz*dt/facp;
- C21ex(:,j,:)=2*epsr(1)*epsz/facp;
- C21ex(:,jh_tot-j+1,:)=2*epsr(1)*epsz/facp;
- C3ez(:,j,:)=facm/facp;
- C3ez(:,jh_tot-j+1,:)=facm/facp;
- C4ez(:,j,:)=1/facp/epsr(1)/epsz;
- C4ez(:,jh_tot-j+1,:)=1/facp/epsr(1)/epsz;
- C41ez(:,j,:)=1/facp;
- C41ez(:,jh_tot-j+1,:)=1/facp;
- D5hy(:,j,:)=facp;
- D5hy(:,jh_tot-j+1,:)=facp;
- D6hy(:,j,:)=facm;
- D6hy(:,jh_tot-j+1,:)=facm;
- end
- % PEC walls
- C1ex(:,1,:)=-1;
- C1ex(:,jh_tot,:)=-1;
- C2ex(:,1,:)=0;
- C2ex(:,jh_tot,:)=0;
- C21ex(:,1,:)=0;
- C21ex(:,jh_tot,:)=0;
- C3ez(:,1,:)=-1;
- C3ez(:,jh_tot,:)=-1;
- C4ez(:,1,:)=0;
- C4ez(:,jh_tot,:)=0;
- C41ez(:,1,:)=0;
- C41ez(:,jh_tot,:)=0;
- % z-varying material properties
- delbc=upml*delta;
- sigmam=-log(rmax)*epsr(1)*epsz*cc*(orderbc+1.0)/(2.0*delbc); %(some questions)
- sigfactor=sigmam/(delta*(delbc^orderbc)*(orderbc+1.0));
- kmax=1.0;
- kfactor=(kmax-1.0)/delta/(orderbc+1.0)/delbc^orderbc;
-
- for k=1:upml
-
- % Coefficients for field components in the center of the grid cell
- z1=(upml-k+1)*delta;
- z2=(upml-k)*delta;
- sigma=sigfactor*(z1^(orderbc+1)-z2^(orderbc+1));
- ki=1+kfactor*(z1^(orderbc+1)-z2^(orderbc+1));
- facm=2*epsr(1)*epsz*ki-sigma*dt;
- facp=2*epsr(1)*epsz*ki+sigma*dt;
- C5ez(:,:,k)=facp;
- C5ez(:,:,ke_tot-k+1)=facp;
- C6ez(:,:,k)=facm;
- C6ez(:,:,ke_tot-k+1)=facm;
- D1hy(:,:,k)=facm/facp;
- D1hy(:,:,ke_tot-k+1)=facm/facp;
- D2hy(:,:,k)=2*epsr(1)*epsz*dt/facp;
- D2hy(:,:,ke_tot-k+1)=2*epsr(1)*epsz*dt/facp;
- D3hx(:,:,k)=facm/facp;
- D3hx(:,:,ke_tot-k+1)=facm/facp;
- D4hx(:,:,k)=1/facp/mur(1)/muz;
- D4hx(:,:,ke_tot-k+1)=1/facp/mur(1)/muz;
-
- % Coefficients for field components on the grid cell boundary
- z1=(upml-k+1.5)*delta;
- z2=(upml-k+0.5)*delta;
- sigma=sigfactor*(z1^(orderbc+1)-z2^(orderbc+1));
- ki=1+kfactor*(z1^(orderbc+1)-z2^(orderbc+1));
- facm=2*epsr(1)*epsz*ki-sigma*dt;
- facp=2*epsr(1)*epsz*ki+sigma*dt;
- C1ey(:,:,k)=facm/facp;
- C1ey(:,:,kh_tot-k+1)=facm/facp;
- C2ey(:,:,k)=2*epsr(1)*epsz*dt/facp;
- C2ey(:,:,kh_tot-k+1)=2*epsr(1)*epsz*dt/facp;
- C21ey(:,:,k)=2*epsr(1)*epsz/facp;
- C21ey(:,:,kh_tot-k+1)=2*epsr(1)*epsz/facp;
- C3ex(:,:,k)=facm/facp;
- C3ex(:,:,kh_tot-k+1)=facm/facp;
- C4ex(:,:,k)=1/facp/epsr(1)/epsz;
- C4ex(:,:,kh_tot-k+1)=1/facp/epsr(1)/epsz;
- C41ex(:,:,k)=1/facp;
- C41ex(:,:,kh_tot-k+1)=1/facp;
- D5hz(:,:,k)=facp;
- D5hz(:,:,kh_tot-k+1)=facp;
- D6hz(:,:,k)=facm;
- D6hz(:,:,kh_tot-k+1)=facm;
- end
- % PEC walls
- C1ey(:,:,1)=-1;
- C1ey(:,:,kh_tot)=-1;
- C2ey(:,:,1)=0;
- C2ey(:,:,kh_tot)=0;
- C21ey(:,:,1)=0;
- C21ey(:,:,kh_tot)=0;
- C3ex(:,:,1)=-1;
- C3ex(:,:,kh_tot)=-1;
- C4ex(:,:,1)=0;
- C4ex(:,:,kh_tot)=0;
- C41ex(:,:,1)=0;
- C41ex(:,:,kh_tot)=0;
- % figure
- % set(gcf,'Double Buffer','on')
- %--------------------------------------------------------
- % Begin time stepping loop
- %--------------------------------------------------------
- for n=1:nmax
- % Update magnetic field
-
- bstore=bx;
- bx(2:ie_tot,:,:)=D1hx(2:ie_tot,:,:).*bx(2:ie_tot,:,:)-...
- D2hx(2:ie_tot,:,:).*((ez(2:ie_tot,2:jh_tot,:)-ez(2:ie_tot,1:je_tot,:))-...
- (ey(2:ie_tot,:,2:kh_tot)-ey(2:ie_tot,:,1:ke_tot)))./delta;
- hx(2:ie_tot,:,:)= D3hx(2:ie_tot,:,:).*hx(2:ie_tot,:,:)+...
- D4hx(2:ie_tot,:,:).*(D5hx(2:ie_tot,:,:).*bx(2:ie_tot,:,:)-...
- D6hx(2:ie_tot,:,:).*bstore(2:ie_tot,:,:));
- bstore=by;
- by(:,2:je_tot,:)=D1hy(:,2:je_tot,:).*by(:,2:je_tot,:)-...
- D2hy(:,2:je_tot,:).*((ex(:,2:je_tot,2:kh_tot)-ex(:,2:je_tot,1:ke_tot))-...
- (ez(2:ih_tot,2:je_tot,:)-ez(1:ie_tot,2:je_tot,:)))./delta;
- hy(:,2:je_tot,:)= D3hy(:,2:je_tot,:).*hy(:,2:je_tot,:)+...
- D4hy(:,2:je_tot,:).*(D5hy(:,2:je_tot,:).*by(:,2:je_tot,:)-...
- D6hy(:,2:je_tot,:).*bstore(:,2:je_tot,:));
- bstore=bz;
- bz(:,:,2:ke_tot)=D1hz(:,:,2:ke_tot).*bz(:,:,2:ke_tot)-...
- D2hz(:,:,2:ke_tot).*((ey(2:ih_tot,:,2:ke_tot)-ey(1:ie_tot,:,2:ke_tot))-...
- (ex(:,2:jh_tot,2:ke_tot)-ex(:,1:je_tot,2:ke_tot)))./delta;
- hz(:,:,2:ke_tot)= D3hz(:,:,2:ke_tot).*hz(:,:,2:ke_tot)+...
- D4hz(:,:,2:ke_tot).*(D5hz(:,:,2:ke_tot).*bz(:,:,2:ke_tot)-...
- D6hz(:,:,2:ke_tot).*bstore(:,:,2:ke_tot));
-
- % Update electric field
- % dstore=dx;
- % dx(:,2:je_tot,2:ke_tot)=C1ex(:,2:je_tot,2:ke_tot).*dx(:,2:je_tot,2:ke_tot)+...
- % C2ex(:,2:je_tot,2:ke_tot).*((hz(:,2:je_tot,2:ke_tot)-hz(:,1:je_tot-1,2:ke_tot))-...
- % (hy(:,2:je_tot,2:ke_tot)-hy(:,2:je_tot,1:ke_tot-1)))./delta;
- % dx(is:is+1,js,ks)=dx(is:is+1,js,ks)+J0*(n-ndelay)*exp(-((n-ndelay)^2/tau^2));
- %
- % ex(:,2:je_tot,2:ke_tot)=C3ex(:,2:je_tot,2:ke_tot).*ex(:,2:je_tot,2:ke_tot)+...
- % C4ex(:,2:je_tot,2:ke_tot).*(C5ex(:,2:je_tot,2:ke_tot).*dx(:,2:je_tot,2:ke_tot)-...
- % C6ex(:,2:je_tot,2:ke_tot).*dstore(:,2:je_tot,2:ke_tot));
- qstore=qx;
- qx(:,2:je_tot,2:ke_tot)=C7ex(:,2:je_tot,2:ke_tot).*qx(:,2:je_tot,2:ke_tot)+...
- C8ex(:,2:je_tot,2:ke_tot).*((hz(:,2:je_tot,2:ke_tot)-hz(:,1:je_tot-1,2:ke_tot))-...
- (hy(:,2:je_tot,2:ke_tot)-hy(:,2:je_tot,1:ke_tot-1)))./delta;
-
- px(:,2:je_tot,2:ke_tot)=C1ex(:,2:je_tot,2:ke_tot).*px(:,2:je_tot,2:ke_tot)+...
- C21ex(:,2:je_tot,2:ke_tot).*(qx(:,2:je_tot,2:ke_tot)-qstore(:,2:je_tot,2:ke_tot));
- pstore=px;
- ex(is:is+1,js,ks)=ex(is:is+1,js,ks)+J0.*(n-ndelay)*exp(-((n-ndelay)^2/tau^2));
-
- ex(:,2:je_tot,2:ke_tot)=C3ex(:,2:je_tot,2:ke_tot).*ex(:,2:je_tot,2:ke_tot)+...
- C41ex(:,2:je_tot,2:ke_tot).*(C5ex(:,2:je_tot,2:ke_tot).*px(:,2:je_tot,2:ke_tot)-...
- C6ex(:,2:je_tot,2:ke_tot).*pstore(:,2:je_tot,2:ke_tot));
- % dstore=dy;
- % dy(2:ie_tot,:,2:ke_tot)=C1ey(2:ie_tot,:,2:ke_tot).*dy(2:ie_tot,:,2:ke_tot)+...
- % C2ey(2:ie_tot,:,2:ke_tot).*((hx(2:ie_tot,:,2:ke_tot)-hx(2:ie_tot,:,1:ke_tot-1))-...
- % (hz(2:ie_tot,:,2:ke_tot)-hz(1:ie_tot-1,:,2:ke_tot)))./delta;
- % % dy(is,js:js+1,ks)=dz(is,js:js+1,ks)+J0*(n-ndelay)*exp(-((n-ndelay)^2/tau^2));
- % ey(2:ie_tot,:,2:ke_tot)=C3ey(2:ie_tot,:,2:ke_tot).*ey(2:ie_tot,:,2:ke_tot)+...
- % C4ey(2:ie_tot,:,2:ke_tot).*(C5ey(2:ie_tot,:,2:ke_tot).*dy(2:ie_tot,:,2:ke_tot)-...
- % C6ey(2:ie_tot,:,2:ke_tot).*dstore(2:ie_tot,:,2:ke_tot));
-
- % qstore=qy;
- % qy(2:ie_tot,:,2:ke_tot)=C7ey(2:ie_tot,:,2:ke_tot).*qy(2:ie_tot,:,2:ke_tot)+...
- % C8ey(2:ie_tot,:,2:ke_tot).*((hx(2:ie_tot,:,2:ke_tot)-hx(2:ie_tot,:,1:ke_tot-1))-...
- % (hz(2:ie_tot,:,2:ke_tot)-hz(1:ie_tot-1,:,2:ke_tot)))./delta;
- %
- % py(2:ie_tot,:,2:ke_tot)=C1ey(2:ie_tot,:,2:ke_tot).*py(2:ie_tot,:,2:ke_tot)+...
- % C21ey(2:ie_tot,:,2:ke_tot).*(qy(2:ie_tot,:,2:ke_tot)-qstore(2:ie_tot,:,2:ke_tot));
- %
- % pstore=py;
- % ey(2:ie_tot,:,2:ke_tot)=C3ey(2:ie_tot,:,2:ke_tot).*ey(2:ie_tot,:,2:ke_tot)+...
- % C41ey(2:ie_tot,:,2:ke_tot).*(C5ey(2:ie_tot,:,2:ke_tot).*py(2:ie_tot,:,2:ke_tot)-...
- % C6ey(2:ie_tot,:,2:ke_tot).*pstore(2:ie_tot,:,2:ke_tot));
- %
- % dstore=dz;
- % dz(2:ie_tot,2:je_tot,:)=C1ez(2:ie_tot,2:je_tot,:).*dz(2:ie_tot,2:je_tot,:)+...
- % C2ez(2:ie_tot,2:je_tot,:).*((hy(2:ie_tot,2:je_tot,:)-hy(1:ie_tot-1,2:je_tot,:))-...
- % (hx(2:ie_tot,2:je_tot,:)-hx(2:ie_tot,1:je_tot-1,:)))./delta;
- % % dz(is,js,ks:ks+1)=dz(is,js,ks:ks+1)+J0*(n-ndelay)*exp(-((n-ndelay)^2/tau^2));
- % ez(2:ie_tot,2:je_tot,:)=C3ez(2:ie_tot,2:je_tot,:).*ez(2:ie_tot,2:je_tot,:)+...
- % C4ez(2:ie_tot,2:je_tot,:).*(C5ez(2:ie_tot,2:je_tot,:).*dz(2:ie_tot,2:je_tot,:)-...
- % C6ez(2:ie_tot,2:je_tot,:).*dstore(2:ie_tot,2:je_tot,:));
-
- % qstore=qz;
- % qz(2:ie_tot,2:je_tot,:)=C7ez(2:ie_tot,2:je_tot,:).*qz(2:ie_tot,2:je_tot,:)+...
- % C8ez(2:ie_tot,2:je_tot,:).*((hy(2:ie_tot,2:je_tot,:)-hy(1:ie_tot-1,2:je_tot,:))-...
- % (hx(2:ie_tot,2:je_tot,:)-hx(2:ie_tot,1:je_tot-1,:)))./delta;
- % pz(2:ie_tot,2:je_tot,:)=C1ez(2:ie_tot,2:je_tot,:).*pz(2:ie_tot,2:je_tot,:)+...
- % C21ez(2:ie_tot,2:je_tot,:).*(qz(2:ie_tot,2:je_tot,:)-qstore(2:ie_tot,2:je_tot,:));
- %
- % pz(is,js,ks:ks+1)=pz(is,js,ks:ks+1)+J0*(n-ndelay)*exp(-((n-ndelay)^2/tau^2));
- % % c(n)=J0*(n-ndelay)*exp(-((n-ndelay)^2/tau^2));
- % pstore=pz;
- % % pz(is,js,ks:ks+1)=source(n);
- % ez(2:ie_tot,2:je_tot,:)=C3ez(2:ie_tot,2:je_tot,:).*ez(2:ie_tot,2:je_tot,:)+...
- % C41ez(2:ie_tot,2:je_tot,:).*(C5ez(2:ie_tot,2:je_tot,:).*pz(2:ie_tot,2:je_tot,:)-...
- % C6ez(2:ie_tot,2:je_tot,:).*pstore(2:ie_tot,2:je_tot,:));
- %***********************************************************************
- % Visualize fields
- %***********************************************************************
- timestep=int2str(n);
- % tview(:,:)=squeeze(ex(ih_bc:upml+ie,jh_bc:upml+je,ks));
- % sview(:,:)=squeeze(ex(ih_bc:upml+ie,js,kh_bc:upml+ke));
- tview(:,:)=squeeze(ex(is,jh_bc:upml+je,kh_bc:upml+ke));
- sview(:,:)=squeeze(ex(ih_bc:upml+ie,js,kh_bc:upml+ke));
- % tview(:,:)=squeeze(hz(ih_bc:upml+ie,jh_bc:upml+je,ks));
- % sview(:,:)=squeeze(hz(ih_bc:upml+ie,js,kh_bc:upml+ke));
- subplot('position',[0.15 0.57 0.7 0.35])
- %imagesc(tview');
- pcolor(tview');
- shading interp;
- caxis([-0.2 0.2]);
- colorbar;
- axis image; axis xy;
- title(['E_z(i,j,k=k_s_o_u_r_c_e), time step = ',timestep]);
- xlabel('i coordinate');
- ylabel('j coordinate');
-
- subplot('position',[0.15 0.08 0.7 0.35])
- %imagesc(tview');
- pcolor(tview');
- shading interp;
- caxis([-0.2 0.2]);
- colorbar;
- axis image; axis xy;
- title(['E_z(i,j=j_s_o_u_r_c_e,k), time step = ',timestep]);
- xlabel('i coordinate');
- ylabel('k coordinate');
- pause(0.05)
-
- end
复制代码
tingo 发表于 2012-12-4 22:09
不客气,有问题欢迎在此版区讨论!
我觉得是程序中电场的迭代下面的迭代出现了问题:
ex(:,2:je_tot,2:ke_tot)=C3ex(:,2:je_tot,2:ke_tot).*ex(:,2:je_tot,2:ke_tot)+...
C41ex(:,2:je_tot,2:ke_tot).*(C5ex(:,2:je_tot,2:ke_tot).*px(:,2:je_tot,2:ke_tot)-...
C6ex(:,2:je_tot,2:ke_tot).*pstore(:,2:je_tot,2:ke_tot));
但这个和葛老师书上的公式一致,我就不知道该如何处理这个问题
你参考这本书中的代码The Finite-Difference Time-Domain Method for Electromagntics with MATLAB Simulations
这本书现在有中文版了,名字叫MATLAB模拟的电磁学时域有限差分法。
英文电子版微网上好像有,你找找看。
这本书中对CPML讲的详细,你再看看,尽可能自己将程序调通,这是一个学习的过程。有原理不懂的可以贴出来,和大家探讨。