Code optimization a (simple) advection difference scheme

Hi,

I’m beginner in Julia. I tried a simple code, but was a little bit disappointed with the performance. Could you give me hints in optimizing this snippet ?
Kind regards, Florian

2D advection equation, periodic boundary conditions, explicit scheme, NxN grid

using PyPlot

N = 800;
u = zeros(N, N);
h = 1.0 / N;
x = h/2 : h : 1-h/2;
y = x;
X = x*ones(1,N);
Y = ones(N,1)*y’;
LEFT = [N; 1:N];
RIGT = [1:N; 1];
TOPP = RIGT;
BOTT = LEFT;

u = 0 .+ ((X.-0.5).^2 + (Y.-0.5).^2 .< 0.125);

cfl = 0.49;
ax = 1.0;
ay = 1.0;
umax = max(ax,ay);
dt = cfl * h / umax;
figure(1);
clf();

for it = 0:1000
phix = 0.5*(axu[LEFT,:]+axu[RIGT,:]) - 0.5abs(ax)(u[RIGT,:] - u[LEFT,:]);
phiy = 0.5*(ayu[:,BOTT]+ayu[:,TOPP]) - 0.5abs(ay)(u[:,TOPP] - u[:,BOTT]);
global u;
u += - (dt/h) * (phix[2:N+1,:] - phix[1:N,:]);
u += - (dt/h) * (phiy[:,2:N+1] - phiy[:,1:N]);
if mod(it,100)==0
clf();
contour(u);
pause(0.1);
end
end

Welcome to the community! The first tip would be for you to study the performance tips in the manual. The very first point would help you quite a lot.

Thank you for the link !