Ensure particle direction is normalized for plotting / volume calculations #2816
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
When generating a plot or running a volume calculation, OpenMC repeatedly makes calls to
exhaustive_find_cell
to determine which cell/material contains a given point. For CSG geometries, the direction of the particle isn't actually used when performing the "find cell" operation and so the value that is assigned is currently some arbitrary value:{0.7071, 0.7071, 0.}
for plotting and{0.5, 0.5, 0.5}
for volume calculations. However, for DAGMC geometries, the direction is used for ray-fire operations to determine which volume contains a given point:openmc/src/dagmc.cpp
Line 655 in f590029
It turns out that MOAB expects the direction being passed to be properly normalized, so the values above cause problems. In particular, if you've compiled OpenMC with DAGMC support and are not using double-down, volume calculations give incorrect results. By ensuring that the arbitrary direction assigned to the particle is normalized before sending to MOAB, the incorrect volume calculation results are fixed.
I also noticed that this fixes some plotting artifacts that are observed when using the plotter. For example, here's a snapshot of a DAGMC geometry without and with the fix from this PR:
Checklist
I have followed the style guidelines for Python source files (if applicable)I have made corresponding changes to the documentation (if applicable)