Block Functions

plot3d.blockfunctions.block_connection_matrix(blocks: List[Block], outer_faces: List[Dict[str, int]] = [], tol: float = 1e-08, *, node_tol_xyz: float = 1e-07, min_shared_frac: float = 0.02, min_shared_abs: int = 4, stride_u: int = 1, stride_v: int = 1, use_area_fallback: bool = True, area_min_overlap_frac: float = 0.01) Tuple[ndarray, ndarray, ndarray, ndarray][source]

Create matrices representing how blocks are connected.

GCD-reduces blocks for speed, then checks every block pair for shared nodes (primary) or overlapping face area (fallback).

Parameters:
  • blocks – List of all blocks.

  • outer_faces – Pre-computed outer faces as dicts with ‘block_index’, ‘lb’, ‘ub’. If empty, outer faces are computed automatically.

  • tol – General tolerance (unused directly; kept for API compat).

  • node_tol_xyz – Tolerance for node-sharing check.

  • min_shared_frac – Minimum fraction of shared nodes to count as connected.

  • min_shared_abs – Minimum absolute number of shared nodes.

  • stride_u – Sampling stride along u-axis for node check.

  • stride_v – Sampling stride along v-axis for node check.

  • use_area_fallback – If True, fall back to polygon-overlap check.

  • area_min_overlap_frac – Minimum overlap fraction for area fallback.

Returns:

Four (n, n) matrices where 1 = connected, -1 = not connected. The last three are axis-specific (both faces I/J/K-constant).

Return type:

(connectivity, connectivity_i, connectivity_j, connectivity_k)

plot3d.blockfunctions.build_connectivity_graph(connectivities: List[List[Dict]]) Graph[source]

Build an undirected graph from a list of face-to-face block connectivities. Each edge connects two block indices.

plot3d.blockfunctions.calculate_outward_normals(block: Block)[source]

Compute outward-facing normal vectors for all six faces of a block.

Uses corner points of each face to compute cross-product normals.

Parameters:

block – Block to compute normals for.

Returns:

Six 3D normal vectors.

Return type:

(n_imin, n_jmin, n_kmin, n_imax, n_jmax, n_kmax)

plot3d.blockfunctions.checkCollinearity(v1: ndarray[tuple[Any, ...], dtype[_ScalarT]], v2: ndarray[tuple[Any, ...], dtype[_ScalarT]])[source]

Check if two 3D vectors are collinear (parallel or anti-parallel).

Parameters:
  • v1 – First 3D vector.

  • v2 – Second 3D vector.

Returns:

True if the cross product is the zero vector, False otherwise.

plot3d.blockfunctions.common_neighbor(G: Graph, a: int, b: int, exclude: Set[int]) int | None[source]

Return a node that is connected to both a and b and not in exclude.

plot3d.blockfunctions.compute_min_gcd(blocks: List[Block]) int[source]

Compute the minimum GCD across all block dimensions.

Parameters:

blocks – List of blocks.

Returns:

The minimum GCD value to use for uniform reduction.

plot3d.blockfunctions.constant_axis(lb: list, ub: list) int[source]

Return the index (0, 1, or 2) of the constant axis on a face, or -1.

Parameters:
  • lb – Lower bound [i, j, k].

  • ub – Upper bound [i, j, k].

Returns:

Axis index where lb[d] == ub[d], or -1 if none found.

plot3d.blockfunctions.get_outer_bounds(blocks: List[Block])[source]

Get outer bounds for a set of blocks

Parameters:

blocks (List[Block]) – Blocks defining your shape

Returns:

xbounds (Tuple[float,float]): xmin,xmax ybounds (Tuple[float,float]): ymin,ymax zbounds (Tuple[float,float]): zmin,zmax

Return type:

(Tuple) containing

plot3d.blockfunctions.plot_blocks(blocks)[source]

Plot all blocks as a 3D wireframe grid using matplotlib.

GCD-reduces blocks for faster rendering, then draws grid lines along each axis for every block with alternating markers.

Parameters:

blocks – List of Block objects to plot.

plot3d.blockfunctions.rotate_block(block, rotation_matrix: ndarray) Block[source]

Rotates a block by a rotation matrix

Parameters:
  • block (Block) – Block to rotate

  • rotation_matrix (np.ndarray) – 3x3 rotation matrix

Returns:

returns a new rotated block

Return type:

Block

plot3d.blockfunctions.scale_face_bounds(face_dicts: list, factor: int, divide: bool = False)[source]

Scale lb/ub bounds in face-match or outer-face dicts by a factor.

For face-match dicts (with ‘block1’/’block2’ sub-dicts) both sides are scaled. For outer-face dicts (flat dict with ‘lb’/’ub’) the bounds are scaled directly.

Modifies face_dicts in place.

Parameters:
  • face_dicts – List of face-match or outer-face dicts.

  • factor – Scale factor.

  • divide – If True, divide by factor; otherwise multiply.

plot3d.blockfunctions.split_blocks(blocks: List[Block], gcd: int = 4)[source]

Split blocks into smaller sub-blocks while preserving GCD divisibility.

Parameters:
  • blocks (List[Block]) – Blocks to split.

  • gcd (int) – Target greatest common divisor for sub-block dimensions.

plot3d.blockfunctions.standardize_block_orientation(block: Block)[source]

Standardizes the orientation of a block so that its physical coordinates increase consistently along each of the indexing axes:

  • X increases along the i-axis

  • Y increases along the j-axis

  • Z increases along the k-axis

This ensures consistent face orientation and alignment across multiple blocks, especially useful when merging, visualizing, or exporting grids. The function checks the dominant physical component (X, Y, or Z) along each axis, and flips the block along that axis if the component decreases.

Parameters:

block (Block) – The input block to be standardized.

Returns:

A new block instance with all three axes oriented consistently.

Return type:

Block