function [S_L,dS_L_dCP] = localArea_functional(Aux)
global Invariant ini_Val

%This function calculate the local area conservation
gaussno = ini_Val.gaussno;
S_L = zeros(ini_Val.ncontrol-Invariant.lower,1);
connect_l = Invariant.connect_l;

% iel=1:size(connect_l,1);
% for ig = 1:gaussno
%     igglob=(iel-1)*gaussno+ig;
%     aux = Aux.au(igglob).*Aux.MC1(igglob,1).*Invariant.gweight(igglob);
%     aux_ = aux * ones(1,size(Invariant.N_hat,2));    
%     L_loc = Invariant.N_hat(igglob,:).*aux_;
% %    for i=1:size(connect_l,2)
% %        S_L(connect_l(iel,i)) = S_L(connect_l(iel,i))+L_loc(:,i);
% %    end
%     S_L(connect_l(iel,1)) = S_L(connect_l(iel,1))+L_loc(:,1);
%     S_L(connect_l(iel,2)) = S_L(connect_l(iel,2))+L_loc(:,2);
%     S_L(connect_l(iel,3)) = S_L(connect_l(iel,3))+L_loc(:,3);
% end
ig=(1:gaussno);
for iel=1:size(connect_l,1)
  igglob=(iel-1)*gaussno+ig;
    aux = Aux.au(igglob).*Aux.MC1(igglob,1).*Invariant.gweight(igglob);
    L_loc = Invariant.N_hat(igglob,:)'*aux;
    S_L(connect_l(iel,:)) = S_L(connect_l(iel,:))+L_loc;
end
S_L = 2*pi*S_L;

if nargout == 2;
    %Derivative of local area
    connect = Invariant.connect;
    dS_L_dCP = zeros((ini_Val.ncontrol-Invariant.lower),2*ini_Val.ncontrol);
    for iel=1:size(connect,1)
        ig=(1:gaussno);
        igglob=(iel-1)*gaussno+ig;
        % r componant
        aux = (Aux.da_dr_l(igglob,:).*Aux.MC1(igglob,:)+Aux.Mau(igglob,:) ...
            .*Invariant.Nshape(igglob,:)).*Aux.Mgweight(igglob,:);%    ./Aux.Mau(igglob,:).^2;%     .*Aux.Mau(igglob,:) .* Aux.MC1(igglob,:);
        D_loc = Invariant.N_hat(igglob,:)'*aux;
        dS_L_dCP(connect_l(iel,:),2*connect(iel,:)-1) = ...
            dS_L_dCP(connect_l(iel,:),2*connect(iel,:)-1) + D_loc;
        % z componant
        aux = Aux.da_dz_l(igglob,:).*Aux.MC1(igglob,:).*Aux.Mgweight(igglob,:);%      ./Aux.Mau(igglob,:).^2;%     .*Aux.Mau(igglob,:) .* Aux.MC1(igglob,:);
        D_loc = Invariant.N_hat(igglob,:)'*aux;
        dS_L_dCP(connect_l(iel,:),2*connect(iel,:)) = ...
            dS_L_dCP(connect_l(iel,:),2*connect(iel,:)) + D_loc;
    end
    dS_L_dCP = 2*pi*dS_L_dCP;
end