MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / randomly_ordered_mesh

Function randomly_ordered_mesh

python/test/unit/fem/test_dof_permuting.py:22–140  ·  view source on GitHub ↗

Create a randomly ordered mesh to use in the test.

(cell_type)

Source from the content-addressed store, hash-verified

20
21
22def randomly_ordered_mesh(cell_type):
23 """Create a randomly ordered mesh to use in the test."""
24 random.seed(6)
25
26 if cell_type == "triangle" or cell_type == "quadrilateral":
27 gdim = 2
28 elif cell_type == "tetrahedron" or cell_type == "hexahedron":
29 gdim = 3
30
31 domain = ufl.Mesh(element("Lagrange", cell_type, 1, shape=(gdim,), dtype=default_real_type))
32 # Create a mesh
33 if MPI.COMM_WORLD.rank == 0:
34 N = 6
35 if cell_type == "triangle" or cell_type == "quadrilateral":
36 temp_points = np.array([[x / 2, y / 2] for y in range(N) for x in range(N)])
37 elif cell_type == "tetrahedron" or cell_type == "hexahedron":
38 temp_points = np.array(
39 [[x / 2, y / 2, z / 2] for z in range(N) for y in range(N) for x in range(N)]
40 )
41
42 order = [i for i, j in enumerate(temp_points)]
43 random.shuffle(order)
44 points = np.zeros(temp_points.shape, dtype=default_real_type)
45 for i, j in enumerate(order):
46 points[j] = temp_points[i]
47
48 if cell_type == "triangle":
49 # Make triangle cells using the randomly ordered points
50 cells = []
51 for x in range(N - 1):
52 for y in range(N - 1):
53 a = N * y + x
54 # Adds two triangle cells:
55 # a+N -- a+N+1
56 # | / |
57 # | / |
58 # | / |
59 # a --- a+1
60 for cell in [[a, a + 1, a + N + 1], [a, a + N + 1, a + N]]:
61 cells.append([order[i] for i in cell])
62
63 elif cell_type == "quadrilateral":
64 cells = []
65 for x in range(N - 1):
66 for y in range(N - 1):
67 a = N * y + x
68 cell = [order[i] for i in [a, a + 1, a + N, a + N + 1]]
69 cells.append(cell)
70
71 elif cell_type == "tetrahedron":
72 cells = []
73 for x in range(N - 1):
74 for y in range(N - 1):
75 for z in range(N - 1):
76 a = N**2 * z + N * y + x
77 for c in [
78 [a + N, a + N**2 + 1, a, a + 1],
79 [a + N, a + N**2 + 1, a + 1, a + N + 1],

Callers 1

test_dof_positionsFunction · 0.85

Calls 3

create_meshFunction · 0.90
MeshMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected