function [A, b, nDir, confined] = BC(X,dom,n)

x1 = dom(1);  x2 = dom(2); 
y1 = dom(3);  y2 = dom(4); 

tol = 1e-6; 
nodesX1 = find(abs(X(:,1)-x1) < tol);
nodesX2 = find(abs(X(:,1)-x2) < tol);
nodesY1 = find(abs(X(:,2)-y1) < tol & abs(X(:,1)-x2)>tol); 
nodesY2 = find(abs(X(:,2)-y2) < tol & abs(X(:,1)-x2)>tol); 


%confined flow(velocity is imposed for all the nodes in the boundary)
confined = 1; 

nodesDir=unique([nodesX1;nodesY1;nodesY2]);
nodesDirg4=unique(nodesX2);

%no. of prescribed dof
nDir=2*length(nodesDir);
nDirg4=2*length(nodesDirg4);

%horizontal and vertical component
C = [2*nodesDir-1; 2*nodesDir
    2*nodesDirg4-1; 2*nodesDirg4];

A = zeros(nDir+nDirg4,n); 
A(:,C) = eye(nDir+nDirg4); 

%imposed value(velocity is set to zero on the boundary)
b = [zeros(nDir,1);zeros(nDirg4/2,1);-ones(nDirg4/2,1)];

nDir=nDir+nDirg4;
end


