Skip to content

cluster_grouping_matrices

cluster_grouping_matrices(l, V, T, return_mass=False)

Computes the grouping matrices for a clustering of tets.

Parameters:

Name Type Description Default
l (t,) int numpy array

Label for each tet

required
V (n, 3) float numpy array

Mesh vertices

required
T (t, 4) int numpy array

Mesh tets

required
return_mass bool

Whether to return the mass of each cluster, tet and the mass fraction of each tet in its cluster.

False

Returns:

Name Type Description
G (c, t) scipy sparse csc matrix

Grouping matrix

Gm (c, t) scipy sparse csc matrix

Grouping matrix with mass normalization

mc (c,) float numpy array

Mass of each cluster, only returned if return_mass is True

mt (t,) float numpy array

Mass of each tet, only returned if return_mass is True

f (t,) float numpy array

Mass fraction of each tet in its cluster, only returned if return_mass is True

Source code in src\fast_cody\cluster_grouping_matrices.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def cluster_grouping_matrices(l, V, T, return_mass=False):
    """Computes the grouping matrices for a clustering of tets.

    Parameters
    ----------
    l : (t,) int numpy array
        Label for each tet
    V : (n, 3) float numpy array
        Mesh vertices
    T : (t, 4) int numpy array
        Mesh tets
    return_mass : bool
        Whether to return the mass of each cluster, tet and the mass fraction of each tet in its cluster.

    Returns
    --------
    G : (c, t) scipy sparse csc matrix
        Grouping matrix
    Gm : (c, t) scipy sparse csc matrix
        Grouping matrix with mass normalization
    mc : (c,) float numpy array
        Mass of each cluster, only returned if return_mass is True
    mt : (t,) float numpy array
        Mass of each tet, only returned if return_mass is True
    f : (t,) float numpy array
        Mass fraction of each tet in its cluster, only returned if return_mass is True

    """
    t = T.shape[0]
    c = l.max() + 1
    assert(T.shape[1] == 4)
    I= l
    J = np.arange(t)
    mt = igl.volume(V, T)
    if mt.ndim==0:
        mt = mt[None]
    mc = np.bincount(l, mt) #mass of each cluster
    Mci = sp.sparse.diags(1/mc, 0)
    Mt = sp.sparse.diags(mt,  0)

    VV = np.ones(t)
    G = sp.sparse.csc_matrix((VV, (I, J)), shape=(c, t))

    Gm = Mci @ G @ Mt

    if return_mass:
         f = mt / mc[l]
         return G, Gm, mc, mt, f
    return G, Gm