porepy.grids.match_grids module
This module contains various functions to find overlaps between grid cells.
The module is primarily intended for replacing individual grids in the
mixed-dimensional grid. It is called mostly inside
MortarGrid
.
That is, the methods herein should as a rule not be invoked directly.
- match_1d(new_g, old_g, tol, scaling=None)[source]
Obtain mappings between the cells of non-matching 1D grids.
The overlapping is identified as a sparse matrix which maps from cells in the old to the new grid.
It is assumed that the two grids are aligned, with common start and endpoints.
- Parameters
new_g (Grid) – Target grid for the mapping. Should have dimension 1.
old_g (Grid) – Original grid. Should have dimension 1.
tol (float) – Tolerance used to filter away false overlaps caused by numerical errors. Should be scaled relative to the cell size.
scaling (Optional[Literal['averaged', 'integrated']]) –
default=None
.Control weights of the returned matrix, see return values for specification.
- Returns
Mapping from the cells in the old to the new grid.
The values in the matrix depend on the parameter
scaling
.If set to ‘averaged’, a mapping fit for intensive quantities (e.g., pressure) is returned (all rows sum to unity).
If set to ‘integrated’, the matrix is a mapping for extensive quantities (column sum is 1).
If None, the matrix elements are 1 for cell-pairs (new and old grid) that overlap. Overlaps with areas less than the parameter
tol
will be ignored.- Return type
- match_2d(new_g, old_g, tol, scaling=None)[source]
Match two simplex tessellations to identify overlapping cells.
The overlaps are identified as a sparse matrix which maps from cells in the old to the new grid.
It is assumed that the two grids are aligned, with common start and endpoints.
- Parameters
new_g (Grid) – Target grid for the mapping. Should have dimension 2.
old_g (Grid) – Original grid. Should have dimension 2.
tol (float) – Tolerance used to filter away false overlaps caused by numerical errors. Should be scaled relative to the cell size.
scaling (Optional[Literal['averaged', 'integrated']]) –
default=None
Control weights of the returned matrix, see return values for specification.
- Returns
Mapping from the cells in the old to the new grid.
The values in the matrix depends on the parameter scaling.
If set to ‘averaged’, a mapping fit for intensive quantities (e.g., pressure) is returned (all rows sum to unity).
If set to ‘integrated’, the matrix is a mapping for extensive quantities (column sum is 1).
If None, the matrix elements are 1 for cell-pairs (new and old grid) that overlap; overlaps with areas less than the parameter tol will be ignored.
- Return type
- match_grids_along_1d_mortar(mg, g_new, g_old, tol, scaling)[source]
Match the faces of two 2D grids along a 1D mortar grid.
The function identifies faces on the 1D segment specified by the MortarGrid, and finds the area weights of the matched faces. Both sides of the mortar grid are taken care of.
Note
The returned matrix can be used to update
porepy.grids.mortar_grid.MortarGrid._primary_to_mortar_int
by right multiplication.- Parameters
mg (MortarGrid) – MortarGrid that specifies the target 1D line. Must be of dimension 1.
g_new (Grid) – New 2D grid. Should have faces split along the 1D line.
g_old (Grid) – Old 2D grid. The mappings in mg from mortar to primary should be set for this grid.
tol (float) – Tolerance used in comparison of geometric quantities.
scaling (Literal['averaged', 'integrated']) – Control weights of the returned matrix, see return values of
match_2d()
for specification.
- Raises
ValueError – If the matching procedure goes wrong.
- Returns
Mapping from the new to the old grid.
- Return type
- mdg_refinement(mdg, mdg_ref, tol=1e-8, mode='nested')[source]
Wrapper for
'coarse_fine_cell_mapping'
in the grid data dictionaries to construct mapping for grids in mixed-dimensional grid.Adds a data dictionary entry to each grid in mdg. The key is
'coarse_fine_cell_mapping'
.Currently, only nested refinement is supported; more general cases are also possible.
..rubric:: Acknowledgement
The code was contributed by Haakon Ervik.
Note
No node prop is added to the reference grids in mdg_ref.
- Parameters
mdg (MixedDimensionalGrid) – Coarse mixed-dimensional grid.
mdg_ref (MixedDimensionalGrid) – Refined mixed-dimensional grid.
tol (float) –
default=1e-8
Tolerance for point_in_poly* -methods
mode (Literal['nested']) –
default='nested'
Refinement mode.
'nested'
corresponds to refinement by splitting.
- Return type
None
- structured_refinement(g, g_ref, point_in_poly_tol=1e-8)[source]
Construct a mapping between cells of a grid and its refined version.
Assuming a regular and a refined mesh, where the refinement is executed by splitting. I.e. a cell in the refined grid is completely contained within a cell in the coarse grid.
Acknowledgement
The code was contributed by Haakon Ervik.
- Parameters
- Raises
AssertionError – If
g_ref
has more cells thang
or if they are of unequal dimension.AssertionError – Depending on the dimension of
g
, a certain number of nodes must be available.AssertionError – If any cell in the finer grid is not contained in exactly one cell of the coarser grid.
- Returns
Column major sparse matrix mapping from coarse to fine cells.
- Return type