function [A,RHS] = Poission_BoundaryTreatment(mesh,Base,u_D,u_N,A,RHS)

% Treat the boundary condition for Poission equation

%-----get the local coordination in the reference edge [0 1)
coord = [Base.nodal_3(3*[0:Base.DOF_3(1)-1]+1,1);Base.nodal_3(3*(Base.DOF_3(1)+[0:Base.DOF_3(2)-1])+1,1)];

N_bd = size(coord,1);
%----deal with the boundary condition--------------------------------------
if Base.DOF_3(1) == 1
    %---we need to treat the boundary nodals
    
    bd=unique(mesh.Dirichlet_node);
    dim2=size(bd,1);
    A(bd,:)=0;
    A(bd,bd)=eye(dim2);
    RHS(bd,1)=u_D(mesh.node(bd,1:2));
    
end

if  Base.DOF_3(2)>0
    Nr_edge = size(mesh.edge,1);
    bd=unique(mesh.Dirichlet_edge);
    dim2 = size(bd,1);
    %----start the Free_deg for boundary edge
    if Base.DOF_3(1)>0
        Nr_node=size(mesh.node,1);
        bd = Nr_node*Base.DOF_3(1)-Nr_edge+bd;
    else
        bd = bd-Nr_edge;
    end
    
end

%----treat boundary edges--------------------------------------------------

for i = Base.DOF_3(1)+1: N_bd
    bd = Nr_edge+bd;
    A(bd,:)=0;
    A(bd,bd)=eye(dim2);
    RHS(bd,1)=u_D(mesh.node(mesh.node4edge(bd,1),1:2)*coord(i)+mesh.node(mesh.node4edge(bd,2),1:2)*(1-coord(i)));
end