.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/Mesh/periodic_gyroid_remesh.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_Mesh_periodic_gyroid_remesh.py: Periodic gyroid mesh from a STEP file ===================================== Generate a gyroid, export it to a STEP file, mesh it periodically with gmsh, and remesh the result with mmg for finite element simulations. Steps performed: 1. Generate a TPMS geometry using the gyroid surface function. 2. Wrap the geometry into a microgen Phase object. 3. Export the geometry as a STEP file. 4. Import the STEP file and create a mesh with periodic constraints and export as VTK. 5. Remesh the mesh while preserving periodicity. Generated files: - periodic_gyroid.step: CAD representation of the TPMS geometry. - periodic_gyroid.vtk: Initial meshed structure. - periodic_gyroid_remeshed.vtk: Quality-improved periodic mesh for FEM. Requires the CAD backend (``pip install microgen[cad]``) and the ``mmg`` executables (``conda install -c conda-forge mmg``). .. GENERATED FROM PYTHON SOURCE LINES 25-73 .. code-block:: Python import pyvista as pv from microgen import Phase, Rve, Tpms, mesh_periodic from microgen.remesh import remesh_keeping_boundaries_for_fem from microgen.shape.surface_functions import gyroid # 1. Generate a TPMS geometry using the gyroid surface function. geometry = Tpms( surface_function=gyroid, density=0.30, resolution=30, ) # 2. Wrap the geometry into a microgen Phase object. phases = [] phases.append(Phase.from_cad(geometry.generate_cad())) rve = Rve(dim=1) # 3. Export the geometry as a STEP file. step_file = "periodic_gyroid.step" phases[0].cad.export_step(step_file) # 4. Import the STEP file and create a mesh with periodic constraints and export as VTK. vtk_file = "periodic_gyroid.vtk" mesh_periodic( mesh_file=step_file, rve=rve, list_phases=phases, order=1, size=0.03, output_file=vtk_file, ) # 5. Remesh the mesh while preserving periodicity. initial_gyroid = pv.UnstructuredGrid(vtk_file) max_element_edge_length = 0.02 remeshed_gyroid = remesh_keeping_boundaries_for_fem( initial_gyroid, periodic=True, hmax=max_element_edge_length, ) remeshed_vtk_file = "periodic_gyroid_remeshed.vtk" remeshed_gyroid.save(remeshed_vtk_file) .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. image:: /_static/examples/periodic_gyroid_remeshed.png sphinx_gallery_thumbnail_path = "_static/examples/periodic_gyroid_remeshed.png" .. _sphx_glr_download_examples_Mesh_periodic_gyroid_remesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: periodic_gyroid_remesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: periodic_gyroid_remesh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: periodic_gyroid_remesh.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_