Foundation Contact and Separation
This example introduces frictional node-to-solid contact by placing a shallow foundation block partly inside an elastic soil domain. Gravity closes the interface. A horizontal load applied above the ground then rocks the block, allowing one side to open while the opposite side remains in compression.
| Application | Shallow-foundation contact and uplift |
| Model | Elastic soil and elastic solid foundation block |
| Interface | Five frictional contact faces |
| Loading | Self-weight followed by a 150 kN lateral load |
| Analysis | Implicit gravity, then explicit rocking |
| Output | VTKHDF displacement history and deformation movie |
Model
The soil and foundation are separate bodies. The block penetrates 0.25 m below the ground surface, placing its base and four short side faces inside the host soil. Those five buried faces can transfer compression and friction while remaining free to open when the block rocks.
The green arrows are the outward block normals supplied to normal_filter.
They select contact candidates; Femora converts them to the host-to-block
orientation required by the solver element.
Worked Workflow
Create independent elastic brick meshes for the soil and foundation. Both use lumped mass because the lateral stage uses explicit integration.
# Units are kN, m, tonne, and s.
soil = model.material.nd.elastic_isotropic(
user_name="soil", E=377000.0, nu=0.3, rho=19.9 / 9.81
)
soil_element = model.element.brick.std(
ndof=3, material=soil, b1=0.0, b2=0.0, b3=-19.9, lumped=True
)
model.meshpart.volume.geometric_rectangular_grid(
user_name="soil",
element=soil_element,
x_min=-2.5, x_max=2.5,
y_min=-2.5, y_max=2.5,
z_min=-5.0, z_max=0.0,
nx=4, ny=4, nz=4,
)
concrete = model.material.nd.elastic_isotropic(
user_name="concrete", E=30.0e6, nu=0.2, rho=2.5
)
block_element = model.element.brick.std(
ndof=3, material=concrete, b1=0.0, b2=0.0, b3=-24.525, lumped=True
)
model.meshpart.volume.geometric_rectangular_grid(
user_name="foundation_block",
element=block_element,
x_min=-1.0, x_max=1.0,
y_min=-1.0, y_max=1.0,
z_min=-0.25, z_max=1.75,
nx=4, ny=4, nz=4,
)
Assemble without merging coincident points. Merging would tie the bodies
and prevent opening or sliding. contact=True selects frictional contact
instead of the tied embedded formulation. Kn controls normal penetration,
Kt controls tangential compliance, and mu is the friction coefficient.
The five calls are explicit so the connection is easy to inspect and adapt.
model.assembler.create_section(
meshparts=["soil", "foundation_block"],
num_partitions=0,
merge_points=False,
)
# The filters select the five buried faces by their outward block normals.
contact_bottom = model.interface.node_interface(
name="block_soil_contact_bottom",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[0.0, 0.0, -1.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_x_min = model.interface.node_interface(
name="block_soil_contact_x_min",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[-1.0, 0.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_x_max = model.interface.node_interface(
name="block_soil_contact_x_max",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[1.0, 0.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_y_min = model.interface.node_interface(
name="block_soil_contact_y_min",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[0.0, -1.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_y_max = model.interface.node_interface(
name="block_soil_contact_y_max",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[0.0, 1.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
model.assembler.assemble(merge_points=False, progress_callback=lambda *_: None)
Set PLOT_INTERFACES = True to inspect each selection. The plots show the
selected host cells, generated interface points, and contact normals.
The interface begins closed, so one implicit static step establishes equilibrium under self-weight efficiently. Preserve that state and reset time before introducing the lateral load.
# Contact begins closed, so an implicit step efficiently establishes gravity.
gravity_analysis = model.analysis.static(
name="implicit_gravity",
constraint_handler=model.analysis.constraint.transformation(),
numberer=model.analysis.numberer.rcm(),
system=model.analysis.system.bandgeneral(),
test=model.analysis.test.normdispincr(tol=1.0e-8, max_iter=30),
algorithm=model.analysis.algorithm.newton(),
integrator=model.analysis.integrator.loadcontrol(incr=1.0),
num_steps=1,
)
model.process.add_step(gravity_analysis, "Establish equilibrium under self-weight")
model.process.add_step(model.actions.load_const(), "Keep the gravity state")
model.process.add_step(model.actions.set_time(0.0), "Reset time for lateral loading")
Distribute 150 kN over all 25 top nodes. Its elevated resultant creates an overturning moment. The explicit stage then follows opening, sliding, and renewed contact without a nonlinear iteration at every increment.
top_nodes = model.mask.nodes.by_bbox(
xmin=-1.001, xmax=1.001,
ymin=-1.001, ymax=1.001,
zmin=1.749, zmax=1.751,
)
if len(top_nodes) != 25:
raise RuntimeError(f"Expected 25 block-top nodes, found {len(top_nodes)}")
lateral_series = model.time_series.ramp(
tStart=0.0, tRamp=LATERAL_DURATION, smoothness=1.0
)
lateral_pattern = model.pattern.plain(time_series=lateral_series)
lateral_pattern.add_load.node(
node_mask=top_nodes,
values=[TOTAL_LATERAL_LOAD / len(top_nodes), 0.0, 0.0],
)
response_recorder = model.recorder.vtkhdf(
file_base_name="block_contact.vtkhdf",
resp_types=["disp"],
delta_t=0.01,
)
explicit_lateral = model.analysis.transient(
name="explicit_lateral_loading",
constraint_handler=model.analysis.constraint.transformation(),
numberer=model.analysis.numberer.rcm(),
system=model.analysis.system.bandgeneral(),
test=model.analysis.test.normdispincr(tol=1.0e-8, max_iter=1),
algorithm=model.analysis.algorithm.linear(),
integrator=model.analysis.integrator.explicitdifference(),
dt=LATERAL_DT,
num_steps=round(LATERAL_DURATION / LATERAL_DT),
max_retries=0,
initialize=True,
)
model.process.add_step(response_recorder, "Record the deformation animation")
model.process.add_step(lateral_pattern, "Ramp the distributed lateral load")
model.process.add_step(explicit_lateral, "Rock the block with explicit integration")
Exporting always works locally. Setting FEMORA_OPENSEES also executes a
compatible OpenSees build directly after export.
tcl_file = OUTPUT_DIR / "embedded_block_contact.tcl"
model.export_to_tcl(str(tcl_file.resolve()), progress_callback=lambda *_: None)
print("\nEmbedded block contact")
print(f" Nodes: {model.assembled_mesh.n_points}")
print(f" Elements: {model.assembled_mesh.n_cells}")
print(f" Tcl model: {tcl_file.resolve()}")
if OPENSEES is None:
print(" Solver: not run (set FEMORA_OPENSEES to a compatible OpenSees executable)")
else:
runtime.run(tcl_file, executable=OPENSEES, cwd=OUTPUT_DIR.resolve())
print(" Solver: completed")
Rocking And Separation
The left panel gives the three-dimensional context; the right panel cuts away the front half of the host soil to expose the interface. Opaque wireframes show the soil mesh in both views. The gray outline is the undeformed foundation, and the displayed rotation is calculated from the vertical displacement difference between opposite top nodes.
The opening visible beneath one edge is the behavior that a tied interface cannot represent. This makes the contact formulation useful for raft and shallow-foundation models where uplift and frictional load transfer matter.
Run Locally
The OpenSees executable must include EmbeddedNodeContact. Point Femora to that
executable, then run the model and postprocessor:
$env:FEMORA_OPENSEES = "D:\path\to\OpenSees.exe"
python examples/soil_structure_interaction/embedded_block_contact.py
python examples/soil_structure_interaction/embedded_block_contact_postprocess.py
The Tcl model and results are written under
example_outputs/embedded_block_contact/.
Complete model source
# =============================================================================
# Femora: Fast Efficient Meta-modeling for OpenSees-based Resilience Analysis
# Copyright 2026 Amin Pakzad and Pedro Arduino
# Developed at the UW Geotechnical Lab
# SPDX-License-Identifier: Apache-2.0
# =============================================================================
# femora-postprocess: examples/soil_structure_interaction/embedded_block_contact_postprocess.py
"""Build and optionally run a foundation block with frictional soil contact."""
from __future__ import annotations
import os
from pathlib import Path
from femora import Model, runtime
OUTPUT_DIR = Path("example_outputs") / "embedded_block_contact"
RESULTS_DIR = OUTPUT_DIR / "results"
OPENSEES = os.environ.get("FEMORA_OPENSEES")
PLOT_INTERFACES = False
TOTAL_LATERAL_LOAD = 150.0 # kN
LATERAL_DT = 1.0e-5
LATERAL_DURATION = 1.0
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
RESULTS_DIR.mkdir(parents=True, exist_ok=True)
model = Model(model_name="embedded_block_contact", model_path=str(OUTPUT_DIR))
model.clear_model()
model.set_results_folder(RESULTS_DIR.resolve().as_posix())
# Units are kN, m, tonne, and s.
soil = model.material.nd.elastic_isotropic(
user_name="soil", E=377000.0, nu=0.3, rho=19.9 / 9.81
)
soil_element = model.element.brick.std(
ndof=3, material=soil, b1=0.0, b2=0.0, b3=-19.9, lumped=True
)
model.meshpart.volume.geometric_rectangular_grid(
user_name="soil",
element=soil_element,
x_min=-2.5, x_max=2.5,
y_min=-2.5, y_max=2.5,
z_min=-5.0, z_max=0.0,
nx=4, ny=4, nz=4,
)
concrete = model.material.nd.elastic_isotropic(
user_name="concrete", E=30.0e6, nu=0.2, rho=2.5
)
block_element = model.element.brick.std(
ndof=3, material=concrete, b1=0.0, b2=0.0, b3=-24.525, lumped=True
)
model.meshpart.volume.geometric_rectangular_grid(
user_name="foundation_block",
element=block_element,
x_min=-1.0, x_max=1.0,
y_min=-1.0, y_max=1.0,
z_min=-0.25, z_max=1.75,
nx=4, ny=4, nz=4,
)
model.assembler.create_section(
meshparts=["soil", "foundation_block"],
num_partitions=0,
merge_points=False,
)
# The filters select the five buried faces by their outward block normals.
contact_bottom = model.interface.node_interface(
name="block_soil_contact_bottom",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[0.0, 0.0, -1.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_x_min = model.interface.node_interface(
name="block_soil_contact_x_min",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[-1.0, 0.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_x_max = model.interface.node_interface(
name="block_soil_contact_x_max",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[1.0, 0.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_y_min = model.interface.node_interface(
name="block_soil_contact_y_min",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[0.0, -1.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
contact_y_max = model.interface.node_interface(
name="block_soil_contact_y_max",
constrained_node="foundation_block",
retained_nodes=["soil"],
normal_filter=[0.0, 1.0, 0.0],
contact=True, Kn=1.0e8, Kt=1.0e8, mu=0.5, int_type=1,
)
model.assembler.assemble(merge_points=False, progress_callback=lambda *_: None)
model.constraint.mp.laminar_boundary(
bounds=(-4.9, 0.0), dofs=[1, 2, 3], direction=3
)
model.constraint.sp.fix_macro_z_min(dofs=[1, 1, 1], tol=1.0e-3)
# Contact begins closed, so an implicit step efficiently establishes gravity.
gravity_analysis = model.analysis.static(
name="implicit_gravity",
constraint_handler=model.analysis.constraint.transformation(),
numberer=model.analysis.numberer.rcm(),
system=model.analysis.system.bandgeneral(),
test=model.analysis.test.normdispincr(tol=1.0e-8, max_iter=30),
algorithm=model.analysis.algorithm.newton(),
integrator=model.analysis.integrator.loadcontrol(incr=1.0),
num_steps=1,
)
model.process.add_step(gravity_analysis, "Establish equilibrium under self-weight")
model.process.add_step(model.actions.load_const(), "Keep the gravity state")
model.process.add_step(model.actions.set_time(0.0), "Reset time for lateral loading")
top_nodes = model.mask.nodes.by_bbox(
xmin=-1.001, xmax=1.001,
ymin=-1.001, ymax=1.001,
zmin=1.749, zmax=1.751,
)
if len(top_nodes) != 25:
raise RuntimeError(f"Expected 25 block-top nodes, found {len(top_nodes)}")
lateral_series = model.time_series.ramp(
tStart=0.0, tRamp=LATERAL_DURATION, smoothness=1.0
)
lateral_pattern = model.pattern.plain(time_series=lateral_series)
lateral_pattern.add_load.node(
node_mask=top_nodes,
values=[TOTAL_LATERAL_LOAD / len(top_nodes), 0.0, 0.0],
)
response_recorder = model.recorder.vtkhdf(
file_base_name="block_contact.vtkhdf",
resp_types=["disp"],
delta_t=0.01,
)
explicit_lateral = model.analysis.transient(
name="explicit_lateral_loading",
constraint_handler=model.analysis.constraint.transformation(),
numberer=model.analysis.numberer.rcm(),
system=model.analysis.system.bandgeneral(),
test=model.analysis.test.normdispincr(tol=1.0e-8, max_iter=1),
algorithm=model.analysis.algorithm.linear(),
integrator=model.analysis.integrator.explicitdifference(),
dt=LATERAL_DT,
num_steps=round(LATERAL_DURATION / LATERAL_DT),
max_retries=0,
initialize=True,
)
model.process.add_step(response_recorder, "Record the deformation animation")
model.process.add_step(lateral_pattern, "Ramp the distributed lateral load")
model.process.add_step(explicit_lateral, "Rock the block with explicit integration")
tcl_file = OUTPUT_DIR / "embedded_block_contact.tcl"
model.export_to_tcl(str(tcl_file.resolve()), progress_callback=lambda *_: None)
print("\nEmbedded block contact")
print(f" Nodes: {model.assembled_mesh.n_points}")
print(f" Elements: {model.assembled_mesh.n_cells}")
print(f" Tcl model: {tcl_file.resolve()}")
if OPENSEES is None:
print(" Solver: not run (set FEMORA_OPENSEES to a compatible OpenSees executable)")
else:
runtime.run(tcl_file, executable=OPENSEES, cwd=OUTPUT_DIR.resolve())
print(" Solver: completed")
if PLOT_INTERFACES:
contact_bottom.plot(show_mesh=True, show_selected_hosts=True, show_normals=True)
contact_x_min.plot(show_mesh=True, show_selected_hosts=True, show_normals=True)
contact_x_max.plot(show_mesh=True, show_selected_hosts=True, show_normals=True)
contact_y_min.plot(show_mesh=True, show_selected_hosts=True, show_normals=True)
contact_y_max.plot(show_mesh=True, show_selected_hosts=True, show_normals=True)
Complete post-processing source
"""Render the embedded foundation contact response as a two-panel movie."""
from pathlib import Path
import numpy as np
import pyvista as pv
import femora as fm
RESULTS = Path("example_outputs/embedded_block_contact/results").resolve()
MOVIE = RESULTS / "block_contact_tilt.mp4"
DEFORMATION_SCALE = 2.0
with fm.results.open(str(RESULTS / "block_contact*.vtkhdf")) as results:
if results.number_of_partitions != 1:
raise RuntimeError("The temporary model expects one VTKHDF partition")
if "displacement" not in results.readers[0].available_point_responses:
raise RuntimeError("The VTKHDF result does not contain displacement")
reader = results.readers[0]
mesh = results.mesh(copy=True)
original_points = mesh.points.copy()
# Soil cell centers are below the embedded block's bottom at z = -0.25 m.
centers = mesh.cell_centers().points
block_3d = mesh.extract_cells(centers[:, 2] > -0.25)
soil_3d = mesh.extract_cells(
(centers[:, 2] < -0.25) & (centers[:, 2] > -2.6)
)
# Retain only the back half of the upper soil layer. This exposes the
# embedded faces and makes opening at the contact readable in side view.
block_section = block_3d.copy(deep=True)
soil_section = mesh.extract_cells(
(centers[:, 2] < -0.25)
& (centers[:, 2] > -2.6)
& (centers[:, 1] > 0.0)
)
block_3d_ids = np.asarray(
block_3d.point_data["vtkOriginalPointIds"], dtype=int
)
soil_3d_ids = np.asarray(
soil_3d.point_data["vtkOriginalPointIds"], dtype=int
)
block_section_ids = np.asarray(
block_section.point_data["vtkOriginalPointIds"], dtype=int
)
soil_section_ids = np.asarray(
soil_section.point_data["vtkOriginalPointIds"], dtype=int
)
undeformed_block_3d = block_3d.copy(deep=True)
undeformed_block_section = block_section.copy(deep=True)
top_left = results.nearest_point((-1.0, 0.0, 1.75), tolerance=1.0e-6)
top_right = results.nearest_point((1.0, 0.0, 1.75), tolerance=1.0e-6)
left_index = top_left.index
right_index = top_right.index
plotter = pv.Plotter(shape=(1, 2), off_screen=True, window_size=(1600, 720))
plotter.subplot(0, 0)
plotter.add_mesh(
soil_3d,
color="#b89b72",
opacity=0.20,
show_edges=False,
)
plotter.add_mesh(
soil_3d,
style="wireframe",
color="#665845",
opacity=1.0,
line_width=1.2,
)
plotter.add_mesh(
undeformed_block_3d,
style="wireframe",
color="#77716a",
opacity=0.45,
line_width=1.0,
)
plotter.add_mesh(
block_3d,
color="#d56345",
show_edges=True,
edge_color="#542d24",
line_width=1.2,
)
plotter.set_background("#f4f1e8")
plotter.reset_camera()
plotter.camera_position = [
(-7.2, -9.0, 4.8),
(0.0, 0.0, -0.4),
(0.0, 0.0, 1.0),
]
plotter.reset_camera_clipping_range()
plotter.add_text("3D model", font_size=14, color="#2d2925")
load_arrow_3d = pv.Arrow(
start=(-2.2, -0.05, 1.35),
direction=(1.0, 0.0, 0.0),
scale=1.1,
tip_length=0.12,
tip_radius=0.055,
shaft_radius=0.020,
)
plotter.add_mesh(load_arrow_3d, color="#2f6f8f")
plotter.subplot(0, 1)
plotter.add_mesh(
soil_section,
color="#b89b72",
opacity=0.38,
show_edges=False,
)
plotter.add_mesh(
soil_section,
style="wireframe",
color="#665845",
opacity=1.0,
line_width=1.2,
)
plotter.add_mesh(
undeformed_block_section,
style="wireframe",
color="#77716a",
opacity=0.50,
line_width=1.0,
)
plotter.add_mesh(
block_section,
color="#d56345",
show_edges=True,
edge_color="#542d24",
line_width=1.2,
)
plotter.set_background("#f4f1e8")
plotter.enable_parallel_projection()
plotter.view_xz()
plotter.reset_camera()
plotter.camera.zoom(1.20)
plotter.add_text("Contact section", font_size=14, color="#2d2925")
load_arrow_section = pv.Arrow(
start=(-2.2, -0.05, 1.35),
direction=(1.0, 0.0, 0.0),
scale=1.1,
tip_length=0.12,
tip_radius=0.055,
shaft_radius=0.020,
)
plotter.add_mesh(load_arrow_section, color="#2f6f8f")
plotter.open_movie(str(MOVIE), framerate=25, quality=8)
times = results.times
try:
for step in range(results.number_of_steps):
displacement = reader.point_frame("displacement", step)[:, :3]
deformed = original_points + DEFORMATION_SCALE * displacement
block_3d.points = deformed[block_3d_ids]
soil_3d.points = deformed[soil_3d_ids]
block_section.points = deformed[block_section_ids]
soil_section.points = deformed[soil_section_ids]
dz = displacement[right_index, 2] - displacement[left_index, 2]
rotation = np.degrees(np.arctan2(dz, 2.0))
load_fraction = min(max(float(times[step]) / float(times[-1]), 0.0), 1.0)
plotter.subplot(0, 1)
plotter.add_text(
f"Time {times[step]:.2f} s | Load {100.0 * load_fraction:.0f}% | "
f"Rotation {rotation:.3f} deg | {DEFORMATION_SCALE:g}x deformation",
name="status",
position="lower_left",
font_size=13,
color="#2d2925",
)
plotter.write_frame()
finally:
plotter.close()
print(f"Created {MOVIE}")