function [B,TB] = boundaryNodes(eDeg,nx,ny)
% Creates matrices with the node numbers corresponding to the boundaries of
% the problem
% Input: 
%   eDeg  = Degree of element interpolation
%   nx,ny = number of elements in each direction
% Output:
%   B  = cell with nodes numbers for all boundaries
%   TB = cell with connectivities of elements in all boundaries

npx = nx*eDeg+1; 
npy = ny*eDeg+1;
TBx = zeros(ny,eDeg+1,2);
TBy = zeros(nx,eDeg+1,2);

for i = 1:ny
    TBx(i,:,1) = (eDeg*i-eDeg)*npx+1:npx:eDeg*i*npx+1;
    TBx(i,:,2) = (eDeg*(i-1)+1)*npx:npx:(eDeg*i+1)*npx;
end
for i = 1:nx
    TBy(i,:,1) = (i-1)*eDeg+1:i*eDeg+1;
    TBy(i,:,2) = npx*(npy-1)+(i-1)*eDeg+1:npx*(npy-1)+i*eDeg+1;
end

B  = {(1:npx:ceil((npx*(npy-1)+1)/2))',(ceil((npx*(npy-1)+1)/2):npx:npx*(npy-1)+1)',(npx*(npy-1)+1:npx*npy)',(npx:npx:npx*npy)',(1:npx)'};
TB = {[(1:nx:nx*ny/2)' TBx(1:ceil(size(TBx,1)/2),:,1)],[(nx*ceil(ny/2)+1:nx:nx*(ny-1)+1)' TBx(ceil(size(TBx,1)/2)+1:end,:,1)],[(nx*(ny-1)+1:nx*ny)' TBy(:,:,2)],[(nx:nx:nx*ny)' TBx(:,:,2)],[(1:nx)' TBy(:,:,1)]};
