% PML
sigma_x_PML = zeros(N_p,K);

% fungovalo pro kombinaci D_PML = 15 a sigma_m = 0.50 do T = 300
D_PML = 15;
sigma_m = 0.50;
beta = 2;

indexes_R = find(x > x_u + NODETOL);
indexes_L = find(x < x_l - NODETOL);
sigma_x_PML(indexes_R) = sigma_m * (abs(x(indexes_R) - x_u) / D_PML) .^ beta;
sigma_x_PML(indexes_L) = sigma_m * (abs(x(indexes_L) - x_l) / D_PML) .^ beta;

sigma_x_PML_times_n_y = sigma_x_PML(Fmask(:),:) .* n_y;


% PML access information
[rows1,cols1] = find(x > x_u + NODETOL);
[rows2,cols2] = find(x < x_l - NODETOL);
elements_PML = unique([cols1; cols2]);

elements_Euler = setdiff((1:K)',elements_PML);

Faces_PML = zeros(3,K);
Faces_PML(:,elements_PML) = ones(3,length(elements_PML));
Faces_PML = Faces_PML(:);
Nodes_PML = ones(N_fp,1) * Faces_PML';
Nodes_PML = Nodes_PML(:);
mapPML = find(Nodes_PML == 1); % faces nalezici elementum v PML
mapPML_M = unique([mapPML;mapP(mapPML)]); % body na faces na vsech elementech lezicich v PML nebo sousedicich s elementem v PML
mapPML_P = mapP(mapPML_M); % prilehajici body na body z mapPML_P
vmapPML = vmapM(mapPML);
vmapPML_M = vmapM(mapPML_M);
vmapPML_P = vmapM(mapPML_P);



% sponge zone
sigma_sponge = zeros(N_p,K);

D_sponge = 100;
sigma_m = 0.50; % lepsi vysledek pro sigma_m = 0.50 nez pro sigma_m = 1.00
beta = 2;

indexes_R = find((x > x_u) & (abs(y) < y_u + NODETOL));
sigma_sponge(indexes_R) = sigma_m * (abs(x(indexes_R) - x_u) / D_sponge) .^ beta;
indexes_L = find((x < x_l) & (abs(y) < y_u + NODETOL));
sigma_sponge(indexes_L) = sigma_m * (abs(x(indexes_L) - x_l) / D_sponge) .^ beta;

elements_sponge = elements_PML;