Skip to content

Commit 636e3ff

Browse files
authored
Merge pull request #382 from jcapriot/bugfixes
Outstanding bugfixes.
2 parents cf1b6b5 + 0c0af0b commit 636e3ff

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

discretize/tree_mesh.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Module containing the TreeMesh implementation."""
22

3+
import warnings
4+
35
# ___ ___ ___ ___ ___ ___
46
# /\ \ /\ \ /\ \ /\ \ /\ \ /\ \
57
# /::\ \ /::\ \ \:\ \ /::\ \ /::\ \ /::\ \
@@ -169,7 +171,7 @@ class TreeMesh(
169171
170172
diagonal_balance : bool, optional
171173
Whether to balance cells along the diagonal of the tree during construction.
172-
This will effect all calls to refine the tree.
174+
This will affect all calls to refine the tree.
173175
174176
Examples
175177
--------
@@ -233,9 +235,20 @@ class TreeMesh(
233235
_items = {"h", "origin", "cell_state"}
234236

235237
# inheriting stuff from BaseTensorMesh that isn't defined in _QuadTree
236-
def __init__(self, h=None, origin=None, diagonal_balance=False, **kwargs):
238+
def __init__(self, h=None, origin=None, diagonal_balance=None, **kwargs):
237239
if "x0" in kwargs:
238240
origin = kwargs.pop("x0")
241+
242+
if diagonal_balance is None:
243+
diagonal_balance = False
244+
warnings.warn(
245+
"In discretize v1.0 the TreeMesh will change the default value of "
246+
"diagonal_balance to True, which will likely slightly change meshes you have"
247+
"previously created. If you need to keep the current behavoir, explicitly set "
248+
"diagonal_balance=False.",
249+
FutureWarning,
250+
stacklevel=2,
251+
)
239252
super().__init__(h=h, origin=origin, diagonal_balance=diagonal_balance)
240253

241254
cell_state = kwargs.pop("cell_state", None)
@@ -926,7 +939,7 @@ def face_z_divergence(self): # NOQA D102
926939

927940
def point2index(self, locs): # NOQA D102
928941
# Documentation inherited from discretize.base.BaseMesh
929-
return self.get_containing_cell_indexes(locs)
942+
return self.get_containing_cells(locs)
930943

931944
def cell_levels_by_index(self, indices):
932945
"""Fast function to return a list of levels for the given cell indices.

tests/tree/test_tree.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,5 +573,22 @@ def test_insert_point(self):
573573
self.assertEqual(mesh1.nC, mesh2.nC)
574574

575575

576+
@pytest.mark.parametrize("dim", [2, 3])
577+
def test_cell_locator(dim):
578+
mesh = discretize.TreeMesh((16, 16, 16)[:dim])
579+
mesh.insert_cells([0.5, 0.5, 0.5][:dim], levels=-1)
580+
581+
query_point = [0.21, 0.42, 0.22][:dim]
582+
identified_cell = mesh.point2index(query_point)
583+
found = False
584+
for i, cell in enumerate(mesh):
585+
bounds = cell.bounds.reshape((-1, 2))
586+
587+
if np.all((bounds[:, 0] <= query_point) & (bounds[:, 1] >= query_point)):
588+
found = True
589+
assert i == identified_cell
590+
assert found
591+
592+
576593
if __name__ == "__main__":
577594
unittest.main()

0 commit comments

Comments
 (0)