forked from nschloe/meshio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_med.py
127 lines (102 loc) · 3.93 KB
/
test_med.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
import os
import numpy
import pytest
import helpers
import meshio
h5py = pytest.importorskip("h5py")
@pytest.mark.parametrize(
"mesh",
[
helpers.line_mesh,
helpers.tri_mesh_2d,
helpers.tri_mesh,
helpers.triangle6_mesh,
helpers.quad_mesh,
helpers.quad8_mesh,
helpers.quad_tri_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, 2),
helpers.add_point_data(helpers.tri_mesh, 3),
helpers.add_point_data(helpers.hex_mesh, 3),
helpers.add_cell_data(helpers.tri_mesh, [("a", (), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (2,), numpy.float64)]),
helpers.add_cell_data(helpers.tri_mesh, [("a", (3,), numpy.float64)]),
],
)
def test_io(mesh):
helpers.write_read(meshio.med.write, meshio.med.read, mesh, 1.0e-15)
def test_generic_io():
helpers.generic_io("test.med")
# With additional, insignificant suffix:
helpers.generic_io("test.0.med")
def test_reference_file_with_mixed_cells():
this_dir = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(this_dir, "meshes", "med", "cylinder.med")
mesh = meshio.read(filename)
# Points
assert numpy.isclose(mesh.points.sum(), 16.53169892762988)
# CellBlock
ref_num_cells = {"pyramid": 18, "quad": 18, "line": 17, "tetra": 63, "triangle": 4}
assert {k: len(v) for k, v in mesh.cells} == ref_num_cells
# Point tags
assert mesh.point_data["point_tags"].sum() == 52
ref_point_tags_info = {2: ["Side"], 3: ["Side", "Top"], 4: ["Top"]}
assert mesh.point_tags == ref_point_tags_info
# Cell tags
ref_sum_cell_tags = {
"pyramid": -116,
"quad": -75,
"line": -48,
"tetra": -24,
"triangle": -30,
}
assert {
c.type: sum(d) for c, d in zip(mesh.cells, mesh.cell_data["cell_tags"])
} == ref_sum_cell_tags
ref_cell_tags_info = {
-6: ["Top circle"],
-7: ["Top", "Top and down"],
-8: ["Top and down"],
-9: ["A", "B"],
-10: ["B"],
-11: ["B", "C"],
-12: ["C"],
}
assert mesh.cell_tags == ref_cell_tags_info
helpers.write_read(meshio.med.write, meshio.med.read, mesh, 1.0e-15)
def test_reference_file_with_point_cell_data():
this_dir = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(this_dir, "meshes", "med", "box.med")
mesh = meshio.read(filename)
# Points
assert numpy.isclose(mesh.points.sum(), 12)
# CellBlock
assert {k: len(v) for k, v in mesh.cells} == {"hexahedron": 1}
# Point data
data_u = mesh.point_data["resu____DEPL"]
assert data_u.shape == (8, 3)
assert numpy.isclose(data_u.sum(), 12)
# Cell data
# ELNO (1 data point for every node of each element)
data_eps = mesh.cell_data["resu____EPSI_ELNO"][0]
assert data_eps.shape == (1, 8, 6) # (n_cells, n_nodes_per_element, n_components)
data_eps_mean = numpy.mean(data_eps, axis=1)[0]
eps_ref = numpy.array([1, 0, 0, 0.5, 0.5, 0])
assert numpy.allclose(data_eps_mean, eps_ref)
data_sig = mesh.cell_data["resu____SIEF_ELNO"][0]
assert data_sig.shape == (1, 8, 6) # (n_cells, n_nodes_per_element, n_components)
data_sig_mean = numpy.mean(data_sig, axis=1)[0]
sig_ref = numpy.array(
[7328.44611253, 2645.87030114, 2034.06063679, 1202.6, 569.752, 0]
)
assert numpy.allclose(data_sig_mean, sig_ref)
data_psi = mesh.cell_data["resu____ENEL_ELNO"][0]
assert data_psi.shape == (1, 8, 1) # (n_cells, n_nodes_per_element, n_components)
# ELEM (1 data point for each element)
data_psi_elem = mesh.cell_data["resu____ENEL_ELEM"][0]
assert numpy.isclose(numpy.mean(data_psi, axis=1)[0, 0], data_psi_elem[0])
helpers.write_read(meshio.med.write, meshio.med.read, mesh, 1.0e-15)