forked from nschloe/meshio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gmsh.py
162 lines (142 loc) · 5.57 KB
/
test_gmsh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import copy
import os
from functools import partial
import numpy
import pytest
import helpers
import meshio
def gmsh_periodic():
mesh = copy.deepcopy(helpers.quad_mesh)
trns = [0] * 16 # just for io testing
mesh.gmsh_periodic = [
[0, (3, 1), None, [[2, 0]]],
[0, (4, 6), None, [[3, 5]]],
[1, (2, 1), trns, [[5, 0], [4, 1], [4, 2]]],
]
return mesh
@pytest.mark.parametrize(
"mesh",
[
helpers.line_mesh,
helpers.tri_mesh,
helpers.triangle6_mesh,
helpers.quad_mesh,
helpers.quad8_mesh,
# helpers.tri_quad_mesh,
helpers.tet_mesh,
helpers.tet10_mesh,
helpers.hex_mesh,
helpers.hex20_mesh,
helpers.add_point_data(helpers.tri_mesh, 1),
helpers.add_point_data(helpers.tri_mesh, 3),
helpers.add_point_data(helpers.tri_mesh, 9),
helpers.add_cell_data(helpers.tri_mesh, [("a", (), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (3,), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (9,), numpy.float64)]),
helpers.add_field_data(helpers.tri_mesh, [1, 2], int),
helpers.add_field_data(helpers.tet_mesh, [1, 3], int),
helpers.add_field_data(helpers.hex_mesh, [1, 3], int),
gmsh_periodic(),
],
)
@pytest.mark.parametrize("binary", [False, True])
def test_gmsh22(mesh, binary):
writer = partial(meshio.gmsh.write, fmt_version="2.2", binary=binary)
helpers.write_read(writer, meshio.gmsh.read, mesh, 1.0e-15)
@pytest.mark.parametrize(
"mesh",
[
helpers.tri_mesh,
helpers.triangle6_mesh,
helpers.quad_mesh,
helpers.quad8_mesh,
# helpers.tri_quad_mesh,
helpers.tet_mesh,
helpers.tet10_mesh,
helpers.hex_mesh,
helpers.hex20_mesh,
helpers.add_point_data(helpers.tri_mesh, 1),
helpers.add_point_data(helpers.tri_mesh, 3),
helpers.add_point_data(helpers.tri_mesh, 9),
helpers.add_cell_data(helpers.tri_mesh, [("a", (), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (3,), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (9,), numpy.float64)]),
helpers.add_field_data(helpers.tri_mesh, [1, 2], int),
helpers.add_field_data(helpers.tet_mesh, [1, 3], int),
helpers.add_field_data(helpers.hex_mesh, [1, 3], int),
],
)
@pytest.mark.parametrize("binary", [False, True])
def test_gmsh40(mesh, binary):
writer = partial(meshio.gmsh.write, fmt_version="4.0", binary=binary)
helpers.write_read(writer, meshio.gmsh.read, mesh, 1.0e-15)
@pytest.mark.parametrize(
"mesh",
[
helpers.tri_mesh,
helpers.triangle6_mesh,
helpers.quad_mesh,
helpers.quad8_mesh,
# helpers.tri_quad_mesh,
helpers.tet_mesh,
helpers.tet10_mesh,
helpers.hex_mesh,
helpers.hex20_mesh,
helpers.add_point_data(helpers.tri_mesh, 1),
helpers.add_point_data(helpers.tri_mesh, 3),
helpers.add_point_data(helpers.tri_mesh, 9),
helpers.add_cell_data(helpers.tri_mesh, [("a", (), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (3,), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (9,), numpy.float64)]),
helpers.add_field_data(helpers.tri_mesh, [1, 2], int),
helpers.add_field_data(helpers.tet_mesh, [1, 3], int),
helpers.add_field_data(helpers.hex_mesh, [1, 3], int),
gmsh_periodic(),
],
)
@pytest.mark.parametrize("binary", [False, True])
def test_gmsh41(mesh, binary):
writer = partial(meshio.gmsh.write, fmt_version="4.1", binary=binary)
helpers.write_read(writer, meshio.gmsh.read, mesh, 1.0e-15)
def test_generic_io():
helpers.generic_io("test.msh")
# With additional, insignificant suffix:
helpers.generic_io("test.0.msh")
@pytest.mark.parametrize(
"filename, ref_sum, ref_num_cells",
[("insulated-2.2.msh", 2.001762136876221, [21, 111])],
)
@pytest.mark.parametrize("binary", [False, True])
def test_reference_file(filename, ref_sum, ref_num_cells, binary):
this_dir = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(this_dir, "meshes", "msh", filename)
mesh = meshio.read(filename)
tol = 1.0e-2
s = mesh.points.sum()
assert abs(s - ref_sum) < tol * ref_sum
assert [c.type for c in mesh.cells] == ["line", "triangle"]
assert [len(c.data) for c in mesh.cells] == ref_num_cells
assert list(map(len, mesh.cell_data["gmsh:geometrical"])) == ref_num_cells
assert list(map(len, mesh.cell_data["gmsh:physical"])) == ref_num_cells
writer = partial(meshio.gmsh.write, fmt_version="2.2", binary=binary)
helpers.write_read(writer, meshio.gmsh.read, mesh, 1.0e-15)
@pytest.mark.parametrize(
"filename, ref_sum, ref_num_cells",
[("insulated-4.1.msh", 2.001762136876221, {"line": 21, "triangle": 111})],
)
def test_reference_file_readonly(filename, ref_sum, ref_num_cells):
this_dir = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(this_dir, "meshes", "msh", filename)
mesh = meshio.read(filename)
tol = 1.0e-2
s = mesh.points.sum()
assert abs(s - ref_sum) < tol * ref_sum
assert {k: len(v) for k, v in mesh.cells_dict.items()} == ref_num_cells
assert {
k: len(v) for k, v in mesh.cell_data_dict["gmsh:physical"].items()
} == ref_num_cells
num_cells = {k: 0 for k in ref_num_cells}
for vv in mesh.cell_sets_dict.values():
for k, v in vv.items():
num_cells[k] += len(v)
assert num_cells == ref_num_cells