diff --git a/README.md b/README.md index 9819ead..ad615fa 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_planar_coil.msh") +your_assembly.assemblyToGmsh(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` @@ -34,6 +34,32 @@ Normal tag names lead to a physical group with the assembly part name prefixed. By prefixing a tag with the `~` character, the part name is ignored, which allows for tagging of a multi-material physical group. For instance, tagging multiple faces with `~contact-with-casing` will produce a physical group with the name `contact-with-casing` that includes all those faces, even if they belong to different parts/solids. +Below is a simple example. + +```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")) + +assy.assemblyToGmsh(mesh_path="tagged_mesh.msh") +``` + +The resulting `.msh` file should have three physical groups in it. The `in_contact` group should include the faces from both the shell and the insert. + ## 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/sample_coils.py b/tests/sample_assemblies.py similarity index 88% rename from tests/sample_coils.py rename to tests/sample_assemblies.py index 0c0d1c9..0c06115 100644 --- a/tests/sample_coils.py +++ b/tests/sample_assemblies.py @@ -1,6 +1,36 @@ import cadquery as cq +def generate_simple_nested_boxes(): + """ + Generates the simplest assembly case where two boxes are nested inside each other. + """ + + # Create the outter shell + 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"), + ) + + return assy + + def generate_test_cross_section(): """ Generates a basic cross-section to verify that the tagged faces are crossing over diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 3576a03..8d70b47 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -1,5 +1,21 @@ import assembly_mesh_plugin.plugin -from sample_coils import generate_test_cross_section, generate_assembly +from tests.sample_assemblies import ( + generate_simple_nested_boxes, + generate_test_cross_section, + generate_assembly, +) + + +def test_basic_assembly(): + """ + Tests to make sure that the most basic assembly works correctly with tagging. + """ + + # Create the 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") def test_basic_cross_section():