Skip to content

A simple axial bar

Demonstrates the generic workflow: model, mesh, solve, and query results. The script uses the configured default plugins without naming them directly.

The model before it is solved: parts, supports and loads

The model before it is solved: its parts, supports (red) and loads (blue).

The result: the deformed shape coloured by displacement (magnitude [mm])

The deformed shape, coloured by displacement (magnitude [mm]), in xfea’s 3D viewer.

Open in 3D turn it, cut it, pick any field: in xfea's viewer, in your browser

examples/scripts/01_getting_started/01_truss.py. Run it from the repository with uv run python examples/scripts/01_getting_started/01_truss.py, or, with xfea-examples installed, xfea-examples run 01_getting_started/01_truss.py.

from xfea.problem import Problem
from xfea.problem import StaticStep
from xfea.results import DisplacementFieldResults
from xfea.results import ReactionFieldResults
from xfea_examples import out_dir
from xfea_examples import show_viewer
from xfea_examples.models import truss_model
tip_load_x = 10_000 # [N] axial tip force
model, _, tip_nodes, _, _, _ = truss_model(name="getting_started_truss")
problem = model.add_problem(Problem(name="truss_problem"))
step = problem.add_step(StaticStep(name="service"))
step.add_uniform_forcefield(nodes=tip_nodes, x=tip_load_x, load_case="service")
disp = DisplacementFieldResults()
react = ReactionFieldResults()
step.add_field_outputs([disp, react])
problem.analyse_and_extract(path=out_dir(model.name), verbose=False)
tip_disp = disp.get_max_result("x")
print(f"Tip displacement in x: {tip_disp.x}")
show_viewer(model, results={disp: "x"}, units="mm")

© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them