% Explicit 2-stage Padé

% Stabilization scheme
% tau = cinput('\nEnter stabilization parameter >> ',1.d-3);
tau = 1.d-3;
switch xDisc
    case 1
        [fST,ST1,ST2,ST3]     = supgMethod(X,T,av,nu,sigma,s,tau,dt,elem,1);
        [fSTm,ST1m,ST2m,ST3m] = supgMethod(X,T,av,nu,sigma,s,tau,dt/2,elem,1);
    case 2
        [fST,ST1,ST2,ST3]     = glsMethod(X,T,av,nu,sigma,s,tau,dt,elem,1);
        [fSTm,ST1m,ST2m,ST3m] = glsMethod(X,T,av,nu,sigma,s,tau,dt/2,elem,1);
    case 3
        [fST,ST1,ST2,ST3]     = doNothing(X,1);
        [fSTm,ST1m,ST2m,ST3m] = doNothing(X,1);
end

% Resolution of the system
nBd           = length(aux);
A             = zeros(nBd,nPt);
A(:,aux(:,1)) = eye(nBd);
b             = aux(:,2);

u      = zeros(nPt,nTl);
us     = zeros(nPt+nBd,nTl);

u(:,1) = u0;

Msm    = [M+ST1m transpose(A);A zeros(nBd)];
Mss    = [M+ST1  transpose(A);A zeros(nBd)];

for n = 1:nStep
    fm             = 0.5*dt*fs;
    Rs3m           = ST3m*u(:,n)-0.5*dt*(Ks)*u(:,n);
    Rs2m           = (ST2m+M)*u(:,n);
    fsm            = [Rs2m+fm+fSTm+Rs3m;b];
    
    usm = Msm\fsm;
    um  = usm(1:nPt);
    
    f             = dt*fs;
    Rs3           = ST3*u(:,n)-dt*(Ks)*u(:,n);
    Rs2           = (ST2+M)*u(:,n);
    fsf           = [Rs2+f+fST+Rs3;b];
    
    us(:,n+1) = Mss\fsf;
    u(:,n+1)  = usm(1:nPt);
end
        