Blocking a wing–body
This tutorial builds a multi-block grid round a half wing–body from an empty box: you split a blocking skeleton, cut a hole where the body is, tie the hole's faces to the CAD body and its base edges to the wing–fuselage junction, wrap the hole in an O-grid, and premesh it with exact projection, wall-normal lines and a 2e-3 first cell. Then you change the CAD model's span and fuselage radius and replay the journal to get the new grid. It is the phase-7 acceptance case (ADR 0051), and every number below is checked by tests/spec/test_wing_body.py.
You need
- SHORE with the
cadextra (build123d, for STEP) and thecgnsextra (h5py):pip install 'shore-mesh[cad,cgns]'. - About 10 s for the script
examples/tutorials/blocking.py(8 s on a laptop, both models included).


1. Build the CAD model
The model is a half model, cut at z = 0, which becomes a symmetry plane: a capsule fuselage along x (radius 0.5, cylinder length 5) and a NACA 0012 wing with a blunt trailing edge (chord 1 from x = 0) along +z to the tip at z = 3, fused into one solid and written as STEP.
def wing_body(path, span=3.0, radius=0.5, length=5.0):
"""Write the half wing-body as STEP: a capsule along x and a NACA 0012 wing along +z."""
from build123d import (
Box,
Cylinder,
Line,
Pos,
Sphere,
Spline,
Wire,
export_step,
extrude,
make_face,
)
from shore.profiles import naca
body = Cylinder(radius, length, rotation=(0, 90, 0))
body = body + Pos(-length / 2, 0, 0) * Sphere(radius) + Pos(length / 2, 0, 0) * Sphere(radius)
sec = naca("0012", 40, closed_te=False) # blunt trailing edge, chord 1 from x = 0
le = int(np.argmin(sec[:, 0]))
upper = [(float(x), float(y), 0.0) for x, y in sec[: le + 1]]
lower = [(float(x), float(y), 0.0) for x, y in sec[le:]]
wire = Wire([Spline(*upper), Spline(*lower), Line(lower[-1], upper[0])])
wing = extrude(make_face(wire), amount=span)
# fuse, then keep the half z >= 0: the plane z = 0 is the symmetry plane
export_step((body + wing) & (Pos(0, 0, 10) * Box(40, 40, 20)), str(path))
return path
wing_body("wb.step")

Blocking needs exact geometry: SHORE reads the STEP file's faces, edges and vertices (OcctGeometry), and can project onto them exactly. A fused STL would do for the walls, but not for the junction curve.
2. Start the blocking
A blocking is a skeleton of hex blocks whose edges carry node counts (ADR 0042). You start with one block over the far field: 53 × 33 × 25 nodes on [-6, 7] × [-4, 4] × [0, 6]. The z = 0 face lies on the symmetry plane, and you declare it as one (ADR 0053): the premesh then makes the faces on it SYMMETRY faces, and the wall-normal lines that start on it stay in it. Without the declaration they are FREE faces, and orthogonalize moves them up to 0.026 off the plane.
p = Project()
p.load_geometry("wb.step", name="wb")
g = p.geometries["wb"].geometry
print("CAD model:", len(g.entities(EntityKind.SURFACE)), "faces,",
len(g.entities(EntityKind.CURVE)), "edges") # fmt: skip
# one block of 53 x 33 x 25 nodes over the far field, the symmetry plane at z = 0
p.create_blocking(53, 33, 25, vmin=(-6, -4, 0), vmax=(7, 4, 6))
# z = 0 is a symmetry plane: its faces become SYMMETRY and stay on it (ADR 0053)
p.symmetry_plane((0, 0, 0), (0, 0, 1))CAD model: 8 faces, 19 edges3. Split it round the body
split_blocking(block, axis, fraction) cuts a block across an axis and carries the cut through every block sharing the cut edges, so the sheet runs through the whole blocking. The helper cut finds the block holding a point on the cut and turns the coordinate into that block's fraction. The cuts bound the fuselage (x = ±3, |y| < 0.8, z < 0.8), the wing root (-0.3 < x < 1.3, |y| < 0.3) and the wing beyond its tip (z < 3.3).
def block_at(point):
"""The label of the blocking block that holds *point*."""
b = p.blocking
for label in b.labels():
pts = b.points[list(b.block(label))]
if np.all(pts.min(axis=0) < point) and np.all(point < pts.max(axis=0)):
return label
raise LookupError(f"no block holds {point}")
def cut(axis, c):
"""Split the blocking across *axis* at coordinate *c* (through the whole sheet)."""
d = "ijk".index(axis)
point = np.array([-5.99, -3.99, 0.01]) # a corner block: every sheet passes through it
point[d] = c
label = block_at(point)
pts = p.blocking.points[list(p.blocking.block(label))]
lo, hi = pts.min(axis=0)[d], pts.max(axis=0)[d]
p.split_blocking(label, axis, (c - lo) / (hi - lo))
for c in (-3.0, -0.3, 1.3, 3.0): # x: nose, wing LE, wing TE, tail
cut("i", c)
for c in (-0.8, -0.3, 0.3, 0.8): # y: fuselage width, wing thickness
cut("j", c)
for c in (0.8, 3.3): # z: fuselage top, beyond the wing tip
cut("k", c)
print("blocks after the splits:", len(p.blocking.labels()))blocks after the splits: 75A cut lands on the node nearest the fraction (the box has 4 nodes per unit length, so x = -0.3 lands on x = -0.25), and the blocks on either side keep the nodes they hold. In the GUI you cut through a picked edge node instead (The same in the GUI).
4. Find the hole and its walls
The hole is the 10 blocks the body occupies: the 3 × 3 blocks round the fuselage and the block round the wing. Their faces that bound the hole are the faces owned by only one of them; the faces on z = 0 are left out, since they lie on the symmetry plane, not on the body.
# the 9 blocks round the fuselage and the one round the wing: the hole
centres = [(x, y, 0.4) for x in (-1.5, 0.5, 2.0) for y in (-0.55, 0.0, 0.55)]
hole = [block_at(np.array(c)) for c in [*centres, (0.5, 0.0, 2.0)]]
wing_block = hole[-1]
# faces of the hole's blocks that bound the hole: owned by one hole block only,
# and not on the symmetry plane
b = p.blocking
owners: dict = {}
for label in hole:
for f in FACES:
owners.setdefault(b.entity(label, f)[0], []).append((label, f))
walls = {
key: faces[0]
for key, faces in owners.items()
if len(faces) == 1 and not np.allclose(b.points[list(key[1:])][:, 2], 0.0)
}
print("hole:", len(hole), "blocks,", len(walls), "wall faces")hole: 10 blocks, 25 wall faces

5. Associate the walls and the junction
An association says where a blocking entity belongs on the geometry; the premesh projects onto it (ADR 0003, ADR 0039). The 25 wall faces go to the body as a whole (kind="body"): each node lands on the nearest point of any CAD face.
The 4 edges at the base of the wing's block run round the wing root, on the fuselage. Associated with the body only, their nodes would land anywhere near the junction, and the grid would cut the corner. Associated with the junction curves (the CAD edges lying on both the fuselage and the wing: upper, lower and trailing-edge base), they land on the junction itself. Without these 4 associations no wall node reaches the junction: all stay more than 1e-3 away (spec case A5).
for label, f in walls.values():
p.associate_blocking(label, f, "wb", "body")
def junction_edges(geometry, radius):
"""The CAD edges lying on the fuselage (radius *radius*) next to the wing."""
out = []
for k, pts in enumerate(geometry.display().curves):
on_fuselage = np.allclose(np.hypot(pts[:, 1], pts[:, 2]), radius, atol=1e-3)
near_root = (np.abs(pts[:, 1]) < 0.07) & (pts[:, 0] > -0.01) & (pts[:, 0] < 1.01)
at_wing = bool(np.all(near_root))
if on_fuselage and at_wing:
out.append(k)
return out
junction = junction_edges(g, 0.5)
print("junction curves:", junction)
# the 4 edges at the base of the wing's block run round the wing root
for edge in ("j_lo_k_lo", "j_hi_k_lo", "i_lo_k_lo", "i_hi_k_lo"):
p.associate_blocking(wing_block, edge, "wb", "curve", junction)junction curves: [6, 7, 8]An edge without an association of its own inherits that of its face; the base edges have their own, so the premesh puts them on the curves and the faces round them on the body. The journal stores the curve indices together with fingerprints, so an edited model's edges are found again even if their indices change.
6. Delete the hole and wrap it in an O-grid
Deleting the 10 blocks leaves a hole whose faces are now owned by the blocks round it. Those faces still carry the associations (they are the same skeleton faces). A blocking face mapped straight onto a curved wall gives skewed cells at the hole's corners, so ogrid inserts a layer of blocks on the hole's 25 faces (ADR 0043): every vertex of a layered face gets an inner copy moved away from the face by (1 - factor) times half its edges leaving the face (factor=0.7: 15 % of the neighbouring block's depth), and nodes=17 sets the node count across the layer.
p.delete_blocks(hole)
# the hole's faces, now owned by the blocks round it
layered = [
(label, f)
for label in p.blocking.labels()
for f in FACES
if p.blocking.entity(label, f)[0] in walls
]
p.ogrid(faces=layered, factor=0.7, nodes=17)
print("blocks after the O-grid:", len(p.blocking.labels()))blocks after the O-grid: 90The new layer blocks take the walls; the old blocks keep the outer part.
7. Premesh, orthogonal lines, wall layer
Three commands make the grid:
p.premesh(exact=True) # tier-2 projection onto the CAD faces and edges
p.orthogonalize(0.5) # wall-normal lines; 1.0 is refused at the concave junction
p.wall_layer(2e-3) # first cell 2e-3 at every wall
print(f"premeshed in {time.perf_counter() - start:.0f} s")premesh(exact=True)meshes every edge and face once, projects them onto their associations and copies them into every block that shares them, so seams match bit for bit; block interiors are filled by transfinite interpolation.exact=Trueis the tier-2 projection onto the CAD surfaces and curves. The tessellation-based tier 1 left wall nodes on the junction up to 4e-3 off the body, because the CAD edge's tessellation and the faces' tessellation do not coincide; exact projection puts them within 1e-9.orthogonalize(0.5)reshapes the lines leaving each wall into cubic curves that start along the wall normal (ADR 0048). Each line becomes a cubic Hermite curve whose start tangent is the normal timesstrengthtimes the line's chord; the nodes keep their arc-length fractions. Strength 1 is refused here (the command refuses to invert a valid block): at the concave junction the normal is the bisector of the fuselage and wing normals, and the wing's side layers would invert. 0.5 brings the wall angle from 24.7° to 9.0° median (95th percentile 68.6° to 25.3°, ADR 0051).wall_layer(2e-3)clusters every wall line geometrically so its first cell is exactly 2e-3 long (ADR 0050).
premeshed in 3 s



8. Check the grid
report measures what the acceptance asks for: the smallest scaled Jacobian, how far the wall nodes are from the CAD body (exact projection), the first cell lengths, and the angle between each wall node's first grid segment and the CAD normal.
def report(project, label):
"""Minimum scaled Jacobian, wall distance to the body, first cells and wall angles."""
blocks = project.mesh.blocks
geometry = project.geometries["wb"].geometry
sj = min(float(scaled_jacobian(blk.nodes).min()) for blk in blocks)
pts, seg = [], []
for blk in blocks:
for face in blk.faces():
if face.bc.name == "WALL":
axis, side = "ijk".index(face.name[0]), face.name.endswith("hi")
wall = np.take(blk.nodes, -1 if side else 0, axis=axis).reshape(-1, 3)
nxt = np.take(blk.nodes, -2 if side else 1, axis=axis).reshape(-1, 3)
pts.append(wall)
seg.append(nxt - wall)
pts, seg = np.concatenate(pts), np.concatenate(seg)
proj = geometry.project(pts, BODY, exact=True)
first = np.linalg.norm(seg, axis=1)
cos = np.abs(np.einsum("ij,ij->i", seg, proj.normals)) / first
angle = np.degrees(np.arccos(np.clip(cos, 0.0, 1.0)))
off = pts[:, 2] > 0.05 # off the symmetry plane
print(f"{label}: {len(blocks)} blocks, min scaled Jacobian {sj:.3f}, "
f"wall off the body {proj.distances.max():.1e}, first cell {first.min():.4g}-"
f"{first.max():.4g}, wall angle median {np.median(angle[off]):.1f} deg") # fmt: skip
report(p, "original")original: 90 blocks, min scaled Jacobian 0.173, wall off the body 9.5e-10, first cell 0.002-0.002, wall angle median 14.3 degThe median here covers every wall node off the symmetry plane. The trailing edge, the tip and the junction have no single normal, and their nodes keep angles near 45°; without them the median is 9.0° (ADR 0051).
9. Write the solver files
p.save_journal("journal.py") # the commands so far: the replay below rebuilds the grid
p.write_cgns("wing_body.cgns") # CGNS/HDF5: a zone per block, 1-to-1 seams, BCs
p.write_xall("xall") # .geo, .grd, cc.par, proc.inputThe journal is saved before the writes, so it holds the 47 commands that build the grid and nothing else. write_cgns writes one zone per block with 1-to-1 connections for the seams, BCWall for the walls and BCSymmetryPlane for the faces on z = 0; the far field's unassociated faces are FREE, written as BCTypeUserDefined (shore:FREE). write_xall writes the .geo files, mesh.grd, cc.par and proc.input under xall/.
10. Edit the model and replay
The edit: span 2.7 instead of 3 and fuselage radius 0.55 instead of 0.5. The journal reads wb.step, so writing the edited file under the same name in edited/ and replaying with input_dir="edited" runs the same 47 commands on it.
Path("edited").mkdir(exist_ok=True)
wing_body("edited/wb.step", span=2.7, radius=0.55) # shorter wing, fatter fuselage
# the journal reads "wb.step"; input_dir resolves it in edited/
q = run_journal("journal.py", input_dir="edited")
report(q, "edited")
q.write_cgns("wing_body_edited.cgns")
print(f"total {time.perf_counter() - start:.0f} s")edited: 90 blocks, min scaled Jacobian 0.135, wall off the body 2.5e-09, first cell 0.002-0.002, wall angle median 15.1 deg
total 7 sThe blocking itself has not moved: the same box, cuts and hole. The fatter fuselage moves the junction, and the junction edges are found again by their fingerprints, not by index; the premesh then projects onto the new faces and curves. The edit must stay inside the hole: a span beyond 3.3 would pierce the wing's block, and the blocking would need new cuts.
Limits
From ADR 0051:
- a half model; full-span and multi-component models are open;
- edits must stay inside the blocking's hole;
- concave junctions need
orthogonalizebelow strength 1; - sharp edges (trailing edge, tip) keep wall angles near 45°;
- wall layers are algebraic: hyperbolic marching of a blocking's walls is deferred.
What you learned
- A blocking starts as a box and is shaped by splits, deletions and O-grids; each is a journaled command.
- Faces are associated with the body, edges with the curves they must follow; the junction needs its own association.
premesh(exact=True)projects onto the CAD entities exactly and keeps every seam closed;orthogonalizeandwall_layershape the near-wall grid.- The journal replays on an edited CAD model and gives a valid grid on the new geometry.
Next
- The same in the GUI: this blocking built with the mouse.
- Blocking and Association: how it works.
- Blocking recipes: vertex moves, partial O-grids.
- Check grid quality, Export CGNS and Plot3D.