Maybe I'll post the numerical schemes here, so one doesn't have to download the file.
The integration scheme (centered in time and space):
Code:
for j=2:jmax-1
for i=2:imax-1
% calculate the coriolis force at the same position, one step in the past (km):
coriolis = f(j)*v(i,j,km);
% calculate the horizontal pressure gradient
% (finite diff. centered in y space of the first derivative)::
horiz_pressure = -g_reduced*(h(i+1,j,k) - h(i-1,j,k))/d2x;
% Diffusion term: A_H * Laplace*U
% Laplace*U = (d^2 U / d x^2) + (d^2 U / d y^2)
% Centered finite difference of the second derivative
diffx = (u(i-1,j,k) - 2*u(i,j,k) + u(i+1,j,k))/dx2;
diffy = (u(i-1,j,k) - 2*u(i,j,k) + u(i+1,j,k))/dy2;
diffusion = A_H*(diffx + diffy);
% windstress
windstress = 0;
% calculate U:
u(i,j,kp)=u(i,j,km)+delta_t*(coriolis-horiz_pressure+diffusion+windstress);
end
end
% Calculate meridional transport (y-direction)
% Finite Difference Formulation of dV/dt:
for j=2:jmax-1
for i=2:imax-1
% calculate the coriolis force at the same position, one step in the past (km):
coriolis = -f(j)*u(i,j,km);
% calculate the horizontal pressure gradient
% (finite diff. centered in y space of the first derivative):
horiz_pressure = -g_reduced*(h(i,j+1,k) - h(i,j-1,k))/d2y;
% Diffusion term: A_H * Laplace*V
% Laplace*V = (d^2 V / d x^2) + (d^2 V / d y^2)
% Centered finite difference of the second derivative
diffx = (v(i-1,j,k) - 2*v(i,j,k) + v(i+1,j,k))/dx2;
diffy = (v(i-1,j,k) - 2*v(i,j,k) + v(i+1,j,k))/dx2;
diffusion = A_H*(diffx + diffy);
% windstress
windstress = 0;
% calculate V:
v(i,j,kp)=v(i,j,km)+delta_t*(coriolis+horiz_pressure+diffusion+windstress);
end
end
% Continuity equation.
% Using forward finite difference instead of centered finite difference!
for j=2:jmax-1
for i=2:imax-1
% hdiv = dU/dx + dV/dy
% use centered finite difference:
% hdiv = (-H*(u(i+1,j,k) - u(i-1,j,k))/d2x) + ((v(i,j+1,k) - v(i,j-1,k))/d2y);
hdiv = (-H*((u(i+1,j,k)-u(i-1,j,k))/d2x+(v(i,j+1,k)-v(i,j-1,k))/d2y)+ A_H*((h(i+1,j,k)+h(i-1,j,k)-2.0*h(i,j,k))/dx2 + (h(i,j+1,k)+h(i,j-1,k)-2.0*h(i,j,k))/dy2));
% new elevation of the thermocline h:
h(i,j,kp) = h(i,j,km) + delta_t*hdiv;
end
end
with the boundary cond. applied every timestep:
Code:
for j=1:jmax
% West:
u(1,j,kp) = -u(3,j,kp); % no normal flow across the rigid boundary
u(2,j,kp) = 0.0; % no-slip at the boundary
v(1,j,kp) = -v(3,j,kp); % same as above but for v-velocity
v(2,j,kp) = 0.0; %
h(1,j,kp) = h(3,j,kp); % thickness restored to neighbouring value
% East
u(imax,j,kp) = -u(imax-2,j,kp);
u(imax-1,j,kp) = 0.0;
v(imax,j,kp) = -v(imax-2,j,kp);
v(imax-1,j,kp) = 0.0;
h(imax,j,kp) = h(imax-2,j,kp);
end
for i=1:imax
% North:
u(i,1,kp) = -u(i,3,kp);
u(i,2,kp) = 0.0;
v(i,1,kp) = -v(3,j,kp);
v(i,2,kp) = 0.0;
h(i,j,kp) = h(i,3,kp);
% South:
u(i,jmax,kp) = -u(i,jmax-2,kp);
u(i,jmax-1,kp) = 0.0;
v(i,jmax,kp) = -v(i,jmax-2,kp);
v(i,jmax-1,kp) = 0.0;
h(i,jmax,kp) = h(i,jmax-2,kp);
end
Bookmarks