function [A,b,nDir] = BoundaryConditions(X,velo)

x1 = min(X(:,1)); x2 = max(X(:,1)); xM = (x1+x2)/2;
y1 = min(X(:,2)); y2 = max(X(:,2)); yM = (y1+y2)/2; 

if velo == 1
    nodes_x1 = find( (abs(X(:,1) - x1)<1e-6) & (X(:,2)<=yM) ); 
    nodes_x2 = find( (abs(X(:,1) - x2)<1e-6) & (X(:,2)>=yM) ); 
    nodes_y1 = find( (abs(X(:,2) - y1)<1e-6) & (X(:,1)>=xM) ); 
    nodes_y2 = find( (abs(X(:,2) - y2)<1e-6) & (X(:,1)<=xM) ); 
    nodesDir0 = unique([nodes_x1; nodes_x2; nodes_y1; nodes_y2]); 
    nodesDir1 = [] ;
elseif velo == 2
    nodesDir0 = find( (abs(X(:,1) - x1)<1e-6)); 
    nodesDir1 = [] ;
elseif velo == 3
    nodes_x2 = find( (abs(X(:,1) - x2)<1e-6)); 
    nodes_y2 = find( (abs(X(:,2) - y2)<1e-6)); 
    nodesDir0 = unique([nodes_x2;nodes_y2]);
    nodesDir1 = [] ;
    %%%%%% Modified BC for exe2(2,4 BC) %%%% 
elseif velo == 4
     
    nodes_g2 = find( X(:,1) == x1 & X(:,2) >= y2/2) ;
    nodes_g4 = find( X(:,1) == x2 );
    nodesDir0 = unique(nodes_g4);
    nodesDir1 = unique(nodes_g2);

elseif velo ==5
    nodesDir0 = [];
    nodesDir1 = [];

end

C = [nodesDir0 , zeros(size(nodesDir0)) ; ...
     nodesDir1 ,  zeros(size(nodesDir1)) ; ] ;

nDir = size(C,1); 
nPt = size(X,1); 
A = zeros(nDir,nPt);
b = zeros(nDir,1) ;
if ~isempty(C)
    A(:,C(:,1)) = eye(nDir);
    b = C(:,2); 
end
