def test_compute_entity_collisions_tree_3d():

    references = [[
        set([18, 19, 20, 21, 22, 23, 42, 43, 44, 45, 46, 47]),
        set([0, 1, 2, 3, 4, 5, 24, 25, 26, 27, 28, 29])
    ], [set([7, 8, 30, 31, 32]),
        set([15, 16, 17, 39, 41])]]

    points = [Point(0.52, 0.51, 0.3), Point(0.9, -0.9, 0.3)]

    for i, point in enumerate(points):

        mesh_A = UnitCubeMesh(MPI.comm_world, 2, 2, 2)
        mesh_B = UnitCubeMesh(MPI.comm_world, 2, 2, 2)

        bgeom = mesh_B.geometry.points
        bgeom += point.array()

        tree_A = BoundingBoxTree(3)
        tree_A.build_mesh(mesh_A, 3)

        tree_B = BoundingBoxTree(3)
        tree_B.build_mesh(mesh_B, 3)

        entities_A, entities_B = tree_A.compute_entity_collisions_bb_mesh(
            tree_B, mesh_A, mesh_B)

        assert set(entities_A) == references[i][0]
        assert set(entities_B) == references[i][1]
Пример #2
0
def test_compute_entity_collisions_tree_3d():

    references = [[set([18, 19, 20, 21, 22, 23, 42, 43, 44, 45, 46, 47]),
                    set([0, 1, 2, 3, 4, 5, 24, 25, 26, 27, 28, 29])],
                  [set([7, 8, 30, 31, 32]),
                    set([15, 16, 17, 39, 41])]]

    points = [Point(0.52, 0.51, 0.3), Point(0.9, -0.9, 0.3)]

    for i, point in enumerate(points):

        mesh_A = UnitCubeMesh(2, 2, 2)
        mesh_B = UnitCubeMesh(2, 2, 2)

        mesh_B.translate(point)

        tree_A = BoundingBoxTree()
        tree_A.build(mesh_A)

        tree_B = BoundingBoxTree()
        tree_B.build(mesh_B)

        entities_A, entities_B = tree_A.compute_entity_collisions(tree_B)

        assert set(entities_A) == references[i][0]
        assert set(entities_B) == references[i][1]
Пример #3
0
def test_meshpool_base_functionality(dim):

    if dim == 2:
        mesh1 = UnitSquareMesh(6, 6)
        mesh2 = UnitSquareMesh(6, 6)
        mesh3 = UnitSquareMesh(6, 6)
        mesh4 = UnitSquareMesh(7, 7)
    elif dim == 3:
        mesh1 = UnitCubeMesh(6, 6, 6)
        mesh2 = UnitCubeMesh(6, 6, 6)
        mesh3 = UnitCubeMesh(6, 6, 6)
        mesh4 = UnitCubeMesh(7, 7, 7)

    mp = argmin(norm(mesh3.coordinates() - array([0.5] * dim), axis=1))
    mesh3.coordinates()[mp, :] += 0.00001

    mesh1 = MeshPool(mesh1)
    mesh2 = MeshPool(mesh2)
    mesh3 = MeshPool(mesh3)
    mesh4 = MeshPool(mesh4)

    assert mesh1.id() == mesh2.id(), "1!=2"
    assert mesh1.id() != mesh3.id(), "1==3"
    assert mesh1.id() != mesh4.id(), "1==4"
    assert mesh3.id() != mesh4.id(), "3==4"

    # FIXME: While weak referencing meshes don't work, we can not run the following tests
    """
Пример #4
0
def test_taylor_hood_cube():
    pytest.xfail("Problem with Mixed Function Spaces")
    meshc = UnitCubeMesh(MPI.comm_world, 2, 2, 2)
    meshf = UnitCubeMesh(MPI.comm_world, 3, 4, 5)

    Ve = VectorElement("CG", meshc.ufl_cell(), 2)
    Qe = FiniteElement("CG", meshc.ufl_cell(), 1)
    Ze = MixedElement([Ve, Qe])

    Zc = FunctionSpace(meshc, Ze)
    Zf = FunctionSpace(meshf, Ze)

    def z(values, x):
        values[:, 0] = x[:, 0] * x[:, 1]
        values[:, 1] = x[:, 1] * x[:, 2]
        values[:, 2] = x[:, 2] * x[:, 0]
        values[:, 3] = x[:, 0] + 3.0 * x[:, 1] + x[:, 2]

    zc = interpolate(z, Zc)
    zf = interpolate(z, Zf)

    mat = PETScDMCollection.create_transfer_matrix(Zc, Zf)
    Zuc = Function(Zf)
    mat.mult(zc.vector, Zuc.vector)
    Zuc.vector.update_ghost_values()

    diff = Function(Zf)
    diff.assign(Zuc - zf)
    assert diff.vector.norm("l2") < 1.0e-12
Пример #5
0
def test_vector_p1_3d():
    meshc = UnitCubeMesh(MPI.comm_world, 2, 3, 4)
    meshf = UnitCubeMesh(MPI.comm_world, 3, 4, 5)

    Vc = VectorFunctionSpace(meshc, ("CG", 1))
    Vf = VectorFunctionSpace(meshf, ("CG", 1))

    def u(x):
        values0 = x[:, 0] + 2.0 * x[:, 1]
        values1 = 4.0 * x[:, 0]
        values2 = 3.0 * x[:, 2] + x[:, 0]
        return np.stack([values0, values1, values2], axis=1)

    uc, uf = Function(Vc), Function(Vf)
    uc.interpolate(u)
    uf.interpolate(u)

    mat = PETScDMCollection.create_transfer_matrix(Vc._cpp_object,
                                                   Vf._cpp_object)
    Vuc = Function(Vf)
    mat.mult(uc.vector, Vuc.vector)

    diff = Vuc.vector
    diff.axpy(-1, uf.vector)
    assert diff.norm() < 1.0e-12
def test_compute_collisions_tree_3d():

    references = [[
        set([18, 19, 20, 21, 22, 23, 42, 43, 44, 45, 46, 47]),
        set([0, 1, 2, 3, 4, 5, 24, 25, 26, 27, 28, 29])
    ],
                  [
                      set([6, 7, 8, 9, 10, 11, 30, 31, 32, 33, 34, 35]),
                      set([12, 13, 14, 15, 16, 17, 36, 37, 38, 39, 40, 41])
                  ]]

    points = [numpy.array([0.52, 0.51, 0.3]), numpy.array([0.9, -0.9, 0.3])]

    for i, point in enumerate(points):

        mesh_A = UnitCubeMesh(MPI.comm_world, 2, 2, 2)
        mesh_B = UnitCubeMesh(MPI.comm_world, 2, 2, 2)

        bgeom = mesh_B.geometry.points
        bgeom += point

        tree_A = BoundingBoxTree(mesh_A, mesh_A.topology.dim)
        tree_B = BoundingBoxTree(mesh_B, mesh_B.topology.dim)

        entities_A, entities_B = tree_A.compute_collisions_bb(tree_B)

        assert set(entities_A) == references[i][0]
        assert set(entities_B) == references[i][1]
Пример #7
0
def test_taylor_hood_cube():
    pytest.xfail("Problem with Mixed Function Spaces")
    meshc = UnitCubeMesh(MPI.comm_world, 2, 2, 2)
    meshf = UnitCubeMesh(MPI.comm_world, 3, 4, 5)

    Ve = VectorElement("CG", meshc.ufl_cell(), 2)
    Qe = FiniteElement("CG", meshc.ufl_cell(), 1)
    Ze = MixedElement([Ve, Qe])

    Zc = FunctionSpace(meshc, Ze)
    Zf = FunctionSpace(meshf, Ze)

    z = Expression(
        ("x[0]*x[1]", "x[1]*x[2]", "x[2]*x[0]", "x[0] + 3*x[1] + x[2]"),
        degree=2)
    zc = interpolate(z, Zc)
    zf = interpolate(z, Zf)

    mat = PETScDMCollection.create_transfer_matrix(Zc, Zf)
    Zuc = Function(Zf)
    mat.mult(zc.vector(), Zuc.vector())
    Zuc.vector().update_ghost_values()

    diff = Function(Zf)
    diff.assign(Zuc - zf)
    assert diff.vector().norm("l2") < 1.0e-12
Пример #8
0
    def test_compute_collisions_tree_3d(self):

        references = [[set([18, 19, 20, 21, 22, 23, 42, 43, 44, 45, 46, 47]),
                       set([0, 1, 2, 3, 4, 5, 24, 25, 26, 27, 28, 29])],
                      [set([6, 7, 8, 9, 10, 11, 30, 31, 32, 33, 34, 35]),
                       set([12, 13, 14, 15, 16, 17, 36, 37, 38, 39, 40, 41])]]

        points = [Point(0.52, 0.51, 0.3), Point(0.9, -0.9, 0.3)]

        for i, point in enumerate(points):

            mesh_A = UnitCubeMesh(2, 2, 2)
            mesh_B = UnitCubeMesh(2, 2, 2)

            mesh_B.translate(point)

            tree_A = BoundingBoxTree()
            tree_A.build(mesh_A)

            tree_B = BoundingBoxTree()
            tree_B.build(mesh_B)

            entities_A, entities_B = tree_A.compute_collisions(tree_B)

            if MPI.size(mesh_A.mpi_comm()) == 1:
                self.assertEqual(set(entities_A), references[i][0])
                self.assertEqual(set(entities_B), references[i][1])
Пример #9
0
def test_vector_p1_3d():
    meshc = UnitCubeMesh(MPI.comm_world, 2, 3, 4)
    meshf = UnitCubeMesh(MPI.comm_world, 3, 4, 5)

    Vc = VectorFunctionSpace(meshc, ("CG", 1))
    Vf = VectorFunctionSpace(meshf, ("CG", 1))

    @function.expression.numba_eval
    def expr_eval(values, x, cell_idx):
        values[:, 0] = x[:, 0] + 2.0 * x[:, 1]
        values[:, 1] = 4.0 * x[:, 0]
        values[:, 2] = 3.0 * x[:, 2] + x[:, 0]

    u = Expression(expr_eval, shape=(3, ))
    uc = interpolate(u, Vc)
    uf = interpolate(u, Vf)

    mat = PETScDMCollection.create_transfer_matrix(Vc._cpp_object,
                                                   Vf._cpp_object)
    Vuc = Function(Vf)
    mat.mult(uc.vector(), Vuc.vector())

    diff = Vuc.vector()
    diff.axpy(-1, uf.vector())
    assert diff.norm() < 1.0e-12
Пример #10
0
def test_scalar_p1_scaled_mesh():
    # Make coarse mesh smaller than fine mesh
    meshc = UnitCubeMesh(MPI.comm_world, 2, 2, 2)
    meshc.geometry.points *= 0.9

    meshf = UnitCubeMesh(MPI.comm_world, 3, 4, 5)

    Vc = FunctionSpace(meshc, "CG", 1)
    Vf = FunctionSpace(meshf, "CG", 1)

    u = Expression("x[0] + 2*x[1] + 3*x[2]", degree=1)
    uc = interpolate(u, Vc)
    uf = interpolate(u, Vf)

    mat = PETScDMCollection.create_transfer_matrix(Vc, Vf).mat()
    Vuc = Function(Vf)
    mat.mult(uc.vector().vec(), Vuc.vector().vec())

    diff = Vuc.vector()
    diff.vec().axpy(-1, uf.vector().vec())

    assert diff.norm(Norm.l2) < 1.0e-12

    # Now make coarse mesh larger than fine mesh
    meshc.geometry.points *= 1.5

    uc = interpolate(u, Vc)

    mat = PETScDMCollection.create_transfer_matrix(Vc, Vf).mat()
    mat.mult(uc.vector().vec(), Vuc.vector().vec())

    diff = Vuc.vector()
    diff.vec().axpy(-1, uf.vector().vec())

    assert diff.norm(Norm.l2) < 1.0e-12
Пример #11
0
def test_compute_entity_collisions_3d():
    reference = set([876, 877, 878, 879, 880, 881])
    p = numpy.array([0.3, 0.3, 0.3])
    mesh = UnitCubeMesh(MPI.comm_world, 8, 8, 8)
    tree = BoundingBoxTree(mesh, mesh.topology.dim)
    entities = tree.compute_entity_collisions_mesh(p, mesh)
    assert set(entities) == reference
Пример #12
0
def test_save_mesh_value_collection(tempdir, encoding, data_type):
    dtype_str, dtype = data_type
    mesh = UnitCubeMesh(MPI.comm_world, 4, 4, 4)
    tdim = mesh.topology.dim
    meshfn = MeshFunction(dtype_str, mesh, mesh.topology.dim, False)
    meshfn.rename("volume_marker")
    for c in Cells(mesh):
        if c.midpoint()[1] > 0.1:
            meshfn[c] = dtype(1)
        if c.midpoint()[1] > 0.9:
            meshfn[c] = dtype(2)

    for mvc_dim in range(0, tdim + 1):
        mvc = MeshValueCollection(dtype_str, mesh, mvc_dim)
        tag = "dim_%d_marker" % mvc_dim
        mvc.rename(tag)
        mesh.init(mvc_dim, tdim)
        for e in MeshEntities(mesh, mvc_dim):
            if (e.midpoint()[0] > 0.5):
                mvc.set_value(e.index(), dtype(1))

        filename = os.path.join(tempdir, "mvc_%d.xdmf" % mvc_dim)

        with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as xdmf:
            xdmf.write(meshfn)
            xdmf.write(mvc)

        with XDMFFile(mesh.mpi_comm(), filename) as xdmf:
            read_function = getattr(xdmf, "read_mvc_" + dtype_str)
            mvc = read_function(mesh, tag)
Пример #13
0
def test_save_3D_facet_function(tempdir, encoding, data_type):
    dtype_str, dtype = data_type
    mesh = UnitCubeMesh(MPI.comm_world, 4, 4, 4)
    mf = MeshFunction(dtype_str, mesh, mesh.topology.dim - 1, 0)
    mf.rename("facets")

    if (MPI.size(mesh.mpi_comm()) == 1):
        for facet in Facets(mesh):
            mf[facet] = dtype(facet.index())
    else:
        for facet in Facets(mesh):
            mf[facet] = dtype(facet.global_index())
    filename = os.path.join(tempdir, "mf_facet_3D_%s.xdmf" % dtype_str)

    with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as xdmf:
        xdmf.write(mf)

    with XDMFFile(mesh.mpi_comm(), filename) as xdmf:
        read_function = getattr(xdmf, "read_mf_" + dtype_str)
        mf_in = read_function(mesh, "facets")

    diff = 0
    for facet in Facets(mesh):
        diff += (mf_in[facet] - mf[facet])
    assert diff == 0
Пример #14
0
def test_facet_iterators():
    """Iterate over facets"""
    mesh = UnitCubeMesh(MPI.comm_world, 5, 5, 5)
    n = 0
    for f in Facets(mesh):
        n += 1
    assert n == mesh.num_entities(mesh.topology.dim - 1)
Пример #15
0
def test_radius_ratio_tetrahedron():

    # Create mesh and compute ratios
    mesh = UnitCubeMesh(MPI.comm_world, 14, 14, 14)
    ratios = MeshQuality.radius_ratios(mesh)
    for c in Cells(mesh):
        assert round(ratios[c] - 0.717438935214, 7) == 0
Пример #16
0
def test_facet_iterators():
    "Iterate over facets"
    mesh = UnitCubeMesh(MPI.comm_world, 5, 5, 5)
    n = 0
    for f in Facets(mesh):
        n += 1
    assert n == mesh.num_facets()
Пример #17
0
def test_face_iterator():
    "Iterate over faces"

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

    # Test connectivity
    cons = [(i, mesh.topology.connectivity(2, 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, f in enumerate(Faces(mesh)):
        n += 1
        for j, con in cons:
            assert numpy.all(con(i) == f.entities(j))

    assert n == mesh.num_entities(2)
Пример #18
0
def imgseq2funvec(img: np.array) -> np.array:
    """Takes a 3D array and returns an array suited to assign to piecewise
    linear approximation on a triangle grid.

    Each pixel corresponds to one vertex of a triangle mesh.

    Args:
        img (np.array): The input array.

    Returns:
        np.array: A vector.

    """
    # Create mesh.
    [m, n, o] = img.shape
    mesh = UnitCubeMesh(m-1, n-1, o-1)
    mc = mesh.coordinates().reshape((-1, 3))

    # Evaluate function at vertices.
    hx, hy, hz = 1./(m-1), 1./(n-1), 1./(o-1)
    x = np.array(np.round(mc[:, 0]/hx), dtype=int)
    y = np.array(np.round(mc[:, 1]/hy), dtype=int)
    z = np.array(np.round(mc[:, 2]/hz), dtype=int)
    fv = img[x, y, z]

    # Create function space.
    V = FunctionSpace(mesh, 'CG', 1)

    # Map pixel values to vertices.
    d2v = dof_to_vertex_map(V)
    return fv[d2v]
Пример #19
0
def test_compute_first_entity_collision_3d():
    reference = [876, 877, 878, 879, 880, 881]
    p = numpy.array([0.3, 0.3, 0.3])
    mesh = UnitCubeMesh(MPI.comm_world, 8, 8, 8)
    tree = BoundingBoxTree(mesh, mesh.topology.dim)
    first = tree.compute_first_entity_collision(p, mesh)
    assert first in reference
Пример #20
0
def test_save_3d_tensor(tempdir, encoding):
    filename = os.path.join(tempdir, "u3t.xdmf")
    mesh = UnitCubeMesh(MPI.comm_world, 4, 4, 4)
    u = Function(TensorFunctionSpace(mesh, ("Lagrange", 2)))
    u.vector.set(1.0 + (1j if has_petsc_complex else 0))
    with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as file:
        file.write(u)
Пример #21
0
def test_radius_ratio_min_radius_ratio_max():
    mesh1d = UnitIntervalMesh(MPI.comm_self, 4)
    x = mesh1d.geometry.points
    x[4] = mesh1d.geometry.points[3]

    # Create 2D mesh with one equilateral triangle
    mesh2d = RectangleMesh(
        MPI.comm_world,
        [numpy.array([0.0, 0.0, 0.0]),
         numpy.array([1.0, 1.0, 0.0])], [1, 1], CellType.Type.triangle,
        cpp.mesh.GhostMode.none, 'left')
    x = mesh2d.geometry.points
    x[3, :2] += 0.5 * (sqrt(3.0) - 1.0)

    # Create 3D mesh with regular tetrahedron and degenerate cells
    mesh3d = UnitCubeMesh(MPI.comm_self, 1, 1, 1)
    x = mesh3d.geometry.points
    x[6][0] = 1.0
    x[3][1] = 0.0
    rmin, rmax = MeshQuality.radius_ratio_min_max(mesh1d)
    assert round(rmin - 0.0, 7) == 0
    assert round(rmax - 1.0, 7) == 0

    rmin, rmax = MeshQuality.radius_ratio_min_max(mesh2d)
    assert round(rmin - 2.0 * sqrt(2.0) / (2.0 + sqrt(2.0)), 7) == 0
    assert round(rmax - 1.0, 7) == 0

    rmin, rmax = MeshQuality.radius_ratio_min_max(mesh3d)
    assert round(rmin - 0.0, 7) == 0
    assert round(rmax - 1.0, 7) == 0
Пример #22
0
def test_UnitCubeMeshDistributed():
    """Create mesh of unit cube."""
    mesh = UnitCubeMesh(MPI.comm_world, 5, 7, 9)
    assert mesh.num_entities_global(0) == 480
    assert mesh.num_entities_global(3) == 1890
    assert mesh.geometry.dim == 3
    assert MPI.sum(mesh.mpi_comm(), mesh.topology.ghost_offset(0)) == 480
Пример #23
0
def test_save_mesh_value_collection(tempdir, encoding, data_type):
    dtype_str, dtype = data_type
    mesh = UnitCubeMesh(MPI.comm_world, 4, 4, 4)
    tdim = mesh.topology.dim
    meshfn = MeshFunction(dtype_str, mesh, mesh.topology.dim, False)
    meshfn.name = "volume_marker"
    mp = cpp.mesh.midpoints(mesh, tdim, range(mesh.num_entities(tdim)))
    for i in range(mesh.num_cells()):
        if mp[i, 1] > 0.1:
            meshfn.values[i] = 1
        if mp[i, 1] > 0.9:
            meshfn.values[i] = 2

    for mvc_dim in range(0, tdim + 1):
        mvc = MeshValueCollection(dtype_str, mesh, mvc_dim)
        tag = "dim_{}_marker".format(mvc_dim)
        mvc.name = tag
        mesh.create_connectivity(mvc_dim, tdim)
        mp = cpp.mesh.midpoints(mesh, mvc_dim,
                                range(mesh.num_entities(mvc_dim)))
        for e in range(mesh.num_entities(mvc_dim)):
            if (mp[e, 0] > 0.5):
                mvc.set_value(e, dtype(1))

        filename = os.path.join(tempdir, "mvc_{}.xdmf".format(mvc_dim))

        with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as xdmf:
            xdmf.write(meshfn)
            xdmf.write(mvc)

        with XDMFFile(mesh.mpi_comm(), filename) as xdmf:
            read_function = getattr(xdmf, "read_mvc_" + dtype_str)
            mvc = read_function(mesh, tag)
Пример #24
0
def test_save_and_read_mesh_value_collection(tempdir):
    ndiv = 2
    filename = os.path.join(tempdir, "mesh_value_collection.h5")
    mesh = UnitCubeMesh(MPI.comm_world, ndiv, ndiv, ndiv)

    def point2list(p):
        return [p[0], p[1], p[2]]

    # write to file
    with HDF5File(mesh.mpi_comm(), filename, 'w') as f:
        for dim in range(mesh.topology.dim):
            mvc = MeshValueCollection("size_t", mesh, dim)
            mesh.create_entities(dim)
            for e in MeshEntities(mesh, dim):
                # this can be easily computed to the check the value
                val = int(ndiv * sum(point2list(e.midpoint()))) + 1
                mvc.set_value(e.index(), val)
            f.write(mvc, "/mesh_value_collection_{}".format(dim))

    # read from file
    with HDF5File(mesh.mpi_comm(), filename, 'r') as f:
        for dim in range(mesh.topology.dim):
            mvc = f.read_mvc_size_t(mesh,
                                    "/mesh_value_collection_{}".format(dim))
            # check the values
            for (cell, lidx), val in mvc.values().items():
                eidx = Cell(mesh, cell).entities(dim)[lidx]
                mid = point2list(MeshEntity(mesh, dim, eidx).midpoint())
                assert val == int(ndiv * sum(mid)) + 1
Пример #25
0
def mesh_factory(tdim, n):
    if tdim == 1:
        return UnitIntervalMesh(MPI.comm_world, n)
    elif tdim == 2:
        return UnitSquareMesh(MPI.comm_world, n, n)
    elif tdim == 3:
        return UnitCubeMesh(MPI.comm_world, n, n, n)
Пример #26
0
def test_edge_iterators():
    """Iterate over edges"""

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

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

    # Test writability
    for i, connectivity in connectivities:

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

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

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

    assert n == mesh.num_entities(1)
Пример #27
0
def mk_scheme(N, Vname, Vorder, cpp_expr, expr_args, convection_inp, dim=2, comm=None):
    if comm is None:
        comm = MPI.comm_world

    parameters['ghost_mode'] = 'shared_vertex'
    if dim == 2:
        mesh = UnitSquareMesh(comm, N, N)
    else:
        mesh = UnitCubeMesh(comm, N, N, N)

    V = FunctionSpace(mesh, Vname, Vorder)
    C = Function(V)
    e = Expression(cpp_expr, element=V.ufl_element(), **expr_args)
    C.interpolate(e)

    D = Function(V)
    D.assign(C)

    sim = Simulation()
    sim.set_mesh(mesh)
    sim.data['constrained_domain'] = None
    sim.data['C'] = C
    for key, value in convection_inp.items():
        sim.input.set_value('convection/C/%s' % key, value)

    scheme_name = convection_inp['convection_scheme']
    return get_convection_scheme(scheme_name)(sim, 'C')
Пример #28
0
def test_compute_first_collision_3d():

    # FIXME: This test should not use facet indices as there are no guarantees
    # on how DOLFIN numbers facets

    reference = {
        1: [1364],
        2: [1967, 1968, 1970, 1972, 1974, 1976],
        3: [876, 877, 878, 879, 880, 881]
    }

    p = Point(0.3, 0.3, 0.3)
    mesh = UnitCubeMesh(MPI.comm_world, 8, 8, 8)
    for dim in range(1, 4):
        tree = BoundingBoxTree(mesh.geometry.dim)
        tree.build_mesh(mesh, dim)
        first = tree.compute_first_collision(p)

        # FIXME: Face and test is excluded because it mistakingly
        # relies in the facet indices
        tdim = mesh.topology.dim
        if dim != tdim - 1 and dim != tdim - 2:
            assert first in reference[dim]

    # FIXME: remove after Mesh is wrapped in Python
    tree_cpp = mesh.bounding_box_tree()
    tree = BoundingBoxTree()
    tree._cpp_object = tree_cpp

    first = tree.compute_first_collision(p)
    assert first in reference[mesh.topology.dim]
Пример #29
0
def test_save_and_read_meshfunction_3D(tempdir):
    filename = os.path.join(tempdir, "meshfn-3d.h5")

    # Write to file
    mesh = UnitCubeMesh(MPI.comm_world, 2, 2, 2)
    mf_file = HDF5File(mesh.mpi_comm(), filename, "w")

    # save meshfuns to compare when reading back
    meshfunctions = []
    for i in range(0, 4):
        mf = MeshFunction('double', mesh, i, 0.0)
        # NB choose a value to set which will be the same
        # on every process for each entity
        for cell in MeshEntities(mesh, i):
            mf[cell] = cell.midpoint()[0]
        meshfunctions.append(mf)
        mf_file.write(mf, "/meshfunction/group/%d/meshfun" % i)
    mf_file.close()

    # Read back from file
    mf_file = HDF5File(mesh.mpi_comm(), filename, "r")
    for i in range(0, 4):
        mf2 = mf_file.read_mf_double(mesh,
                                     "/meshfunction/group/%d/meshfun" % i)
        for cell in MeshEntities(mesh, i):
            assert meshfunctions[i][cell] == mf2[cell]
    mf_file.close()
def test_compute_first_collision_3d():

    # FIXME: This test should not use facet indices as there are no guarantees
    # on how DOLFIN numbers facets

    reference = {
        1: [1364],
        2: [1967, 1968, 1970, 1972, 1974, 1976],
        3: [876, 877, 878, 879, 880, 881]
    }

    p = Point(0.3, 0.3, 0.3)
    mesh = UnitCubeMesh(8, 8, 8)
    for dim in range(1, 4):
        tree = BoundingBoxTree()
        tree.build(mesh, dim)
        first = tree.compute_first_collision(p)

        # FIXME: Face and test is excluded because it mistakingly
        # relies in the facet indices
        tdim = mesh.topology().dim()
        if dim != tdim - 1 and dim != tdim - 2:
            assert first in reference[dim]

    tree = mesh.bounding_box_tree()
    first = tree.compute_first_collision(p)
    assert first in reference[mesh.topology().dim()]