From a24d088877bd95370486602fc2539d1b08d11c95 Mon Sep 17 00:00:00 2001 From: Lars Kaiser <71793357+kaiserls@users.noreply.github.com> Date: Sat, 16 Mar 2024 01:07:56 +0100 Subject: [PATCH 1/2] [XdmfTimeSeries] Fix lines type in xdmf time series files --- src/meshio/xdmf/time_series.py | 2 +- tests/test_xdmf.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/meshio/xdmf/time_series.py b/src/meshio/xdmf/time_series.py index a3f85030a..3276d8788 100644 --- a/src/meshio/xdmf/time_series.py +++ b/src/meshio/xdmf/time_series.py @@ -410,7 +410,7 @@ def cells( # number of nodes. Hence, prepend 2. for c in cell_blocks: if c.type == "line": - c.data[:] = np.insert(c.data, 0, 2, axis=1) + c.data = np.insert(c.data, 0, 2, axis=1) dim += len(c.data) dim = str(dim) cd = np.concatenate( diff --git a/tests/test_xdmf.py b/tests/test_xdmf.py index e962f98d0..217a889d8 100644 --- a/tests/test_xdmf.py +++ b/tests/test_xdmf.py @@ -6,7 +6,7 @@ from . import helpers test_set_full = [ - helpers.empty_mesh, + #helpers.empty_mesh, helpers.line_mesh, helpers.tri_mesh, helpers.line_tri_mesh, @@ -59,26 +59,33 @@ def test_generic_io(tmp_path): # With additional, insignificant suffix: helpers.generic_io(tmp_path / "test.0.xdmf") - -def test_time_series(): +@pytest.mark.parametrize("mesh", test_set_full) +def test_time_series(mesh): # write the data filename = "out.xdmf" with meshio.xdmf.TimeSeriesWriter(filename) as writer: - writer.write_points_cells(helpers.tri_mesh_2d.points, helpers.tri_mesh_2d.cells) - n = helpers.tri_mesh_2d.points.shape[0] + writer.write_points_cells(mesh.points, mesh.cells) + n = mesh.points.shape[0] times = np.linspace(0.0, 1.0, 5) point_data = [ { "phi": np.full(n, t), - "u": np.full(helpers.tri_mesh_2d.points.shape, t), + "u": np.full(mesh.points.shape, t), + } + for t in times + ] + cell_data = [ + { + "a": [np.full(c.data.shape[0], t) for c in mesh.cells], + "b": [np.full(c.data.shape[0], t) for c in mesh.cells] } for t in times ] - for t, pd in zip(times, point_data): + for t, pd, cd in zip(times, point_data, cell_data): writer.write_data( - t, point_data=pd, cell_data={"a": {"triangle": [3.0, 4.2]}} + t, point_data=pd, cell_data=cd ) # read it back in From 843b96041dca7f823f9430e55397f9924adbfc75 Mon Sep 17 00:00:00 2001 From: Lars Kaiser <71793357+kaiserls@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:17:12 +0100 Subject: [PATCH 2/2] [Tests] Disable empty mesh test for TimeSeriesWriter and reintroduce for xdmf3 --- tests/test_xdmf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_xdmf.py b/tests/test_xdmf.py index 217a889d8..60f043e21 100644 --- a/tests/test_xdmf.py +++ b/tests/test_xdmf.py @@ -6,7 +6,7 @@ from . import helpers test_set_full = [ - #helpers.empty_mesh, + helpers.empty_mesh, helpers.line_mesh, helpers.tri_mesh, helpers.line_tri_mesh, @@ -59,7 +59,7 @@ def test_generic_io(tmp_path): # With additional, insignificant suffix: helpers.generic_io(tmp_path / "test.0.xdmf") -@pytest.mark.parametrize("mesh", test_set_full) +@pytest.mark.parametrize("mesh", [mesh for mesh in test_set_full if mesh != helpers.empty_mesh]) def test_time_series(mesh): # write the data filename = "out.xdmf"