Cutting

Marching cubes algorithm and 3D structured grid cutting utilities.

This module implements the marching cubes algorithm for extracting isosurfaces from 3D structured grids, along with utilities for creating both structured meridional cuts and unstructured triangulated cuts, returned as UnstructuredBlock. The marching cubes implementation uses a precomputed lookup table (TRITABLE) to determine how to triangulate the cell edges an isosurface intersects. Key functionality includes extracting unstructured triangular cuts using signed distance fields, creating structured 2D meridional slices by interpolating along grid lines, and converting between structured quad meshes and unstructured triangle meshes. The module supports both direct marching cubes output and subsequent interpolation of unstructured data back onto structured grids for easier analysis.

Cuts along grid surfaces by index

The functions here extract cuts along an arbitrary meridional curve. To take a cut along a grid surface of constant index, none of them are needed: a Block supports numpy-style indexing, so block[i] or block[:, j] returns a lower-dimensional structured cut that shares the parent’s data as a zero-copy view. See the indexing section of ember.block for the full rules.

cut.signed_distance(xr, xr_query)[source]

Distance above or below a piecewise line in meridional plane.

Note that this becomes increasingly inaccurate far away from the curve but the zero level is correct (which is sufficient for cutting).

Parameters:
  • xr (Array, shape (nseg, 2)) – Coordinates of the cut plane segments following ember convention with components in last axis.

  • xr_query (Array, shape (..., 2)) – Meridional coordinates to evaluate distance at.

Returns:

Signed distance above or below the cut, in single precision like the coordinates it is measured from.

Return type:

Array, shape (…)

cut.CUT_EXTEND = 0.1

How far past each end of a cut curve unstructured() looks for the blocks it reaches, as a fraction of the end segment’s length. Enough to take in a block whose wall cells straddle the end of a hub-to-casing line; short enough not to reach back into the fluid. Within a block it does reach, the cut runs on along the end segments’ lines regardless.

cut.unstructured(grid, xr_cut)[source]

Take an unstructured cut through a grid using marching cubes.

Extracts a triangulated isosurface where the meridional cut curve intersects the grid, by running the marching cubes algorithm on the signed distance field of each block. Triangles from all intersected blocks are concatenated into a single unstructured block. Within each block the curve reaches, or comes within CUT_EXTEND of its end segments’ length of reaching, the cut runs on past both ends straight along those segments, so a curve ending on an endwall cuts the wall cells cleanly. A single straight segment is thus its whole line, which is also the quicker case to evaluate.

Parameters:
  • grid (Grid or Block) – Grid containing blocks to cut, or a single block.

  • xr_cut (array_like, shape (n_segments, 2)) – Meridional \((x, r)\) curve segments defining the cut surface.

Returns:

cut – Unstructured triangulated cut, or None if the curve does not intersect any block.

Return type:

UnstructuredBlock or None

cut.structured_meridional(grid, xr_cut)[source]

Slice a grid along a meridional curve into structured 2D cuts.

For each block, walks every \((i, k)\) grid line and linearly interpolates to the first j location where the signed distance to the cut curve changes sign, producing one structured (ni, nk) cut per intersected block. Within a block the curve reaches, the cut runs on past both ends straight along the end segments, as in unstructured(), so a single straight segment cuts along its whole line.

Parameters:
  • grid (Grid or Block) – Grid containing blocks to cut, or a single block.

  • xr_cut (array_like, shape (n_segments, 2)) – Meridional \((x, r)\) curve segments defining the cut surface.

Returns:

cut – Grid of 2D structured blocks, each shape (ni, nk), holding the cut data. Blocks that the curve does not intersect are omitted, so the grid is empty when there is no intersection.

Return type:

Grid

cut.interpolate_to_structured(unstructured_block, interp_shape, Beta=0.0, periodic=True, rtol=0.05)[source]

Interpolate an unstructured triangular cut onto a structured grid.

Builds a structured (ni, nj) grid that conforms to the meridional line of the cut and resolves the circumferential direction, then interpolates the triangle-vertex point cloud onto it:

  • index i runs along the meridional line. A constant-i gridline has (x, r) = const and varies only in theta. Nodes are cosine-clustered along the normalised arc length \(\zeta \in [0, 1]\) (double-sided cosine clustering), resolving both extremities of the line.

  • index j runs in theta, uniformly over the fluid on each constant-i line. Where the cut is clear of any solid that is one full pitch, and constant-j gridlines have theta = const (straight lines). Where it passes through a solid, such as an H-mesh trailing edge cusp, each line spans one pitch less the solid it meets, found by slicing the cut’s triangles with it, and the constant-j lines bend to follow the solid. Laid over the whole pitch, the nodes on the solid would carry flow.

Straight constant-theta lines rely on the solution being periodic in theta with period pitch = 2*pi/Nb: source points are wrapped modulo the pitch so a single uniform theta window is fully covered however the cut’s theta band skews along the line. Flow variables are interpolated in the unfolded \((\zeta, \theta)\) unit space using linear interpolation with a nearest-neighbour fallback at the arc-length ends.

Parameters:
  • unstructured_block (UnstructuredBlock) – Unstructured triangulated cut, for example from unstructured().

  • interp_shape (tuple of int) – Target structured grid shape (ni, nj).

  • Beta (float, optional) – Pitch angle in degrees fixing the meridional travel direction: the arc-length-zero end is the one with the smallest projection onto d = (-sin Beta, cos Beta). Beta = 0 puts arc length 0 at minimum r; Beta = +/-90 at maximum / minimum x. Default 0.

  • periodic (bool, optional) – If True (default), wrap theta modulo the pitch so the uniform theta window is fully populated. If False, span the raw cloud theta range and rely on the nearest-neighbour fallback outside the data hull.

  • rtol (float, optional) – Relative tolerance for the periodic coverage check. With periodic=True the cloud theta span must be at least (1 - rtol) * pitch or a ValueError is raised. Default 0.05.

Returns:

cut – Structured block with the coordinates and conserved variables interpolated onto the line-conforming grid, and the fluid, length scale, rotation, blade count and label of the cut. Solver fields such as the wall distance are not carried over.

Return type:

Block, shape (ni, nj)

cut.N_REF_BIN = 1000

Bins of the projection interpolate_to_structured() averages the cut’s vertices over to find the line it measures arc length along.

cut.triangulate_to_unstructured(block)[source]

Convert a structured 2D cut into a triangulated unstructured cut.

Every node becomes a vertex, and every structured quad face is split into two triangles, giving n_face = 2 (ni - 1) (nj - 1) faces.

Parameters:

block (Block, shape (ni, nj)) – 2D structured block to triangulate.

Returns:

cut – Unstructured block with n_vert = ni * nj vertices.

Return type:

UnstructuredBlock