function [Solver,BMesh]=BoundaryEigenMode(BMesh,Physic,Material,Solver)
%output
%BEigenMode-Storing solution-related information
%BMesh-updated mesh data
%input
%BMesh-original mesh data
%Physic-physical variables
%MaterialLib-material 
%Solver-solution setting

BMesh.NbrNodes=length(BMesh.Nodes);
epsilonrF=Material.epsilonrF-1i*Material.sigmaF*Material.temp;

%assembling matrics
[A,B,BMesh.EdgesOfElements,PECInd,Solver.Dof,r]=...
    EigenModeMatrixAssembly(BMesh.Nodes,BMesh.NewFaces,BMesh.FacesIndex,...
    Physic.lam0,epsilonrF,Material.murF);

%solving
sigma=-(Physic.k0*Solver.targetNeff)^2;
[x,GAMA_sq]=eigs(A,B,Solver.modeNum,sigma);

%processing solution
q=zeros(length(r),1);
for i=1:length(r)
    q(r(i))=i;
end
for i=1:Solver.modeNum
   x(:,i)=x(q,i); 
end
%processing PEC
for i=1:length(PECInd)-1
    n=PECInd(i);
    x=[x(1:n-1,:);zeros(1,Solver.modeNum);x(n:end,:)];
end
i=length(PECInd);
n=PECInd(i);
if n<=length(x)
    x=[x(1:n-1,:);zeros(1,Solver.modeNum);x(n:end,:)];
else
    x=[x(1:n-1,:);zeros(1,Solver.modeNum);];
end

%solution
Solver.gamma=diag(sqrt(GAMA_sq));
Solver.neff=((-1i*Solver.gamma)./Physic.k0);
Solver.Ez=x(1:BMesh.NbrNodes,:).*Solver.gamma;
Solver.Et=x(BMesh.NbrNodes+1:Solver.Dof,:);%./(Solver.gamma);

%Reconstructing electric field Ex, Ey and normE
Solver.Ex=zeros(BMesh.NbrNodes,Solver.modeNum);
Solver.Ey=zeros(BMesh.NbrNodes,Solver.modeNum);
Solver.normE=zeros(BMesh.NbrNodes,Solver.modeNum);
for i=1:Solver.modeNum
    [Solver.Ex(:,i),Solver.Ey(:,i)]=GetExEy(BMesh.Nodes,BMesh.NewFaces,...
        BMesh.EdgesOfElements,Solver.Et(:,i));
    Solver.normE(:,i)=sqrt(abs(Solver.Ex(:,i).*Solver.Ex(:,i))+...
        abs(Solver.Ey(:,i).*Solver.Ey(:,i))+abs(Solver.Ez(:,i).*Solver.Ez(:,i)));
end
% [Solver.Ex,Solver.Ey,Solver.Ezz]=GetExEy2(BMesh.Nodes,BMesh.NewFaces,...
%             BMesh.EdgesOfElements,Solver.Et(:,1),Solver.Ez(:,1));
% Solver.normE=sqrt(abs(Solver.Ex.*Solver.Ex)+...
%             abs(Solver.Ey.*Solver.Ey)+abs(Solver.Ezz.*Solver.Ezz));

end