Stellarmesh is a meshing library for nuclear workflows. Principally, it supports the creation of DAGMC geometry from CAD models. Stellarmesh is developed by the original authors of Thea-Energy/stellarmesh, CAD-to-DAGMC, and CAD-to-OpenMC.
Features:
- Import of CadQuery, build123d, STEP and BREP geometry
- Correct implementation of surface-sense
- Imprinting and merging of conformal geometry
- Mesh refinement
- Automated testing and integration
- Programatic manipulation of .h5m tags e.g. materials
See the project Roadmap.
pip install stellarmesh
or install the development version with:
pip install git+https://github.com/stellarmesh/stellarmesh
Note: Stellarmesh requires an installation of MOAB with pymoab, which is not available on PyPi and must be installed either from source or using Conda.
Stellarmesh supports both build123d (recommended) and CadQuery for geometry construction but does not depend on either.
The included examples use build123d. To install, run:
pip install build123d
For documentation and usage examples, see Read the Docs.
import build123d as bd
import stellarmesh as sm
solids = [bd.Solid.make_torus(1000, 100)]
for _ in range(3):
solids.append(solids[-1].faces()[0].thicken(100))
solids = solids[1:]
geometry = sm.Geometry(solids, material_names=["a", "a", "c"])
mesh = sm.Mesh.from_geometry(geometry, min_mesh_size=50, max_mesh_size=50)
mesh.write("test.msh")
mesh.render("doc/torus-mesh-reversed.png", rotation_xyz=(90, 0, -90), normals=15)
h5m = sm.DAGMCModel.from_mesh(mesh)
h5m.write("dagmc.h5m")
h5m.write("dagmc.vtk")
Check overlaps
❯ overlap_check dagmc.h5m
NOTICE:
Performing overlap check using triangle vertex locations only.
Use the '-p' option to check more points on the triangle edges.
Run '$ overlap_check --help' for more information.
Running overlap check:
100% |===============================================================>|+
No overlaps were found.
Check materials
❯ mbsize -ll dagmc.h5m | grep mat:
NAME = mat:a
NAME = mat:c
Check watertight
❯ check_watertight dagmc.h5m
number of surfaces=4
number of volumes=3
0/0 (nan%) unmatched edges
0/4 (0%) unsealed surfaces
0/3 (0%) unsealed volumes
leaky surface ids=
leaky volume ids=
0.173068 seconds
Stellarmesh uses the logging library for debug, info and warning messages. Set the level with:
import logging
logging.basicConfig() # Required in Jupyter to correctly set output stream
logging.getLogger("stellarmesh").setLevel(logging.INFO)
Note
Given CAD geometry, Gmsh often produces high-quality meshes that do not benefit from remeshing.
Stellarmesh supports mesh refinement using the mmg library. Refine a mesh with:
refined_mesh = mesh.refine(
...
)
and consult the Mesh.refine
and mmgs documentations for parameter values.
The refined mesh has more triangles in regions with high curvature thanks to the hausdorff parameter.
Many thanks to Erik B. Knudsen for his work on remeshing for CAD-to-OpenMC.
Stellarmesh is originally a project of Thea Energy, who are building the world's first planar coil stellarator.