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
from femorph_solver import ELEMENTS

Build a 10 × 2 × 2 hex cantilever#

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()

Wrap as a femorph_solver.Model and stamp material#

m = femorph_solver.Model.from_grid(grid)
m.assign(ELEMENTS.HEX8, material={"EX": E, "PRXY": NU, "DENS": 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]
m.fix(nodes=fixed.tolist(), dof="ALL")

tip = node_nums[pts[:, 0] > LX - 1e-9]
fz_per_node = -10_000.0 / len(tip)
for nn in tip:
    m.apply_force(int(nn), fz=fz_per_node)

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()
example quickstart static

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

Gallery generated by Sphinx-Gallery