function [EtoE,EtoF] = Connectivity2D()

% build global connectivity arrays for grid based on standard EToV input array from grid generator
% both arrays are of size K x N_faces

Globals2D;

face_def = [1, 2; 2, 3; 1, 3]; % matice 3x2

spFtoV = sparse(K * N_faces,N_v); % sparse matice N_faces*K x N_v ukazujici, ktere uzly site tvori hranice
face = 1;
for i = 1:K
	for j = 1:N_faces
		spFtoV(face,E(face_def(j,:),i)) = 1;
		face = face + 1;
	end
end

spFtoF = spFtoV * spFtoV' - 2 * speye(K * N_faces); % matice Nfaces*K x Nfaces*K ukazujici, ktere hranice na sebe navazuji

[faces1,faces2] = find(spFtoF == 2); % odpovidajici prvky faces1 a faces2 rikaji, ktera hrana prileha na kterou hranu v globalni siti

% potrebujeme cisla 1:K; napr 1,2,3 patri elementu 1 atd
element1 = floor((faces1 - 1) / N_faces) + 1;
element2 = floor((faces2 - 1) / N_faces) + 1;
% potrebujeme cisla 1,2,3; napr 22 je 1 (z globalni site na referencni element)
face1 = mod(faces1 - 1,N_faces) + 1;
face2 = mod(faces2 - 1,N_faces) + 1;

% inicializace poli EtoE a EtoF jako kdyby byly vsechny elementy rozpojeny
EtoE = ((1:K)') * ones(1,N_faces);
EtoF = ones(K,1) * (1:N_faces);

indexes = sub2ind([K, N_faces],element1,face1);
EtoE(indexes) = element2;
EtoF(indexes) = face2;

end