magnet.mesh.AggMesh#
- class magnet.mesh.AggMesh(vertices: ndarray | None = None, cells: list[Cell] | None = None, adjacency: csr_matrix | None = None, coords: ndarray | None = None, volumes: ndarray | None = None, physical_groups: ndarray | None = None, boundary: Boundary | None = None)#
Bases:
Mesh
Agglomerable mesh.
- Parameters:
vertices (np.ndarray of float) – Coordinates of the vertices of the mesh.
cells (list of Cell) – The connectivity data of the cells of the mesh.
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.
boundary (Boundary, optional) – Mesh boundary (faces that form the boundary and their tags). Default is None; it is not needed for agglomeration.
- Variables:
dim (int) – Spatial dimensions of the mesh (2 or 3).
num_cells (int) – Number of cells in the mesh.
Vertices (np.ndarray of float) – Array of shape (N, dim), where N is the number of total vertices of the mesh, containing the coordinates of the vertices.
Cells (list of Cell) – List of length num_cells that contains the connectivity data of the cells of 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) – Array with shape (num_cells,1) containing the physical group of each cell. Values should be between 0 and 1.
Boundary (Boundary) – Mesh boundary (faces that form the boundary and their tags).
Notes
This class inherits from Mesh for class extension and to have a common interface rather than overriding methods.
Constructor
- __init__(vertices: ndarray | None = None, cells: list[Cell] | None = None, adjacency: csr_matrix | None = None, coords: ndarray | None = None, volumes: ndarray | None = None, physical_groups: ndarray | None = None, boundary: Boundary | None = None) None #
Methods
__init__
([vertices, cells, adjacency, ...])Compute compactness metric of all mesh elements.
Compute circle ratios of all mesh elements.
Compute mean CR, APR, UF, VD.
get_quality_metrics
([boxplot])Compute CR, UF, VD together.
Compute the size of all elements of the mesh.
Compute fraction of elements with discontinuities in physical group.
Compute uniformity factor of all mesh elements.
view
([figsize, colors, palette, edge_color, ...])Plot the mesh.
volumes_difference
([to_one])Compute volume difference of all mesh elements.
- __init__(vertices: ndarray | None = None, cells: list[Cell] | None = None, adjacency: csr_matrix | None = None, coords: ndarray | None = None, volumes: ndarray | None = None, physical_groups: ndarray | None = None, boundary: Boundary | None = None) None #
- area_perimeter_ratio() ndarray #
Compute compactness metric of all mesh elements.
For 2D meshes, the area to perimeter ratio is computed; for 3D elements, sphericity is computed instead.
- Parameters:
None
- Returns:
Array of lenght num_cells of the compactness metrics.
- Return type:
np.ndarray of float
- circle_ratio() ndarray #
Compute circle ratios of all mesh elements.
Computes (approximatively) the ratio of the diameters of the biggest inscribed sphere and the smallest circumscribed one for each element of the mesh (this value is always between 0 and 1).
- Parameters:
None
- Returns:
Array of lenght num_cells of the computed circle ratios.
- Return type:
np.ndarray of float
- get_mean_quality_metrics() ndarray #
Compute mean CR, APR, UF, VD.
- Parameters:
None
- Returns:
Array of length 3 containing mean CR, UF, VD.
- Return type:
np.ndarray of float
- get_quality_metrics(boxplot=False) ndarray #
Compute CR, UF, VD together.
- Parameters:
boxplot (bool, optional) – If True, make a boxplot of the quality metrics (default is False).
- Returns:
Array of shape (num_cells, 3), where each column corresponds to a different quality metric (CR, UF, VD respectively).
- Return type:
np.ndarray of float
- mesh_elements_sizes() ndarray #
Compute the size of all elements of the mesh.
- Parameters:
None
- Returns:
Array of lenght num_cells of element sizes.
- Return type:
np.ndarray of float
- non_homogeneous_fraction() float #
Compute fraction of elements with discontinuities in physical group.
- Parameters:
None
- Returns:
The computed fraction.
- Return type:
float
Notes
This is intended only for agglomerated meshes where the original physical groups where all either 0 or 1.
- uniformity_factor() ndarray #
Compute uniformity factor of all mesh elements.
Computes the ratio of the diameters of each element to that of the element with the largest diameter of the mesh (this value is always between 0 and 1).
- Parameters:
None
- Returns:
Array of lenght num_cells of the computed uniformity factors.
- Return type:
np.ndarray of float
- view(figsize=(7, 7), colors=None, palette=None, edge_color='black', line_width=None, alpha: float = 0.5, view_phys: bool = False, axes: Axes | None = None, title=None) None #
Plot the mesh.
- Parameters:
figsize (tuple of [int, int]) – Size of the plot figure (default is (7, 7))
edge_color (optional) – Color of the cell edges (default is ‘black’).
alpha (float, optional) – Transparency value of the cell colors (Default is 0.5).
view_phys (bool, optional) – If True, assign colors based on physical group of the cell (default is false).
- Return type:
None
Notes
In the 2D case, only edges are plotted and cells appear white. In the 3D case, agglomerated elements have distinct colors, but due to matplotlib limitations some polygons in background may appear in the foreground instead. For 3D mesh visualization, it is recommended to use io.exploded_view.
See also
magnet.io.exploded_view
visualize the mesh using vtk interactor.
- volumes_difference(to_one: bool = False) ndarray #
Compute volume difference of all mesh elements.
Computes the relative difference of the volume of each element with respect to the mean volume (they are positive values).
- Parameters:
to_one (bool, optional) – If True, rescale the metric to [0,1] so that VD=1 implies that all elements have the same volume. Default is False.
- Returns:
Array of lenght num_cells of the computed volume differences.
- Return type:
np.ndarray of float
Inherited Methods
subgraph
(node_ids)Extract submesh corresponding to given element ids.
visualize_as_graph
([classes, ...])Visualize the graph representing the mesh.