function [Accd_n, bccd_n] =  NBC_Cavity(nx,ny,nunk)
% [Accd_n, bccd_n] =  NBC_Cavity(nx,ny,nunk)
% This function creates matrices Accd_n and bccd_n to impose Dirichlet 
% boudary conditions in the normal direction for the Cavity flow 
% problem using Lagrange multipliers method.
%
%   nx,ny:  number of elements on each direction
%   nunk:   number of degrees of freedom for the velocity field
%

% Nodes on the Dirichlet boundary
nodosDy0 = [1:nx+1]';                       
nodosDx1 = [2*(nx+1):nx+1:(ny+1)*(nx)]';    
nodosDy1 = [(ny+1)*(nx+1):-1:ny*(nx+1)+1]'; 
nodosDx0 = [(ny-1)*(nx+1)+1:-(nx+1):nx+2]'; 
nodosD   = [nodosDy0;nodosDx1;nodosDx0;nodosDy1];

% Normal component of the prescribed velocity
NCy0 = [2*nodosDy0  , zeros(size(nodosDy0,1),1)];
NCx1 = [2*nodosDx1-1, zeros(size(nodosDx1,1),1)];
NCx0 = [2*nodosDx0-1, zeros(size(nodosDx0,1),1)];
NCy1 = [2*nodosDy1  , zeros(size(nodosDy1,1),1)];

% Corner nodes
CCN = [1, 0; 2*(nx+1)-1, 0; 2*(ny*(nx+1)+1)-1, 1; 2*(ny+1)*(nx+1)-1, 1];

NC = [NCy0; NCx1; NCx0; NCy1; CCN];

nDir = size(NC,1); 
Accd_n = zeros(nDir,nunk);
Accd_n(:,NC(:,1)) = eye(nDir);
bccd_n = NC(:,2);
