Extracts information from DAGMC h5m files including volumes number, material tags
Project description
dagmc-h5m-file-inspector
A minimal Python package that inspects DAGMC h5m files to extract volume IDs, material tags, bounding boxes, geometric volumes, and surface areas.
Installation
pip install dagmc-h5m-file-inspector
The package uses h5py as the default backend. Optionally, pymoab can be used as an alternative backend if installed.
Python API Usage
Finding volume IDs
import dagmc_h5m_file_inspector as di
di.get_volumes_from_h5m("dagmc.h5m")
>>> [1, 2]
Finding material tags
import dagmc_h5m_file_inspector as di
di.get_materials_from_h5m("dagmc.h5m")
>>> ['big_box', 'small_box']
Finding volume IDs with their materials
import dagmc_h5m_file_inspector as di
di.get_volumes_and_materials_from_h5m("dagmc.h5m")
>>> {1: 'small_box', 2: 'big_box'}
Getting the bounding box
Returns a BoundingBox object that is API compatible with OpenMC's openmc.BoundingBox.
import dagmc_h5m_file_inspector as di
bbox = di.get_bounding_box_from_h5m("dagmc.h5m")
>>> bbox
BoundingBox((-5.0, -10.0, -10.0), (25.0, 10.0, 10.0))
>>> bbox.lower_left
(-5.0, -10.0, -10.0)
>>> bbox.upper_right
(25.0, 10.0, 10.0)
>>> bbox.center
(10.0, 0.0, 0.0)
>>> bbox.volume
18000.0
>>> bbox.width
(30.0, 20.0, 20.0)
>>> bbox.extent
{'xy': (-5.0, 25.0, -10.0, 10.0), 'xz': (-5.0, 25.0, -10.0, 10.0), 'yz': (-10.0, 10.0, -10.0, 10.0)}
The BoundingBox supports indexing, unpacking, containment checks, and set operations:
# Unpacking
lower_left, upper_right = bbox
# Indexing
>>> bbox[0]
(-5.0, -10.0, -10.0)
# Point containment
>>> (0.0, 0.0, 0.0) in bbox
True
# Intersection and union of two bounding boxes
bbox_intersection = bbox1 & bbox2
bbox_union = bbox1 | bbox2
Optionally filter by material tag to get the bounding box for specific materials:
import dagmc_h5m_file_inspector as di
# Bounding box for a single material
bbox = di.get_bounding_box_from_h5m("dagmc.h5m", materials="small_box")
>>> bbox.lower_left
(-5.0, -5.0, -5.0)
>>> bbox.upper_right
(5.0, 5.0, 5.0)
# Bounding box for multiple materials (combined)
bbox = di.get_bounding_box_from_h5m("dagmc.h5m", materials=["small_box", "big_box"])
>>> bbox.lower_left
(-5.0, -10.0, -10.0)
>>> bbox.upper_right
(25.0, 10.0, 10.0)
Getting geometric volume sizes by cell ID
import dagmc_h5m_file_inspector as di
di.get_volumes_from_h5m_by_cell_id("dagmc.h5m")
>>> {1: 1000.0, 2: 8000.0}
Getting geometric volume sizes by material name
import dagmc_h5m_file_inspector as di
di.get_volumes_from_h5m_by_material_name("dagmc.h5m")
>>> {'small_box': 1000.0, 'big_box': 8000.0}
Getting geometric volume sizes by cell ID and material name
import dagmc_h5m_file_inspector as di
di.get_volumes_from_h5m_by_cell_id_and_material_name("dagmc.h5m")
>>> {(1, 'small_box'): 1000.0, (2, 'big_box'): 8000.0}
Getting surface areas by cell ID
Returns a list of surface areas, one per DAGMC surface bounding the volume.
import dagmc_h5m_file_inspector as di
di.get_surface_area_by_cell_id("dagmc.h5m", cell_id=1)
>>> [100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
Getting surface areas by material name
Returns a list of surface areas for all DAGMC surfaces bounding volumes with the given material.
import dagmc_h5m_file_inspector as di
di.get_surface_area_by_material_name("dagmc.h5m", material="small_box")
>>> [100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
Getting surface shared status
Returns a dictionary mapping each surface ID to the cell IDs and materials that share it. Useful for identifying interfaces between volumes.
import dagmc_h5m_file_inspector as di
di.get_surface_shared_status("dagmc.h5m")
>>> {1: {'materials': ['small_box'], 'cell_ids': [1]},
2: {'materials': ['small_box'], 'cell_ids': [1]},
...
7: {'materials': ['small_box', 'big_box'], 'cell_ids': [1, 2]},
...}
Setting OpenMC material volumes from DAGMC geometry
This function reads the DAGMC file, matches materials by name, and sets the
volume attribute on the corresponding OpenMC Material objects.
import openmc
import dagmc_h5m_file_inspector as di
# Create OpenMC materials with names matching the DAGMC file
small_box = openmc.Material(name='small_box')
big_box = openmc.Material(name='big_box')
materials = openmc.Materials([small_box, big_box])
# Set volumes from DAGMC geometry
di.set_openmc_material_volumes_from_h5m(materials, "dagmc.h5m")
>>> small_box.volume
1000.0
>>> big_box.volume
8000.0
Getting triangle connectivity and coordinates for each volume
This function extracts the triangle mesh data for each volume, returning the connectivity (vertex indices) and coordinates (3D points) needed for visualization or mesh processing.
import dagmc_h5m_file_inspector as di
data = di.get_triangle_conn_and_coords_by_volume("dagmc.h5m")
>>> data
{1: (array([[0, 1, 2], [0, 2, 3], ...]), array([[0., 0., 0.], [10., 0., 0.], ...])),
2: (array([[0, 1, 2], [0, 2, 3], ...]), array([[-5., -10., -10.], [25., -10., -10.], ...]))}
# Access data for a specific volume
connectivity, coordinates = data[1]
>>> connectivity.shape
(12, 3) # 12 triangles, each with 3 vertex indices
>>> coordinates.shape
(8, 3) # 8 unique vertices, each with x, y, z coordinates
Convert h5m file to vtkhdf
Convert DAGMC h5m files to vtkhdf which can be directly opened in Paraview 5.13+.
The resulting Paraview files have color for cell IDs and material tags present within the h5m file.
import dagmc_h5m_file_inspector as di
di.convert_h5m_to_vtkhdf(h5m_filename='dagmc.h5m', vtkhdf_filename= 'dagmc.vtkhdf')
Removing materials from h5m files
Remove one or more materials (and their associated volumes) from a DAGMC h5m file, writing the result to a new file.
import dagmc_h5m_file_inspector as di
di.get_materials_from_h5m("dagmc.h5m")
>>> ['big_box', 'small_box']
# Remove a single material
di.remove_materials_from_h5m(
input_filename="dagmc.h5m",
output_filename="dagmc_reduced.h5m",
materials_to_remove="small_box",
)
di.get_materials_from_h5m("dagmc_reduced.h5m")
>>> ['big_box']
import dagmc_h5m_file_inspector as di
di.get_materials_from_h5m("reactor.h5m")
>>> ['blanket', 'first_wall', 'shield']
# Remove multiple materials
di.remove_materials_from_h5m(
input_filename="reactor.h5m",
output_filename="reactor_reduced.h5m",
materials_to_remove=["blanket", "shield"],
)
di.get_materials_from_h5m("reactor_reduced.h5m")
>>> ['first_wall']
Rotating a DAGMC geometry around an axis
Rotate the mesh coordinates around a coordinate axis and write a new h5m file.
import dagmc_h5m_file_inspector as di
di.rotate_around_axis(
filename="dagmc.h5m",
axis="z",
degrees=90,
output="dagmc_rotated.h5m",
)
Moving a DAGMC geometry
Translate (move) the mesh coordinates by an offset and write a new h5m file.
import dagmc_h5m_file_inspector as di
di.move(
filename="dagmc.h5m",
x=10.0,
y=0.0,
z=0.0,
output="dagmc_moved.h5m",
)
Combining multiple DAGMC h5m files
Merge multiple DAGMC h5m files into a single file. Volumes are renumbered sequentially in the output. It is the caller's responsibility to ensure the geometries do not overlap.
import dagmc_h5m_file_inspector as di
di.combine_h5m_files(
input_files=["file_a.h5m", "file_b.h5m"],
output_file="combined.h5m",
)
di.get_volumes_from_h5m("combined.h5m")
>>> [1, 2]
di.get_materials_from_h5m("combined.h5m")
>>> ['mat_a', 'mat_b']
Using the pymoab backend
All functions support an optional backend parameter. The default is "h5py",
but "pymoab" can be used if pymoab is installed:
import dagmc_h5m_file_inspector as di
di.get_volumes_from_h5m("dagmc.h5m", backend="pymoab")
>>> [1, 2]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dagmc_h5m_file_inspector-0.6.9.tar.gz.
File metadata
- Download URL: dagmc_h5m_file_inspector-0.6.9.tar.gz
- Upload date:
- Size: 17.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35032e256bd3f5326d10d35280ea59016da87a6d3b224619464a0536e238757e
|
|
| MD5 |
7cae6cf6624bd1d36dbe7c4e517479b8
|
|
| BLAKE2b-256 |
5a61e337017fc9f12a6ccb294365c74936a747d0c4e1b32c7e78866b66be8f3f
|
File details
Details for the file dagmc_h5m_file_inspector-0.6.9-py3-none-any.whl.
File metadata
- Download URL: dagmc_h5m_file_inspector-0.6.9-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40c6d5976042da2f3d80f6e6cdcdf18e783421c6a99b3638d997bc0c8bbdf6ea
|
|
| MD5 |
47d1e6e5e497a745f31f26713e57f285
|
|
| BLAKE2b-256 |
d3cc9d3c0d93d626c903e1f7960f9003c78ba7b752d6912354ca1dd93538c4fe
|