Skip to content

Commit

Permalink
Added a readme example that was also made into a test, and restructur…
Browse files Browse the repository at this point in the history
…ed a bit
  • Loading branch information
jmwright committed Jan 28, 2025
1 parent bcc717a commit abb9988
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,40 @@ 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`

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[-2]").tag("~in_contact")

# Create the insert
insert = cq.Workplane("XY").box(20, 20, 50)
insert.faces("<X").tag("~in_contact")
insert.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.
Expand Down
30 changes: 30 additions & 0 deletions tests/sample_coils.py → tests/sample_assemblies.py
Original file line number Diff line number Diff line change
@@ -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[-2]").tag("~in_contact")

# Create the insert
insert = cq.Workplane("XY").box(20, 20, 50)
insert.faces("<X").tag("~in_contact")
insert.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
Expand Down
18 changes: 17 additions & 1 deletion tests/smoke_test.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down

0 comments on commit abb9988

Please sign in to comment.