.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/quickstart/example_quickstart_static.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_gallery_quickstart_example_quickstart_static.py: Static cantilever — first example ================================= A 60-second introduction to femorph-solver's static analysis path: build a steel cantilever beam as a structured pyvista grid, clamp the ``x=0`` end, push the tip downward, and plot the deformed mesh. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python from __future__ import annotations import numpy as np import pyvista as pv import femorph_solver as fs .. GENERATED FROM PYTHON SOURCE LINES 18-20 Build a 10 × 2 × 2 hex cantilever --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 20-31 .. code-block:: Python LX, LY, LZ = 1.0, 0.1, 0.1 grid = pv.StructuredGrid( *np.meshgrid( np.linspace(0.0, LX, 11), np.linspace(0.0, LY, 3), np.linspace(0.0, LZ, 3), indexing="ij", ) ).cast_to_unstructured_grid() .. GENERATED FROM PYTHON SOURCE LINES 32-34 Wrap as a :class:`femorph_solver.Model` and stamp steel ------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Python m = fs.Model.from_grid(grid) m.assign(fs.ELEMENTS.HEX8, material={"EX": 2.1e11, "PRXY": 0.30, "DENS": 7850.0}) .. GENERATED FROM PYTHON SOURCE LINES 38-40 Clamp the x=0 face, push the tip down with 10 kN distributed ------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python x = np.asarray(grid.points)[:, 0] m.fix(where=x < 1e-9) m.apply_force(where=x > LX - 1e-9, fz=-10_000.0, total=True) .. GENERATED FROM PYTHON SOURCE LINES 45-47 Solve + report -------------- .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python res = m.solve_static() print(f"tip UZ = {res.displacement[2::3].min():.3e} m") .. rst-class:: sphx-glr-script-out .. code-block:: none tip UZ = -1.458e-03 m .. GENERATED FROM PYTHON SOURCE LINES 51-53 Plot the deformed shape ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 53-65 .. code-block:: Python deformed = fs.io.static_result_to_grid(m, res) plotter = pv.Plotter(off_screen=True) plotter.add_mesh(deformed, style="wireframe", color="gray", opacity=0.35, label="undeformed") plotter.add_mesh( deformed.warp_by_vector("displacement", factor=50.0), scalars="displacement_magnitude", scalar_bar_args={"title": "|u| [m]"}, label="deformed (×50)", ) plotter.add_legend() plotter.add_axes() plotter.show() .. image-sg:: /gallery/quickstart/images/sphx_glr_example_quickstart_static_001.png :alt: example quickstart static :srcset: /gallery/quickstart/images/sphx_glr_example_quickstart_static_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.042 seconds) .. _sphx_glr_download_gallery_quickstart_example_quickstart_static.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_quickstart_static.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_quickstart_static.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_quickstart_static.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_