function [A, nDir, nodesDirBC, Dir_u, confined] = BC(nx,ny,n,degree,alpha)
% [A, b, nDir, confined] = BC(X,dom,n)
% Matrices to impose Dirichlet boundary conditions using Lagrange
% multipliers on a rectangular domain
% Input: 
%    X: nodal coordinates
%    dom: domain description [x1,x2,y1,y2]
%    n: number of velocity degrees of freedom
% Output:
%    A,b: matrix and r.h.s. vector to impose the boundary conditions using
%         Lagrange multipliers
%    nDir: number of prescribed degrees of freedom
%    confined: 
%==========================================================================
%       Application of Boundary condtions for Velocity
%==========================================================================
% confined flow (velocity is imposed for all the nodes in the boundary)
confined = 1; 
% number of prescribed degrees of freedom
Ntheta = nx;  Nr = ny;
nptheta = degree*Ntheta + 1;
npr = degree*Nr + 1;
% npt = nptheta*npr;

nodesDy0 = [1 : nptheta]';
% nodesDx1 = [2*(nptheta) : (nptheta) : (npr)*(nptheta-1)]';
nodesDy1 = [(npr-1)*(nptheta)+1:1:(npr)*(nptheta)]';
% nodesDx0 = [(npr-2)*(nptheta)+1 : -(nptheta) : nptheta+1]';
nodesDirBC = [nodesDy0; nodesDy1]; 
nDiry0 = 2*length(nodesDy0);
nDiry1 = 2*length(nodesDy1);

nDir = 2*length(nodesDirBC); 
% Degrees of freedom where the velocity is prescribed
% (horizontal and vertical component)
C = [2*nodesDirBC - 1; 2*nodesDirBC];
C1=reshape(C,nDir/2,2);
C2 =reshape(C1',nDir,1);  %%number of components of dirichlet velocity

A = zeros(nDir,n); 
A(:,C2) = eye(nDir); 

%==========================================================================
% Taking advantage of the angle  relationships in Polar Coordinates
%==========================================================================

% Introduce the imposed velocity values  on the boundary)
val_ut0 = 0; val_ur0 = -0.15;
val_ut1 = 0; val_ur1 = -0.3;
%%%%%%%%%%% In catersian its theta = 90- alpha %%%%%%%%%
vx0 = val_ut0*sin(pi/2-alpha) + val_ur0*cos(pi/2-alpha);
vy0 = -val_ut0*cos(pi/2-alpha) + val_ur0*sin(pi/2-alpha);
vx1 = val_ut1*sin(pi/2-alpha) + val_ur1*cos(pi/2-alpha);
vy1 = -val_ut1*cos(pi/2-alpha) + val_ur1*sin(pi/2-alpha);

b1 = [vx0' vy0';vx1'   vy1'];
b2 =reshape(b1',nDir,1);
Dir_u = [C2 b2];     % Required output
%==========================================================================
%                      End of the applied BC
%==========================================================================