def test_numbering_two_d_P2BxP1(): # # Top view Side view # x---x # | | # 2 5 x---x---x---x # /|\ /| | | | # / | \ / | x---x---x # / | \ / | | | # 0---1---3---4 x---x dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [3, 4, 5]], [[0, 0], [1, 0], [1, 1], [2, 0], [3, 0], [3, 1]], COMM_WORLD) dm.markBoundaryFaces("Face Sets") mesh2d = Mesh(dm, reorder=False) extmesh = ExtrudedMesh(mesh2d, [[0, 2], [1, 1], [2, 1]], layer_height=1) U = FiniteElement("CG", triangle, 2) B = FiniteElement("B", triangle, 3) V = FiniteElement("CG", interval, 1) W = TensorProductElement(U + B, V) V = FunctionSpace(extmesh, W) assert V.dof_dset.size == 42 assert numpy.equal( V.cell_node_map().values, [[12, 13, 15, 16, 18, 19, 6, 7, 9, 10, 3, 4, 0, 1], [16, 17, 19, 20, 27, 28, 23, 24, 25, 26, 7, 8, 21, 22], [28, 29, 38, 39, 40, 41, 34, 35, 36, 37, 32, 33, 30, 31]]).all() bc_bottom = DirichletBC(V, 0, "bottom") bc_top = DirichletBC(V, 0, "top") assert numpy.equal(bc_bottom.nodes, [ 0, 3, 6, 7, 9, 12, 15, 16, 18, 19, 21, 23, 25, 27, 28, 30, 32, 34, 36, 38, 40 ]).all() assert numpy.equal( bc_top.nodes, [2, 5, 8, 11, 14, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35, 37, 39, 41 ]).all() bc_side = DirichletBC(V, 0, 1) assert numpy.equal(bc_side.nodes, [ 3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41 ]).all()
def test_numbering_two_d_P1(): # # Top view Side view # x---x # | | # 2 5 x---x---x---x # /|\ /| | | | # / | \ / | x---x---x # / | \ / | | | # 0---1---3---4 x---x dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [3, 4, 5]], [[0, 0], [1, 0], [1, 1], [2, 0], [3, 0], [3, 1]], COMM_WORLD) dm.markBoundaryFaces("Face Sets") mesh2d = Mesh(dm, reorder=False) extmesh = ExtrudedMesh(mesh2d, [[0, 2], [1, 1], [2, 1]], layer_height=1) V = FunctionSpace(extmesh, "CG", 1) assert V.dof_dset.size == 16 assert numpy.equal(V.cell_node_map().values, [[0, 1, 3, 4, 6, 7], [4, 5, 7, 8, 9, 10], [10, 11, 12, 13, 14, 15]]).all() bc_bottom = DirichletBC(V, 0, "bottom") bc_top = DirichletBC(V, 0, "top") assert numpy.equal(bc_bottom.nodes, [0, 3, 4, 6, 7, 9, 10, 12, 14]).all() assert numpy.equal(bc_top.nodes, [2, 5, 8, 10, 11, 13, 15]).all() bc_side = DirichletBC(V, 0, 1) assert numpy.equal(bc_side.nodes, numpy.arange(16)).all()
def test_bc_nodes_cover_ghost_dofs(): # 4 # +----+----+ # |\ 1 | 2 / # 1 | \ | / 2 # | \ | / # | 0 \|/ # +----+ # 3 # Rank 0 gets cell 0 # Rank 1 gets cells 1 & 2 dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [1, 3, 4]], [[0, 0], [1, 0], [0, 1], [0.5, 1], [1, 1]], COMM_WORLD) dm.createLabel("Face Sets") if dm.comm.rank == 0: dm.setLabelValue("Face Sets", 14, 2) dm.setLabelValue("Face Sets", 13, 4) dm.setLabelValue("Face Sets", 11, 4) dm.setLabelValue("Face Sets", 10, 1) dm.setLabelValue("Face Sets", 8, 3) if dm.comm.rank == 0: sizes = np.asarray([1, 2], dtype=IntType) points = np.asarray([0, 1, 2], dtype=IntType) else: sizes = None points = None mesh = Mesh(dm, reorder=False, distribution_parameters={"partition": (sizes, points)}) V = FunctionSpace(mesh, "CG", 1) bc = DirichletBC(V, 0, 2) if mesh.comm.rank == 0: assert np.allclose(bc.nodes, [1]) else: assert np.allclose(bc.nodes, [1, 2])
def test_two_d_mesh_volume(): dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [3, 4, 5], [1, 3, 6]], [[0, 0], [1, 0], [1, 1], [2, 0], [3, 0], [3, 1], [2, -1]], COMM_WORLD) mesh2d = Mesh(dm, reorder=False) extmesh = ExtrudedMesh(mesh2d, [[0, 2], [1, 2], [3, 1], [2, 1]], layer_height=1) assert numpy.allclose(assemble(1*dx(domain=extmesh)), 0.5*(2 + 2 + 1 + 1))
def test_layer_extents_parallel_vertex_owners(): dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [2, 3, 4]], [[0, 0], [1, 0], [0, 1], [1, 1], [2, 0]], comm=COMM_WORLD) if COMM_WORLD.rank == 0: sizes = numpy.asarray([1, 1, 1], dtype=IntType) points = numpy.asarray([0, 1, 2], dtype=IntType) else: sizes = None points = None mesh = Mesh(dm, reorder=False, distribution_parameters={"partition": (sizes, points)}) V = FunctionSpace(mesh, "DG", 0) x, _ = SpatialCoordinate(mesh) selector = interpolate(x, V) layers = numpy.empty((mesh.num_cells(), 2), dtype=IntType) data = selector.dat.data_ro_with_halos.real for cell in V.cell_node_map().values_with_halo: if data[cell] < 0.5: layers[cell, :] = [1, 1] else: layers[cell, :] = [0, 3] extmesh = ExtrudedMesh(mesh, layers=layers, layer_height=1) if mesh.comm.rank == 0: # Top view, plex points # 3--9--5 # |\ 1 | # | \ | # 7 8 10 # | \ | # | 0 \| # 2--6--4 expected = numpy.asarray( [ # cells [1, 3, 1, 3], [0, 4, 0, 4], # vertices [1, 3, 1, 3], [0, 4, 1, 3], [0, 4, 1, 3], [0, 4, 0, 4], # edges [1, 3, 1, 3], [1, 3, 1, 3], [0, 4, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4] ], dtype=IntType) elif mesh.comm.rank == 1: # Top view, plex points # 3--9--6 # |\ 0 |\ # | \ | \ # 11 8 12 13 # | \ | \ # | 1 \| 2 \ # 4--10-5--14-7 expected = numpy.asarray( [ # cells [0, 4, 0, 4], [1, 3, 1, 3], [0, 4, 0, 4], # vertices [0, 4, 1, 3], [1, 3, 1, 3], [0, 4, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4], # edges [0, 4, 1, 3], [0, 4, 0, 4], [1, 3, 1, 3], [1, 3, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 0, 4] ], dtype=IntType) elif mesh.comm.rank == 2: # Top view, plex points # 5--10-3 # \ 1 |\ # \ | \ # 9 6 7 # \ | \ # \| 0 \ # 2--8--4 expected = numpy.asarray( [ # cells [0, 4, 0, 4], [0, 4, 0, 4], # vertices [0, 4, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 1, 3], # edges [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 1, 3], [0, 4, 0, 4] ], dtype=IntType) assert numpy.equal(extmesh.layer_extents, expected).all() V = FunctionSpace(extmesh, "CG", 1) assert V.dof_dset.layout_vec.getSize() == 18
def test_numbering_two_d_bigger(): # # Top view, plex points # 6 9 # /|\ /| # / | \ / | # 13 | 14 18 | # / 12 \ / 17 # / 0 | 1 \ / 2 | # 4--11-5--15-7--16-8 # \ 3 | # \ 19 # 20 | # \ | # \| # 10 dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [3, 4, 5], [1, 3, 6]], [[0, 0], [1, 0], [1, 1], [2, 0], [3, 0], [3, 1], [2, -1]], COMM_WORLD) dm.createLabel("Face Sets") for faces, val in [ ((11, 13), 1), ((14, 20), 2), ((16, ), 3), ((17, 18, 19), 4), # This one is an interior face ((12, ), 5) ]: for face in faces: dm.setLabelValue("Face Sets", face, val) mesh2d = Mesh(dm, reorder=False) extmesh = ExtrudedMesh(mesh2d, [[0, 2], [1, 2], [3, 1], [2, 1]], layer_height=1) V = FunctionSpace(extmesh, "CG", 1) assert V.dof_dset.size == 21 assert numpy.equal( V.cell_node_map().values, [[0, 1, 3, 4, 7, 8], [4, 5, 8, 9, 11, 12], [13, 14, 15, 16, 17, 18], [5, 6, 12, 13, 19, 20]]).all() bc_bottom = DirichletBC(V, 0, "bottom") bc_top = DirichletBC(V, 0, "top") assert numpy.equal(bc_bottom.nodes, [0, 3, 4, 5, 7, 8, 11, 12, 13, 15, 17, 19]).all() assert numpy.equal(bc_top.nodes, [2, 5, 6, 9, 10, 13, 14, 16, 18, 20]).all() bc_side = DirichletBC(V, 0, "on_boundary") assert numpy.equal(bc_side.nodes, numpy.arange(21)).all() assert numpy.equal( DirichletBC(V, 0, 1).nodes, [0, 1, 2, 3, 4, 5, 7, 8, 9]).all() assert numpy.equal( DirichletBC(V, 0, 2).nodes, [5, 6, 8, 9, 10, 11, 12, 13, 19, 20]).all() assert numpy.equal(DirichletBC(V, 0, 3).nodes, [13, 14, 15, 16]).all() assert numpy.equal(DirichletBC(V, 0, 3).nodes, [13, 14, 15, 16]).all() assert numpy.equal( DirichletBC(V, 0, 4).nodes, [12, 13, 14, 15, 16, 17, 18, 19, 20]).all() # Interior face between base plex cells 0 and 1. assert numpy.equal(DirichletBC(V, 0, 5).nodes, [4, 5, 8, 9]).all()
def test_layer_extents_parallel_vertex_owners(): dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [2, 3, 4]], [[0, 0], [1, 0], [0, 1], [1, 1], [2, 0]], comm=COMM_WORLD) if COMM_WORLD.rank == 0: sizes = numpy.asarray([1, 1, 1], dtype=IntType) points = numpy.asarray([0, 1, 2], dtype=IntType) else: sizes = None points = None mesh = Mesh(dm, reorder=False, distribution_parameters={"partition": (sizes, points)}) V = FunctionSpace(mesh, "DG", 0) x, _ = SpatialCoordinate(mesh) selector = interpolate(x, V) layers = numpy.empty((mesh.num_cells(), 2), dtype=IntType) data = selector.dat.data_ro_with_halos for cell in V.cell_node_map().values_with_halo: if data[cell] < 0.5: layers[cell, :] = [1, 1] else: layers[cell, :] = [0, 3] extmesh = ExtrudedMesh(mesh, layers=layers, layer_height=1) if mesh.comm.rank == 0: # Top view, plex points # 3--9--5 # |\ 1 | # | \ | # 7 8 10 # | \ | # | 0 \| # 2--6--4 expected = numpy.asarray([ # cells [1, 3, 1, 3], [0, 4, 0, 4], # vertices [1, 3, 1, 3], [0, 4, 1, 3], [0, 4, 1, 3], [0, 4, 0, 4], # edges [1, 3, 1, 3], [1, 3, 1, 3], [0, 4, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4]], dtype=IntType) elif mesh.comm.rank == 1: # Top view, plex points # 3--9--6 # |\ 0 |\ # | \ | \ # 11 8 12 13 # | \ | \ # | 1 \| 2 \ # 4--10-5--14-7 expected = numpy.asarray([ # cells [0, 4, 0, 4], [1, 3, 1, 3], [0, 4, 0, 4], # vertices [0, 4, 1, 3], [1, 3, 1, 3], [0, 4, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4], # edges [0, 4, 1, 3], [0, 4, 0, 4], [1, 3, 1, 3], [1, 3, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 0, 4]], dtype=IntType) elif mesh.comm.rank == 2: # Top view, plex points # 5--10-3 # \ 1 |\ # \ | \ # 9 6 7 # \ | \ # \| 0 \ # 2--8--4 expected = numpy.asarray([ # cells [0, 4, 0, 4], [0, 4, 0, 4], # vertices [0, 4, 1, 3], [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 1, 3], # edges [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 0, 4], [0, 4, 1, 3], [0, 4, 0, 4]], dtype=IntType) assert numpy.equal(extmesh.layer_extents, expected).all() V = FunctionSpace(extmesh, "CG", 1) assert V.dof_dset.layout_vec.getSize() == 18
def test_numbering_two_d_bigger(bc_method): # # Top view, plex points # 6 9 # /|\ /| # / | \ / | # 13 | 14 18 | # / 12 \ / 17 # / 0 | 1 \ / 2 | # 4--11-5--15-7--16-8 # \ 3 | # \ 19 # 20 | # \ | # \| # 10 dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [3, 4, 5], [1, 3, 6]], [[0, 0], [1, 0], [1, 1], [2, 0], [3, 0], [3, 1], [2, -1]], COMM_WORLD) dm.createLabel("Face Sets") for faces, val in [((11, 13), 1), ((14, 20), 2), ((16, ), 3), ((17, 18, 19), 4)]: for face in faces: dm.setLabelValue("Face Sets", face, val) mesh2d = Mesh(dm, reorder=False) extmesh = ExtrudedMesh(mesh2d, [[0, 2], [1, 2], [3, 1], [2, 1]], layer_height=1) V = FunctionSpace(extmesh, "CG", 1) assert V.dof_dset.size == 21 assert numpy.equal(V.cell_node_map().values, [[0, 1, 3, 4, 7, 8], [4, 5, 8, 9, 11, 12], [13, 14, 15, 16, 17, 18], [5, 6, 12, 13, 19, 20]]).all() bc_bottom = DirichletBC(V, 0, "bottom", method=bc_method) bc_top = DirichletBC(V, 0, "top", method=bc_method) assert numpy.equal(bc_bottom.nodes, [0, 3, 4, 5, 7, 8, 11, 12, 13, 15, 17, 19]).all() assert numpy.equal(bc_top.nodes, [2, 5, 6, 9, 10, 13, 14, 16, 18, 20]).all() bc_side = DirichletBC(V, 0, "on_boundary", method=bc_method) assert numpy.equal(bc_side.nodes, numpy.arange(21)).all() assert numpy.equal(DirichletBC(V, 0, 1, method=bc_method).nodes, [0, 1, 2, 3, 4, 5, 7, 8, 9]).all() assert numpy.equal(DirichletBC(V, 0, 2, method=bc_method).nodes, [5, 6, 8, 9, 10, 11, 12, 13, 19, 20]).all() assert numpy.equal(DirichletBC(V, 0, 3, method=bc_method).nodes, [13, 14, 15, 16]).all() assert numpy.equal(DirichletBC(V, 0, 3, method=bc_method).nodes, [13, 14, 15, 16]).all() assert numpy.equal(DirichletBC(V, 0, 4, method=bc_method).nodes, [12, 13, 14, 15, 16, 17, 18, 19, 20]).all()
def test_numbering_two_d_P2BxP1(): # # Top view Side view # x---x # | | # 2 5 x---x---x---x # /|\ /| | | | # / | \ / | x---x---x # / | \ / | | | # 0---1---3---4 x---x dm = create_dm(2, [[0, 1, 2], [1, 2, 3], [3, 4, 5]], [[0, 0], [1, 0], [1, 1], [2, 0], [3, 0], [3, 1]], COMM_WORLD) dm.markBoundaryFaces("Face Sets") mesh2d = Mesh(dm, reorder=False) extmesh = ExtrudedMesh(mesh2d, [[0, 2], [1, 1], [2, 1]], layer_height=1) U = FiniteElement("CG", triangle, 2) B = FiniteElement("B", triangle, 3) V = FiniteElement("CG", interval, 1) W = TensorProductElement(U+B, V) V = FunctionSpace(extmesh, W) assert V.dof_dset.size == 42 assert numpy.equal(V.cell_node_map().values, [[12, 13, 15, 16, 18, 19, 6, 7, 9, 10, 3, 4, 0, 1], [16, 17, 19, 20, 27, 28, 23, 24, 25, 26, 7, 8, 21, 22], [28, 29, 38, 39, 40, 41, 34, 35, 36, 37, 32, 33, 30, 31]]).all() bc_bottom = DirichletBC(V, 0, "bottom") bc_top = DirichletBC(V, 0, "top") assert numpy.equal(bc_bottom.nodes, [0, 3, 6, 7, 9, 12, 15, 16, 18, 19, 21, 23, 25, 27, 28, 30, 32, 34, 36, 38, 40]).all() assert numpy.equal(bc_top.nodes, [2, 5, 8, 11, 14, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35, 37, 39, 41]).all() bc_side = DirichletBC(V, 0, 1) assert numpy.equal(bc_side.nodes, [3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41]).all()