porepy.geometry.constrain_geometry module
Module with various functions to constrain a geometry.
Examples are to cut objects to lie within other objects, etc.
- lines_by_polygon(poly_pts, pts, edges)[source]
Compute the intersections between a polygon (also not convex) and a set of lines.
The computation is done line by line to avoid the splitting of edges caused by other edges. The implementation assumes that the polygon and lines are on the plane
(x, y)
.- Parameters
- Returns
A 3-tuple containing
ndarray
:shape=(2, np)
Points associated to the lines after the intersection.
ndarray
:(shape=(2, np), dtype=int)
For each column the id of the points for the line after the intersection. If the input edges have tags, stored in
rows[2:]
, these will be preserved.ndarray
:(shape=(np, ), dtype=int)
Column index of the kept edges. This will have recurring values if an edge is cut by a non-convex domain.
- Return type
- polygons_by_polyhedron(polygons, polyhedron, tol=1e-8)[source]
Constrain polygons in 3d to lie inside a (generally non-convex) polyhedron.
Polygons not inside the polyhedron will be removed from descriptions. For non-convex polyhedra, polygons can be split in several parts.
- Parameters
polygons (Union[ndarray, list[numpy.ndarray]]) – Each element is an array of
shape=(3, num_vertex)
, describing the vertexes of a polygon.polyhedron (list[numpy.ndarray]) – Each element is an array of
shape=(3, num_vertex)
, describing the vertexes of the polygons that together form the polygon.tol (float) –
default=1e-8
Tolerance used to compare points.
- Returns
A tuple with two elements.
list of
ndarray
:Polygons lying inside the polyhedra. Each array has
shape=(3, num_vertex)
.ndarray
:(shape=(num_polygons, ), dytpe=int)
For each constrained polygon, corresponding list of its original polygon.
- Return type
- snap_points_to_segments(p_edges, edges, tol, p_to_snap=None)[source]
Snap points in the proximity of lines to the lines.
Note that if two vertices of two edges are close, they may effectively be co-located by the snapping. Thus, the modified point set may have duplicate coordinates.
- Parameters
p_edges (ndarray) –
shape=(nd, np)
Points defining endpoints of segments.
edges (ndarray) –
shape=(2, num_edges)
Connection between lines in
p_edges
. Ifedges.shape[0] > 2
, the extra rows are ignored.tol (float) – Tolerance for snapping, points that are closer will be snapped.
p_to_snap (Optional[ndarray]) –
(shape=(nd, np_to_snap), default=None)
The points to snap. If not provided,
p_edges
will be snapped, that is, the lines will be modified.
- Returns
A copy of
p_to_snap
(orp_edges
) with modified coordinates ofshape=(nd, np_to_snap)
.- Return type