From 3595878e0890d8a4f4671eb7fdbad4fe5537b2cc Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Wed, 29 Jan 2025 08:09:07 -0500 Subject: [PATCH] Switched the method names in the test and added a getTaggedGmsh example in the readme --- README.md | 35 +++++++++++++++++++++++++++++++++-- tests/smoke_test.py | 6 +++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83bf795..4d13763 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ import cadquery_assembly_mesh_plugin.plugin You can then tag faces in each of the assembly parts and create your asembly. To export the assembly to a mesh file, you do the following. ```python -your_assembly.assemblyToGmsh(mesh_path="tagged_mesh.msh") +your_assembly.saveToGmsh(mesh_path="tagged_mesh.msh") ``` Normal tag names lead to a physical group with the assembly part name prefixed. So a tag name of `inner-bottom` on an assembly part with the name `steel_plate` will be `steel_plate_inner-bottom` @@ -54,11 +54,42 @@ assy = cq.Assembly() assy.add(shell, name="shell", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("red")) assy.add(insert, name="insert", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("blue")) -assy.assemblyToGmsh(mesh_path="tagged_mesh.msh") +assy.saveToGmsh(mesh_path="tagged_mesh.msh") ``` The resulting `.msh` file should have three physical groups named for tags in it. The `in_contact` group should include the faces from both the shell and the insert. +If you want more control over the mesh generation and export, you can use the `getTaggedGmsh` method and then finalize the mesh yourself. + +```python +import cadquery as cq +import cadquery_assembly_mesh_plugin.plugin +import gmsh + +shell = cq.Workplane("XY").box(50, 50, 50) +shell = shell.faces(">Z").workplane().rect(21, 21).cutThruAll() +shell.faces(">X[-2]").tag("inner-right") +shell.faces("X").tag("outer-right") + +assy = cq.Assembly() +assy.add(shell, name="shell", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("red")) +assy.add(insert, name="insert", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("blue")) + +# Get a Gmsh object back with all the tagged faces as physical groups +gmsh = assy.getTaggedGmsh() + +# Generate the mesh and write it to the file +gmsh.model.mesh.field.setAsBackgroundMesh(2) +gmsh.model.mesh.generate(3) +gmsh.write(mesh_path) +gmsh.finalize() +``` + ## Tests These tests are also run in Github Actions, and the meshes which are generated can be viewed as artifacts on the successful `tests` Actions there. diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 8d70b47..eb36f75 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -15,7 +15,7 @@ def test_basic_assembly(): assy = generate_simple_nested_boxes() # Create a mesh that has all the faces tagged as physical groups - assy.assemblyToGmsh(mesh_path="tagged_mesh.msh") + assy.saveToGmsh(mesh_path="tagged_mesh.msh") def test_basic_cross_section(): @@ -27,7 +27,7 @@ def test_basic_cross_section(): assy = generate_test_cross_section() # Create a mesh that has all the faces in the correct physical groups - assy.assemblyToGmsh(mesh_path="tagged_cross_section.msh") + assy.saveToGmsh(mesh_path="tagged_cross_section.msh") def test_planar_coil(): @@ -39,4 +39,4 @@ def test_planar_coil(): assy = generate_assembly() # Create a mesh that has all the faces in the correct physical groups - assy.assemblyToGmsh(mesh_path="tagged_planar_coil.msh") + assy.saveToGmsh(mesh_path="tagged_planar_coil.msh")