-
Notifications
You must be signed in to change notification settings - Fork 184
Exclude faces that touch NaN nodes from the SpatialHash table #2802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
26371a4
958bb6c
9989792
4db92d1
8202e71
3f35124
3c5c414
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,7 +261,17 @@ def _total_hash_entries(self, bitwidth): | |
| nx = xqhigh.astype(np.int64) - xqlow + 1 | ||
| ny = yqhigh.astype(np.int64) - yqlow + 1 | ||
| nz = zqhigh.astype(np.int64) - zqlow + 1 | ||
| return int((nx * ny * nz).sum()) | ||
| # NaN values are not allowed in the SpatialHash table, so faces with a NaN | ||
| # bounding box do not contribute to the entry count | ||
| invalid_face = ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We tend to think of masks here, so perhaps rename to |
||
| np.isnan(self._xlow) | ||
| | np.isnan(self._xhigh) | ||
| | np.isnan(self._ylow) | ||
| | np.isnan(self._yhigh) | ||
| | np.isnan(self._zlow) | ||
| | np.isnan(self._zhigh) | ||
| ) | ||
| return int(np.where(invalid_face, 0, nx * ny * nz).sum()) | ||
|
|
||
| def _initialize_hash_table(self): | ||
| """Create a mapping that relates unstructured grid faces to hash indices by determining | ||
|
|
@@ -302,7 +312,18 @@ def _initialize_hash_table(self): | |
| nx = (xqhigh - xqlow + 1).astype(np.int32, copy=False) | ||
| ny = (yqhigh - yqlow + 1).astype(np.int32, copy=False) | ||
| nz = (zqhigh - zqlow + 1).astype(np.int32, copy=False) | ||
| num_hash_per_face = (nx * ny * nz).astype( | ||
|
|
||
| # prevent NaN values from entering the SpatialHash table by setting their | ||
| # num_hash_per_face equal to 0 | ||
| invalid_face = ( | ||
| np.isnan(self._xlow) | ||
| | np.isnan(self._xhigh) | ||
| | np.isnan(self._ylow) | ||
| | np.isnan(self._yhigh) | ||
| | np.isnan(self._zlow) | ||
| | np.isnan(self._zhigh) | ||
| ).ravel() | ||
| num_hash_per_face = np.where(invalid_face, 0, nx * ny * nz).astype( | ||
| np.int32, copy=False | ||
| ) # Since nx, ny, nz are in the 10-bit range, their product fits in int32 | ||
| # Sums over faces can exceed int32, so accumulate in int64 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,7 +298,7 @@ def spatialhash_describe(spatialhash: SpatialHash) -> str: | |
| "Bitwidth (current / max)": f"{spatialhash._bitwidth} / 1023 (higher = finer resolution hash grid)", | ||
| "Total hash cells": f"{n_total_cells:,d}", | ||
| "Occupied hash cells": f"{n_occupied_cells:,d}, {n_occupied_cells / n_total_cells * 100:.4f}%", | ||
| "Total (hash cell --> gird face) entries": f"{n_entries:,d}", | ||
| "Total (hash cell --> grid face) entries": f"{n_entries:,d}", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left-over typo from #2796 that I only spotted now... |
||
| "Entries per occupied hash cell (avg)": f"{n_entries / n_occupied_cells:.2f}" if n_occupied_cells else "-", | ||
| "Entries per face (avg)": f"{n_entries / n_faces:.2f}" if n_faces else "-", | ||
| "Faces per occupied hash cell (min / mean / max)": ( | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test, but should we also add a check that the number of unique mesh faces is less than the number of original grid cells - because the NaNs are filtered out? I think this should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution is very elegant! Nice work @wyatt-fluidnumerics
The only thing I wonder about is if it's worth to make a helper function to construct the
invalid_facearray. Because the same code is now used twice. Or will that make going through the code only more confusing?