A cantilever beam
A first analysis from start to end: a steel cantilever 2 m long, 50 mm by 100 mm, with 1 kN at its tip. It is small enough to check by hand, which is the point.
The blocks below, one after the other, are the whole script. Save them as cantilever.py and run it with
python cantilever.py. Units are N, mm, MPa and tonnes throughout.
Before you start: xfea installed with Gmsh meshing, and solving set up. See Setup.
1. The model
Section titled “1. The model”A model holds parts. A part holds nodes and elements, and each element has a section, which has a material.
from pathlib import Path
from xfea.geometry import Linefrom xfea.meshing import MeshingSettingsfrom xfea.model import BeamElement, ElasticIsotropic, Model, Part, RectangularSection
length = 2000.0 # mmload = -1000.0 # N, down
model = Model(name="cantilever")
steel = ElasticIsotropic(E=210_000, v=0.3, density=7.85e-9)section = RectangularSection(w=50, h=100, material=steel)2. The mesh
Section titled “2. The mesh”The part gets its geometry, a line along x, and is meshed into beam elements about 100 mm long.
part = model.add_part(Part(name="beam"))part.base_geometry = Line((0, 0, 0), (length, 0, 0))part.mesh( settings=MeshingSettings(max=100), section=section, element_cls=BeamElement, orientation=[0, 1, 0],)print(len(part.nodes), "nodes,", len(part.elements), "elements")orientation=[0, 1, 0] is the beams’ local y axis, the axis the section’s Ixx is about. With it, the section’s
100 mm is vertical and Ixx = w h³ / 12 carries the vertical load.
3. The support
Section titled “3. The support”Supports go on nodes, found by where they are.
start = part.find_closest_nodes_to_point((0, 0, 0))tip = part.find_closest_nodes_to_point((length, 0, 0))
model.add_fix_bc(nodes=start)
for warning in model.check(): print(warning)add_fix_bc holds the three translations and the three rotations. model.check() lists what a solver would get
wrong without saying so; here it has nothing to say.
4. The problem
Section titled “4. The problem”A problem is what happens to the model: one static step, with the load and the results to keep.
from xfea.problem import Problem, StaticStepfrom xfea.results import DisplacementFieldResults, ReactionFieldResults
problem = model.add_problem(Problem(name="tip_load"))step = problem.add_step(StaticStep(name="load"))step.add_uniform_forcefield(nodes=tip, z=load)
disp = DisplacementFieldResults()react = ReactionFieldResults()step.add_field_outputs([disp, react])5. The solve
Section titled “5. The solve”output = Path(__file__).resolve().parent / "output"problem.analyse_and_extract(path=output)The solver’s input is written through the conversion service, the solver runs on your machine, and the results are
read into output/tip_load/tip_load-results.db.
6. The answer, and the check
Section titled “6. The answer, and the check”deflection = disp.get_min_result("z").zby_hand = load * length**3 / (3 * steel.E * section.Ixx)
print(f"tip deflection: {deflection:.3f} mm") # -3.038print(f"by hand, P L³ / 3 E I: {by_hand:.3f} mm") # -3.048print(f"reaction: {react.get_max_result('z').z:.1f} N") # 1000.0The two deflections differ by 0.3 %: the solver’s twenty beam elements are slightly stiffer than the formula’s beam. The reaction equals the load.
7. The record
Section titled “7. The record”problem.record_result("tip deflection", deflection, "mm", note=f"by hand {by_hand:.3f} mm")print(problem.path)Open report.html in that folder: the result you just kept, the solve’s convergence, the model’s make-up and the
warnings, on one page.
Where to go next
Section titled “Where to go next”© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them