function [Accd, bccd] =  BC(nx,ny,nunk)
% [Accd, bccd] =  BC(nx,ny,nunk)
% This function creates matrices Accd and bccd to impose Dirichlet 
% boundary conditions on a scalar field using Lagrange multipliers method.
% Homogeneous Dirichlet boundary conditions are imposed on the 
% whole boundary.
%
% Input:
%   nx,ny:  number of elements on each direction
%   nunk:   number of degrees of freedom for the velocity field
%


% Nodes on the Dirichlet boundary
nodesDy0 = [1 : nx+1]';                             % y = 0
nodesDx1 = [2*(nx+1) : nx+1 : (ny+1)*nx]';          % x = 1
nodesDx0 = [(ny-1)*(nx+1)+1 : -(nx+1) : nx+2]';     % x = 0
nodesDy1 = [(ny+1)*(nx+1) : -1 : ny*(nx+1)+1]';     % y = 1
nodesD   = [nodesDy0;nodesDx1;nodesDx0;nodesDy1];

% Prescribed boundary conditions
Cy0 = [nodesDy0, zeros(length(nodesDy0),1)];
Cx1 = [nodesDx1, zeros(length(nodesDx1),1)];
Cx0 = [nodesDx0, zeros(length(nodesDx0),1)];
Cy1 = [nodesDy1, zeros(length(nodesDy1),1)];
C = [Cy0; Cx1; Cx0; Cy1];

% Boundary conditions' matrix
nDir = size(C,1);
Accd = zeros(nDir,nunk);
Accd(:,C(:,1)) = eye(nDir);
% Boundary conditions' vector
bccd = C(:,2);

