dctkit.mesh namespace
Submodules
dctkit.mesh.circumcenter module
- dctkit.mesh.circumcenter.circumcenter(S: ndarray[tuple[Any, ...], dtype[_ScalarT]], node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]]) Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]
- Compute the circumcenter of a set of simplices (arranged row-wise).
(Reference: Bell, Hirani, PyDEC: Software and Algorithms for Discretization of Exterior Calculus, 2012, Section 10.1).
- Parameters:
S – matrix containing the IDs of the nodes belonging to each simplex.
node_coords – coordinates (cols) of each node of the complex to which the simplices belongs.
- Returns:
a tuple consisting of the Cartesian coordinates of the circumcenter and the barycentric coordinates.
dctkit.mesh.simplex module
- class dctkit.mesh.simplex.SimplicialComplex(tet_node_tags: ndarray[tuple[Any, ...], dtype[_ScalarT]], node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]], space_dim: int = 3)[source]
Bases:
objectSimplicial complex class.
- Parameters:
tet_node_tags – matrix containing the IDs of the nodes (cols) belonging to each tetrahedron or top-level simplex (rows).
node_coords – Cartesian coordinates (columns) of all the nodes (rows) of the simplicial complex.
space_dim – dimension of the ambient space.
- S
list where each entry p is a matrix containing the IDs of the nodes belonging to each p-simplex.
- Type:
- circ
list where each entry p is a matrix containing the coordinates of the circumcenters (cols) of all the p-simplexes (rows).
- Type:
- node_coords
Cartesian coordinates (cols) of the nodes (rows) of the simplicial complex.
- Type:
npt.NDArray
- primal_volumes
list where each entry p is an array containing all the volumes of the primal p-simplices.
- Type:
- dual_volumes
list where each entry p is an array containing all the volumes of the dual p-simplices.
- Type:
- simplices_faces
list where each entry p is a matrix containing the IDs of the (p-1)-simplices (cols) belonging to each p-simplex (rows).
- Type:
- hodge_star
list where each entry is an array containing the diagonal of the Hodge star matrix.
- Type:
- compute_cup_product_entry(simplex, perm_vec, p, S_p, S_q)[source]
Vectorized version of compute_cup_product_entry. Takes similar arguments as compute_cup_product_entry but with additional array axes over which compute_cup_product_entry is mapped.
- find_simplex_idx(s: Array, S: Array) Array[source]
Vectorized version of find_simplex_idx. Takes similar arguments as find_simplex_idx but with additional array axes over which find_simplex_idx is mapped.
Original documentation:
Finds the index of a given simplex in a set of simplices.
- Parameters:
s – A 1D array representing a simplex (e.g., a set of vertex indices).
S – A 2D array where each row is a simplex.
- Returns:
the index of the simplex s in S. If s is not found, returns -1.
- get_S_dual()[source]
Compute S_dual[k] for all k = 0.1
Each S_dual[k] is a matrix where each row contains the indices of dual nodes (i.e., circumcenters of top-dimensional simplices) that form a dual k-simplex.
Stores the result in self.S_dual[k].
- get_cup_product_coeffs()[source]
Precompute lookup tables for the discrete cup product.
This method builds and stores the coefficient tables required to evaluate the cup product between discrete p- and q-cochains, for both the primal and dual cell complexes.
- get_current_covariant_basis(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array) Array[source]
Compute the current covariant basis of each face of a 2D simplicial complex.
- Parameters:
node_coords – matrix of shape (n, space_dim) where the i-th row is the vector of coordinates of i-th node of the simplex in the current configuration.
- Returns:
the multiarray of shape (n, 2, 2), where n is the number of 2-simplices and each 2x2 matrix is the current covariant basis of the corresponding 2-simplex.
- get_current_metric_2D(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array) Array[source]
Compute the current metric of a 2D simplicial complex.
- Parameters:
node_coords – matrix of shape (n, space_dim) where the i-th row is the vector of coordinates of i-th node of the simplex in the current configuration.
- Returns:
the multiarray of shape (n, 2, 2), where n is the number of 2-simplices and each 2x2 matrix is the current metric of the corresponding 2-simplex.
- get_deformation_gradient(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]]) Array[source]
Compute the deformation gradient of a 2D simplicial complex.
- Parameters:
node_coords – matrix of shape (n, space_dim) where the i-th row is the vector of coordinates of i-th node of the simplex in the current configuration.
- Returns:
the multiarray of shape (n, 2, 2), where n is the number of 2-simplices and each 2x2 matrix is the deformation gradient of the corresponding 2-simplex.
- get_flat_DPD_weights()[source]
Compute the matrix where each non-negative entry (i,j) is the ratio between the length of the j-th dual edge contained in the i-th n-simplex and the total length of the j-th dual edge.
This ratio appears as a weighting factor in the computation of the discrete flat operator.
- get_flat_PDP_weights()[source]
Construct the primal-dual-primal (PDP) weighting matrix for the discrete flat operator.
- get_flat_dual_upw_weights()[source]
Compute the matrix where each nonzero entry (i, j) corresponds to the contribution of the j-th dual (n-1)-cell (dual edge) to the i-th n-simplex. The weight represents the fraction of the dual edge length that lies inside the n-simplex. In the current implementation, this contribution is treated as unitary (value 1.0) when the dual edge intersects the simplex in a non-degenerate way, and zero otherwise.
This ratio appears as a weighting factor in the computation of the discrete flat operator.
- dctkit.mesh.simplex.compute_boundary_COO(S: ndarray[tuple[Any, ...], dtype[_ScalarT]]) Tuple[list, ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]
Compute the COO representation of the boundary matrix of all p-simplices.
- Parameters:
S – matrix of the IDs of the nodes (cols) belonging to each p-simplex (rows).
- Returns:
a tuple containing a list with the COO representation of the boundary, the matrix of node IDs belonging to each (p-1)-face ordered lexicographically, and a matrix containing the IDs of the nodes (cols) belonging to each p-simplex (rows) counted with repetition and ordered lexicographically.
- dctkit.mesh.simplex.compute_simplices_faces(S: ndarray[tuple[Any, ...], dtype[_ScalarT]], faces_ordered: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Compute the matrix containing the IDs of the (p-1)-simplices (cols) belonging to each p-simplex (rows).
- Parameters:
S – matrix of the IDs of the nodes (cols) belonging to each p-simplex (rows).
- Returns:
a matrix containing the IDs of the (p-1)-simplices (cols) belonging to each p-simplex (rows).
- dctkit.mesh.simplex.get_cofaces(faces_ids: list[int] | ndarray[tuple[Any, ...], dtype[_ScalarT]], faces_dim: int, S: SimplicialComplex) List[ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]
Get the IDs of the cofaces of a simplex, i.e. the neighour simplices of one higher dimension.
- Parameters:
faces_ids – list or array containing the IDs of the faces for which the cofaces should be determined.
faces_dim – dimension of each face in the list.
S – simplicial complex to which the faces belong.
- Returns:
list of arrays, where each array contains the IDs of the cofaces of a face.
dctkit.mesh.util module
- dctkit.mesh.util.build_complex_from_mesh(mesh: Mesh, space_dim: int = 3) SimplicialComplex[source]
Build a SimplicialComplex object from a meshio.Mesh object.
- Parameters:
mesh – a meshio.Mesh object.
space_dim – dimension of the ambient space
- Returns:
a SimplicialComplex object.
- dctkit.mesh.util.generate_cube_mesh(lc: float, L: float = 1.0) Tuple[Mesh, Geometry][source]
Generate the mesh of a cube.
- Parameters:
lc – target mesh size.
L – side length.
- Returns:
a tuple containing a meshio Mesh and a pygmsh Geometry objects.
- dctkit.mesh.util.generate_hexagon_mesh(a: float, lc: float) Tuple[Mesh, Geometry][source]
Generate the mesh of a regular hexagon.
- Parameters:
a – edge length.
lc – target mesh size.
- Returns:
a tuple containing a meshio Mesh and a pygmsh Geometry objects.
- dctkit.mesh.util.generate_line_mesh(num_nodes: int, L: float = 1.0, x_min: float = 0.0) Tuple[Mesh, Geometry][source]
Generate a uniform mesh in an interval of given length.
- Parameters:
num_nodes – number of nodes.
L – length of the interval.
- Returns:
a tuple containing a meshio Mesh and a pygmsh Geometry objects.
- dctkit.mesh.util.generate_square_mesh(lc: float, L: float = 1.0) Tuple[Mesh, Geometry][source]
Generate the mesh of a square.
- Parameters:
lc – target mesh size.
L – side length.
- Returns:
a tuple containing a meshio Mesh and a pygmsh Geometry objects.
- dctkit.mesh.util.generate_tet_mesh(lc: float) Tuple[Mesh, Geometry][source]
Generate the mesh of a tetrahedron.
- Parameters:
lc – target mesh size.
- Returns:
a tuple containing a meshio Mesh and a pygmsh Geometry objects.
- dctkit.mesh.util.get_edges_for_physical_group(S: SimplicialComplex, mesh: Mesh, group_name: str) List[int][source]
Find the IDs of the edges belonging to a physical group within the mesh object.
- Parameters:
S – SimplicialComplex object associated to the mesh.
mesh – a meshio object.
group_name – name of the physical group.
- Returns:
list of the node IDs belonging to the physical group.
- dctkit.mesh.util.get_nodes_for_physical_group(mesh: Mesh, dim: int, group_name: str) List[int][source]
Find the IDs of the nodes belonging to a physical group within the mesh object.
- Parameters:
mesh – a meshio object.
dim – dimension of the cells belonging to the physical group.
group_name – name of the physical group.
- Returns:
list of the node IDs belonging to the physical group.
dctkit.mesh.volume module
- dctkit.mesh.volume.signed_volume(S: ndarray[tuple[Any, ...], dtype[_ScalarT]], node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]]) float[source]
Compute the signed volume of a set of simplices.
- Parameters:
S – matrix containing the IDs (cols) of the nodes belonging to each simplex (rows).
node_coords – coordinates of every node of the cell complex.
- Returns:
signed volume of the simplex.
- dctkit.mesh.volume.unsigned_volume(S: ndarray[tuple[Any, ...], dtype[_ScalarT]], node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]]) float[source]
Compute the unsigned volume of a set of simplices.
- Parameters:
S – matrix containing the IDs of the nodes belonging to each simplex.
node_coords – coordinates of the points of the cell complex to which the set of simplices belongs.
- Returns:
unsigned volume of the simplex.