コード例 #1
0
ファイル: matrices.py プロジェクト: chiarasharp/py3DViewer
def laplacian_matrix(mesh):
    n = mesh.num_vertices
    #e =  np.c_[mesh.faces[:,:2], mesh.faces[:,1:], mesh.faces[:,2], mesh.faces[:,0]]
    e = mesh.edges
    A = sp_matrix((n, n))
    A[e[:, 0], e[:, 1]] = -1
    D = sp_matrix(A.shape)
    D.setdiag(np.sum(A, axis=1))
    L = D - A
    return L
コード例 #2
0
def mass_matrix(mesh):

    nv = mesh.num_vertices
    mass = np.ones((nv))

    for i in range(nv):
        volumes = []
        if mesh.mesh_is_volumetric:
            if mesh.polys.shape[1] == 4:
                _, volumes = tet_volume(mesh.vertices,
                                        mesh.polys[mesh.adj_vtx2poly[i]])
            else:
                _, volumes = hex_volume(mesh.vertices,
                                        mesh.polys[mesh.adj_vtx2poly[i]])

        elif mesh.mesh_is_surface:
            if (mesh.polys.shape[1] == 3):
                _, volumes = triangle_area(mesh.vertices,
                                           mesh.polys[mesh.adj_vtx2poly[i]])
            else:
                _, volumes = quad_area(mesh.vertices,
                                       mesh.polys[mesh.adj_vtx2poly[i]])

        mass[i] *= (np.sum(volumes) / volumes.shape[0])

    MM = sp_matrix((nv, nv))
    MM.setdiag(mass)

    return MM
コード例 #3
0
ファイル: matrices.py プロジェクト: chiarasharp/py3DViewer
def mass_matrix(mesh):

    nv = mesh.num_vertices
    mass = np.ones((nv))

    for i in range(nv):
        volumes = []
        if (hasattr(mesh, 'hexes')):
            v2p = mesh.vtx2hex[i]
            _, volumes = hex_volume(mesh.vertices, mesh.hexes[v2p])
        elif (hasattr(mesh, 'tets')):
            v2p = mesh.vtx2tet[i]
            _, volumes = tet_volume(mesh.vertices, mesh.tets[v2p])
        elif (hasattr(mesh, 'faces')):
            v2p = mesh.vtx2face[i]
            if (mesh.faces.shape[1] == 3):
                _, volumes = triangle_area(mesh.vertices, mesh.faces[v2p])
            else:
                _, volumes = quad_area(mesh.vertices, mesh.faces[v2p])

        mass[i] *= (np.sum(volumes) / volumes.shape[0])

    MM = sp_matrix((nv, nv))
    MM.setdiag(mass)

    return MM
コード例 #4
0
def adjacency_matrix(mesh, type='std'):
    assert (type == 'std' or type == 'cot')
    n = mesh.num_vertices
    e = mesh.edges
    A = sp_matrix((n, n), dtype=np.float64)
    if type == 'std':
        A[e[:, 0], e[:, 1]] = 1
        A[e[:, 1], e[:, 0]] = 1
    else:
        raise NotImplementedError("not implemented yet")

    return A
コード例 #5
0
def degree_matrix(A):
    D = sp_matrix(A.shape, dtype=np.float64)
    D.setdiag(np.sum(A, axis=1))
    return D