discretize.TreeMesh.refine_bounding_box#
- TreeMesh.refine_bounding_box(points, level=-1, padding_cells_by_level=None, finalize=True, diagonal_balance=None)[source]#
Refine within a bounding box based on the maximum and minimum extent of scattered points.
This function refines the tree mesh based on the bounding box defined by the maximum and minimum extent of the scattered input points. It will refine the tree mesh for each level given.
It also optionally pads the bounding box at each level based on the number of padding cells at each dimension.
- Parameters:
- points(
N
,dim
) array_like The bounding box will be the maximum and minimum extent of these points
- level
int
,optional
The level of the treemesh to refine the bounding box to. Negative values index tree levels backwards, (e.g. -1 is max_level).
- padding_cells_by_level
None
,int
, (n_level
) array_likeor
(n_level
,dim
) array_like,optional
The number of cells to pad the bounding box at each level of refinement. If a single number, each level below
level
will be padded with those number of cells. If array_like, n_level`s below ``level` will be padded, where if a 1D array, each dimension will be padded with the same number of cells, or 2D array supports variable padding along each dimension. None implies no padding.- finalizebool,
optional
Whether to finalize the mesh after the call.
- diagonal_balance
None
or bool,optional
Whether to balance cells diagonally in the refinement, None implies using the same setting used to instantiate the TreeMesh`.
- points(
See also
Examples
Given a set of points, we want to refine the tree mesh with the bounding box that surrounds those points. The arbitrary points we use for this example are uniformly scattered between [3/8, 5/8] in the first and second dimension.
>>> import discretize >>> import matplotlib.pyplot as plt >>> import matplotlib.patches as patches >>> mesh = discretize.TreeMesh([32, 32]) >>> rng = np.random.default_rng(852) >>> points = rng.random((20, 2)) * 0.25 + 3/8
Now we want to refine to the maximum level, with no padding the in x direction and 2 cells in y. At the second highest level we want 2 padding cells in each direction beyond that.
>>> padding = [[0, 2], [2, 2]] >>> mesh.refine_bounding_box(points, -1, padding)
For demonstration we, overlay the bounding box to show the effects of padding.
>>> ax = mesh.plot_grid() >>> rect = patches.Rectangle([3/8, 3/8], 1/4, 1/4, facecolor='none', edgecolor='r', linewidth=3) >>> ax.add_patch(rect) >>> plt.show()
(
Source code
,png
,pdf
)