Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write mesh type as a dataset always #3253

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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_);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -969,7 +968,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 @@ -1155,7 +1153,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 @@ -1430,7 +1427,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 @@ -1742,7 +1738,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
Loading