pygeon.numerics.spanningtree module
Module for spanning tree computation.
- class pygeon.numerics.spanningtree.SpanningTree(mdg, starting_faces='first_bdry')[source]
Bases:
objectClass that can perform a spanning tree solve, aka a “grid sweep”. Useful to rapidly compute a flux field that balances a mass source.
- __init__(mdg, starting_faces='first_bdry')[source]
Initializes a SpanningTree object.
- setup_system(mdg, flagged_faces)[source]
Sets up the linear system for solving the spanning tree problem.
- Parameters:
mdg (pg.MixedDimensionalGrid) – The mixed-dimensional grid.
flagged_faces (np.ndarray) – Array of flagged faces.
- Returns:
None
- find_starting_faces(mdg, starting_faces)[source]
Find the starting face for the spanning tree. By default, this method returns the indices of the boundary faces of the mesh.
- Parameters:
mdg (pg.MixedDimensionalGrid) – The mixed-dimensional grid object.
starting_faces –
“first_bdry” (default): Choose the first boundary face.
”all_bdry”: Choose all boundary faces.
np.array or int: Indices of the starting faces.
- Returns:
The indices of the starting faces for the spanning tree.
- Return type:
np.ndarray
- Raises:
KeyError – if starting_faces does not have the right type
- find_starting_cells()[source]
Find the starting cell for the spanning tree.
- Returns:
The indices of the starting cells.
- Return type:
np.ndarray
- add_outside_cell()[source]
Include a fictitious outside cell in the div operator. This cell will be used as the root of the tree.
- remove_outside_cell()[source]
Remove the fictitious outside cell from the div operator and the tree
- compute_tree()[source]
Construct a spanning tree of the elements.
- Returns:
The computed spanning tree as a compressed sparse column matrix.
- Return type:
sps.csc_array
- flag_tree_faces()[source]
Flag the faces in the mesh that correspond to edges of the tree.
- Returns:
A boolean array indicating the flagged faces in the mesh.
- Return type:
np.ndarray
- solve(f)[source]
Perform a spanning tree solve to compute a conservative flux field for given mass source.
- Parameters:
f (np.ndarray) – Mass source, integrated against PwConstants.
- Returns:
The post-processed flux field
- Return type:
np.ndarray
- assemble_SI()[source]
Assembles the operator S_I as a sparse array.
- Returns:
S_I, a right inverse of the B-operator
- Return type:
sps.sparray
Notes
This will be slow for large systems. If you only need the action of S_I, consider using self.solve() instead.
- solve_transpose(rhs)[source]
Post-process the pressure by performing a transposed solve.
- Parameters:
rhs (np.ndarray) – Right-hand side, usually the mass matrix times the flux minus boundary terms.
- Returns:
The post-processed pressure field
- Return type:
np.ndarray
- class pygeon.numerics.spanningtree.SpanningTreeElasticity(mdg, starting_faces='first_bdry')[source]
Bases:
SpanningTreeRepresents a class for computing the spanning tree for the elastic problem.
- setup_system(mdg, flagged_faces)[source]
Set up the system for the spanning tree algorithm.
- Parameters:
mdg (pg.MixedDimensionalGrid) – The mixed-dimensional grid.
flagged_faces (np.ndarray) – Array of flagged faces.
- Returns:
None
- compute_expand(sd, flagged_faces)[source]
Compute the expanded matrix for spanning tree computation.
- Parameters:
sd (pg.Grid) – The grid object.
flagged_faces (np.ndarray) – Array of flagged faces.
- Returns:
The expanded matrix for spanning tree computation.
- Return type:
sps.csc_array
- compute_system(sd)[source]
Computes the system matrix for the given grid.
- Parameters:
sd (pg.Grid) – The grid object representing the domain.
- Returns:
The computed system matrix.
- Return type:
sps.csc_array
- class pygeon.numerics.spanningtree.SpanningTreeCosserat(mdg, starting_faces='first_bdry')[source]
Bases:
SpanningTreeElasticityRepresents a class for computing the spanning tree for the Cosserat problem.
- compute_expand(sd, flagged_faces)[source]
Compute the expanded matrix for spanning tree computation.
- Parameters:
sd (pg.Grid) – The grid object.
flagged_faces (np.ndarray) – Array of flagged faces.
- Returns:
The expanded matrix for spanning tree computation.
- Return type:
sps.csc_array
- compute_system(sd)[source]
Computes the system matrix for the given grid.
- Parameters:
sd (pg.Grid) – The grid object representing the domain.
- Returns:
The computed system matrix.
- Return type:
sps.csc_array
- class pygeon.numerics.spanningtree.SpanningWeightedTrees(mdg, spt, weights, starting_faces=None)[source]
Bases:
objectClass that can perform a spanning weighted trees solve, based on one of the previously introduced classes SpanningTree and SpanningTreeElasticity. It works very similarly to the previous one by considering multiple trees instead.
- __init__(mdg, spt, weights, starting_faces=None)[source]
Constructor of the class.
- Parameters:
mdg (pg.MixedDimensionalGrid) – The mixed dimensional grid.
spt (object) – The spanning tree object to use.
weights (np.ndarray) – The weights to impose for each spanning tree, they need to sum to 1.
starting_faces (np.ndarray) – The set of starting faces, if not specified equi-distributed boundary faces are selected.
- solve(f)[source]
Perform a spanning weighted trees solve to compute a conservative flux field for given mass source.
- Parameters:
f (np.ndarray) – Mass source, integrated against PwConstants.
- Returns:
The post-processed flux field.
- Return type:
np.ndarray
- assemble_SI()[source]
Assembles the operator S_I as a sparse array. NOTE: This will be slow for large systems. If you only need the action of S_I, consider using self.solve() instead.
- Returns:
S_I, a right inverse of the B-operator
- Return type:
sps.sparray
- solve_transpose(rhs)[source]
Post-process the pressure by performing a transposed solve.
- Parameters:
rhs (np.ndarray) – Right-hand side, usually the mass matrix times the flux minus boundary terms.
- Returns:
The post-processed pressure field.
- Return type:
np.ndarray
- find_starting_faces(mdg, num)[source]
Find the starting faces for each spanning tree if None is provided in the constructor. By default, an equidistribution of boundary faces is constructed.
- Parameters:
mdg (pg.MixedDimensionalGrid) – The (mixed dimensional) grid.
num (int) – Number of faces to be selected.
- Returns:
The selected faces at the boundary.
- Return type:
np.ndarray