% lab5.m - Solving the Navier-Stokes equations in vorticity-stream function % formulation % % Equations: % % Vorticity-transport: % % omega_t + u omega_x + v omega_y = nu (omega_xx + omega_yy) % % Stream function: % % psi_xx+psi_yy = -omega % % Velocities in terms of stream function: % % u = psi_y v=-psi_x % % Boundary conditions: periodic in x and y % % % Problem: Decay of an initial random vorticity distribution % clear all; % Set up problem: % nu=1.0e-3; I=sqrt(-1); nx=32; ny=32; hx=2*pi/nx; hy=2*pi/ny; x=(0:nx-1)*hx; y=(0:ny-1)*hy; omega=zeros([nx ny]); omega_x=omega; omega_y=omega; del_omega=omega; omega_hat=omega; omega_x_hat=omega; omega_y_hat=omega; u=omega; v=omega; u_hat=omega; v_hat=omega; conv=omega; conv_hat=omega; psi_hat=omega; omega=random('unif',-1,1,nx,ny); t=0.; tfinal=10.0; dt=1.0e-3; % Form matrices of wavenumbers so we can use matrix operations kx=zeros([nx ny]); ky=zeros([nx ny]); kmod2=zeros([nx ny]); for l=1:nx for m=1:ny kx(l,m)=I*wavenumber(l,nx); ky(l,m)=I*wavenumber(m,ny); kmod2(l,m)=kx(l,m)^2+ky(l,m)^2; if (kx(l,m)>=2/3*nx) | (ky(l,m)>=2/3*ny) alias(l,m)=0; else alias(l,m)=1; end end end kmod2(1,1)=1; % Enter time loop while t