porepy.grids.md_grid module
A module to store the grid hierarchy formed by a set of fractures and their intersections along with a surrounding matrix in the form of a mixed-dimensional grid.
- class MixedDimensionalGrid[source]
Bases:
object
Container for the hierarchy of grids formed by fractures and their intersections along with a surrounding matrix.
- add_interface(intf, sd_pair, primary_secondary_map)[source]
Add an interface to the mixed-dimensional grid.
Note
If the grids have different dimensions, the coupling will be defined with the higher-dimensional grid as the first (primary) subdomain. For equal dimensions, the ordering of the subdomains is the same as in input grids.
- Parameters
intf (MortarGrid) – MortarGrid that represents this interface.
sd_pair (tuple[porepy.grids.grid.Grid, porepy.grids.grid.Grid]) –
len==2
A 2-tuple containing grids to be connected. The ordering is arbitrary.
primary_secondary_map (spmatrix) –
Identity mapping between faces in the higher-dimensional grid and cells in the lower-dimensional grid. No assumptions are made on the type of the object at this stage.
In the
grids[0].dim = grids[1].dim
case, the mapping is from faces of the first grid to faces of the second one. In the co-dimension 2 case, it maps from cells to cells.
- Raises
ValueError – If the interface is not specified by exactly two grids
ValueError – If the interface already exists.
ValueError – If the two grids are not between zero and two dimensions apart.
- Return type
None
- add_subdomains(new_subdomains)[source]
Add new subdomains to the mixed-dimensional grid.
- Parameters
new_subdomains (Union[Grid, Iterable[Grid]]) – The subdomains to be added. None of these should have been added previously.
- Raises
ValueError – If a subdomain is already present in the mixed-dimensional grid.
- Return type
None
- argsort_grids(grids)[source]
Return indices that would sort the subdomains or interfaces.
Sorting is done according to two criteria:
Descending dimension.
Ascending (mortar) grid ID (for each dimension). The ID is assigned on instantiation of a (mortar) grid. The codimension is not considered for interfaces.
Example
>>> inds = mdg.argsort_grids(subdomain_list) >>> sorted_subdomains = [subdomain_list[i] for i in inds]
- Parameters
grids (Iterable[Union[Grid, MortarGrid]]) – List of subdomain grids.
- Returns
Array that sorts the grids with
shape=(len(grids),)
.- Return type
- boundaries(dim=None)[source]
Get a sorted list of boundary grids in the mixed-dimensional grid.
Optionally, the boundary grids can be filtered by dimension.
Sorting by descending boundary dimension and increasing BoundaryGrid id, see
argsort_grids()
.- Parameters
default=None
If provided, only boundary grids of the specified dimension will be returned.
- Returns
A list of boundary grids.
- Return type
- copy()[source]
Make a shallow copy of the mixed-dimensional grid. The underlying subdomain and interface grids are not copied.
- Returns
Copy of this mixed-dimensional grid.
- Return type
- diameter(cond=None)[source]
Compute the cell diameter (mesh size) of the mixed-dimensional grid.
A function can be passed to filter subdomains and/or interfaces.
- dim_max()[source]
Get the maximal dimension represented in the grid.
- Returns
Maximum dimension of the grids present in the hierarchy.
- Return type
- dim_min()[source]
Get the minimal dimension represented in the mixed-dimensional grid.
- Returns
Minimum dimension of the grids present in the hierarchy.
- Return type
- interface_data(intf)[source]
Getter for the interface data dictionary.
- Parameters
intf (MortarGrid) – The mortar grid associated with the interface.
- Returns
The data dictionary associated with the interface.
- Return type
- interface_to_subdomain_pair(intf)[source]
Obtain the subdomains of an interface.
The subdomains will be given in descending order with respect to their dimension. If the interface is between grids of the same dimension, ascending subdomain ordering (as defined by
sort_subdomain_tuple()
) is used.- Parameters
intf (MortarGrid) – The mortar grid associated with an interface.
- Returns
A 2-tuple containing
The primary subdomain neighboring this interface. Normally, this will be the subdomain with the higher dimension.
The secondary subdomain neighboring this interface. Normally, this will be the subdomain with the lower dimension.
- Return type
- interfaces(return_data: Literal[False] = False, dim: Optional[int] = None) list[porepy.grids.mortar_grid.MortarGrid] [source]
- interfaces(return_data: Literal[True], dim: Optional[int] = None) list[tuple[porepy.grids.mortar_grid.MortarGrid, dict]]
Get a sorted list of interfaces in the mixed-dimensional grid.
Optionally, the interfaces can be filtered on dimension. Also, the data dictionary belonging to the interfaces can be returned.
Sorting by descending interface dimension and increasing MortarGrid ID, see
argsort_grids()
.- Parameters
return_data –
default=False
If True, the data dictionary of the interface will be returned together with the interface mortar grids. Defaults to False.
dim –
default=None
If provided, only interfaces of the specified dimension will be returned.
- Returns
Either a list of mortar grids associated with interfaces (default), or (if
return_data=True
) list of tuples, where the first tuple item is the interface mortar grid, the second is the associated data dictionary.
- neighboring_subdomains(sd, only_higher=False, only_lower=False)[source]
Get the subdomain neighbors of a subdomain (going through interfaces).
Optionally, return only neighbors corresponding to higher or lower dimension. At most one of only_higher and only_lower can be True.
- Parameters
- Raises
ValueError – If both
only_higher
andonly_lower
are True.- Returns
Subdomain neighbors of
sd
.- Return type
- num_interface_cells(cond=None)[source]
Compute the total number of mortar cells of the mixed-dimensional grid.
A function can be passed to filter interfaces.
- Parameters
cond (Optional[Callable[[MortarGrid], bool]]) –
default=None
Predicate with an interface as input.
- Returns
The total number of mortar cells of the grid bucket.
- Return type
- num_interfaces()[source]
- Returns
Total number of interfaces in the mixed-dimensional grid.
- Return type
- num_subdomain_cells(cond=None)[source]
Compute the total number of subdomain cells of the mixed-dimensional grid.
A function can be passed to filter subdomains.
- num_subdomains()[source]
- Returns
Total number of subdomains in the mixed-dimensional grid.
- Return type
- remove_subdomain(sd)[source]
Remove a subdomain and related interfaces from the mixed-dimensional grid.
- Parameters
sd (Grid) – The subdomain to be removed.
- Return type
None
- replace_subdomains_and_interfaces(sd_map=None, intf_map=None, tol=1e-6)[source]
Replace grids and/or mortar grids in the mixed-dimensional grid.
- Parameters
sd_map (Optional[dict[porepy.grids.grid.Grid, porepy.grids.grid.Grid]]) –
default=None
Mapping between the old and new grids. Keys are the old grids, and values are the new grids.
intf_map (Optional[dict[porepy.grids.mortar_grid.MortarGrid, Union[porepy.grids.mortar_grid.MortarGrid, dict[porepy.grids.mortar_grid.MortarSides, porepy.grids.grid.Grid]]]]) –
default=None
Mapping between the old mortar grid and new (side grids of the) mortar grid. Keys are the old mortar grids, and values are dictionaries with side grid number as keys, and side grids as values. Optionally, the mapping can be directly from old to new mortar grid (sometimes it is easier to construct the new mortar grid right away, before replacing it in the mixed-dimensional grid).
tol (float) –
default=1e-6
Geometric tolerance used when updating mortar projections.
- Return type
None
- sort_interfaces(interfaces)[source]
Sort interfaces.
Sorting by descending interface dimension and increasing MortarGrid ID, see
argsort_grids()
.- Parameters
interfaces (list[porepy.grids.mortar_grid.MortarGrid]) – list of interfaces.
- Returns
List containing the same interfaces, sorted.
- Return type
- sort_subdomain_tuple(subdomains)[source]
Sort two subdomains.
Sorting by descending subdomain dimension and increasing node ID, see
argsort_grids()
.- Parameters
subdomains (tuple[porepy.grids.grid.Grid, porepy.grids.grid.Grid]) –
len=2
Tuple of two subdomains.
- Returns
Tuple containing the same two subdomains, sorted.
- Return type
- sort_subdomains(subdomains)[source]
Sort subdomains.
Sorting by descending subdomain dimension and increasing node ID, see
argsort_grids()
.- Parameters
subdomains (list[porepy.grids.grid.Grid]) – List of subdomains.
- Returns
List containing the same subdomains, sorted.
- Return type
- subdomain_pair_to_interface(sd_pair)[source]
Get an interface from a pair of subdomains.
- Parameters
sd_pair (tuple[porepy.grids.grid.Grid, porepy.grids.grid.Grid]) – Pair of subdomains. Should exist in the mixed-dimensional grid.
- Raises
KeyError – If the subdomain pair is not represented in the mixed-dimensional grid.
- Returns
The interface that connects the subdomain pairs, represented by a MortarGrid.
- Return type
- subdomain_to_boundary_grid(sd)[source]
Get the boundary grid associated with a subdomain.
- Parameters
sd (Grid) – A subdomain in the mixed-dimensional grid.
- Returns
The boundary grid associated with this subdomain.
- Return type
- subdomain_to_interfaces(sd)[source]
Iterator over the interfaces of a specific subdomain.
- Parameters
sd (Grid) – A subdomain in the mixed-dimensional grid.
- Returns
Sorted list of interfaces associated with the subdomain (see
sort_interfaces()
).- Return type
- subdomains(return_data: Literal[False] = False, dim: Optional[int] = None) list[porepy.grids.grid.Grid] [source]
- subdomains(return_data: Literal[True], dim: Optional[int] = None) list[tuple[porepy.grids.grid.Grid, dict]]
Get a sorted list of subdomains in the mixed-dimensional grid.
Optionally, the subdomains can be filtered by dimension. Also, the data dictionary belonging to the subdomain can be returned.
Sorted by descending subdomain dimension and increasing Grid ID, see
argsort_grids()
.- Parameters
return_data –
default=False
If True, the data dictionary of the subdomain will be returned together with the subdomain grids.
dim –
default=None
If provided, only subdomains of the specified dimension will be returned.
- Returns
Either a list of grids associated with subdomains (default), or (if
return_data=True
) list of tuples, where the first tuple item is the subdomain grid, the second is the associated data dictionary.
- name
Name of the md-grid, initiated as
'Mixed-dimensional grid'
.