Exemple #1
0
def test_3DEdgeLength(cube):
    """Iterate over edges and sum length."""
    length = 0.0
    cube.init(1)
    for e in Edges(cube):
        length += e.length()
    assert round(length - 278.58049080280125053832, 7) == 0
Exemple #2
0
def test_edge_iterators():
    "Iterate over edges"

    mesh = UnitCubeMesh(MPI.comm_world, 5, 5, 5)
    for i in range(4):
        mesh.init(1, i)

    # Test connectivity
    cons = [(i, mesh.topology.connectivity(1, i)) for i in range(4)]

    # Test writability
    for i, con in cons:

        def assign(con, i):
            con(i)[0] = 1

        with pytest.raises(Exception):
            assign(con, i)

    n = 0
    for i, e in enumerate(Edges(mesh)):
        n += 1
        for j, con in cons:
            assert numpy.all(con(i) == e.entities(j))

    assert n == mesh.num_entities(1)
Exemple #3
0
def test_2DEdgeLength(square):
    """Iterate over edges and sum length."""
    length = 0.0
    square.init(1)
    print(square.num_entities(1))
    for e in Edges(square):
        length += e.length()
    assert round(length - 19.07106781186544708362, 7) == 0
Exemple #4
0
def test_save_3D_edge_function(tempdir, encoding, data_type):
    dtype_str, dtype = data_type
    mesh = UnitCubeMesh(MPI.comm_world, 4, 4, 4)
    mf = MeshFunction(dtype_str, mesh, 1, 0)
    mf.rename("edges")
    for edge in Edges(mesh):
        mf[edge] = dtype(edge.index())

    filename = os.path.join(tempdir, "mf_edge_3D_%s.xdmf" % dtype_str)
    with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as file:
        file.write(mf)
Exemple #5
0
def test_EdgeDot(meshes):
    """Iterate over edges compute dot product with ."""
    meshes.init(1)
    for e in Edges(meshes):
        dot = e.dot(e) / (e.length()**2)
        assert round(dot - 1.0, 7) == 0