%% (time dependent) sin flow with pressure field
clear all
close all
[x,y] = meshgrid(-1:0.01:1,-1:0.01:1);
alpha=-1;
beta=3;
step=10;
scale=1/20;
rho=1000;
Po=1000;
fname=['sin_flow.avi'];
aviobj=VideoWriter(fname);
aviobj.FrameRate=7;
aviobj.Quality=100;
open(aviobj);

h=figure('Color',[1 1 1],'units','normalized','outerposition',[-.75 0 .4 .75]);
for t=0:0.1:4*pi
    u = alpha*x.^3*sin(t);
    v = beta*y.^3*sin(t);
    P = Po - rho*(beta*y.^4/4-alpha*x.^4/4).*cos(t)+((alpha^2).*x.^6+beta^2.*y.^6).*sin(t);
    
    imagesc(-1:0.01:1,-1:0.01:1,P/1000)
    hold on
    quiver(x(1:step:end,1:step:end),y(1:step:end,1:step:end),u(1:step:end,1:step:end)*scale,v(1:step:end,1:step:end)*scale,0,'k')
    title(['t = ' num2str(t/pi,2) '\pi'])
    axis equal
    xlabel('$x/L$','interpreter','latex')
    ylabel('$y/L$','interpreter','latex')
    caxis([0 2])
    hh=colorbar;
    ylabel(hh,'$P/P_0$','interpreter','latex')
    set(gca,'FontSize',15,'ticklength',1.5*get(gca,'ticklength'),'Layer', 'Top','xtick',-1:.5:1,'ytick',-1:.5:1)
    axis([-1 1 -1 1])
    pause(.1)
    F = getframe(h);
    writeVideo(aviobj,F)
    pause(.1)
    clf
end
close(aviobj)