Skip to content

Commit 49f794b

Browse files
santisolerjcapriot
andauthored
Cleaner implementation of cell_bounds
Co-authored-by: Joseph Capriotti <josephrcapriotti@gmail.com>
1 parent 21d5333 commit 49f794b

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

discretize/tensor_mesh.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -602,25 +602,15 @@ def cell_bounds(self):
602602
a particular cell in the following order: ``x1``, ``x2``, ``y1``,
603603
``y2``, ``z1``, ``z2``, where ``x1 < x2``, ``y1 < y2`` and ``z1 < z2``.
604604
"""
605-
centers, widths = self.cell_centers, self.h_gridded
606-
if self.dim == 1:
607-
bounds = (centers - widths.ravel() / 2, centers + widths.ravel() / 2)
608-
elif self.dim == 2:
609-
x1 = centers[:, 0] - widths[:, 0] / 2
610-
x2 = centers[:, 0] + widths[:, 0] / 2
611-
y1 = centers[:, 1] - widths[:, 1] / 2
612-
y2 = centers[:, 1] + widths[:, 1] / 2
613-
bounds = (x1, x2, y1, y2)
614-
else:
615-
x1 = centers[:, 0] - widths[:, 0] / 2
616-
x2 = centers[:, 0] + widths[:, 0] / 2
617-
y1 = centers[:, 1] - widths[:, 1] / 2
618-
y2 = centers[:, 1] + widths[:, 1] / 2
619-
z1 = centers[:, 2] - widths[:, 2] / 2
620-
z2 = centers[:, 2] + widths[:, 2] / 2
621-
bounds = (x1, x2, y1, y2, z1, z2)
622-
623-
cell_bounds = np.hstack(tuple(v[:, np.newaxis] for v in bounds))
605+
nodes = self.nodes.reshape((*self.shape_nodes, -1), order="F")
606+
607+
min_nodes = nodes[(slice(-1), )*self.dim]
608+
min_nodes = min_nodes.reshape((self.n_cells, -1), order="F")
609+
max_nodes = nodes[(slice(1, None), )*self.dim]
610+
max_nodes = max_nodes.reshape((self.n_cells, -1), order="F")
611+
612+
cell_bounds = np.stack((min_nodes, max_nodes), axis=-1)
613+
cell_bounds = cell_bounds.reshape((self.n_cells, -1))
624614
return cell_bounds
625615

626616
@property

0 commit comments

Comments
 (0)