.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/3Doperations/voronoi.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_3Doperations_voronoi.py: Voronoi polycrystal =================== Import the cells of a Neper tessellation as polyhedra with :meth:`microgen.Neper.voronoi_from_tess_file`, build a CAD compound and mesh it with gmsh. Requires the CAD backend: ``pip install microgen[cad]``. .. GENERATED FROM PYTHON SOURCE LINES 11-37 .. code-block:: Python import pyvista as pv from microgen import Neper, Phase, mesh from microgen.cad import make_compound tess_file = "voronoi.tess" polyhedra = Neper.voronoi_from_tess_file(tess_file) shapes = [poly.generate_cad() for poly in polyhedra] compound = make_compound(shapes) step_file = "voronoi.step" compound.export_step(step_file) phases = [Phase.from_cad(shape) for shape in shapes] vtk_file = "voronoi.vtk" mesh( mesh_file=step_file, list_phases=phases, size=0.05, order=1, output_file=vtk_file, ) .. GENERATED FROM PYTHON SOURCE LINES 38-39 One color per grain. .. GENERATED FROM PYTHON SOURCE LINES 39-50 .. code-block:: Python grid = pv.read(vtk_file) grains = grid.cell_data.keys()[0] grid.extract_surface(algorithm="dataset_surface").plot( scalars=grains, preference="cell", cmap="tab20", smooth_shading=True, split_sharp_edges=True, show_scalar_bar=False, ) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/3Doperations/images/sphx_glr_voronoi_001.png :alt: voronoi :srcset: /examples/3Doperations/images/sphx_glr_voronoi_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/microgen/microgen/docs/examples/3Doperations/images/sphx_glr_voronoi_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 51-53 The tetrahedral mesh: each grain is a separate physical volume, with matching nodes on the grain boundaries. .. GENERATED FROM PYTHON SOURCE LINES 53-54 .. code-block:: Python grid.plot(show_edges=True, scalars=grains, cmap="tab20", show_scalar_bar=False) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/3Doperations/images/sphx_glr_voronoi_002.png :alt: voronoi :srcset: /examples/3Doperations/images/sphx_glr_voronoi_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/microgen/microgen/docs/examples/3Doperations/images/sphx_glr_voronoi_002.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.535 seconds) .. _sphx_glr_download_examples_3Doperations_voronoi.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: voronoi.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: voronoi.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: voronoi.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_