Skip to content
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

Non-unique nearest point calculation in ww3_bounc #1344

Open
dahonegger opened this issue Jan 7, 2025 · 0 comments
Open

Non-unique nearest point calculation in ww3_bounc #1344

dahonegger opened this issue Jan 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@dahonegger
Copy link

Describe the bug
When assigning NetCDF spectra to input boundary nodes (MAPSTA=2, assigned via INBND_NML in ww3_grid.nml), ww3_bounc uses an iterative method to identify the two nearest neighbor spectra in spec.list. Custom diagnostic output in ww3_bounc reveals that points even one kilometer apart can be calculated as having a separation distance of zero. Moreover, some input point - boundary point pairs result in a returned distance of NaN. As a result, assignment of spectra to boundary nodes is sensitive to the ordering of the boundary nodes and to the ordering of the provided spectra in a manner that is not explicit in the code.

To Reproduce

  1. Run ww3_grid
  2. Provide multiple spectra that are within one kilometer of a boundary input node via files itemized in spec.list.
  3. Run ww3_bounc

Expected behavior
Only one input spectrum is identified as having a minimum distance from each boundary node when using a grid/mesh with reasonable resolution.

Screenshot of the issue
image

Additional context
The screenshot consists of custom diagnostic output in ww3_bounc. Columns (labeled) are:

  1. Boundary node index (outer loop)
  2. Input spectrum file index (inner loop)
  3. Distance in longitude between the boundary node and the input spectrum file
  4. Distance in latitude between the boundary node and the input spectrum file
  5. Total distance as calculated by DIST_SPHERE
  6. Minimum distance from the boundary node to all input spectrum files (so far)
  7. 2nd shortest distance from the boundary node to all input spectrum files (so far)

Note the presence of multiple locations with zero and NaN values for distance despite meridional and zonal distances (0.001-0.01 deg) that can reasonably be found along the boundaries of coastal grids/meshes. The example provided is at a location near the USACE FRF in Duck, North Carolina, USA (-75.7513, 36.1821).

Proposed fix
Calculate geographic distances with an updated formula that employs haversines. Haversine-based great-arc distances are more robust both to small angles and to floating point errors that can produce arccos arguments that are larger than one (and hence imaginary results). This fix, along with the additional lines of diagnostic stdout, is employed in a new branch in erdc/WW3, The screenshot below demonstrates the expected behavior.

Screenshot of the proposed fix
image

@dahonegger dahonegger added the bug Something isn't working label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant