Hi All,
I am trying to use MOAB to read a .cub file and I am having an error with all my volume global ids being -1 in the .cub file. I am importing an exodus mesh and then using cubit to name my volumes then saving as a .cub file but when I run the code below I get all my volumes as unamed and global id -1. Is there a reason for this? Im susspecting it is the import of exodus mesh because I have imported a step file and named volumes and saved as .cub file and all my names and global ids show up correctly.
from pymoab import core, types
mb = core.Core()
mb.load_file(’/home/travis/Projects/LIFE/Updated_Model_v4/OpenMC/Meshes/Updated_Simplified_Model_v4.cub’)
mb.load_file(‘unitCell.cub’)
name_tag = mb.tag_get_handle(“NAME”)
category_tag = mb.tag_get_handle(“CATEGORY”)
geom_dim_tag = mb.tag_get_handle(“GEOM_DIMENSION”)
global_id_tag = mb.tag_get_handle(“GLOBAL_ID”)
all_sets = mb.get_entities_by_type(0, types.MBENTITYSET)
print(f"Total entity sets in unitCelltest.cub: {len(all_sets)}")
print("\nGroups with mat: names:")
print("=" * 70)
for entity_set in all_sets:
try:
name_data = mb.tag_get_data(name_tag, [entity_set])[0]
name_str = name_data.decode('utf-8', errors='ignore').strip('\x00') if isinstance(name_data, bytes) else str(name_data).strip('\x00')
cat_data = mb.tag_get_data(category_tag, [entity_set])[0]
cat_str = cat_data.decode('utf-8', errors='ignore').strip('\x00') if isinstance(cat_data, bytes) else str(cat_data).strip('\x00')
if 'mat:' in name_str:
print(f"\nFound: {name_str}")
print(f" Category: {cat_str}")
# Get child entity sets
child_sets = mb.get_entities_by_type(entity_set, types.MBENTITYSET)
print(f" Child entity sets: {len(child_sets)}")
if len(child_sets) > 0:
for i, child in enumerate(list(child_sets)[:3]):
try:
child_dim = mb.tag_get_data(geom_dim_tag, [child])[0][0]
child_cat = mb.tag_get_data(category_tag, [child])[0]
child_cat_str = child_cat.decode('utf-8', errors='ignore').strip('\x00') if isinstance(child_cat, bytes) else str(child_cat).strip('\x00')
print(f" Child {i+1}: Dim={child_dim}, Category={child_cat_str}")
except Exception as e:
print(f" Child {i+1}: Error - {e}")
except:
pass
Count volumes and show details
print("\n\nVolume Details:")
print("=" * 70)
volume_count = 0
for entity_set in all_sets:
try:
dim = mb.tag_get_data(geom_dim_tag, [entity_set])[0][0]
cat = mb.tag_get_data(category_tag, [entity_set])[0]
cat_str = cat.decode('utf-8', errors='ignore').strip('\x00') if isinstance(cat, bytes) else str(cat).strip('\x00')
if dim == 3: # Volume
volume_count += 1
# Get GLOBAL_ID
try:
global_id = mb.tag_get_data(global_id_tag, [entity_set])[0][0]
except:
global_id = "N/A"
# Get name
try:
vol_name_data = mb.tag_get_data(name_tag, [entity_set])[0]
vol_name = vol_name_data.decode('utf-8', errors='ignore').strip('\x00') if isinstance(vol_name_data, bytes) else str(vol_name_data).strip('\x00')
except:
vol_name = "(unnamed)"
print(f"Volume {volume_count}: GLOBAL_ID={global_id}, Name={vol_name}, Category={cat_str}")
except:
pass
print(f"\nTotal volumes in CUB file: {volume_count}")