gridap / Gridap.jl

Grid-based approximation of partial differential equations in Julia
MIT License
710 stars 97 forks source link

Issue finding cells in interpolate #727

Open oriolcg opened 2 years ago

oriolcg commented 2 years ago

Hi @fverdugo,

there is an error in the algorithm for finding the cell where a given point lies for unstructured grids. This error is manifested when a point lies in an element whose vertices are not the closes vertex to the point. See for instance the following example:

tmp :

One possibility for a workaround would be to find through the neighboring elements if no cell is found in the first pass. But I'm not sure if this is efficient and I don't know how to implement it in the most efficient manner. Any ideas?

fverdugo commented 2 years ago

@Balaje any thoughts on this?

Balaje commented 2 years ago

Hi @fverdugo @oriolcg ,

I think the best way is to look at the other neighbouring points (I think knn does that instead of nn https://github.com/KristofferC/NearestNeighbors.jl#k-nearest-neighbor-knn-searches) and see if the correct element is found. I can see that this is what @oriolcg has implemented.

Balaje commented 2 years ago

Also, @oriolcg loops over 3 nearest neightbours right now. Can we also have an option for the level of searching, something like what is done here using searchMethod https://doc.freefem.org/documentation/finite-element.html#a-fast-finite-element-interpolator?

oriolcg commented 2 years ago

Actually, I'm only looping for the first and if not found it goes to second and third. So, keeping aside the time of getting the closest 3 vertices instead of only 1, extra work is only done for the pathologic cases.