Coulomb friction verification
Two stacked solid blocks with frictional contact (mu = 0.3). A compressive force is applied first, followed by a lateral force that is below the Coulomb friction limit.
Step 1 — Compression:
F_z = -100 kN (uniform on top face)Expected: uniaxial compression, no slidingStep 2 — Lateral load below friction limit:
F_x = 20 kN (uniform on top face)Coulomb limit: F_t_max = mu * |F_z| = 0.3 * 100 = 30 kNSince F_x = 20 kN < 30 kN => stick (no sliding expected)The top block should displace laterally due to elastic shear deformation, but no macro-sliding should occur at the interface.
References
Section titled “References”- Wriggers, P. “Computational Contact Mechanics”, 2nd ed., Springer, 2006.
- The solver’s own penalty-contact examples.

The model before it is solved: its parts, supports (red) and loads (blue).
![The result: the model coloured by displacement (magnitude [mm])](/examples/core-concepts/contact/contact-friction-results.webp)
The model, 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
The script
Section titled “The script”examples/scripts/02_core_concepts/contact/contact_friction.py. Run it from the repository with uv run python examples/scripts/02_core_concepts/contact/contact_friction.py, or, with xfea-examples installed, xfea-examples run 02_core_concepts/contact/contact_friction.py.
from xfea.geometry import Translation
from xfea.model import HardContactFrictionPenaltyfrom xfea.problem import ContactControlsfrom xfea.problem import Problemfrom xfea.problem import StaticStepfrom xfea.results import ContactForcesFieldResultsfrom xfea.results import DisplacementFieldResultsfrom xfea.results import ReactionFieldResults
from xfea_examples import out_dirfrom xfea_examples import viewer_wantedfrom xfea_examples.models import solid_box_model
from xfea.viewers import Viewer
# 1. Model: two stacked blocks with frictional contact (mu = 0.3)stack_offset_z = 1000 # [mm] vertical offset between blocksmu = 0.3 # [-] friction coefficientF_z = -100_000 # [N] compressive vertical force (-100 kN)F_x = 20_000 # [N] lateral force (20 kN, below mu*|F_z|=30 kN)
model, part_a, _, _, _ = solid_box_model(name="reference_contact_friction", element_order=2)part_b = part_a.copy()part_b.name = "upper_block"part_b.transform(Translation.from_vector([0, 0, stack_offset_z]))model.add_part(part_b)
contact = HardContactFrictionPenalty(mu=mu, tol=1)model.detect_interfaces(behavior=contact, method="face_intersection")
# 2. Boundary conditions# Fix the base of the lower block (all DOFs).base_nodes = part_a.find_nodes_on_plane(part_a.bottom_plane)model.add_fix_bc(base_nodes)
# Constrain Y (out-of-plane) on the top face to keep the problem 2-D in# the XZ plane. X and Z remain free.top_nodes = part_b.find_nodes_on_plane(part_b.top_plane)model.add_rollerXZ_bc(top_nodes)
# 3. Contact convergence controls# Shared across both steps. The defaults are already tuned for contact, but# we tighten residual_tolerance for this verification case.cc = ContactControls( residual_tolerance=0.005, # tight -- this is a verification case correction_tolerance=0.01,)
# 4. Step 1: vertical compressionproblem = model.add_problem(Problem(name="friction_problem"))
# Small initial increment for stable contact convergence.# nlgeom not needed for this small-strain problem.step1 = problem.add_step( StaticStep( name="compression", nlgeom=False, initial_inc_size=0.05, max_inc_size=0.1, contact_controls=cc, ))step1.add_uniform_forcefield( nodes=top_nodes, z=F_z / max(1, len(top_nodes)), load_case="compression")
disp1 = DisplacementFieldResults()react1 = ReactionFieldResults()cf1 = ContactForcesFieldResults()step1.add_field_outputs([disp1, react1, cf1])
# 5. Step 2: lateral force below friction limit# Compression from step 1 is carried forward automatically by the solver.step2 = problem.add_step( StaticStep( name="lateral_load", nlgeom=False, initial_inc_size=0.05, max_inc_size=0.1, contact_controls=cc, ))step2.add_uniform_forcefield( nodes=top_nodes, x=F_x / max(1, len(top_nodes)), load_case="lateral")
disp2 = DisplacementFieldResults()react2 = ReactionFieldResults()cf2 = ContactForcesFieldResults()step2.add_field_outputs([disp2, react2, cf2])
# 6. Analyseproblem.analyse_and_extract(path=out_dir(model.name), verbose=True, cpus=1)
# 7. Results comparisonF_z_val = abs(F_z) # [N]F_x_val = F_x # [N]coulomb_limit = mu * F_z_val
print()print("=" * 60)print("CONTACT FRICTION - Reference Case")print("=" * 60)print()print("Setup:")print(f" Friction coefficient (mu): {mu}")print(f" Vertical force: {F_z_val / 1e3:.0f} kN")print(f" Lateral force: {F_x_val / 1e3:.0f} kN")print(f" Coulomb limit (mu*Fz): {coulomb_limit / 1e3:.0f} kN")print(f" Interfaces detected: {len(model.interfaces)}")print()print("Step 1 - Compression:")print(f" Max vertical disp: {disp1.get_min_result('z').z}")print()print("Step 2 - Lateral load (below Coulomb limit => stick):")print(f" Applied F_x: {F_x_val / 1e3:.0f} kN")print(f" Coulomb limit: {coulomb_limit / 1e3:.0f} kN")print(f" Status: {'STICK (F_x < mu*Fz)' if F_x_val < coulomb_limit else 'SLIP'}")print(f" Max lateral disp: {disp2.get_max_result('x').x}")
viewer = Viewer(plugin="browser")viewer.add_model(model)viewer.add_results({disp1: "x"}, units="mm")viewer.add_results({disp2: "x"}, units="mm")if viewer_wanted(): # XFEA_EXAMPLES_SHOW_VIEWER=1, or `xfea-examples config set-show-viewer on` viewer.run()© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them