Closed shimwell closed 2 years ago
ah sorry I misunderstood, the above script gets tags while this one gets material ids https://gist.github.com/pshriwise/ba911ea159d3b6cc0152cd6c4c2f7864
from pymoab import core, types
def load_moab_file(filename):
mb = core.Core()
mb.load_file(filename)
return mb
def find_moab_ids_by_type(mb: core.Core(), geom_type: str) -> List[int]:
"""Returns the ids for a given geometry entity type.
mb: A PyMOAB instance with the file of interest already loaded
geom_type: The type of geometry entity to provide IDs for. One of ("Group",
"Volume", "Surface", "Curve", "Vertex")
Returns: a sorted list of IDs for the geometry type
"""
_VALID_GEOM_TYPES = ("Group", "Volume", "Surface", "Curve", "Vertex")
if geom_type not in _VALID_GEOM_TYPES:
raise
# retrieve the category tag on the instance
try:
cat_tag = mb.tag_get_handle(types.CATEGORY_TAG_NAME)
except types.MB_ENTITY_NOT_FOUND:
raise RuntimeError("The category tag could not be found in the PyMOAB instance."
"Please check that the DAGMC file has been loaded.")
# get the id tag
gid_tag = mb.tag_get_handle(types.GLOBAL_ID_TAG_NAME)
print(gid_tag)
# get the set of entities using the provided category tag name
# (0 means search on the instance's root set)
ents = mb.get_entities_by_type_and_tag(0, types.MBENTITYSET, [cat_tag], [geom_type])
# retrieve the IDs of the entities
ids = mb.tag_get_data(gid_tag, ents).flatten()
return sorted(list(ids))
required functionality has bee added to dagmc-h5m-file-inspector package
pshriwise wrote this code snippet a while back and I have not got around to incorporating it quite yet.
I shall get this done next week