Skip to content

Commit

Permalink
Revert "wip change cells_ignore ordering"
Browse files Browse the repository at this point in the history
This reverts commit 4969d37.
  • Loading branch information
ReubenHill committed Dec 15, 2023
1 parent 4969d37 commit c46ed00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions firedrake/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ def locate_cells_ref_coords_and_dists(self, xs, tolerance=None, cells_ignore=Non
this from default will cause the spatial index to be rebuilt which
can take some time.
:kwarg cells_ignore: Cell numbers to ignore in the search for each
point in xs. Shape should be (npoints, n_ignore_pts). Each column
point in xs. Shape should be (n_ignore_pts, npoints). Each column
corresponds to a single coordinate in xs. To not ignore any cells,
pass None. To ensure a full cell search for any given point, set
the corresponding entries to -1.
Expand All @@ -2231,12 +2231,12 @@ def locate_cells_ref_coords_and_dists(self, xs, tolerance=None, cells_ignore=Non
Xs = np.empty_like(xs)
npoints = len(xs)
if cells_ignore is None or cells_ignore[0][0] is None:
cells_ignore = np.full((npoints, 1), -1, dtype=IntType, order="C")
cells_ignore = np.full((1, npoints), -1, dtype=IntType)
else:
cells_ignore = np.asarray(cells_ignore, dtype=IntType, order="C")
if cells_ignore.shape[0] != npoints:
cells_ignore = np.asarray(cells_ignore, dtype=IntType)
if cells_ignore.shape[1] != npoints:
raise ValueError("Number of cells to ignore does not match number of points")
assert cells_ignore.shape == (npoints, cells_ignore.shape[1])
assert cells_ignore.shape == (cells_ignore.shape[0], npoints)
ref_cell_dists_l1 = np.empty(npoints, dtype=utils.RealType)
cells = np.empty(npoints, dtype=IntType)
assert xs.size == npoints * self.geometric_dimension()
Expand All @@ -2246,8 +2246,8 @@ def locate_cells_ref_coords_and_dists(self, xs, tolerance=None, cells_ignore=Non
ref_cell_dists_l1.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
cells.ctypes.data_as(ctypes.POINTER(ctypes.c_int)),
npoints,
cells_ignore.shape[1],
cells_ignore)
cells_ignore.shape[0],
cells_ignore.ctypes.data_as(ctypes.POINTER(ctypes.c_int)))
return cells, Xs, ref_cell_dists_l1

def _c_locator(self, tolerance=None):
Expand Down Expand Up @@ -2276,7 +2276,7 @@ def _c_locator(self, tolerance=None):
pointquery_utils.py. If they contain python calls, this loop will
not run at c-loop speed. */
/* cells_ignore has shape (npoints, ncells_ignore) - find the ith row */
/* cells_ignore has shape (ncells_ignore, npoints) - find the ith column */
int *cells_ignore_i = cells_ignore + i*ncells_ignore;
cells[i] = locate_cell(f, &x[j], %(geometric_dimension)d, &to_reference_coords, &to_reference_coords_xtr, &temp_reference_coords, &found_reference_coords, &ref_cell_dists_l1[i], ncells_ignore, cells_ignore_i);
Expand Down Expand Up @@ -2304,7 +2304,7 @@ def _c_locator(self, tolerance=None):
ctypes.POINTER(ctypes.c_int),
ctypes.c_size_t,
ctypes.c_size_t,
np.ctypeslib.ndpointer(ctypes.c_int, flags="C_CONTIGUOUS")]
ctypes.POINTER(ctypes.c_int)]
locator.restype = ctypes.c_int
return cache.setdefault(tolerance, locator)

Expand Down
8 changes: 4 additions & 4 deletions tests/regression/test_locate_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def test_locate_cells_ref_coords_and_dists(meshdata):
cells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points)
assert np.allclose(f.dat.data[cells], [1, 2, 3, 4, 5, 6, 7, 8, 9])
assert np.allclose(l1_dists, 0.0)
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:1], cells[1:2]]))
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:1], cells[1:2]]).T)
assert fcells[0] == -1 or fcells[0] in cells[1:]
assert fcells[1] == -1 or fcells[1] in cells[2:] or fcells[1] in cells[:1]
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:2], cells[1:3]]))
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:2], cells[1:3]]).T)
assert fcells[0] == -1 or fcells[0] in cells[2:]
assert fcells[1] == -1 or fcells[1] in cells[3:] or fcells[1] in cells[:1]
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:3], cells[1:4]]))
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:3], cells[1:4]]).T)
assert fcells[0] == -1 or fcells[0] in cells[3:]
assert fcells[1] == -1 or fcells[1] in cells[4:] or fcells[1] in cells[:1]
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:4], cells[1:5]]))
fcells, ref_coords, l1_dists = m.locate_cells_ref_coords_and_dists(points[:2], cells_ignore=np.array([cells[:4], cells[1:5]]).T)
assert fcells[0] == -1 or fcells[0] in cells[4:]
assert fcells[1] == -1 or fcells[1] in cells[5:] or fcells[1] in cells[:1]

0 comments on commit c46ed00

Please sign in to comment.