From 5fba6969bb08f677f2ce687e64e76312fdebc3ad Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 8 Jan 2025 10:55:16 -0600 Subject: [PATCH 1/2] Writing mesh type as a dataset. Removing redundant calls in concrete implementations Mesh. Updating docs --- docs/source/io_formats/statepoint.rst | 2 +- src/mesh.cpp | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/source/io_formats/statepoint.rst b/docs/source/io_formats/statepoint.rst index 82d20a76302..fd00a3e7735 100644 --- a/docs/source/io_formats/statepoint.rst +++ b/docs/source/io_formats/statepoint.rst @@ -73,9 +73,9 @@ The current version of the statepoint file format is 18.1. **/tallies/meshes/mesh /** :Attributes: - **id** (*int*) -- ID of the mesh - - **type** (*char[]*) -- Type of mesh. :Datasets: - **name** (*char[]*) -- Name of the mesh. + - **type** (*char[]*) -- Type of mesh. - **dimension** (*int*) -- Number of mesh cells in each dimension. - **Regular Mesh Only:** - **lower_left** (*double[]*) -- Coordinates of lower-left corner of diff --git a/src/mesh.cpp b/src/mesh.cpp index 2ee616f28dc..7e5681929ce 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -245,7 +245,7 @@ void Mesh::to_hdf5(hid_t group) const hid_t mesh_group = create_group(group, group_name.c_str()); // Write mesh type - write_attribute(mesh_group, "type", this->get_mesh_type()); + write_dataset(mesh_group, "type", this->get_mesh_type()); // Write mesh ID write_attribute(mesh_group, "id", id_); @@ -307,7 +307,6 @@ Position StructuredMesh::sample_element( UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node) { - // check the mesh type if (check_for_node(node, "type")) { auto temp = get_node_value(node, "type", true, true); @@ -969,7 +968,6 @@ std::pair, vector> RegularMesh::plot( void RegularMesh::to_hdf5_inner(hid_t mesh_group) const { - write_dataset(mesh_group, "type", "regular"); write_dataset(mesh_group, "dimension", get_x_shape()); write_dataset(mesh_group, "lower_left", lower_left_); write_dataset(mesh_group, "upper_right", upper_right_); @@ -1155,7 +1153,6 @@ std::pair, vector> RectilinearMesh::plot( void RectilinearMesh::to_hdf5_inner(hid_t mesh_group) const { - write_dataset(mesh_group, "type", "rectilinear"); write_dataset(mesh_group, "x_grid", grid_[0]); write_dataset(mesh_group, "y_grid", grid_[1]); write_dataset(mesh_group, "z_grid", grid_[2]); @@ -1430,7 +1427,6 @@ std::pair, vector> CylindricalMesh::plot( void CylindricalMesh::to_hdf5_inner(hid_t mesh_group) const { - write_dataset(mesh_group, "type", "cylindrical"); write_dataset(mesh_group, "r_grid", grid_[0]); write_dataset(mesh_group, "phi_grid", grid_[1]); write_dataset(mesh_group, "z_grid", grid_[2]); @@ -1742,7 +1738,6 @@ std::pair, vector> SphericalMesh::plot( void SphericalMesh::to_hdf5_inner(hid_t mesh_group) const { - write_dataset(mesh_group, "type", SphericalMesh::mesh_type); write_dataset(mesh_group, "r_grid", grid_[0]); write_dataset(mesh_group, "theta_grid", grid_[1]); write_dataset(mesh_group, "phi_grid", grid_[2]); From aff508ea9104f0079d46ec325cb10e9153999364 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 8 Jan 2025 12:48:18 -0600 Subject: [PATCH 2/2] Updating attribute check in Mesh.from_hdf5 --- openmc/mesh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 0b6f6b84e4b..e4d83d81d3d 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -99,7 +99,7 @@ def from_hdf5(cls, group: h5py.Group): Instance of a MeshBase subclass """ - mesh_type = 'regular' if 'type' not in group.attrs else group.attrs['type'].decode() + mesh_type = 'regular' if 'type' not in group.keys() else group['type'][()].decode() mesh_id = int(group.name.split('/')[-1].lstrip('mesh ')) mesh_name = '' if not 'name' in group else group['name'][()].decode()