Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We should clear spatialindex when moving the mesh #89

Open
stephankramer opened this issue May 14, 2024 · 0 comments
Open

We should clear spatialindex when moving the mesh #89

stephankramer opened this issue May 14, 2024 · 0 comments
Assignees
Labels
bug Something isn't working PRIORITY We should address this ASAP
Milestone

Comments

@stephankramer
Copy link
Collaborator

Consider the following code:

from firedrake import *

mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, "CG", 1)
x, y = SpatialCoordinate(mesh)
u = Function(V)
u.interpolate(x)

print(u.at([0.5, 0.5]))
mesh.coordinates.dat.data[:] **= 2
print(u.at((0.5, 0.5)))

The second point interpolation at (0.5, 0.5) fails with a PointNotInDomainError. This is because it uses a spatialindex that got created and cached on the first point interpolation call and thus returns candidate elements in which the point would have originally been located, but these elements have since moved elsewhere. Firedrake then tries these elements, and finds none of them contain the queried point. This can be fixed by call mesh.clear_spatialindex() after each move.

Note that this specifically only addresses interpolating in individual points via the at() (or __call__()) method. I believe function-to-function interpolate now uses VertexOnlyMesh. I don't currently have any evidence that is not doing the right thing, but we should be really careful as AFAIK this stuff isn't really supported (if the warning here https://www.firedrakeproject.org/mesh-coordinates.html is still valid) but we should add some tests to verify it is working as we expect, and to ensure it isn't broken in the future. The same goes for when we use cross-mesh project() as this probably involves a spatial index that is stored in yet another place (super mesh).

@jwallwork23 jwallwork23 added bug Something isn't working PRIORITY We should address this ASAP labels May 14, 2024
@jwallwork23 jwallwork23 added this to the Version 1 milestone May 14, 2024
stephankramer added a commit that referenced this issue May 20, 2024
Call clear_spatial_index() on the moved mesh when updating its
coordinates in MA mover. Otherwise if a point was queried (e.g. with
Function.at()) before the update, the same spatial index will still be
used when the query is repeated after the update but at that time the
point may be located in a completely different cell resulting in
PointNotInDomainErrors.
@stephankramer stephankramer self-assigned this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PRIORITY We should address this ASAP
Projects
Development

No branches or pull requests

2 participants