File: test_netgen.py

package info (click to toggle)
python-meshio 7.0.0-really-5.3.5-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,952 kB
  • sloc: python: 14,908; makefile: 19
file content (119 lines) | stat: -rw-r--r-- 3,057 bytes parent folder | download | duplicates (2)
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
import pathlib

import numpy as np
import pytest

import meshio

from . import helpers

test_set = [
    helpers.empty_mesh,
    helpers.line_mesh,
    helpers.tri_mesh_2d,
    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.pyramid_mesh,
    helpers.wedge_mesh,
    helpers.add_cell_data(helpers.tri_mesh, [("netgen:index", (), int)]),
]


this_dir = pathlib.Path(__file__).resolve().parent
netgen_mesh_directory = this_dir / "meshes" / "netgen"

PERIODIC_1D = "periodic_1d.vol"
PERIODIC_2D = "periodic_2d.vol"
PERIODIC_3D = "periodic_3d.vol"

netgen_meshes = [PERIODIC_1D, PERIODIC_2D, PERIODIC_3D]


@pytest.mark.parametrize("mesh", test_set)
@pytest.mark.parametrize("suffix", [".vol", ".vol.gz"])
def test(mesh, suffix, tmp_path):
    helpers.write_read(
        tmp_path,
        meshio.netgen.write,
        meshio.netgen.read,
        mesh,
        1.0e-13,
        extension=suffix,
    )


expected_identifications = {
    PERIODIC_1D: np.array([[1, 51, 1]]),
    PERIODIC_2D: np.array(
        [[2, 1, 4], [3, 4, 4], [9, 17, 4], [10, 18, 4], [11, 19, 4], [12, 20, 4]]
    ),
    PERIODIC_3D: np.array(
        [
            [1, 3, 1],
            [2, 5, 1],
            [4, 7, 1],
            [6, 8, 1],
            [9, 11, 1],
            [10, 12, 1],
            [15, 13, 1],
            [16, 14, 1],
            [21, 19, 1],
            [22, 20, 1],
            [25, 23, 1],
            [26, 24, 1],
            [38, 54, 1],
            [39, 55, 1],
            [40, 56, 1],
        ]
    ),
}

expected_identificationtypes = {
    PERIODIC_1D: np.array([[2]]),
    PERIODIC_2D: np.array([[1, 1, 1, 2]]),
    PERIODIC_3D: np.array([[2]]),
}

expected_field_data = {
    PERIODIC_1D: {},
    PERIODIC_2D: {"outer": [3, 1], "periodic": [4, 1]},
    PERIODIC_3D: {"outer": [6, 2], "default": [3, 2]},
}


@pytest.mark.parametrize("netgen_mesh", [PERIODIC_1D, PERIODIC_2D, PERIODIC_3D])
def test_advanced(netgen_mesh, tmp_path):
    mesh = meshio.read(str(netgen_mesh_directory / netgen_mesh))

    p = tmp_path / f"{netgen_mesh}_out.vol"
    mesh.write(p)
    mesh_out = meshio.read(p)

    assert np.all(
        mesh.info["netgen:identifications"] == expected_identifications[netgen_mesh]
    )
    assert np.all(
        mesh.info["netgen:identifications"] == mesh_out.info["netgen:identifications"]
    )
    assert np.all(
        mesh.info["netgen:identificationtypes"]
        == expected_identificationtypes[netgen_mesh]
    )
    assert np.all(
        mesh.info["netgen:identificationtypes"]
        == mesh_out.info["netgen:identificationtypes"]
    )
    for kk, vv in mesh.field_data.items():
        assert np.all(vv == expected_field_data[netgen_mesh][kk])
        assert np.all(vv == mesh_out.field_data[kk])
    for cd, cd_out in zip(
        mesh.cell_data["netgen:index"], mesh_out.cell_data["netgen:index"]
    ):
        assert np.all(cd == cd_out)