Conversation
The distance to collision is now sampled before the distance to the nearest boundary and passed to the boundary search as a maximum distance. The search through a complex cell, which moves from one surface crossing to the next until one changes whether the ray is in the cell, stops once it passes the collision site, since a farther boundary is not used. The boundary search uses no random numbers, so results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014RN7JroEkrbkLKVHbMDap9
Electrons and positrons whose energy is deposited locally have a distance to collision of zero, so the distance to the nearest boundary is never used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014RN7JroEkrbkLKVHbMDap9
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Since #3934, the distance to the boundary of a complex cell is found by moving from one surface crossing to the next until a crossing changes whether the ray is in the cell. Each step recomputes the distance to every surface of the cell and evaluates its region expression. Cells written as unions of many pieces have many such virtual crossings: for example, CAD-to-CSG conversions that split non-convex solids into convex pieces. On those cells the search is expensive, and it was the source of the 10–30% slowdowns reported for the JET and ITER models.
Most of that search is wasted. In an optically thick material, a particle usually collides long before reaching the boundary, and a boundary beyond the collision site is never used.
This PR samples the distance to collision before the distance to the boundary and passes it to the boundary search as a maximum distance. The search through a complex cell stops as soon as it passes the collision site. It returns
INFTY, which the caller already handles as "collision first". Simple cells, lattices and DAGMC cells are unaffected.The boundary search uses no random numbers, so sampling the collision distance first doesn't change the random number sequence. A boundary at or beyond the collision site was never selected before either (
collision_distance > boundary.distanceis false in both cases), so results are bitwise identical.Particles that collide in place, such as electrons and positrons deposited locally with TTB, now skip the boundary search entirely, since its result was never used. This is for consistency; it has no measurable effect on run time.
Changes:
Cell::distance,Region::distanceanddistance_to_boundarytake an optionalmax_distance(defaultINFTY). Other callers (plotting, ray tracing, volume calculations, mesh material volumes) are unchanged.Particle::event_advancesamples the collision distance first and passes it asmax_distance.Performance
Single thread, transport time, mean of 3 runs (2 for the scan). Tallies are bitwise identical to
developin every case.Shield written as a union of convex blocks. A 2 m concrete cube around a 40 cm void room with a Watt fission source at its center. The concrete is one cell written as the union of the blocks of a grid, as a CAD-to-CSG converter would emit it. The physical geometry is the same for every decomposition, and the shield flux is identical across all of them.
Other models.
It would be great if someone with access to the JET or ITER E-lite models from #3934 could check how much of that slowdown this recovers.
Checklist
I have followed the style guidelines for Python source files (if applicable)I have made corresponding changes to the documentation (if applicable)