From fab43a96d00abf996c4f8d839918e48bc682b809 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 20 Apr 2024 09:37:39 +0200 Subject: [PATCH] Fix bug in reading legacy mesh. Should check that file exist before opening it --- src/adios4dolfinx/legacy_readers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/adios4dolfinx/legacy_readers.py b/src/adios4dolfinx/legacy_readers.py index 6df3bfe..9497274 100644 --- a/src/adios4dolfinx/legacy_readers.py +++ b/src/adios4dolfinx/legacy_readers.py @@ -276,6 +276,11 @@ def read_mesh_from_legacy_h5( group: Name of mesh in `h5`-file cell_type: What type of cell type, by default tetrahedron. """ + # Make sure we use the HDF5File and check that the file is present + filename = pathlib.Path(filename).with_suffix(".h5") + if not filename.is_file(): + raise FileNotFoundError(f"File {filename} does not exist") + # Create ADIOS2 reader adios = adios2.ADIOS(comm) with ADIOSFile( @@ -285,11 +290,6 @@ def read_mesh_from_legacy_h5( io_name="Mesh reader", engine="HDF5", ) as adios_file: - # Make sure we use the HDF5File and check that the file is present - filename = pathlib.Path(filename).with_suffix(".h5") - if not filename.is_file(): - raise FileNotFoundError(f"File {filename} does not exist") - # Get mesh topology (distributed) if f"{group}/topology" not in adios_file.io.AvailableVariables().keys(): raise KeyError(f"Mesh topology not found at '{group}/topology'")