如何使用有限差分求解圆柱坐标中圆棒的波动方程?

计算科学 有限差分 电磁学 波传播
2021-12-01 19:57:39

我对柱坐标中波动方程的有限差分法的稳定性有疑问。

方程是:

2ωnr2+1rωnr+2ωnz2ωnr2=1c22ωnt2

当我在 Matlab 中运行它时,我得到以下结果:

图1

有谁知道问题出在哪里?

我把代码放在这里,如果有人知道问题出在哪里,请帮助我。

%domain
clear;
Lx=10;
Ly=10;
dx=0.1;
dy=dx;
nx=fix(Lx/dx);
ny=fix(Ly/dy);
x=linspace(0,Lx,nx);
y=linspace(0,Ly,ny);
%time
T=10;
%varables
wn=zeros(nx,ny);
wnm1=wn; %w at time n-1
wnp1=wn; %w at tome n+1
%parameters
CFL=0.5; %CFL=c.dt/dx
c=1;
dt=(CFL*dx/c);

%dt=1e-6;

%%initial conditions
%%time stepping loop
t=0;
while(t<T)
    %reflecting boundary conditions
    wn(:,[1 end])=0;
    wn([1 end],:)=0;


    %solution
    t=t+dt;
    wnm1=wn; wn=wnp1; %save current and previous arrays

    %sourse
    wn(50,50)=dt^2*20*sin(30*pi*t/20);
    for i=2:nx-1 for j=2:ny-1

           wnp1(i,j)=2*wn(i,j)-wnm1(i,j)...
               +CFL^2*(((wn(i+1,j)-2*wn(i,j)+wn(i-1,j))/dx^2+(1/(2*i*dx^2))*(wn(i+1,j)-wn(i-1,j))+(wn(i,j+1)-2*wn(i,j)+wn(i,j-1))/dy^2-wn(i,j)/(i*dx)^2));

        end,end
    %chek convergence

    %visualize at selected steps
    clf;
    subplot(2,1,1);
    imagesc(x,y,wn'); colorbar;caxis([-0.02 0.02])
    title(sprintf('t=%.2f',t));
    subplot(2,1,2);
    mesh(x,y,wn'); colorbar;caxis([-0.02 0.02])
    axis([0 Lx 0 Ly -0.05 0.05]);
    shg; pause(0.01);
end
0个回答
没有发现任何回复~