Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ab20b0c
  • /
  • util
  • /
  • elementAdjacencyMatrix.m
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:d13c8906d1e695b495765b59500ed6dbbeef405f
directory badge Iframe embedding
swh:1:dir:c972bf0de4dfda0435931428db3887921be81de0
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
elementAdjacencyMatrix.m
function [AdjagencyMatrix,TetsPerParticle,Graph] = elementAdjacencyMatrix(T,N)
    TetsPerParticle = cell(N, 1, 1);
    Tsorted = sort(T,2);
    sharedFaces = containers.Map('KeyType','char','ValueType','any');
    iimat = [];
    jjmat = [];
    vals = [];
    for i = 1:1:size(Tsorted, 1)
        for j = 1:size(Tsorted,2)
                TetsPerParticle{Tsorted(i,j)} = [TetsPerParticle{Tsorted(i,j)},i];
        end

        if size(Tsorted,2) == 3
            % Check all triangles with higher index, to see which
            % indices are shared with our triangle... and if exactly
            % two are shared then we share an edge with that triangle!
            % That is, we've found the adjacent triangles.
            edge1 = key_enc([Tsorted(i,1),Tsorted(i,2)]);
            edge2 = key_enc([Tsorted(i,1),Tsorted(i,3)]);
            edge3 = key_enc([Tsorted(i,2),Tsorted(i,3)]);
            edges = [edge1,edge2,edge3];
            for j = 1:numel(edges)
                if isKey(sharedFaces,edges{j})
                    matching = sharedFaces(edges{j});
                    iimat = [iimat;i;matching];
                    jjmat = [jjmat;matching;i];
                    vals = [vals;1;1];
                else
                    sharedFaces(edges{j}) = i;
                end
            end
        
        else
%             TetsPerParticle(inds) = cellfun(@(x) [x, i], TetsPerParticle(inds), 'UniformOutput', false);

            face1 = key_enc([Tsorted(i,1),Tsorted(i,2),Tsorted(i,3)]);
            face2 = key_enc([Tsorted(i,1),Tsorted(i,2),Tsorted(i,4)]);
            face3 = key_enc([Tsorted(i,1),Tsorted(i,3),Tsorted(i,4)]);
            face4 = key_enc([Tsorted(i,2),Tsorted(i,3),Tsorted(i,4)]);
            faces = [face1,face2,face3,face4];
            for j = 1:numel(faces)
                if isKey(sharedFaces,faces{j})
                    matching = sharedFaces(faces{j});
                    iimat = [iimat;i;matching];
                    jjmat = [jjmat;matching;i];
                    vals = [vals;1;1];
                else
                    sharedFaces(faces{j}) = i;
                end
            end
        end
    end
    AdjagencyMatrix = sparse(iimat,jjmat,vals,size(T,1),size(T,1));
    Graph = graph(AdjagencyMatrix);

    function key1_char =  key_enc(key1)
        [m,n] = size(key1);
        key1_char=repmat({char(ones(1,16*n))},m,1);
        tmp = num2hex(key1);
        for ii=1:m  
        key1_char{ii,:} = reshape((tmp(ii:m:end,:).'),1,16*n);
        end
    end
end

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top