@@ -161,6 +161,7 @@ def get_gmsh(self, imprint=True):
161161 tagged_faces = {}
162162 multi_material_groups = {}
163163 surface_groups = {}
164+ solid_materials = []
164165
165166 gmsh .initialize ()
166167 gmsh .option .setNumber (
@@ -171,13 +172,23 @@ def get_gmsh(self, imprint=True):
171172 # Get all of the subshapes and their corresponding names/positions
172173 extract_subshape_names (self , self .name )
173174
174- # Imprint the assembly
175- imprinted_assembly , imprinted_solids_with_orginal_ids = (
176- cq .occ_impl .assembly .imprint (self )
177- )
178-
179175 # Handle the imprinted assembly
180176 if imprint :
177+ # Imprint the assembly
178+ imprinted_assembly , imprinted_solids_with_orginal_ids = (
179+ cq .occ_impl .assembly .imprint (self )
180+ )
181+
182+ # Collect the materials
183+ for imp_solid , solid_id in imprinted_solids_with_orginal_ids .items ():
184+ # Track down the original assembly object so that we can retrieve materials, if present
185+ short_id = solid_id [0 ].split ("/" )[- 1 ] if "/" in solid_id [0 ] else solid_id [0 ]
186+ subassy = self .objects [short_id ]
187+
188+ # Save the assembly material associated with this solid
189+ if subassy .material :
190+ solid_materials .append (subassy .material .name )
191+
181192 for solid , name in imprinted_solids_with_orginal_ids .items ():
182193 # Get just the name of the current assembly
183194 short_name = name [0 ].split ("/" )[- 1 ]
@@ -202,11 +213,22 @@ def get_gmsh(self, imprint=True):
202213 # Add faces to the mesh and handle tagged faces
203214 add_faces_to_mesh (gmsh , solid , short_name , loc )
204215
216+ # Keep track of the materials
217+ if self .objects [name .split ("/" )[- 1 ]].material :
218+ solid_materials .append (self .objects [name .split ("/" )[- 1 ]].material .name )
219+
205220 # Step through each of the volumes and add physical groups for each
206221 for volume_id in volumes .keys ():
207222 gmsh .model .occ .synchronize ()
223+
224+ # Include the material name, if present
208225 ps = gmsh .model .addPhysicalGroup (3 , volumes [volume_id ][0 ])
209- gmsh .model .setPhysicalName (3 , ps , f"{ volume_map [volume_id ]} " )
226+
227+ # See if we need to include the material name as part of the physical volume name
228+ volume_name = f"{ volume_map [volume_id ]} "
229+ if len (solid_materials ) >= volume_id :
230+ volume_name = f"{ volume_map [volume_id ]} ~{ solid_materials [volume_id - 1 ]} "
231+ gmsh .model .setPhysicalName (3 , ps , volume_name )
210232
211233 # Handle tagged surface groups
212234 for t_name , surf_group in surface_groups .items ():
0 commit comments