Refinement Algorithms#
Triangle and rectangle subdivision algorithms for mesh refinement.
- sphedron.refine.split_edges(edge_extremes: ndarray[tuple[Any, ...], dtype[_ScalarT]], num_segments: int, use_angle: bool = False)[source]#
Splits edges defined by pairs of extremities into equally spaced points.
Given an array of E pairs of extremities, this function returns new points that are equally distanced by edge_length/num_segments. If num_segments is set to 1, the function returns an empty array. When the extremities are located on a sphere, the new points can be split so that they are equally distanced by angle when use_angle is set to True, ensuring that the normalized points are also equally spaced.
- Parameters:
edge_extremes – Extremities of shape (E, 2, 3).
num_segments – Number of segments to split the edges into.
use_angle – If set to True, the new points will be equally distanced by angle (arc length).
- Returns:
Array of shape (E * (num_segments - 1), 3) containing the new points.
- sphedron.refine.refine_triangles(nodes: ndarray[tuple[Any, ...], dtype[_ScalarT]], triangles: ndarray[tuple[Any, ...], dtype[_ScalarT]], factor: int, use_angle: bool = False) Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#
Refine a triangular mesh by subdividing each face.
Vectorized implementation – all edge splitting, interior computation, and connectivity wiring are batched into array operations with no per-face Python loop.
- Parameters:
nodes – Coordinates of the mesh nodes, shape (N, 3).
triangles – Triangular face indices, shape (T, 3).
factor – Subdivision factor per edge.
use_angle – Use angle-based (geodesic) interpolation.
- Returns:
Tuple of (refined_nodes, refined_faces) where refined_nodes has shape (M, 3) and refined_faces has shape (T*factor^2, 3).
- sphedron.refine.triangle_template(nu: int) ndarray[tuple[Any, ...], dtype[int64]][source]#
Template for linking subfaces in a subdivision of a triangular face.
Returns faces with node indexing given by reading order.
Illustration for nu=4:
0 / \ 1---2 / \ / \ 3---4---5 / \ / \ / \ 6---7---8---9 / \ / \ / \ / \ 10--11--12--13--14
- Parameters:
nu – Subdivision factor.
- Returns:
Faces template of shape (nu^2, 3).
- sphedron.refine.triangles_order(nu: int)[source]#
Permutation that reorders reading-order node indices.
Reorders into: corners first, then on-edge nodes, then interior nodes.
Illustration for nu=4:
0 / \ 3---6 / \ / \ 4---12--7 / \ / \ / \ 5---13--14--8 / \ / \ / \ / \ 1---9--10--11---2
- Parameters:
nu – Subdivision factor.
- Returns:
Ordering array of length (nu+1)*(nu+2)//2.
- sphedron.refine.triangle_interior(ab: ndarray[tuple[Any, ...], dtype[_ScalarT]], ac: ndarray[tuple[Any, ...], dtype[_ScalarT]], use_angle: bool = False)[source]#
Compute interior nodes for a subdivided triangular face.
Given on-edge nodes AB[i] and AC[i], computes the interior nodes (marked by
*below):A / \ AB0--AC0 / \ / \ AB1--*--AC1 / \ / \ / \ AB2---*---*---AC2 / \ / \ / \ / \ B-BC1--BC2--BC3-C
- Parameters:
ab – On-edge nodes from A toward B, shape (factor-1, 3).
ac – On-edge nodes from A toward C, shape (factor-1, 3).
use_angle – Use angle-based (geodesic) interpolation between corresponding AB and AC nodes.
- Returns:
Interior node coordinates, shape ((factor-1)*(factor-2)//2, 3). Returns None when factor <= 2 (no interior nodes).
- sphedron.refine.refine_rectrangles(nodes: ndarray[tuple[Any, ...], dtype[_ScalarT]], rectangles: ndarray[tuple[Any, ...], dtype[_ScalarT]], factor: int, use_angle: bool = False) Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#
Refine a rectangular mesh by subdividing each face.
Vectorized implementation – all edge splitting, interior computation, and connectivity wiring are batched into array operations with no per-face Python loop.
- Parameters:
nodes – Coordinates of the mesh nodes, shape (N, 3).
rectangles – Rectangular face indices, shape (R, 4).
factor – Subdivision factor per edge.
use_angle – Use angle-based (geodesic) interpolation.
- Returns:
Tuple of (refined_nodes, refined_faces) where refined_nodes has shape (M, 3) and refined_faces has shape (R*factor^2, 4).
- sphedron.refine.rectangle_template(nu: int) ndarray[tuple[Any, ...], dtype[int64]][source]#
Template for linking subfaces in a subdivision of a rectangular face.
Returns faces with node indexing given by reading order.
Illustration for nu=3:
0---1---2---3 | | | | 4---5---6---7 | | | | 8---9---10--11 | | | | 12--13--14--15
- Parameters:
nu – Subdivision factor.
- Returns:
Faces template of shape (nu^2, 4).
- sphedron.refine.rectangles_order(nu: int)[source]#
Permutation that reorders reading-order node indices for rectangles.
Reorders into: corners first, then on-edge nodes, then interior nodes.
Illustration for nu=3:
0---4---5---1 | | | | 6---12--13--8 | | | | 7---14--15--9 | | | | 3---11--10--2
- Parameters:
nu – Subdivision factor.
- Returns:
Ordering array of length (nu+1)^2.
- sphedron.refine.rectangle_interior(ad: ndarray[tuple[Any, ...], dtype[_ScalarT]], bc: ndarray[tuple[Any, ...], dtype[_ScalarT]], use_angle: bool = False)[source]#
Compute interior nodes for a subdivided rectangular face.
Given on-edge nodes AD[i] and BC[i], computes the interior nodes (marked by
*below):A---AB0--AB1--AB2--B | | | | | AD0--*----*----*---BC0 | | | | | AD1--*----*----*---BC1 | | | | | AD2--*----*----*---BC2 | | | | | D---DC0--DC1--DC2--C
- Parameters:
ad – On-edge nodes from A toward D, shape (factor-1, 3).
bc – On-edge nodes from B toward C, shape (factor-1, 3).
use_angle – Use angle-based (geodesic) interpolation.
- Returns:
Interior node coordinates, shape ((factor-1)^2, 3).