Fix raytrace infinite loop.#3423
Conversation
be2ab1e to
1a7e5c8
Compare
paulromano
left a comment
There was a problem hiding this comment.
@GuySten Thanks for fixing this bug. I spent quite a bit of time digging into this to figure out what is going on and I'll share my findings for posterity. The real issue here is that the first call to get_indices:
Line 933 in 2eeba89
can result in a wrong index because the check doesn't account for the direction of the particle. Specifically in the case from #2855, the z index gets assigned to -1 when it really should be 0, which in turn causes the z position to be coincident with the value returned from positive_grid_boundary (thus resulting in a zero distance and an infinite loop). This problem only occurs when the particle is coincident with a boundary outside the "well-defined" portion of the regular mesh because in the in_mesh case, the zero distance just results in the index getting bumped forward, and on the next check everything is well.
A cleaner solution would be to explicitly account for the particle's position and direction in the call the get_indices, which would be able to disambiguate when a position is coincident with a grid boundary.
Agreed that this would be a cleaner solution, but not straightforward to implement for all of our mesh types so I think the solution here will do for now. In a future situation where we can use mesh as geometry for the structured/periodic mesh types, we may want to rework the ray tracing algorithms a bit. |
|
@pshriwise Agreed on all points! |
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Description
Currently, StructuredMesh::raytrace_mesh can enter an infinite loop because under specific conditions the raytrace algorithm is stuck in the same state.
This pull request assure that the raytrace algorithm progress by at least a TINY_BIT.
Fixes #2855
I suspect that it might fix #3057
Checklist