Skip to content

Commit

Permalink
Unit test for grid bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
keileg committed Mar 16, 2018
1 parent 6719bf6 commit 7346339
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/porepy/grids/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ def cell_connection_map(self):
def bounding_box(self):
"""
Return the bounding box of the grid.
Returns:
np.array (size 3): Minimum node coordinates in each direction.
np.array (size 3): Maximum node coordinates in each direction.
"""
return np.amin(self.nodes, axis=1), np.amax(self.nodes, axis=1)

Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def test_get_internal_nodes_empty(self):
int_nodes = g.get_internal_nodes()
assert int_nodes.size == 0

def test_bounding_box(self):
g = pp.CartGrid([1, 1])
g.nodes = np.random.random((g.dim, g.num_nodes))

bmin, bmax = g.bounding_box()
assert np.allclose(bmin, g.nodes.min(axis=1))
assert np.allclose(bmax, g.nodes.max(axis=1))


if __name__ == '__main__':
unittest.main()

0 comments on commit 7346339

Please sign in to comment.