function [Accd,bccd, nodesDir0, nodesDir1] = BoundaryConditionMat(X,nx,ny)
% [Accd, bccd] =  BC(nx,ny,nunk)
% This function creates matrices Accd and bccd to impose homogeneous 
% Dirichlet boudary conditions using Lagrange multipliers method.
%
%   nx,ny:  number of elements on each direction
%

% Nodes on the boundaries
nodes_y0 = [1:nx]';                           % Nodes on the boundary y=0
nodes_x1 = [(nx+1):nx+1:(ny+1)*(nx+1)]' ;     % Nodes on the boundary x=1
nodes_y1 = [(ny+1)*(nx+1)+nx:-1:(ny+1)*(nx+1)+1]' ;   % Nodes on the boundary y=1
nodes_x0 = [ny*(nx+1)+1:-(nx+1):nx+2]';     % Nodes on the boundary x=0

% Nodes on which solution is u=1
nodesDir1 = nodes_x0(X(nodes_x0,2) >= 1.5 );

% Nodes on which solution is u=0
nodesDir0 = nodes_x1;

% Boundary condition matrix for Lagrange multipliers method
C = [nodesDir0, zeros(length(nodesDir0),1);
     nodesDir1, ones(length(nodesDir1),1)];

% Boundary conditions matrix
nunk = size(X,1); % number of unknows of the problem (nodes)
nDir = size(C,1);
Accd = zeros(nDir,nunk);
Accd(:,C(:,1)) = eye(nDir);
% Boundary conditions vector
bccd = C(:,2);
end