% Input of a vector can be a scalar or matlab expresion involving x and y.
% Example: 4*x+3*y.

addpath('Functions/unsteady')

tEnd  = cinput('\nEnter the time of integration >> ',5);
nStep = cinput('Enter the number of timesteps >> '  ,100);
dt    = tEnd/nStep;
t     = 0:dt:tEnd;

nPt   = size(X,1);
nEl   = size(T,1);
nTl   = length(t);

fprintf('\nDefine equation parameters:\n')
ax    = cinput('Enter x component of velocity >> ',1.d-3);
ay    = cinput('Enter y component of velocity >> ',0);
av    = compVel(X,[ax,ay]);
nu    = cinput('Enter diffusion parameter >> ',1.d-3);
sigma = cinput('Enter reaction parameter >> ',1.d-0);
s     = source(X,0);

a     = sqrt(ax^2+ay^2);
h     = max(max(X(:,1))/nx,max(X(:,2))/ny);
Pe    = a*h/(2*nu);
Cou   = a*dt/h;

fprintf('\nSelect stabilization method:\n')
xDisc = cinput('[1] SUPG method\n[2] GLS method\n[3] No stabilization\n>> ',1);
fprintf('\nSelect time discretization method:\n')
tDisc = cinput(['[1] 2-stage explicit Padé scheme\n[2] 1-stage implicit '...
                'Padé scheme\n[3] 2-stage implicit Padé scheme\n>> '],1);

fprintf('\nSetting initial condition.\n')
u0    = InitialCondition(X,XB,bType,bVal);

% System creation
[M,K,C,f]     = femMatrices(X,T,av,s,elem);
[Mo,Ko,Co,fo] = outflowMatrices(X,T,TB,av,s,elem);
fn            = prescFlow (X,T,TB,bType,bVal,elem);
aux           = prescBound(XB,bType,bVal,u0);

Ks = C+nu*K+sigma*M;
fs = f+fn;

% Time discretization
switch tDisc
    case 1; R20
    case 2; R11
    case 3; R22
end

% Plotting of the results
if (eDeg == 2)
    if (eType == 1);        TP = [T(:,1) T(:,2) T(:,3)];
    elseif (eType == 0);    TP = [T(:,1) T(:,2) T(:,3) T(:,4)];
    end
else
    TP = T;
end

for i = 1:nTl
    figure
    clf
    patch('faces',TP,'vertices',[X(:,1) X(:,2) u(:,i)],'facevertexcdata',u(:,i),...
          'FaceColor','interp','EdgeColor',[0.5,0.5,0.5]);
    colormap(jet(100));
    zlim([min(min(u)) max(max(u))])
    xlabel('x')
    ylabel('y')
    view(3)
    pause(1/25)writeVideo(wObj, frame);
end