Skip to content

Hanging mass on a tension-only cable — TieElement end-to-end demo

Part 1 of the unilateral-elements series.

A single cable hangs from a fixed anchor; a point mass at the free end is loaded vertically. Three small models are solved side-by-side:

(a) TrussElement — bilateral baseline (truss, carries either sign).
(b) TieElement, pushed up — cable slack, carries no force.
(c) TieElement, pulled down — cable taut, behaves like the truss.

A TieElement carries no force in compression: it has the truss’s axial stiffness when stretched and none when shortened, so the cable cannot be pushed. The TrussElement is an ordinary truss.

The script reads the axial force from the nodal displacements and the element’s force-elongation law:

δ = (u2 − u1) · axis (signed elongation, positive = stretch)
K = E · A / L (linear axial stiffness)
N = K · δ if δ is on the active branch else 0

In the “push up” case the tie would have to shorten, and it carries no force in compression: nothing holds the tip against the load, so there is no equilibrium and the solver finds no solution. The script reports that case as slack, N = 0, with no displacement to show.

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

from __future__ import annotations
import math
from xfea.model import (
ElasticIsotropic,
Model,
Node,
Part,
TieElement,
TieSection,
TrussElement,
TrussSection,
)
from xfea.problem import Problem, StaticStep
from xfea.results import DisplacementFieldResults
from xfea_examples import out_dir
# Geometry / material
L = 1_000.0 # [mm] cable length
A = 100.0 # [mm²] cross-section area
F = 10_000.0 # [N] tip load magnitude
steel = ElasticIsotropic(E=210_000.0, v=0.3, density=7.85e-9, name="steel")
def build_cable_model(name: str, element_cls, section_cls) -> Model:
"""Vertical cable: anchor at top, free tip at the bottom."""
model = Model(name=name)
part = model.add_part(Part(name="cable"))
n_top = part.add_node(Node(xyz=[0.0, 0.0, L]))
n_tip = part.add_node(Node(xyz=[0.0, 0.0, 0.0]))
section = section_cls(A=A, material=steel)
part.add_element(element_cls(nodes=[n_top, n_tip], section=section))
# Anchor the top (translations only — truss and tie elements have no
# rotational DOFs, so constraining rotations would trigger a solver
# error on degrees of freedom no element carries). Tip is free along z only.
model.add_pin_bc(nodes=[n_top])
model.add_rollerZ_bc(nodes=[n_tip])
return model
def _axis(n1: Node, n2: Node) -> tuple[float, float, float]:
"""Unit vector from n1 toward n2."""
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:
"""Signed elongation: positive = stretched, negative = compressed."""
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]:
"""Return (elongation, stiffness K, axial force N) consistent with the
unilateral constitutive law: N = K·δ on the active branch, 0 otherwise.
``mode`` is ``"bilateral"``, ``"tie"``, or ``"strut"``."""
L_el = float(element.length)
E = float(element.section.material.E)
A_el = float(element.section.A)
K = E * A_el / 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, tip_force_z: float, mode: str
) -> dict | None:
model = build_cable_model(f"cable_{tag}", element_cls, section_cls)
tip_group = model.parts[0].nodes.subgroup(lambda n: abs(float(n.z)) < 1e-6)
problem = model.add_problem(Problem(name=f"{model.name}_gravity"))
step = problem.add_step(
StaticStep(
name="pull",
nlgeom=True,
initial_inc_size=0.5,
max_inc_size=1.0,
min_inc_size=1e-3,
max_increments=20,
)
)
step.add_uniform_forcefield(nodes=tip_group, z=tip_force_z, load_case="pull")
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_tip = list(tip_group)[0]
element = list(model.parts[0].elements)[0]
try:
dz = float(disp.get_result_at(n_tip, 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 tie went slack and nothing else holds the tip: 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)
return {
"ok": True,
"dz": dz,
"delta": delta,
"K": K,
"N": N,
"slack": mode in ("tie", "strut") and abs(N) < 1e-3,
}
if __name__ == "__main__":
print(
"Hanging-cable demo — vertical cable of length",
f"L={L:.0f} mm,",
f"A={A:.0f} mm², E={steel.E:.0f} MPa.",
)
print()
K_ref = steel.E * A / L # linear stiffness
dz_ref = -F / K_ref # downward displacement
N_ref = F # tension when pulled down
print("Reference (linear elastic):")
print(f" K = E·A/L = {K_ref:.1f} N/mm")
print(f" δz = -F/K = {dz_ref:+.4f} mm (downward pull)")
print(f" N = F = {N_ref:+.1f} N (tension)")
print()
# The last case solved is one with results: its model is the one left to look at.
cases = [
("TrussElement, pull down", TrussElement, TrussSection, -F, "bilateral"),
("TieElement, push up ", TieElement, TieSection, +F, "tie"),
("TieElement, pull down", TieElement, TieSection, -F, "tie"),
]
for label, el_cls, sec_cls, load_z, mode in cases:
print(f"--- {label} ---")
tag = label.replace(",", "").replace(" ", "_").lower()
res = solve_case(el_cls, sec_cls, tag, load_z, mode)
if not res["ok"]:
print(f" solver failure: {res['error']}")
continue
if res.get("no_equilibrium"):
print(" no equilibrium : the tie carries nothing in compression and the")
print(" loaded tip is free, so the solver finds no solution")
print(" N : +0.0 N (slack)")
else:
tag_slack = " (slack)" if res.get("slack") else ""
print(f" tip δz (FEA) : {res['dz']:+.4f} mm")
print(f" elongation δ : {res['delta']:+.4f} mm")
print(f" N = K·δ (law) : {res['N']:+.1f} N{tag_slack}")
print()
print(
"Interpretation:\n"
" Row 1 (truss, pulled down): K·δ ≈ +F — the cable stretches\n"
" by F/K and carries F in tension.\n"
" Row 2 (tie, pushed up): the cable would have to shorten and\n"
" carries no force in compression: it goes slack, N = 0, and\n"
" nothing else holds the tip, so there is no equilibrium and\n"
" no displacement to report — exactly as a real cable pushed\n"
" from below.\n"
" Row 3 (tie, pulled down): same numbers as row 1 — ties behave\n"
" exactly like trusses when loaded in tension.\n"
)

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