.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/TPMS/cylindrical_graded.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_TPMS_cylindrical_graded.py: Radially graded cylindrical gyroid ================================== A cylindrical gyroid whose offset increases with the radius, from an empty core to a fully dense skin. .. GENERATED FROM PYTHON SOURCE LINES 8-62 .. code-block:: Python from __future__ import annotations from functools import partial import numpy as np import pyvista as pv from microgen import CylindricalTpms from microgen.shape.surface_functions import gyroid def swapped_gyroid(x: np.ndarray, y: np.ndarray, z: np.ndarray) -> np.ndarray: """Compute swapped gyroid function.""" return gyroid(x=z, y=y, z=x) def grading( x: np.ndarray, y: np.ndarray, _: np.ndarray, min_offset: float | np.ndarray = 0.0, max_offset: float | np.ndarray = 3.0, ) -> np.ndarray: """Compute grading function based on radial distance.""" rad = np.sqrt(x**2 + y**2) max_rad = np.max(rad) min_rad = np.min(rad) return min_offset + (max_offset - min_offset) * (rad - min_rad) / ( max_rad - min_rad ) full_density_offset = CylindricalTpms.offset_from_density( surface_function=swapped_gyroid, part_type="sheet", density=1.0, ) geometry = CylindricalTpms( radius=5, surface_function=swapped_gyroid, offset=partial( grading, min_offset=0.0, max_offset=full_density_offset, ), cell_size=(1, 1, 1), repeat_cell=(5, 0, 1), resolution=20, ) sheet = geometry.sheet .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/hostedtoolcache/Python/3.12.16/x64/lib/python3.12/site-packages/autograd/numpy/numpy_vjps.py:187: RuntimeWarning: divide by zero encountered in power defvjp(anp.sqrt, lambda ans, x: lambda g: g * 0.5 * x**-0.5) /opt/hostedtoolcache/Python/3.12.16/x64/lib/python3.12/site-packages/autograd/numpy/numpy_vjps.py:141: RuntimeWarning: invalid value encountered in multiply lambda ans, x, y: unbroadcast_f(x, lambda g: g * y * x ** anp.where(y, y - 1, 1.0)), /opt/hostedtoolcache/Python/3.12.16/x64/lib/python3.12/site-packages/autograd/numpy/numpy_vjps.py:147: RuntimeWarning: invalid value encountered in divide lambda ans, x, y: unbroadcast_f(y, lambda g: g * -x / (x**2 + y**2)), /opt/hostedtoolcache/Python/3.12.16/x64/lib/python3.12/site-packages/autograd/numpy/numpy_vjps.py:146: RuntimeWarning: invalid value encountered in divide lambda ans, x, y: unbroadcast_f(x, lambda g: g * y / (x**2 + y**2)), .. GENERATED FROM PYTHON SOURCE LINES 63-69 .. code-block:: Python plotter = pv.Plotter() plotter.add_mesh(sheet, smooth_shading=True, color="#ef7d2d") plotter.view_xy() plotter.enable_parallel_projection() plotter.show_axes() plotter.show() .. image-sg:: /examples/TPMS/images/sphx_glr_cylindrical_graded_001.png :alt: cylindrical graded :srcset: /examples/TPMS/images/sphx_glr_cylindrical_graded_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.547 seconds) .. _sphx_glr_download_examples_TPMS_cylindrical_graded.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cylindrical_graded.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cylindrical_graded.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cylindrical_graded.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_