Skip to content

Commit

Permalink
Merge branch 'adding_material_tags_with_cad' of github.com:fusion-ene…
Browse files Browse the repository at this point in the history
…rgy/cad_to_dagmc into adding_material_tags_with_cad
  • Loading branch information
shimwell committed Apr 13, 2024
2 parents a6e6056 + 0bb7479 commit 5b82cd2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/surface_mesh/multiple_cadquery_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
box_with_round_corners = cq.Workplane("XY").box(2, 1, 1)

my_model = CadToDagmc()
my_model.add_cadquery_object(cadquery_object=box,material_tags=["mat1"])
my_model.add_cadquery_object(cadquery_object=box_with_round_corners,material_tags=["mat2"])
my_model.add_cadquery_object(cadquery_object=box, material_tags=["mat1"])
my_model.add_cadquery_object(cadquery_object=box_with_round_corners, material_tags=["mat2"])
my_model.export_dagmc_h5m_file()
3 changes: 2 additions & 1 deletion examples/surface_mesh/single_stp_file_multiple_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
my_model = CadToDagmc()
# the d and c from the word dagmc would be tagged with one material and the agm are tagged with another material
my_model.add_stp_file(
filename="text_dagmc.stp", material_tags=["mat1", "mat2", "mat2", "mat2", "mat1"])
filename="text_dagmc.stp", material_tags=["mat1", "mat2", "mat2", "mat2", "mat1"]
)
my_model.export_dagmc_h5m_file()
18 changes: 7 additions & 11 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,18 @@ def _check_material_tags(material_tags, iterable_solids):
if material_tags:
if len(material_tags) != len(iterable_solids):
msg = (
'When setting material_tags the number of material_tags \n'
'should be equal to the number of volumes in the CAD \n'
f'geometry {len(iterable_solids)} volumes found in model \n'
f'and {len(material_tags)} material_tags found'
)
"When setting material_tags the number of material_tags \n"
"should be equal to the number of volumes in the CAD \n"
f"geometry {len(iterable_solids)} volumes found in model \n"
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)



def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags):
material_tags_in_brep_order = []
for brep_id in scrambled_id:
Expand Down Expand Up @@ -415,10 +414,7 @@ def add_stp_file(
scaled_part = part
else:
scaled_part = part.scale(scale_factor)
self.add_cadquery_object(
cadquery_object=scaled_part,
material_tags=material_tags
)
self.add_cadquery_object(cadquery_object=scaled_part, material_tags=material_tags)

def add_cadquery_object(
self,
Expand Down Expand Up @@ -446,7 +442,7 @@ def add_cadquery_object(
iterable_solids = cadquery_object.Solids()
else:
iterable_solids = cadquery_object.val().Solids()

_check_material_tags(material_tags, iterable_solids)
self.material_tags = self.material_tags + material_tags
self.parts = self.parts + iterable_solids
Expand Down

0 comments on commit 5b82cd2

Please sign in to comment.