Line data Source code
1 22 : function adjacencymatrix(mesh::Mesh; one = 1, boundary=true)
2 22 : i = Vector{Int}(undef, nh(mesh))
3 22 : j = Vector{Int}(undef, nh(mesh))
4 11 : n = 0
5 :
6 22 : for e in edges(mesh)
7 132 : h = halfedge(e, 1)
8 :
9 168 : if boundary || !isboundary(mesh, e)
10 114 : vi = Int.(vertices(mesh, e))
11 :
12 114 : i[n+1], i[n+2] = vi
13 114 : j[n+2], j[n+1] = vi
14 :
15 114 : n += 2
16 : else
17 18 : @massert isboundary(mesh, e)
18 18 : h = halfedge(e, 1)
19 36 : isboundary(mesh, h) || (h = halfedge(e, 2))
20 :
21 18 : vi = Int.(vertices(mesh, h))
22 :
23 18 : i[n+1], j[n+1] = vi
24 :
25 18 : n += 1
26 : end
27 253 : end
28 :
29 11 : resize!(i, n)
30 11 : resize!(j, n)
31 :
32 11 : sparse(i, j, one, nv(mesh), nv(mesh))
33 : end
34 :
35 : """
36 : A = adjacencymatrix(mesh[; one=1, boundary=true])
37 :
38 : Get *sparse* adjacency matrix with `A[i, j] == one` if
39 : [`halfedge`](@ref) `(i, j)` exists **and** either `boundary==true` or
40 : `(i, j)` is not a boundary half-edge.
41 :
42 : - `A` has [`nv`](@ref) rows and columns.
43 : - The optional argument `one` determines the type of
44 : `A::SparseMatrix{typof(one)}`.
45 : - If `boundary==true`, `A` is *always symmetric*. If `boundary==false`,
46 : `A` is *symmetric* only if `mesh` has no boundary.
47 :
48 : !!! note
49 : Use the optional `boundary` argument to mimic construction of an
50 : adjacency matrix from, e.g., a [`facetable`](@ref)
51 :
52 : See also [`graphlaplacian`](@ref)
53 : """ adjacencymatrix
|