normalize new_u after periodic crossing to prevent unnormalized direction#4015
normalize new_u after periodic crossing to prevent unnormalized direction#4015lewisgross1296 wants to merge 1 commit into
Conversation
…ror cannot create an unnormalized direction vector. add comments to the other handle_particle methods, which already do the same
a515e2f to
f5cfcad
Compare
|
I wasn't expecting tests to pass per se, but maybe the examples are not as affected by the change enough to affect the statistics to a noticeable degree? I.e. the effect of normalization when hitting the periodic surface isn't enough to bias k and its uncertainty in these examples. |
First, I'm pretty sure the periodic tests aren't being compared statistically, but are expected to be numerically exact. That said, they each use only 4000-5000 histories total, so it conceivable that they never encounter a history where this normalization has an impact. |
Description
Closes #3970. After many months and much support from @pshriwise and @gonuke, we've come to a resolution to an issue I was having with my model related to using a periodic BC aligned to the y-axis, see forum post.
It turns out that most boundary conditions in OpenMC re-normalize particle direction after they cross a boundary (e.g. reflective or white BCs) and that ~6 years ago, this was not done for the periodic case. It wasn't an issue for a while due to the restriction that models must use z-axis aligned periodicity. However, allowing arbitrary periodic BCs #3591 combined with logic in rotate_angle exposed a rare, but consistent, behavior that the un-normalized nature of the direction vector could grow beyond unity until eventually, a negative distance to collision gets computed. This negative distance results from an assumption of unity norm directions in the function logic. In this case, OpenMC reports a
-nanbatch and has a fatal error.We've tried a lot to debug, however the most relevant is that
-nangoes away-nangoes away-nanby removing the normalization in the reflective BC case inboundary_condition.cppand re-running my y-aligned model while only changing the BC to reflective.It seems there are very small amounts of floating point error picked up that magnify each time they cross a boundary or for lucky (unlucky?) directions interacting with
rotate_angle's branching on thebparameter.This solution will make the code more consistent with itself i.e. normalizing after any type of boundary crossing that is not transnational. Thankfully, this solution means that only periodic BC related tests need to be re-golded (which I will do in the next commit). I have a feeling of which tests should fail with this change (see below), but I'm going to let them fail just to be sure.
Checklist
I have followed the style guidelines for Python source files (if applicable)I have made corresponding changes to the documentation (if applicable)