magnet.mesh.Mesh#
- class magnet.mesh.Mesh(adjacency: csr_matrix, coords: ndarray, volumes: ndarray, physical_groups: ndarray | None = None)#
Bases:
object
Graph data that describes a mesh.
Each cell of the mesh corresponds to a node of the graph: 2 nodes are connected by an edge if the corresponding cells are adjacent in the mesh. Each node is also characterized by its node features: coordinates and a area/volumes of the respective cell. This information is held in 3 corresponding attributes (Adjacency, Coords, Volumes). Heterogeneity is described by an additional node feature, Physical_Groups.
Used as interface for running agglomeration models and training GNNs. It does not contain the full data needed to describe the mesh (that is reserved to the AgglomerableMeshHeterogeneous class).
- Parameters:
adjacency (sparse.csr_matrix of np.uint8) – Adjacency matrix describing the mesh.
coords (np.ndarray of float) – Centroid coordinates of each cell of the mesh.
volumes (np.ndarray of float) – Volumes (or areas, if the mesh is 2D) of the cells.
physical_groups (np.ndarray of float) – Physical group of each cell. Values should be between 0 and 1.
- Variables:
dim (int) – Spatial dimensions of the mesh (2 or 3).
num_cells (int) – Number of cells in the mesh.
Adjacency (sparse.csr_matrix of np.uint8) – Adjacency matrix of shape (num_cells, num_cells) describing the mesh. Adjacency[i, j]=1 if cells i and j are adjacent, 0 otherwise.
Coords (np.ndarray of float) – Array with shape (num_cells, dim) containing the centroid coordinates of each cell of the mesh.
Volumes (np.ndarray of float) – Array with shape (num_cells, 1) containing the volumes (or areas, if the mesh is 2D) of the cells.
Physical_Groups (np.ndarray of float, optional) – Array with shape (num_cells,1) containing the physical group of each cell. By default, set all physical groups to 0, i.e. the mesh is considered homogeneous.
See also
AggMesh
Agglomerable version.
Constructor
- __init__(adjacency: csr_matrix, coords: ndarray, volumes: ndarray, physical_groups: ndarray | None = None) None #
Methods
__init__
(adjacency, coords, volumes[, ...])subgraph
(node_ids)Extract submesh corresponding to given element ids.
visualize_as_graph
([classes, ...])Visualize the graph representing the mesh.
- __init__(adjacency: csr_matrix, coords: ndarray, volumes: ndarray, physical_groups: ndarray | None = None) None #
- subgraph(node_ids: Iterable[int]) Mesh #
Extract submesh corresponding to given element ids.
- Parameters:
node_ids (Iterable of int) – Iterable containing the ids of the elements that will bellong to the new submesh.
- Returns:
The new submesh.
- Return type:
- visualize_as_graph(classes: List[ndarray[int]] | None = None, view_phys_groups: bool = False, palette: Iterable[str] | None = None, edge_color: str = 'tab:gray', edge_width: float = 1, node_size: Iterable[float] | None = None) None #
Visualize the graph representing the mesh.
If a partition of the graph defined by classes is provided, color each portion differently. Alternatively, using view_phys_groups=True, each physicallly heterogeneoous part of the mesh is colored differently.
- Parameters:
classes (ClassList, optional) – Graph partition (e.g. coming from an agglomeration model). If provided, color each set differently.
view_phys_groups (bool, optional) – If True, color nodes based on physical groups; in that case, classes parameter will be ignored. Default id False.
palette (str or Iterable[str], optional) – Single color for graph nodes, or color palette to be used in conjunction with classes or view_phys_groups. By default, uses matplotlib default color palette.
node_size (Iterable[float], optional) – Size of each node drawn in the graph. If a single value is provided, draw all nodes with that size. By default, node dimensions scale with the corresponding element area/volume.
edge_color (str, optional) – Color of the graph edges. Default is tab:gray.
edge_width (float, optional) – Width of the graph edges.
- Return type:
None