-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(prt): avoid fpes, patch centroid calculation (#2119)
Fix several related issues that can occur with the generalized tracking method on vertex grids. 1. The polygon centroid formula used when dividing cells into subcells can fail due to floating (im)precision when the vertex coordinates are all large and near to one another, i.e. big grids with really small cells. One option is to do a point-in-polygon check on the result of the centroid calculation and use a simple geometric mean if it fails, but the check is not cheap. Another option is to always use the geo mean instead of the polygon centroid — to guarantee that this is safe we will need to check that the cell vertices don't "wrap around" or contain duplicates I think. In the meantime this PR aims for an 80/20 solution and uses the geometric mean if the cell has 3 vertices, otherwise the full formula. This avoids the error in the common case that the very small cell is a triangle. 2. The tracking routine could encounter floating point exceptions due to a failure to terminate particles in subcells with no exit face. 3. Avoid floating point exceptions due to log of a negative number in the subroutine to calculate travel time to exit. This is done by taking the absolute value of the argument to `log`. Is this safe? I think so because the direction of travel is determined elsewhere.
- Loading branch information
Showing
3 changed files
with
48 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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