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
|
import io
import pathlib
import numpy as np
import pytest
import meshio
from . import helpers
@pytest.mark.parametrize(
"mesh",
[
helpers.empty_mesh,
helpers.tri_mesh,
helpers.tri_mesh_2d,
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,
],
)
def test(mesh, tmp_path):
helpers.write_read(
tmp_path, meshio.nastran.write, meshio.nastran.read, mesh, 1.0e-13
)
@pytest.mark.parametrize("filename", ["cylinder.fem", "cylinder_cells_first.fem"])
def test_reference_file(filename):
this_dir = pathlib.Path(__file__).resolve().parent
filename = this_dir / "meshes" / "nastran" / filename
mesh = meshio.read(filename)
# points
assert np.isclose(mesh.points.sum(), 16.5316866)
# cells
ref_num_cells = {
"line": 241,
"triangle": 171,
"quad": 721,
"pyramid": 1180,
"tetra": 5309,
}
assert {
cell_block.type: cell_block.data.sum() for cell_block in mesh.cells
} == ref_num_cells
def test_long_format():
filename = io.StringIO(
"BEGIN BULK\n"
"GRID* 43 1.50000000000000 0.0\n"
"* 0.\n"
"ENDDATA\n"
)
mesh = meshio.read(filename, "nastran")
# points
assert len(mesh.points) == 1
assert np.isclose(mesh.points.sum(), 1.5)
|