Determine surface-source starting half-space from particle direction#4024
Open
paulromano wants to merge 3 commits into
Open
Determine surface-source starting half-space from particle direction#4024paulromano wants to merge 3 commits into
paulromano wants to merge 3 commits into
Conversation
GuySten
approved these changes
Jul 21, 2026
GuySten
left a comment
Contributor
There was a problem hiding this comment.
Except for one suggestion.
Looks good to me.
Comment on lines
+557
to
+574
| if (site.surf_id != SURFACE_NONE) { | ||
| auto it = model::surface_map.find(std::abs(site.surf_id)); | ||
| if (it == model::surface_map.end()) { | ||
| site.surf_id = SURFACE_NONE; | ||
| } else { | ||
| const auto& surf = *model::surfaces[it->second]; | ||
| if (surf.geom_type() == GeometryType::CSG && | ||
| std::abs(surf.evaluate(site.r)) < FP_COINCIDENT) { | ||
| int surf_id = std::abs(site.surf_id); | ||
| site.surf_id = | ||
| (site.u.dot(surf.normal(site.r)) > 0.0) ? surf_id : -surf_id; | ||
| } else { | ||
| site.surf_id = SURFACE_NONE; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return site; |
Contributor
There was a problem hiding this comment.
Suggested change
| if (site.surf_id != SURFACE_NONE) { | |
| auto it = model::surface_map.find(std::abs(site.surf_id)); | |
| if (it == model::surface_map.end()) { | |
| site.surf_id = SURFACE_NONE; | |
| } else { | |
| const auto& surf = *model::surfaces[it->second]; | |
| if (surf.geom_type() == GeometryType::CSG && | |
| std::abs(surf.evaluate(site.r)) < FP_COINCIDENT) { | |
| int surf_id = std::abs(site.surf_id); | |
| site.surf_id = | |
| (site.u.dot(surf.normal(site.r)) > 0.0) ? surf_id : -surf_id; | |
| } else { | |
| site.surf_id = SURFACE_NONE; | |
| } | |
| } | |
| } | |
| return site; | |
| if (site.surf_id != SURFACE_NONE) { | |
| auto it = model::surface_map.find(std::abs(site.surf_id)); | |
| if (it != model::surface_map.end()) { | |
| const auto& surf = *model::surfaces[it->second]; | |
| if (surf.geom_type() == GeometryType::CSG && | |
| std::abs(surf.evaluate(site.r)) < FP_COINCIDENT) { | |
| int surf_id = std::abs(site.surf_id); | |
| site.surf_id = | |
| (site.u.dot(surf.normal(site.r)) > 0.0) ? surf_id : -surf_id; | |
| return site; | |
| } | |
| } | |
| site.surf_id = SURFACE_NONE; | |
| } | |
| return site; |
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
Recently, I've been working with some colleagues on a two-step workflow for a shielding calculation. In the first step, particles are accumulated on a surface through surface source, and in the second step the surface source is used as the starting source. We ran into problems with particles getting lost in the second step and I've traced it down to some bugs with how surface IDs that are written to a surface source file are used when that source file is used as the source in a new calculation. First, the surface ID that is written to the source file is unsigned, but when OpenMC reads the source file it treats the surface ID as being signed (i.e., always on the positive side of the surface). Second, if the surface ID is not present in the model, rather than being ignored it ends up defaulting to the first surface in the model by virtue of calling
surface_map[surf_id]whensurf_idis not in the map.Rather than write a signed surface ID to the surface source file, I've fixed the underlying issue by having surface source particles determine their starting half-space using the particle direction and the referenced surface normal. The surface ID is used only when the ID exists and the source position is coincident with that CSG surface; missing or mismatched IDs fall back to normal cell search.
Checklist