function [BFaces,BFacesIndex]=GetBFaces(Faces,FacesIndex,BoundaryIndex)
%output:
%BFaces-boundary faces connectivity (Global encoding)
%BFacesIndex-boundary faces index (Global encoding)
%input:
%Faces-all faces connectivity
%FacesIndex-all faces index
%BoundaryIndex-target faces index

NumbersOfBFaces=find(FacesIndex==BoundaryIndex(1));
BFacesIndex=ones(length(NumbersOfBFaces),1)*BoundaryIndex(1);

if length(BoundaryIndex)>=2
   for i=2:length(BoundaryIndex)
       temp=find(FacesIndex==BoundaryIndex(i));
       NumbersOfBFaces=[NumbersOfBFaces;temp];
       BFacesIndex=[BFacesIndex;ones(length(temp),1)*BoundaryIndex(i)];
   end
end
BFaces=Faces(NumbersOfBFaces,:);

end