.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/Lattices/octet_truss.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_Lattices_octet_truss.py: Periodic octet-truss mesh ========================= Build an octet-truss from cylinders read in a data file, make it periodic with :func:`microgen.periodic_split_and_translate`, and mesh it with :func:`microgen.mesh_periodic` so that opposite faces have matching nodes. Requires the CAD backend: ``pip install microgen[cad]``. .. GENERATED FROM PYTHON SOURCE LINES 11-25 .. code-block:: Python import numpy as np import pyvista as pv from microgen import ( Cylinder, Phase, Rve, cut_phases, mesh_periodic, periodic_split_and_translate, ) from microgen.cad import make_compound .. GENERATED FROM PYTHON SOURCE LINES 26-27 Read the strut positions, orientations and dimensions. .. GENERATED FROM PYTHON SOURCE LINES 27-61 .. code-block:: Python data_file = "octet_truss.dat" dt = np.dtype( [ ("number", int), ("shape", np.str_, 10), ("xc", np.float64), ("yc", np.float64), ("zc", np.float64), ("psi", np.float64), ("theta", np.float64), ("phi", np.float64), ("a1", np.float64), ("a2", np.float64), ] ) data = np.loadtxt( data_file, dtype=dt, usecols=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), skiprows=1, unpack=True, ndmin=1, ) xc = data[2] yc = data[3] zc = data[4] psi = data[5] theta = data[6] phi = data[7] height = data[8] radius = data[9] .. GENERATED FROM PYTHON SOURCE LINES 62-64 Build the struts, split the parts that cross the RVE faces and translate them to the opposite side. .. GENERATED FROM PYTHON SOURCE LINES 64-86 .. code-block:: Python rve = Rve(dim=1) list_phases = [] for i in range(len(xc)): elem = Cylinder( center=(xc[i] - 0.5, yc[i] - 0.5, zc[i] - 0.5), orientation=(psi[i], theta[i], phi[i]), height=height[i], radius=radius[i], ) list_phases.append(Phase.from_cad(elem.generate_cad())) periodic_phases = [ periodic_split_and_translate(phase=phase, rve=rve) for phase in list_phases ] phases_cut = cut_phases(phases=periodic_phases, reverse_order=False) compound = make_compound([phase.cad for phase in phases_cut]) step_file = "octet_truss.step" compound.export_step(step_file) compound.export_stl("octet_truss.stl") .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/microgen/microgen/microgen/periodic.py:297: UserWarning: Object intersecting x+ and x- faces: not doing anything in this direction intersected_faces, rve_planes, partitions = _detect_intersected_faces(shape, rve) /home/runner/work/microgen/microgen/microgen/periodic.py:297: UserWarning: Object intersecting y+ and y- faces: not doing anything in this direction intersected_faces, rve_planes, partitions = _detect_intersected_faces(shape, rve) /home/runner/work/microgen/microgen/microgen/periodic.py:297: UserWarning: Object intersecting z+ and z- faces: not doing anything in this direction intersected_faces, rve_planes, partitions = _detect_intersected_faces(shape, rve) .. GENERATED FROM PYTHON SOURCE LINES 87-88 Periodic tetrahedral mesh. .. GENERATED FROM PYTHON SOURCE LINES 88-98 .. code-block:: Python vtk_file = "octet_truss.vtk" mesh_periodic( mesh_file=step_file, rve=rve, list_phases=phases_cut, order=1, size=0.03, output_file=vtk_file, ) .. GENERATED FROM PYTHON SOURCE LINES 99-100 .. code-block:: Python pv.read(vtk_file).plot(show_edges=True, color="#ef7d2d") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/Lattices/images/sphx_glr_octet_truss_001.png :alt: octet truss :srcset: /examples/Lattices/images/sphx_glr_octet_truss_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/microgen/microgen/docs/examples/Lattices/images/sphx_glr_octet_truss_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.797 seconds) .. _sphx_glr_download_examples_Lattices_octet_truss.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: octet_truss.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: octet_truss.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: octet_truss.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_