diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index d470060..cb117f7 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -5,6 +5,7 @@ from cadquery import importers from pymoab import core, types import tempfile +import warnings def _define_moab_core_and_tags() -> tuple[core.Core, dict]: @@ -347,6 +348,12 @@ def _check_material_tags(material_tags, iterable_solids): if not isinstance(material_tag, str): msg = f"material_tags should be an iterable of strings." raise ValueError(msg) + if len(material_tag) > 28: + msg = ( + f"Material tag {material_tag} is too long. DAGMC will truncate this material tag " + f"to 28 characters. The resulting tag in the h5m file will be {material_tag[:28]}" + ) + warnings.warn(msg) def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags): diff --git a/tests/test_python_api.py b/tests/test_python_api.py index b29e9f2..76bbe78 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -3,7 +3,8 @@ import pytest import cadquery as cq from cad_to_dagmc import CadToDagmc - +import warnings +from cad_to_dagmc.core import _check_material_tags from pathlib import Path @@ -208,3 +209,13 @@ def test_export_gmsh_mesh_file_handel_paths_folders_strings(filename): assert Path(filename).is_file() os.system(f"rm -rf {filename}") + + +def test_check_material_tags_too_long(): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + _check_material_tags(["a" * 29], [1]) + assert len(w) == 1 + assert issubclass(w[-1].category, UserWarning) + assert "Material tag" in str(w[-1].message) + assert "a" * 29 in str(w[-1].message)