Skip to content
3MAHPublic

About

Microstructure generation

Resources

Stars

133 stars

Watchers

4 watching

Forks

Repository files navigation

Microgen logo

microgen is a Python library designed to facilitate microstructure generation and meshing. Here are its core features:

  • Triply Periodic Minimal Surfaces (TPMS): gyroid, Schwarz, Schoen, Neovius, Fischer-Koch… as sheets or skeletons, graded in density, cell size or cell type, in Cartesian, cylindrical or spherical frames, and as infill of any mesh.
  • Spinodoids: random, anisotropic bicontinuous microstructures from Gaussian random fields.
  • Lattices: octet-truss, honeycomb, preset and custom (e.g. auxetic) strut lattices.
  • Virtual composites: periodic RVEs of spheres, short fibres, ellipsoids and other inclusions.
  • 3D Voronoi tessellation: granular materials and polycrystalline metals, also combined with TPMS.
  • Implicit workflow: shapes as implicit fields (F-rep), with boolean operations and blending.
  • Meshing: regular and periodic meshing using Gmsh, level-set remeshing using Mmg.

Generation of 3D objects is achievable through functions that utilize Open CASCADE (via cadquery-ocp-novtk, the direct OCCT Python binding) or VTK (using PyVista). Neper offers tools for 3D tessellation, while Gmsh handles the generation of both regular and periodic meshes, with Mmg handling remeshing tasks.

The CAD path (.generate_cad() on shapes, Phase, fuse_shapes, periodic split, lattice CAD) is optional — install with pip install 'microgen[cad]'. The default pip install microgen gives you mesh + implicit-field (F-rep) workflows only, which is sufficient for many applications and has a much lighter dependency footprint (no OCCT, no VTK version pin).

TPMS, spinodoids and strut lattices generated with microgen Wireframe spinodoid morphing between two random realisations

Hello, gyroid (implicit-first, no CAD needed)

from microgen import Phase, Tpms, surface_functions

gyroid = Tpms(surface_function=surface_functions.gyroid, offset=0.3)
phase  = Phase.from_shape(gyroid, resolution=80)

phase.surface_mesh().save("gyroid.stl")  # marching cubes from the SDF
print(f"COM = {phase.center_of_mass}, pieces = {len(phase.pieces)}")

A Phase built via Phase.from_shape carries the implicit field directly — marching cubes, connected components (phase.pieces), and grid-quadrature moments all run from the SDF, no OCCT required. CAD (phase.cad, STEP export, gmsh setPeriodic) is materialised lazily and only needs the [cad] extra.

PyPI package PyPI
Conda forge package Conda
Documentation Documentation
Status Status
Citation DOI
License License
Website Website

Installation

Core (mesh + implicit-field / F-rep, no CAD kernel) — lighter, works with VTK 9.4+:

pip install microgen

With CAD capabilities (OCCT via cadquery-ocp-novtk, enables .generate_cad(), Phase, fuse_shapes, periodic split, lattice CAD):

pip install 'microgen[cad]'

With the Meshers volume-mesh backend (generate_volume_mesh(backend="meshers"): tetrahedra meshed directly from the implicit field, with periodic node pairs; wheels for Linux x86-64, macOS and Windows):

pip install 'microgen[meshers]'

Everything (CAD, Meshers and ray tracing; Meshers is skipped on Linux aarch64, where it has no wheel):

pip install 'microgen[all]'

With conda:

conda install conda-forge::microgen          # core
conda install conda-forge::microgen ocp      # core + CAD

Python version notes: Python 3.11 to 3.14 is supported on Linux, macOS (Apple Silicon), and Windows, for both core and [cad], on both PyPI and conda-forge.

What you can do in each mode:

Core install [cad] install
Shape.generate_surface_mesh() (viz) ✅ ✅
Implicit fields, TPMS F-rep, booleans ✅ ✅
Shape.generate_cad() (OCCT BREP) ❌ ✅
Phase, fuse_shapes, cut_* ❌ ✅
Periodic split, lattice CAD export ❌ ✅
VTK 9.4+ ✅ ✅

To modify the sources, clone this repository and install microgen:

git clone https://github.com/3MAH/microgen.git
cd microgen
pip install -e '.[all,dev,docs]'
pre-commit install

The -e or --editable option allows to modify the sources without having to reinstall the package; [all] installs every optional feature (CAD, Meshers, ray tracing) and [dev,docs] the development and documentation tools.

Run tests with pytest:

pytest tests -n auto

Examples

Click on an image to open the example in the gallery of microgen's documentation. The images are rendered by the documentation build, so they always show the current version of each example.

Triply Periodic Minimal Surfaces (TPMS)

Available TPMS Gyroid Fischer-Koch S surface Gyroid in a shell Spherical gyroid

Graded TPMS

Density grading Cell size grading Morphing between TPMS types

Cylindrical and spherical TPMS

Cylindrical gyroid Radially graded cylindrical gyroid Spherical gyroid shell Spherical, cylindrical and swept frames

TPMS infill

Gyroid infill of a mesh Infill graded by the distance to the surface Gyroid infilled by a gyroid

Spinodoids

Spinodoid

Lattices

Periodic octet-truss mesh Honeycomb Preset strut lattices Custom auxetic lattice

Particle and fibre RVEs

Periodic RVE of spheres Periodic RVE of short fibres Short fibre composite

Implicit workflow

Gyroid as an implicit Phase Boolean operations on implicit fields

Basic shapes and 3D operations

Basic shapes Platonic solids Repeat a unit cell Rasterized ellipsoid Voronoi polycrystal Voronoi gyroid

Meshing and remeshing

Tetrahedral mesh of a Voronoi polycrystal Periodic gyroid mesh from a STEP file Periodic remeshing Level-set remeshing with mmg Level-set remeshing of a Voronoi mesh

Citation

If you use microgen in academic work, please cite it using the concept DOI, which always resolves to the latest archived version on Zenodo:

10.5281/zenodo.6793573

A BibTeX entry suitable for the latest release:

@software{microgen,
  author    = {Marchais, Kevin and
               Chemisky, Yves and
               Legerstee, Yasmin and
               Guevara Garban, Manuel Ricardo},
  title     = {{microgen: microstructure generation and meshing}},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.6793573},
  url       = {https://doi.org/10.5281/zenodo.6793573}
}

To cite a specific release instead of the concept, follow the concept DOI to its Zenodo page and pick the version DOI for the release you used. Machine-readable metadata is also available in CITATION.cff.

Authors and contributors

microgen is developed by the 3MAH group and external collaborators.

Authors

  • Kevin Marchais
  • Yves Chemisky
  • Yasmin Legerstee
  • Manuel Ricardo Guevara Garban

Contributors

  • Louise Le Barbenchon
  • Karim Haffar
  • Romain d'Esparbès
  • Sudeep Kumar Sahoo

About

Microstructure generation

Resources

Stars

133 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages