Skip to content

Inclined compression prop — StrutElement end-to-end demo

Part 2 of the unilateral-elements series.

An inclined bar acts as a prop between a pinned base anchor and a loaded node held against a horizontal floor (the floor is modelled as an in-plane roller — the loaded node can only translate vertically):

▓▓▓ n_top (vertical load applied here, restrained in x/y)
/
/
/ <- strut (length r, angle θ above horizontal)
/
/
o n_base (pinned)

Three cases are solved: (a) TrussElement, load = −F (down) : bilateral truss, carries compression. (b) StrutElement, load = +F (up) : would require tension → the strut carries no force in tension → the loaded node has no vertical restraint: no equilibrium, the solver finds no solution. (c) StrutElement, load = −F (down) : compression-only, same answer as (a).

Expected physics for the downward case (linear elastic, small strain): axial force N = -F / sinθ (compression, negative) top δz δz = -F · r / (E · A · sin²θ)

Axial force is recovered from the nodal displacements: project the relative displacement of the two end nodes onto the element axis, then apply the unilateral constitutive law (N = K·δ on the active branch, 0 otherwise).

Units: mm / N / MPa.

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/02_core_concepts/unilateral_elements/02_compression_prop.py. Run it from the repository with uv run python examples/scripts/02_core_concepts/unilateral_elements/02_compression_prop.py, or, with xfea-examples installed, xfea-examples run 02_core_concepts/unilateral_elements/02_compression_prop.py.

from __future__ import annotations
import math
from xfea.model import (
ElasticIsotropic,
Model,
Node,
Part,
StrutElement,
StrutSection,
TrussElement,
TrussSection,
)
from xfea.problem import Problem, StaticStep
from xfea.results import DisplacementFieldResults
from xfea_examples import out_dir
# Geometry / material / load
BASE_X = 0.0 # [mm]
TOP_X = 1_500.0 # [mm] horizontal run of the prop
TOP_Z = 1_500.0 # [mm] rise
A = 2_500.0 # [mm²] section area (e.g. 50×50 mm timber)
F = 20_000.0 # [N] vertical tip load magnitude
r = math.hypot(TOP_X - BASE_X, TOP_Z)
theta = math.atan2(TOP_Z, TOP_X - BASE_X)
timber = ElasticIsotropic(E=11_000.0, v=0.3, density=4.5e-10, name="timber")
def build_prop(name: str, element_cls, section_cls) -> Model:
"""Base pinned; top constrained so it can only translate in z."""
model = Model(name=name)
part = model.add_part(Part(name="prop"))
n_base = part.add_node(Node(xyz=[BASE_X, 0.0, 0.0]))
n_top = part.add_node(Node(xyz=[TOP_X, 0.0, TOP_Z]))
section = section_cls(A=A, material=timber)
part.add_element(element_cls(nodes=[n_base, n_top], section=section))
# Translations-only clamp (pin_bc) on the base — truss and strut elements
# have no rotational DOFs, so constraining rotations with fix_bc would
# produce a solver error on degrees of freedom no element carries.
model.add_pin_bc(nodes=[n_base])
# Top can move only in z (mimics a wall restraint in the horizontal
# plane while letting the load settle vertically).
model.add_rollerZ_bc(nodes=[n_top])
return model
def _axis(n1: Node, n2: Node) -> tuple[float, float, float]:
dx = float(n2.x) - float(n1.x)
dy = float(n2.y) - float(n1.y)
dz = float(n2.z) - float(n1.z)
mag = math.sqrt(dx * dx + dy * dy + dz * dz)
return (dx / mag, dy / mag, dz / mag)
def _elongation(element, disp_field, time) -> float:
n1, n2 = element.nodes
u1 = disp_field.get_result_at(n1, time=time)
u2 = disp_field.get_result_at(n2, time=time)
du = (float(u2.x) - float(u1.x),
float(u2.y) - float(u1.y),
float(u2.z) - float(u1.z))
ax, ay, az = _axis(n1, n2)
return du[0] * ax + du[1] * ay + du[2] * az
def _axial_force(element, disp_field, time, mode: str) -> tuple[float, float, float]:
L_el = float(element.length)
K = float(element.section.material.E) * float(element.section.A) / L_el
delta = _elongation(element, disp_field, time)
if mode == "bilateral":
N = K * delta
elif mode == "tie":
N = K * delta if delta > 0 else 0.0
elif mode == "strut":
N = K * delta if delta < 0 else 0.0
else:
raise ValueError(mode)
return delta, K, N
def solve_case(element_cls, section_cls, tag: str, load_z: float, mode: str) -> dict:
model = build_prop(f"prop_{tag}", element_cls, section_cls)
top_group = model.parts[0].nodes.subgroup(
lambda n: abs(float(n.z) - TOP_Z) < 1e-6
)
problem = model.add_problem(Problem(name=f"{model.name}_run"))
step = problem.add_step(
StaticStep(
name=tag,
nlgeom=True,
initial_inc_size=0.5,
max_inc_size=1.0,
min_inc_size=1e-3,
max_increments=30,
)
)
step.add_uniform_forcefield(nodes=top_group, z=load_z, load_case=tag)
disp = DisplacementFieldResults()
step.add_field_outputs([disp])
try:
problem.analyse_and_extract(path=out_dir(model.name), verbose=False)
except Exception as exc:
return {"ok": False, "error": f"{type(exc).__name__}: {exc}"}
STEP_END = 1.0
n_top = list(top_group)[0]
element = list(model.parts[0].elements)[0]
try:
dz = float(disp.get_result_at(n_top, time=STEP_END).z)
except (ValueError, TypeError, AttributeError):
dz = float("nan") # the solver wrote no results: it found no equilibrium
if not math.isfinite(dz):
# The strut went slack and nothing else holds the top: no equilibrium, no force.
return {"ok": True, "no_equilibrium": True, "N": 0.0, "slack": True}
delta, K, N = _axial_force(element, disp, STEP_END, mode)
is_slack = mode in ("tie", "strut") and abs(N) < 1e-3
return {"ok": True, "dz": dz, "delta": delta, "K": K, "N": N,
"slack": is_slack}
def _print_result(label: str, res: dict):
print(f"--- {label} ---")
if not res["ok"]:
print(f" solver failure: {res['error']}")
return
if res.get("no_equilibrium"):
print(" no equilibrium : the strut carries nothing in tension and the")
print(" loaded top is free, so the solver finds no solution")
print(" N : +0.0 N (slack)")
else:
tag = " (slack)" if res.get("slack") else ""
print(f" top δz (FEA) : {res['dz']:+.4f} mm")
print(f" elongation δ : {res['delta']:+.4f} mm")
print(f" N = K·δ (law) : {res['N']:+.1f} N{tag}")
print()
if __name__ == "__main__":
print("Inclined prop demo — pinned base, roof held against a wall.")
print(f" geometry : base=(0,0,0) → top=({TOP_X:.0f},0,{TOP_Z:.0f}), "
f"length r={r:.1f} mm, θ={math.degrees(theta):.1f}°")
print(f" material : E={timber.E:.0f} MPa, A={A:.0f} mm²")
print(f" load : F_z at the top (magnitude {F:.0f} N)")
print()
N_ref = -F / math.sin(theta)
dz_ref = -F * r / (timber.E * A * math.sin(theta) ** 2)
print("Reference (downward load, linear elastic):")
print(f" N = -F / sinθ = {N_ref:+.1f} N")
print(f" δz = -F·r / (E·A·sin²θ) = {dz_ref:+.4f} mm")
print()
_print_result(
"TrussElement, load down (compression)",
solve_case(TrussElement, TrussSection, "truss_down", -F, "bilateral"),
)
# The last case solved is one with results: its model is the one left to look at.
_print_result(
"StrutElement, load up (tension → slack)",
solve_case(StrutElement, StrutSection, "strut_up", +F, "strut"),
)
_print_result(
"StrutElement, load down (compression)",
solve_case(StrutElement, StrutSection, "strut_down", -F, "strut"),
)
print(
"Interpretation:\n"
" Rows 1 & 3 (downward load): truss and strut both carry the\n"
" full compression load and settle by F·r/(E·A·sin²θ). In\n"
" pure compression the strut stays on its active branch and\n"
" behaves exactly like a regular truss.\n"
"\n"
" Row 2 (upward load): the strut would need to carry tension\n"
" and carries no force in tension — it goes slack, N = 0, and\n"
" nothing else holds the top node vertically, so there is no\n"
" equilibrium and no displacement to report. That is the\n"
" expected physical answer: a prop cannot be pulled.\n"
)

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