%% 施加边界条件 Apply boundary conditions
% 采用“01赋值”方法强加边界条件,假设边界棱边场值c
% The boundary conditions are enforced using the "01 assignment" method, assuming that the boundary edge field value is c.
% \left\lbrace \begin{array}{ll}
% b_j =b_j -{\textrm{cA}}_{j,i}  & \;\\
% b_j =c & \;
% \end{array},\left\lbrace \begin{array}{ll}
% A_{j,i} =A_{i,j} =0 & j\not= i\\
% A_{j,j} =1 & j=i
% \end{array}\right.\right.

function [A,b2]  = set_Boundary(beField,bedgeID,A,b)


%% 右端项施加边界条件
%% Apply the boundary conditions to the right-hand side terms.

b2.TM = b - A(:,bedgeID.all)*beField.E2all;
b2.TM(bedgeID.all,1)  = beField.E2all;

b2.TE = b - A(:,bedgeID.all)*beField.E1all;
b2.TE(bedgeID.all,1)  = beField.E1all;

%% 系数矩阵施加边界条件
%% Apply boundary conditions to the coefficient matrix.
nA     = size(A,1);
ii      = bedgeID.all(:,1);
A(:,ii)   = 0;% set all elements of the specified column to 0
A(ii,:)   = 0;% set all elements of the specified row to 0

% Abnd    = sparse(ii,ii,ones(size(ii)),nA,nA);
% Abnd    = A + Abnd;% Set the specified ii-th diagonal element to 1.
% Abnd    = tril(Abnd);%pardiso

A    = A + sparse(ii,ii,ones(size(ii)),nA,nA);
end