From 658618eed23d20a562888afc72177731d4fba7e7 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 16 Jun 2025 14:33:24 -0400 Subject: [PATCH 1/3] Created get_imprinted_assembly method --- assembly_mesh_plugin/plugin.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/assembly_mesh_plugin/plugin.py b/assembly_mesh_plugin/plugin.py index 8d6143a..e58427d 100644 --- a/assembly_mesh_plugin/plugin.py +++ b/assembly_mesh_plugin/plugin.py @@ -182,11 +182,12 @@ def assembly_to_gmsh(self, mesh_path="tagged_mesh.msh"): gmsh.finalize() -def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"): +def get_imprinted_gmsh(self): """ - Exports an imprinted assembly to capture conformal meshes. + Allows the user to get a gmsh object from the assembly, with the assembly being imprinted. """ + # Initialize gmsh and create a new model gmsh.initialize() gmsh.option.setNumber("General.Terminal", 0) gmsh.model.add("assembly") @@ -297,6 +298,17 @@ def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"): gmsh.model.occ.synchronize() + return gmsh + + +def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"): + """ + Exports an imprinted assembly to capture conformal meshes. + """ + + # Turn this assembly into a imprinted gmsh object + gmsh = get_imprinted_gmsh(self) + gmsh.model.mesh.field.setAsBackgroundMesh(2) gmsh.model.mesh.generate(3) From 99130d46ee746117d81a14c42f7c91e601939e58 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 16 Jun 2025 14:37:49 -0400 Subject: [PATCH 2/3] Forgot to monkey-patch the methods into the Assembly class --- assembly_mesh_plugin/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly_mesh_plugin/plugin.py b/assembly_mesh_plugin/plugin.py index e58427d..27a6613 100644 --- a/assembly_mesh_plugin/plugin.py +++ b/assembly_mesh_plugin/plugin.py @@ -209,7 +209,6 @@ def get_imprinted_gmsh(self): cq.occ_impl.assembly.imprint(self) ) - print(imprinted_solids_with_orginal_ids) for solid, id in imprinted_solids_with_orginal_ids.items(): # Add the current solid to the mesh # Work-around for a segfault with in-memory passing of OCCT objects @@ -322,3 +321,4 @@ def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"): cq.Assembly.saveToGmsh = assembly_to_gmsh # Alias name that works better on cq.Assembly cq.Assembly.getTaggedGmsh = get_tagged_gmsh cq.Assembly.assemblyToImprintedGmsh = assembly_to_imprinted_gmsh +cq.Assembly.getImprintedGmsh = get_imprinted_gmsh From 7152e1d2bcd923887281fbda71e006d3fb37131f Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Tue, 17 Jun 2025 12:08:01 -0400 Subject: [PATCH 3/3] Added a smoke test for the imprinted gmsh object --- tests/smoke_test.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 6fb8ba5..620e010 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -24,6 +24,22 @@ def test_nested_cubes(): assert len(surfaces) == 18 +def test_imprinted_assembly_mesh(): + """ + Tests to make sure that the imprinted assembly mesh works correctly with tagging. + """ + + # Create the basic assembly + assy = generate_test_cross_section() + + # Convert eh assembly to an imprinted GMSH mesh + gmsh = assy.getImprintedGmsh() + + # Make sure we have the correct number of surfaces + surfaces = gmsh.model.getEntities(2) + assert len(surfaces) == 56 + + def test_basic_assembly(): """ Tests to make sure that the most basic assembly works correctly with tagging.