.. 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 .. GENERATED FROM PYTHON SOURCE LINES 18-20 Build a 10 × 2 × 2 hex cantilever --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 20-29 .. code-block:: Python E, NU, RHO = 2.1e11, 0.30, 7850.0 LX, LY, LZ = 1.0, 0.1, 0.1 NX, NY, NZ = 10, 2, 2 xs = np.linspace(0.0, LX, NX + 1) ys = np.linspace(0.0, LY, NY + 1) zs = np.linspace(0.0, LZ, NZ + 1) grid = pv.StructuredGrid(*np.meshgrid(xs, ys, zs, indexing="ij")).cast_to_unstructured_grid() .. GENERATED FROM PYTHON SOURCE LINES 30-32 Wrap as a :class:`femorph_solver.Model` and stamp material ---------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python m = femorph_solver.Model.from_grid(grid) m.et(1, "SOLID185") m.mp("EX", 1, E) m.mp("PRXY", 1, NU) m.mp("DENS", 1, RHO) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_static.py:33: DeprecationWarning: Model.et(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).et(et_id, name)` for line-by-line APDL deck porting, or the native `Model.assign("HEX8", material)` for new code. m.et(1, "SOLID185") /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_static.py:34: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("EX", 1, E) /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_static.py:35: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("PRXY", 1, NU) /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_static.py:36: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("DENS", 1, RHO) .. GENERATED FROM PYTHON SOURCE LINES 39-41 Clamp the x=0 face, push the tip down ------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 41-51 .. code-block:: Python pts = np.asarray(grid.points) node_nums = np.asarray(grid.point_data["ansys_node_num"]) fixed = node_nums[pts[:, 0] < 1e-9] for nn in fixed: m.d(int(nn), "ALL") tip = node_nums[pts[:, 0] > LX - 1e-9] for nn in tip: m.f(int(nn), "FZ", -10_000.0 / len(tip)) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_static.py:45: DeprecationWarning: Model.d(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).d(node, label, value)` for line-by-line APDL deck porting, or the native `Model.fix(nodes=..., where=..., dof=...)` for new code. m.d(int(nn), "ALL") /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_static.py:49: DeprecationWarning: Model.f(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).f(node, label, value)` for line-by-line APDL deck porting, or the native `Model.apply_force(node, fx=..., fy=..., fz=...)` for new code. m.f(int(nn), "FZ", -10_000.0 / len(tip)) .. GENERATED FROM PYTHON SOURCE LINES 52-54 Solve ----- .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python res = m.solve() print(f"Tip displacement (UZ) = {res.displacement[2::3][tip - 1].mean():.3e} m") .. rst-class:: sphx-glr-script-out .. code-block:: none Tip displacement (UZ) = -1.458e-03 m .. GENERATED FROM PYTHON SOURCE LINES 58-60 Plot the deformed shape ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-72 .. code-block:: Python deformed = femorph_solver.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 2.306 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 `_