Skip to content

Commit

Permalink
Write mesh type as a dataset always (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise authored Jan 9, 2025
1 parent 0d4a85d commit 1eca46f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/source/io_formats/statepoint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ The current version of the statepoint file format is 18.1.
**/tallies/meshes/mesh <uid>/**

: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
Expand Down
2 changes: 1 addition & 1 deletion openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 1 addition & 6 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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_);
Expand Down Expand Up @@ -308,7 +308,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);
Expand Down Expand Up @@ -970,7 +969,6 @@ std::pair<vector<double>, vector<double>> 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_);
Expand Down Expand Up @@ -1156,7 +1154,6 @@ std::pair<vector<double>, vector<double>> 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]);
Expand Down Expand Up @@ -1431,7 +1428,6 @@ std::pair<vector<double>, vector<double>> 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]);
Expand Down Expand Up @@ -1743,7 +1739,6 @@ std::pair<vector<double>, vector<double>> 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]);
Expand Down

0 comments on commit 1eca46f

Please sign in to comment.