Skip to content

Commit

Permalink
Merge pull request #108 from fusion-energy/adding-tag-length-check
Browse files Browse the repository at this point in the history
added check for length of 28 chars
  • Loading branch information
jon-proximafusion authored Dec 19, 2024
2 parents 17d3203 + 12ab557 commit 8b1fd33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion tests/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 8b1fd33

Please sign in to comment.