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
Fix: solving issues of find active cell around point(cache) with points at the edge #5512
Conversation
3e7d4f2
to
cdc85a3
Compare
5eac006
to
164591f
Compare
Update: I found the problem, it was with tolerance: points at the edge where sometimes trashed. What I did was adapting what happens in the old version of find active cell around point: every time a cell is checked, if the point is not inside we check the distance of the transformed point to the unit cell. If it is less than the tolerance, we keep track of this "good" cell and lower the tolerance... if, in the end, no "inside" cell was found but we found a good cell, this is returned. I really think this shall make (finally) #5411 work :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in the behavior of this function. I think it should be documented.
source/grid/grid_tools.cc
Outdated
// It is possible the vertex is close | ||
// to an edge, thus we add a tolerance | ||
// setting it initially to 1e-10 | ||
// to keep also the "best" point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"best" point -> "best" cell
best_distance = dist; | ||
cell_and_position_approx.first = *cell; | ||
cell_and_position_approx.second = p_unit; | ||
approx_cell = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you lack a break
statement here. Or is your intention to keep searching through the other cells? If so, I think a comment in front of this block would be nice of the sort "The point is not inside this cell, but let us see how far outside it is and whether we want to use this cell as a backup if we can't find a cell within which it is."
I'd say that it would also be easier to read if in the block above (the one where p_unit
is inside the cell) you'd set approx_cell = false
, just to make clear that you are discarding the approximate cell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention is to keep searching: maybe the point is close to the edge but inside another cell. Thus I want to return it only if I'm sure it's inside a cell or it's the best approximation among all possible cases, to avoid "false positives".
I believe this is also the thinking behind
find_active_cell_around_point (const Mapping<dim,spacedim> &mapping, const MeshType<dim,spacedim> &mesh, const Point<spacedim> &p, const std::vector<bool> &marked_vertices)
but, for how that function is made, I believe currently best_distance is not really used (because, as soon as a "close enough point" is found we exit the cycle by setting found to true... so it doesn't make sense to set best_distance = dist;
but this is for another PR).
Thank you for your comments: updating soon
@bangerth for the change in behaviour which should be documented: actually the documentation of all find_active_cell_around_point is of the like "a version of the previous function with...". The original one is the following function:
Also: the way I shall return the cell it's slightly different from this original find_active_cell_around_point version where, as soon as the point is close enough, it is returned... |
Thanks for digging into the documentation -- if it's already mentioned elsewhere, then that's good enough. No need for further changes! /run-tests |
Ok, grid/find_active_cell_around_point_03.debug is failing which is bad (but the release version is passing, at least on my machine); I'm looking into this problem right now |
8d8e67b
to
b313818
Compare
Ok, problem fixed: the debug failed because I used something like I think I shall update this in the documentation and fix a few things in the old find active cell around point (just not right now: my schedule it's a bit too busy for the next week). |
On 11/25/2017 02:25 AM, Giovanni Alzetta wrote:
Ok, problem fixed: the debug failed because I used something like
|auto my_pair_1 = find_active_cell_around_point|
with the old version of the function which has two versions, differing only in
output, and the "auto" worked differently in the debug and release version
(also on my machine).
I don't think I understand this. Can you elaborate?
|
@bangerth it's actually easy, so sorry if I managed not to be clear immediately! In the first version of the test, the one which failed, instead of writing |
On 11/25/2017 09:22 AM, Giovanni Alzetta wrote:
No, that can't be it. C++ does not allow this. Functions need to differ in input argument types or a compiler can not determine which function to call. (C++ does not consider the return type as part of overload resolution.)
That also can't be it -- we do not let the compiler choose a different function call in debug than in release mode. There must be another reason for your issue. |
@bangerth then I really don't know where the problem was and, I guess, it was just fixed by luck: if you take line 61-62 of the grid/find_active_cell_around_point_03 from to
My guess was confusion between the following functions (which, actually, do not have the exact same input arguments, but in the second one the last variable has a default value); but honestly I don't know C++ enough and so, if you say this simply can't be...it means I really don't know why the change I made makes everything work...
and
|
The problem is simply that you can't convert a |
Since, @bangerth didn't request any further changes, this looks good to me and all the test pass, I merge. |
Thank you @masterleinad , I really coudln't figure out why it was now working!! |
@masterleinad Sorry for bothering you, but I seem to be facing the same problem as above. I'm using
I've tried tons of different methods, only to get the errors again and again
I couldn't figure out where the program convert the Could you please to explain
in more details? And is there any examples about how to use a cached version of Thanks a lot :) |
There's an entry in the FAQ on this: Can I convert Triangulation cell iterators to DoFHandler cell iterators? |
@jppelteret Thanks a lot, but I'm still confused of when the conversion happens and how to avoid it. Do you mean that I should do the conversion manually or something? |
Would it be possible to move this discussion either to the slack channel or the mailing list? We should try to solve this, but this GitHub issue is not the best location to do so. |
Yes, I guess so. If you have a look at the signature of the specific function you are calling, returns a It should be possible to implement another more general version of this function, say template<int dim, template< int, int > class MeshType, int spacedim>
std::pair< typename MeshType< dim, spacedim >::active_cell_iterator, Point< dim > >
GridTools::find_active_cell_around_point (
const Cache< dim, spacedim > & cache,
const MeshType< dim, spacedim > & mesh,
const Point< spacedim > & p,
const typename MeshType< dim, spacedim >::active_cell_iterator & cell_hint = typename MeshType<dim, spacedim>::active_cell_iterator(),
const std::vector< bool > & marked_vertices = std::vector<bool>() ) that does the conversion automatically. If you would like to implement this feature then we'd be happy to include it in the next release. |
@drwells Sorry for that, I'm a newer both to dealii and github, and didn't realized that I might have bothered a lot of people. I've been trapped by this error for almost a month and when came to this related issue I just couldn't help putting forward my questions. And thank you @jppelteret for your patience and kindness, I would try this out and attempt to implement the automatic conversion later on. It would be a great honor to have any contributions to the dealii project! |
Don't worry about it. Its more important that your questions get answered (but it does help if things stay sorted). |
Dear everyone,
working on #5411 I've found a problem with the Cached version of compute point locations: the new version is failing, there's probably some issue when looking for points which are on the edge of the Triangulation.
This test currently fails: it shall pass once the bug is found and corrected ( @luca-heltai I guess that's also something I shall need to do).
Best,
Giovanni