sktopt.mesh.utils

sktopt.mesh.utils.build_element_adjacency_matrix(mesh)

Returns sparse adjacency matrix A such that A[i, j] = 1 if element i and j share at least one node.

sktopt.mesh.utils.build_element_adjacency_matrix_fast(mesh)
sktopt.mesh.utils.fix_elements_orientation(mesh)
sktopt.mesh.utils.fix_hexahedron_orientation(t, p)

Ensures that each hexahedral element in the mesh has positive volume (i.e., right-handed orientation). Adjusts the order of nodes if needed.

Parameters:
  • t ((8, n_elem) int) – Hexahedral element connectivity (e.g., mesh.t)

  • p ((3, n_nodes) float) – Node coordinates (e.g., mesh.p)

Returns:

t_fixed – Corrected node ordering for each element.

Return type:

(8, n_elem) int

sktopt.mesh.utils.fix_tetrahedron_orientation(t, p)

Returns a corrected version of t where all tetrahedral elements follow a right-handed (positive volume) orientation.

Parameters:
  • t ((4, n_elem) int) – Tetrahedral element connectivity array (e.g., mesh.t in scikit-fem), where each column contains indices of 4 nodes forming one element.

  • p ((3, n_nodes) float) – Coordinates of the mesh nodes (e.g., mesh.p in scikit-fem), where each column represents a node in 3D space.

Returns:

t_fixed – A corrected connectivity array where the node ordering of each tetrahedron is adjusted (if needed) to ensure positive volume.

Return type:

(4, n_elem) int

sktopt.mesh.utils.fix_tetrahedron_orientation_numba(t, p)

Returns a corrected version of t where all tetrahedral elements follow a right-handed (positive volume) orientation.

Parameters:
  • t ((4, n_elem) int) – Tetrahedral element connectivity array (e.g., mesh.t in scikit-fem), where each column contains indices of 4 nodes forming one element.

  • p ((3, n_nodes) float) – Coordinates of the mesh nodes (e.g., mesh.p in scikit-fem), where each column represents a node in 3D space.

Returns:

t_fixed – A corrected connectivity array where the node ordering of each tetrahedron is adjusted (if needed) to ensure positive volume.

Return type:

(4, n_elem) int

sktopt.mesh.utils.get_adjacent_elements(mesh, element_indices)

Given a list of element indices, return the set of elements that are adjacent (share at least one node) with any of them.

sktopt.mesh.utils.get_adjacent_elements_fast(adjacency, element_indices)
sktopt.mesh.utils.get_elements_by_nodes(mesh: Mesh, target_nodes: ndarray | list[ndarray]) ndarray
Fast retrieval of element indices that

contain any of the given node indices.

Parameters:
  • mesh (skfem.Mesh) – The mesh object from scikit-fem.

  • target_nodes (np.ndarray | list[np.ndarray]) – Array or list of arrays of global node indices.

Returns:

elems – Sorted, unique array of element indices that include any of the target nodes.

Return type:

np.ndarray

sktopt.mesh.utils.get_points_in_range(x_rng, y_rng, z_rng)