Exemplo n.º 1
0
def test_faces():
    """check whether faces are correct"""
    for mesh in meshes.itervalues():
        sc = simplicial_complex(mesh)

        for face_data, cell_data in zip(sc[:-1], sc[1:]):
            #compute all faces and store in a set

            boundary_set = set()
            for row in cell_data.simplices:
                boundary_set.update(simplex(row).boundary())

            face_set = set([simplex(row) for row in face_data.simplices])

            assert_equal(boundary_set, face_set)
Exemplo n.º 2
0
def test_faces():
    """check whether faces are correct"""
    for mesh in meshes.itervalues():
        sc = simplicial_complex(mesh)

        for face_data,cell_data in zip(sc[:-1],sc[1:]):
            #compute all faces and store in a set

            boundary_set = set()
            for row in cell_data.simplices:
                boundary_set.update(simplex(row).boundary())

            face_set = set([simplex(row) for row in face_data.simplices])

            assert_equal(boundary_set, face_set)
Exemplo n.º 3
0
    def test_simple(self):
        V = array([[0,0],[1,0],[0,1]])
        S = array([[0,1,2]])

        sc = simplicial_complex((V,S))

        rows,cols = massmatrix_rowcols(sc,0)

        assert_equal(rows,array([0,0,0,1,1,1,2,2,2]))
        assert_equal(cols,array([0,1,2,0,1,2,0,1,2]))


        rows,cols = massmatrix_rowcols(sc,1)

        edges = [simplex(x) for x in combinations(range(3),2)]
        edge0 = sc[1].simplex_to_index[edges[0]]
        edge1 = sc[1].simplex_to_index[edges[1]]
        edge2 = sc[1].simplex_to_index[edges[2]]

        assert_equal(rows,array([edge0,edge0,edge0,edge1,edge1,edge1,edge2,edge2,edge2]))
        assert_equal(cols,array([edge0,edge1,edge2,edge0,edge1,edge2,edge0,edge1,edge2]))


        rows,cols = massmatrix_rowcols(sc,2)

        assert_equal(rows,array([0]))
        assert_equal(cols,array([0]))
Exemplo n.º 4
0
    def test_simple(self):
        V = array([[0, 0], [1, 0], [0, 1]])
        S = array([[0, 1, 2]])

        sc = simplicial_complex((V, S))

        rows, cols = massmatrix_rowcols(sc, 0)

        assert_equal(rows, array([0, 0, 0, 1, 1, 1, 2, 2, 2]))
        assert_equal(cols, array([0, 1, 2, 0, 1, 2, 0, 1, 2]))

        rows, cols = massmatrix_rowcols(sc, 1)

        edges = [simplex(x) for x in combinations(range(3), 2)]
        edge0 = sc[1].simplex_to_index[edges[0]]
        edge1 = sc[1].simplex_to_index[edges[1]]
        edge2 = sc[1].simplex_to_index[edges[2]]

        assert_equal(
            rows,
            array([
                edge0, edge0, edge0, edge1, edge1, edge1, edge2, edge2, edge2
            ]))
        assert_equal(
            cols,
            array([
                edge0, edge1, edge2, edge0, edge1, edge2, edge0, edge1, edge2
            ]))

        rows, cols = massmatrix_rowcols(sc, 2)

        assert_equal(rows, array([0]))
        assert_equal(cols, array([0]))
Exemplo n.º 5
0
def test_boundary():
    """check boundary operators (assumes correct faces)"""

    for mesh in meshes.itervalues():
        sc = simplicial_complex(mesh)
        assert_equal(sc[0].boundary.shape, (1, sc[0].simplices.shape[0]))
        assert_equal(sc[0].boundary.nnz, 0)

        for face_data, cell_data in zip(sc[:-1], sc[1:]):
            B = cell_data.boundary

            assert_equal(B.shape,
                         (face_data.num_simplices, cell_data.num_simplices))
            assert_equal(B.nnz, cell_data.num_simplices * (cell_data.dim + 1))

            for row, parity in zip(cell_data.simplices,
                                   cell_data.simplex_parity):
                s = simplex(row)

                s_index = cell_data.simplex_to_index[s]

                for f in s.boundary():
                    f_index = face_data.simplex_to_index[f]

                    assert_equal(B[f_index, s_index],
                                 (-1)**(f.parity ^ int(parity)))
Exemplo n.º 6
0
    def test_all(self):
        for k,v,s,o,expected in self.cases:
            sc = simplicial_complex((v,s))
            M = whitney_innerproduct(sc,k)
            M = M.todense()
            
            #Permute the matrix to coincide with the ordering of the known matrix
            permute = [sc[k].simplex_to_index[simplex(x)] for x in o]                                           

            M = M[permute,:][:,permute]
            
            assert_almost_equal(M,expected)
            
            #check whether matrix is S.P.D.
            self.assert_(alltrue(isreal(eigvals(M))))
            self.assert_(min(real(eigvals(M))) >= 0)
            assert_almost_equal(M,M.T)
Exemplo n.º 7
0
    def test_all(self):
        for k, v, s, o, expected in self.cases:
            sc = simplicial_complex((v, s))
            M = whitney_innerproduct(sc, k)
            M = M.todense()

            #Permute the matrix to coincide with the ordering of the known matrix
            permute = [sc[k].simplex_to_index[simplex(x)] for x in o]

            M = M[permute, :][:, permute]

            assert_almost_equal(M, expected)

            #check whether matrix is S.P.D.
            self.assert_(alltrue(isreal(eigvals(M))))
            self.assert_(min(real(eigvals(M))) >= 0)
            assert_almost_equal(M, M.T)
Exemplo n.º 8
0
def test_boundary():
    """check boundary operators (assumes correct faces)"""
    
    for mesh in meshes.itervalues():
        sc = simplicial_complex(mesh)
        assert_equal(sc[0].boundary.shape,(1,sc[0].simplices.shape[0]))
        assert_equal(sc[0].boundary.nnz,0)

        for face_data,cell_data in zip(sc[:-1],sc[1:]):
            B = cell_data.boundary
           
            assert_equal(B.shape,(face_data.num_simplices,cell_data.num_simplices))
            assert_equal(B.nnz,cell_data.num_simplices*(cell_data.dim+1))
            
            for row,parity in zip(cell_data.simplices,cell_data.simplex_parity):
                s = simplex(row)
                
                s_index = cell_data.simplex_to_index[s]
                
                for f in s.boundary():
                    f_index = face_data.simplex_to_index[f]

                    assert_equal(B[f_index,s_index],(-1)**(f.parity ^ int(parity)))