| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
CadQuery plugin to create a mesh of an assembly with corresponding data.
This plugin makes use of CadQuery tags to collect surfaces into Gmsh physical groups. The tagged faces are matched to their corresponding surfaces in the mesh via their position in the CadQuery solid(s) vs the Gmsh surface ID. There are a few challenges with mapping tags to surfaces to be aware of.
You can install via PyPI
pip install assembly-mesh-plugin
PLEASE NOTE: This plugin currently needs to be run in an Anaconda/Mamba environment because of a crash with the PyPI packages when passing OpenCASCADE objects to Gmesh in memory.
The plugin needs to be imported in order to monkey-patch its method into CadQuery:
import assembly_mesh_pluginYou can then tag faces in each of the assembly parts and create your assembly. To export the assembly to a mesh file, you do the following.
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
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.
import cadquery as cq
import assembly_mesh_plugin
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")
assy.add(insert, name="insert")
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.
import cadquery as cq
import assembly_mesh_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")
assy.add(insert, name="insert")
# Get a Gmsh object back with all the tagged faces as physical groups
gmsh_object = assy.getTaggedGmsh()
# Generate the mesh and write it to the file
gmsh_object.model.mesh.field.setAsBackgroundMesh(2)
gmsh_object.model.mesh.generate(3)
gmsh_object.write("tagged_mesh.msh")
gmsh_object.finalize()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.
Once the test has been run (using the pytest command), two mesh files (.msh extension) be created in the root of the repository.
These mesh files will have many physical groups since each surface gets its own physical group, but it should also contain physical groups corresponding to the tags that were created for the faces in the assembly parts.
| Back | FazBrowse Home | New Git URL |