Skip to main content

Meshing library for nuclear workflows.

Project description

Tests

Stellarmesh is a meshing library for nuclear workflows. Principally, it supports the creation of DAGMC geometry from CAD models.

Features:

  • Import of CadQuery, build123d, STEP and BREP geometry
  • Surface and volume meshing
  • Gmsh and OpenCASCADE meshing backends
  • Linear and angular mesh tolerances
  • Imprinting and merging of conformal geometry
  • Mesh refinement
  • Programatic manipulation of .h5m tags
  • Automated testing and integration

Contents

Installation

Stellarmesh requires several dependencies that must be installed either from source or from conda-forge. At a minimum, these are moab, python-gmsh, and OCP. However, most users will likely also want build123d for geometry construction and openmc for simulation. See environment.yml for a sample conda environment.

From there, Stellarmesh can be installed from PyPI.

pip install stellarmesh

[!WARNING] While OCP and Gmsh can both be installed from PyPI, they are not ABI compatible. Usage of these packages will result in errors for some geometries.

Usage

For documentation and usage examples, see the examples and tutorials folders.

Geometry construction

Stellarmesh supports both build123d (recommended) and CadQuery for geometry construction but does not depend on either.

The included examples use build123d, which can be installed from conda-forge.

Meshing

Stellarmesh supports surface meshing with both OCC and Gmsh backends.

OCC

The OpenCASCADE (OCC) meshing backend is the preferred backend when linear or angular mesh tolerances are required.

Gmsh

The Gmsh meshing backend offers a number of meshing algorithms for both surface and volume meshes. More detailed documentation, see gmsh.info.

Example

Simple torus geometry

import build123d as bd
import stellarmesh as sm

solids = [bd.Solid.make_torus(1000, 100)]
for _ in range(3):
    solids.append(bd.Solid.thicken(solids[-1].faces()[0], 100))
solids = solids[1:]

geometry = sm.Geometry(solids[::-1], material_names=["a", "a", "c"])
mesh = sm.SurfaceMesh.from_geometry(
    geometry, sm.GmshSurfaceOptions(min_mesh_size=50, max_mesh_size=200)
)
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")


Rendered mesh with normals.

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

Other

Logging

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)

Mesh refinement

[!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.

Acknowledgements

Stellarmesh is originally a project of Thea Energy, who are building the world's first planar coil stellarator.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stellarmesh-1.0.0b1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stellarmesh-1.0.0b1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file stellarmesh-1.0.0b1.tar.gz.

File metadata

  • Download URL: stellarmesh-1.0.0b1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stellarmesh-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 f9eae46cba116d1cb6c3728003c8fc8b602e624162d15e5d8da4b27f612eae55
MD5 86adddf979b4c5576d46e69925b1012b
BLAKE2b-256 e306d70d642f714940fdfedce84554e39f98f17e7172e636af9882f5479cc88b

See more details on using hashes here.

Provenance

The following attestation bundles were made for stellarmesh-1.0.0b1.tar.gz:

Publisher: release.yml on stellarmesh/stellarmesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stellarmesh-1.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: stellarmesh-1.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stellarmesh-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 342aefbfdebd51e0853987d1222c4a072f29a2f1f11d9c8ac04f27303b4c9b26
MD5 99b97c3cf986d696f4fcd464eb367e9b
BLAKE2b-256 db93743488e7929044c247e6f3949fad1120622070f28f8dcf8a4fc342f10a19

See more details on using hashes here.

Provenance

The following attestation bundles were made for stellarmesh-1.0.0b1-py3-none-any.whl:

Publisher: release.yml on stellarmesh/stellarmesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page