diff --git a/examples/surface_mesh/cadquery_object_and_stp_file.py b/examples/surface_mesh/cadquery_object_and_stp_file.py index 8d170ad..d1c4247 100644 --- a/examples/surface_mesh/cadquery_object_and_stp_file.py +++ b/examples/surface_mesh/cadquery_object_and_stp_file.py @@ -5,12 +5,15 @@ my_model = CadToDagmc() -my_model.add_cadquery_object(cadquery_object=result) +my_model.add_cadquery_object( + cadquery_object=result, + material_tags=["mat1"], +) my_model.add_stp_file( filename="single_cube.stp", scale_factor=0.1, - material_tags=["mat1", "mat2"], + material_tags=["mat2"], ) my_model.export_dagmc_h5m_file( diff --git a/examples/surface_mesh/cadquery_text.py b/examples/surface_mesh/cadquery_text.py index 5099fe7..a2b1b1b 100644 --- a/examples/surface_mesh/cadquery_text.py +++ b/examples/surface_mesh/cadquery_text.py @@ -5,12 +5,8 @@ my_model = CadToDagmc() -my_model.add_cadquery_object(cadquery_object=text) - -my_model.export_dagmc_h5m_file( - filename="cadquery_text.h5m", - max_mesh_size=0.2, - min_mesh_size=0.1, +my_model.add_cadquery_object( + cadquery_object=text, material_tags=[ "mat1", "mat2", @@ -19,3 +15,9 @@ "mat5", ], # 5 volumes one for each letter ) + +my_model.export_dagmc_h5m_file( + filename="cadquery_text.h5m", + max_mesh_size=0.2, + min_mesh_size=0.1, +) diff --git a/src/cad_to_dagmc/core.py b/src/cad_to_dagmc/core.py index c2027bd..9159662 100644 --- a/src/cad_to_dagmc/core.py +++ b/src/cad_to_dagmc/core.py @@ -311,10 +311,10 @@ def _check_material_tags(material_tags, iterable_solids): f"and {len(material_tags)} material_tags found" ) raise ValueError(msg) - for material_tag in material_tags: - if not isinstance(material_tag, str): - msg = f"material_tags should be an iterable of strings." - raise ValueError(msg) + for material_tag in material_tags: + if not isinstance(material_tag, str): + msg = f"material_tags should be an iterable of strings." + raise ValueError(msg) def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags): @@ -331,6 +331,9 @@ class MeshToDagmc: def __init__(self, filename: str): self.filename = filename + # TODO add export_unstructured_mesh_file + # TODO add add_gmsh_msh_file + def export_dagmc_h5m_file( self, material_tags: typing.Iterable[str], diff --git a/tests/test_file_creation.py b/tests/test_file_creation.py index 149e904..bcbad59 100644 --- a/tests/test_file_creation.py +++ b/tests/test_file_creation.py @@ -50,8 +50,8 @@ def test_h5m_with_single_volume_list(): h5m_file = "tests/single_cube.h5m" mesh_file = "test.msh" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/single_cube.stp") - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=["mat1"]) + my_model.add_stp_file(filename="tests/single_cube.stp", material_tags=["mat1"]) + my_model.export_dagmc_h5m_file(filename=h5m_file) my_model.export_gmsh_mesh_file(filename=mesh_file) assert Path(mesh_file).is_file() my_model.export_gmsh_mesh_file(filename="test3d.msh", dimensions=3) @@ -71,8 +71,8 @@ def test_h5m_with_single_volume_2(): h5m_file = "tests/curved_extrude.h5m" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/curved_extrude.stp") - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=["mat1"]) + my_model.add_stp_file(filename="tests/curved_extrude.stp", material_tags=["mat1"]) + my_model.export_dagmc_h5m_file(filename=h5m_file) assert get_volumes_and_materials_from_h5m(h5m_file) == {1: "mat:mat1"} @@ -89,9 +89,9 @@ def test_h5m_with_multi_volume_not_touching(): ] for stp_file, mat_tags, h5m_file in zip(stp_files, material_tags, h5m_files): my_model = CadToDagmc() - my_model.add_stp_file(filename=stp_file) + my_model.add_stp_file(filename=stp_file, material_tags=mat_tags) - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=mat_tags) + my_model.export_dagmc_h5m_file(filename=h5m_file) tags_dict = {} for counter, loop_mat_tag in enumerate(mat_tags, 1): @@ -114,9 +114,9 @@ def test_h5m_with_multi_volume_touching(): ] for stp_file, mat_tags, h5m_file in zip(stp_files, material_tags, h5m_files): my_model = CadToDagmc() - my_model.add_stp_file(stp_file) + my_model.add_stp_file(stp_file, material_tags=mat_tags) - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=mat_tags) + my_model.export_dagmc_h5m_file(filename=h5m_file) my_model.export_gmsh_mesh_file(filename=h5m_file + ".msh") tags_dict = {} @@ -152,12 +152,14 @@ def test_cq_compound(): compound_of_workplanes = cq.Compound.makeCompound([cq_shape_1.val(), cq_shape_2.val()]) my_model = CadToDagmc() - my_model.add_cadquery_object(object=compound_of_workplanes) + my_model.add_cadquery_object( + cadquery_object=compound_of_workplanes, + material_tags=["mat1", "mat2"], + ) my_model.export_dagmc_h5m_file( filename="compound_dagmc.h5m", max_mesh_size=0.2, min_mesh_size=0.1, - material_tags=["mat1", "mat2"], ) assert Path("compound_dagmc.h5m").is_file() @@ -204,7 +206,7 @@ def test_gmsh_mesh_with_multi_volume_not_touching(): ] for stp_file, mat_tags, gmsh_mesh_file in zip(stp_files, material_tags, gmsh_mesh_files): my_model = CadToDagmc() - my_model.add_stp_file(filename=stp_file) + my_model.add_stp_file(filename=stp_file, material_tags=mat_tags) my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file) @@ -224,7 +226,7 @@ def test_gmsh_mesh_with_multi_volume_touching(): ] for stp_file, mat_tags, gmsh_mesh_file in zip(stp_files, material_tags, gmsh_mesh_files): my_model = CadToDagmc() - my_model.add_stp_file(stp_file) + my_model.add_stp_file(stp_file, material_tags=mat_tags) my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file) diff --git a/tests/test_h5m_in_transport.py b/tests/test_h5m_in_transport.py index 299f161..528b94b 100644 --- a/tests/test_h5m_in_transport.py +++ b/tests/test_h5m_in_transport.py @@ -133,10 +133,10 @@ def test_transport_result_h5m_with_2_sep_volumes(): # cq.Assembly().add(workplane1).add(workplane2) my_model = CadToDagmc() - my_model.add_cadquery_object(workplane1) - my_model.add_cadquery_object(workplane2) + my_model.add_cadquery_object(workplane1, material_tags=[material_tags[0]]) + my_model.add_cadquery_object(workplane2, material_tags=[material_tags[1]]) my_model.export_dagmc_h5m_file( - filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]] + filename=h5m_filename ) transport_particles_on_h5m_geometry( @@ -155,8 +155,8 @@ def test_transport_result_h5m_with_1_curved_volumes(): workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4) my_model = CadToDagmc() - my_model.add_cadquery_object(workplane1) - my_model.export_dagmc_h5m_file(filename=h5m_filename, material_tags=[material_tags[0]]) + my_model.add_cadquery_object(workplane1, material_tags=[material_tags[0]]) + my_model.export_dagmc_h5m_file(filename=h5m_filename) transport_particles_on_h5m_geometry( h5m_filename=h5m_filename, @@ -175,10 +175,10 @@ def test_transport_result_h5m_with_2_joined_curved_volumes(): workplane2 = cq.Workplane("XY").cylinder(height=10, radius=5).cut(workplane1) my_model = CadToDagmc() - my_model.add_cadquery_object(workplane1) - my_model.add_cadquery_object(workplane2) + my_model.add_cadquery_object(workplane1,material_tags=[material_tags[0]]) + my_model.add_cadquery_object(workplane2, material_tags=[material_tags[1]]) my_model.export_dagmc_h5m_file( - filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]] + filename=h5m_filename, ) transport_particles_on_h5m_geometry( @@ -195,8 +195,8 @@ def test_h5m_with_single_volume_list(): h5m_file = "tests/single_cube.h5m" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/single_cube.stp") - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=["mat1"]) + my_model.add_stp_file(filename="tests/single_cube.stp", material_tags=["mat1"]) + my_model.export_dagmc_h5m_file(filename=h5m_file) h5m_files = [ "tests/single_cube.h5m", @@ -216,8 +216,8 @@ def test_h5m_with_multi_volume_not_touching(): h5m_file = "tests/two_disconnected_cubes.h5m" my_model = CadToDagmc() - my_model.add_stp_file(filename="tests/two_disconnected_cubes.stp") - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=["mat1", "mat2"]) + my_model.add_stp_file(filename="tests/two_disconnected_cubes.stp", material_tags=["mat1", "mat2"]) + my_model.export_dagmc_h5m_file(filename=h5m_file) transport_particles_on_h5m_geometry( h5m_filename="tests/two_disconnected_cubes.h5m", @@ -243,9 +243,12 @@ def test_h5m_with_multi_volume_touching(): for stp_file, mat_tags, h5m_file in zip(stp_files, material_tags, h5m_files): my_model = CadToDagmc() - my_model.add_stp_file(stp_file) + my_model.add_stp_file( + filename=stp_file, + material_tags=mat_tags, + ) - my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=mat_tags) + my_model.export_dagmc_h5m_file(filename=h5m_file) transport_particles_on_h5m_geometry( h5m_filename=h5m_file, diff --git a/tests/test_python_api.py b/tests/test_python_api.py index aa14765..0f9fbe2 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -48,28 +48,25 @@ def test_max_mesh_size_impacts_file_size(): sphere = cq.Workplane().sphere(100) c2d = CadToDagmc() - c2d.add_cadquery_object(sphere) + c2d.add_cadquery_object(sphere, material_tags=["m1"]) os.system("rm *.h5m") c2d.export_dagmc_h5m_file( min_mesh_size=10, max_mesh_size=20, mesh_algorithm=1, - filename="test_10_30.h5m", - material_tags=["m1"], + filename="test_10_30.h5m", ) c2d.export_dagmc_h5m_file( min_mesh_size=20, max_mesh_size=30, mesh_algorithm=1, filename="test_20_30.h5m", - material_tags=["m1"], ) c2d.export_dagmc_h5m_file( min_mesh_size=20, max_mesh_size=25, mesh_algorithm=1, filename="test_20_25.h5m", - material_tags=["m1"], ) assert Path("test_10_30.h5m").is_file() @@ -91,15 +88,15 @@ def test_h5m_file_tags(): sphere3 = cq.Workplane().moveTo(-100, -100).sphere(20) c2d = CadToDagmc() - c2d.add_cadquery_object(sphere1) - c2d.add_cadquery_object(sphere2) - c2d.add_cadquery_object(sphere3) + c2d.add_cadquery_object(sphere1, material_tags=["mat1"]) + c2d.add_cadquery_object(sphere2, material_tags=["mat2"]) + c2d.add_cadquery_object(sphere3, material_tags=["mat3"]) test_h5m_filename = "test_dagmc.h5m" os.system(f"rm {test_h5m_filename}") returned_filename = c2d.export_dagmc_h5m_file( - filename=test_h5m_filename, material_tags=["mat1", "mat2", "mat3"] + filename=test_h5m_filename ) assert Path(test_h5m_filename).is_file()