Note
Go to the end to download the full example code.
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.
from __future__ import annotations
import numpy as np
import pyvista as pv
import femorph_solver
Build a 10 × 2 × 2 hex cantilever#
Wrap as a femorph_solver.Model and stamp material#
/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)
Clamp the x=0 face, push the tip down#
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))
/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))
Solve#
res = m.solve()
print(f"Tip displacement (UZ) = {res.displacement[2::3][tip - 1].mean():.3e} m")
Tip displacement (UZ) = -1.458e-03 m
Plot the deformed shape#
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()

Total running time of the script: (0 minutes 2.306 seconds)