Skip to content

Meshing a surface into shells

A surface is given as a mesh of its faces, here a grid. divisions keeps those faces, each cut into n x n elements, quads staying quads; without it, the surface is meshed again in triangles of the size asked for, finer where refine says. groups names the edge the slab is held along.

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

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

Open in 3D turn it, cut it, hide parts: in xfea's viewer, in your browser

examples/scripts/02_core_concepts/geometry_and_meshing/mesh_a_surface.py. Run it from the repository with uv run python examples/scripts/02_core_concepts/geometry_and_meshing/mesh_a_surface.py, or, with xfea-examples installed, xfea-examples run 02_core_concepts/geometry_and_meshing/mesh_a_surface.py.

from xfea.geometry import Mesh
from xfea.meshing import MeshingSettings
from xfea.meshing import Refine
from xfea.meshing import Select
from xfea.model import ElasticIsotropic
from xfea.model import Model
from xfea.model import Part
from xfea.model import ShellSection
from xfea_examples import show_viewer
concrete = ElasticIsotropic(E=30_000, v=0.2, density=2.4e-9) # N, mm, t
section = ShellSection(t=200, material=concrete)
model = Model(name="mesh_a_surface")
slab = model.add_part(Part(name="slab"))
slab.base_geometry = Mesh.from_meshgrid(4000, 8, 2000, 4) # 4 m by 2 m in the xy plane, 8 x 4 quads
# The grid as it is: 32 quads.
slab.mesh(settings=MeshingSettings(divisions=1), section=section)
print(f"divisions=1: {len(slab.elements)} elements of {len(slab.elements[0].nodes)} nodes")
# Each quad cut 2 x 2, quadratic: 128 eight-node quads.
slab.mesh(settings=MeshingSettings(divisions=2, element_order=2), section=section)
print(f"divisions=2, order 2: {len(slab.elements)} elements of {len(slab.elements[0].nodes)} nodes")
# Meshed again in quadratic triangles of 250 mm, finer round a column head at the centre, the edge at x = 0 named.
slab.mesh(
settings=MeshingSettings(max=250, element_order=2,
refine=[Refine.around((2000, 1000, 0), radius=200, size=50, reach=400)]),
groups={"held_edge": Select.edges(on_plane=((0, 0, 0), "x"))},
section=section,
)
print(f"remeshed and refined: {len(slab.elements)} elements of {len(slab.elements[0].nodes)} nodes, "
f"{len(slab.find_group_by_name('held_edge'))} nodes on the held edge")
model.add_pin_bc(nodes=slab.find_group_by_name("held_edge"))
show_viewer(model, units="mm")

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