Redistribute the nodes along an edge
Use this when a built or marched grid has the right shape but the wrong node spacing along one direction: you pick a block edge and a spacing law, and every grid line of that block along the edge's axis is resampled, through the seams.
Cluster the nodes along one block edge
python
p = Project()
p.build_primitive("box", vmin=(0.0, 0.0, 0.0), vmax=(2.0, 1.0, 1.0), ni=9, nj=5, nk=5)
# cluster the i-lines towards i = 0: the law is taken over the edge j_lo_k_lo
p.redistribute("box", "j_lo_k_lo", "tanh", beta=3.0)
print("tanh :", np.round(p.mesh.blocks[0].nodes[:, 0, 0, 0], 4))
# or hold the first and last cells (lengths along the edge) around a uniform interior
p.undo()
p.redistribute("box", "j_lo_k_lo", "pinned", first_step=0.05, last_step=0.4)
x = p.mesh.blocks[0].nodes[:, 0, 0, 0]
print("pinned:", np.round(x, 4), "first", x[1] - x[0], "last", x[-1] - x[-2])text
tanh : [0. 0.011 0.0342 0.0824 0.1807 0.3734 0.7234 1.2797 2. ]
pinned: [0. 0.05 0.3083 0.5667 0.825 1.0833 1.3417 1.6 2. ] first 0.05 last 0.3999999999999999- The edge names the axis:
j_lo_k_lofixes j and k, so it runs along i. The twelve edge names are listed on the block model page. - Laws:
uniform,tanh(one-sided,beta),tanh2(two-sided,beta,cluster_atas a fraction of the edge),pinned(first_stepandlast_stepas lengths along the picked edge,interiorlaw between them). The law is evaluated over the picked edge's arc length and turned into arc-length fractions. - Every other line along the axis takes the same fractions of its own arc length. Nodes stay on the line's old polyline and the two end nodes do not move, so the two faces across the axis are unchanged bit for bit.
- It is one command:
p.undo()restores the nodes bit for bit, and the journal recordsp.redistribute('box', 'j_lo_k_lo', 'tanh')(defaults, herebeta=3.0, are left out).
Redistribute through seams on a marched grid
python
shapes.sphere(radius=1.0, subdivisions=3).export("sphere.stl")
s = Project()
s.load_geometry("sphere.stl")
s.build_topology(
"cubed_sphere", nk=5, ds=0.05, growth=1.1, ni=33, nj=64, theta_cap=np.deg2rad(35.0)
)
s.march()
before = {b.label: b.nodes.copy() for b in s.mesh.blocks}
# along i of sub0: the four equatorial blocks follow through their SHARED j-seams
s.redistribute("sub0", "j_lo_k_lo", "tanh2", beta=2.0)
for b in s.mesh.blocks:
print(f"{b.label:10s} changed: {not np.array_equal(b.nodes, before[b.label])}")
# the wall nodes moved along their old polylines: put them back on the body
s.snap()
s.write_geo("sphere_redistributed")text
sub0 changed: True
sub1 changed: True
sub2 changed: True
sub3 changed: True
cap_north changed: False
cap_south changed: False- The redistribution follows every SHARED or DIRICHLET face that contains the axis, transitively, and maps the axis across each seam (reversed across a flipped one, such as the C-grid wake cut). Seams stay closed. Here the i-direction of
sub0reaches the other three equatorial blocks; the caps only touch the equator through faces across i, so they do not change. - Associated nodes are not re-projected: a wall node resampled along a polyline lies on its chord, not on the body. Run
p.snap()after (see Associate with geometry). - It works on a project loaded without replay too: there the seams are copies, not views, and the command writes them through (ADR 0040).
marchkeeps its own k schedule; to change the wall-normal spacing before marching see Wall-normal spacing.
Know what is refused
python
journal = p.journal()
for args, kwargs in [
(("box", "k_lo", "tanh"), {}), # a face, not an edge
(("box", "j_lo_k_lo", "spline"), {}), # an unknown law
(("box", "j_lo_k_lo", "pinned"), {"first_step": 1.5, "last_step": 1.5}), # longer than the edge
]:
try:
p.redistribute(*args, **kwargs)
except ParameterError as err:
print("refused:", err)
assert p.journal() == journal # nothing recorded, nothing movedtext
refused: redistribute: 'k_lo' is not an edge of 'box'; edges: ['j_lo_k_lo', ...].
refused: redistribute: law must be one of ('uniform', 'tanh', 'tanh2', 'pinned'), got 'spline'.
refused: first_step + last_step (3) exceeds interval span (2)Each refusal is a ParameterError, raised before anything moves: the nodes and the journal are unchanged. Refused as well:
- a law that does not give increasing nodes over the edge;
- a seam face shared with several blocks on the way (the CH hybrid's
body.k_hi, which faces several channel blocks); - a PERIODIC face containing the axis;
- seams that loop back and would need two different distributions on one block.
See also
- Spacing laws and Per-edge spacing
- Block model: edges, faces, axis maps
shore.mesh.redistribute- ADR 0041, ADR 0040