% Implicit 2-stage Padé

% Stabilization scheme
W = [7/24 -1/24;13/24 5/24];
w = [1/2;1/2];

% tau = cinput('\nEnter stabilization parameter >> ',1.d-3*ones(2,2));
tau = 1.d-3*ones(2,2);

switch xDisc
    case 1; [fST,ST,ST2] = supgMethod(X,T,av,nu,sigma,s,tau,dt,elem,3,W,w);
    case 2; [fST,ST,ST2] = glsMethod (X,T,av,nu,sigma,s,tau,dt,elem,3,W,w);
    case 3; [fST,ST,ST2] = doNothing (X,3);
end

% Resolution of the system
SKs = [1/dt*M+W(1,1)*Ks  W(1,2)*Ks;
       W(2,1)*Ks         1/dt*M+W(2,2)*Ks]+ST;

nBd           = length(aux);
A             = zeros(nBd,nPt);
A(:,aux(:,1)) = eye(nBd);
A             = [A zeros(size(A));zeros(size(A)) A];
b             = [aux(:,2)-aux(:,2);aux(:,2)-aux(:,2)];

u      = zeros(nPt,nTl);
KSs    = [SKs transpose(A);A zeros(2*nBd)];

u(:,1) = u0;

for n = 1:nStep
    wfs = [w(1)*fs;w(2)*fs];
    wKs = [w(1)*Ks*u(:,n);w(2)*Ks*u(:,n)];
    STs = ST2*[u(:,n);u(:,n)];
    
    Sfs      = [wfs+fST-wKs+STs;b];
    Du       = KSs\Sfs;
    u(:,n+1) = Du(nPt+1:2*nPt) + Du(1:nPt) + u(:,n);
end