Skip to content

Fix raytrace infinite loop.#3423

Merged
paulromano merged 2 commits intoopenmc-dev:developfrom
GuySten:regular_mesh_debug
Jun 11, 2025
Merged

Fix raytrace infinite loop.#3423
paulromano merged 2 commits intoopenmc-dev:developfrom
GuySten:regular_mesh_debug

Conversation

@GuySten
Copy link
Copy Markdown
Contributor

@GuySten GuySten commented May 29, 2025

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

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@GuySten GuySten force-pushed the regular_mesh_debug branch from be2ab1e to 1a7e5c8 Compare June 10, 2025 19:34
Copy link
Copy Markdown
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:

MeshIndex ijk = get_indices(global_r + TINY_BIT * u, in_mesh);

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.

@paulromano paulromano enabled auto-merge (squash) June 11, 2025 18:55
@paulromano paulromano merged commit e678b1a into openmc-dev:develop Jun 11, 2025
14 checks passed
@pshriwise
Copy link
Copy Markdown
Contributor

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.

@paulromano
Copy link
Copy Markdown
Contributor

@pshriwise Agreed on all points!

@GuySten GuySten deleted the regular_mesh_debug branch June 12, 2025 02:44
@jtramm jtramm mentioned this pull request Jun 19, 2025
5 tasks
yardasol pushed a commit to yardasol/openmc that referenced this pull request Dec 26, 2025
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mesh Tally Crashes the Simulation Simple Simulation runs into endless loop with openmc.MeshSurfaceFilter

3 participants