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

LatitudeLongitudeGrid may have incorrect metrics for y-Periodic domains #3465

Closed
glwagner opened this issue Feb 7, 2024 · 6 comments
Closed
Labels
bug 🐞 Even a perfect program still has bugs grids 🗺️

Comments

@glwagner
Copy link
Member

glwagner commented Feb 7, 2024

This code:

using Oceananigans
grid = LatitudeLongitudeGrid(longitude = (215, 215.25),
                             latitude = (50, 50.25),
                             size = (1, 1, 50),
                             halo = (1, 1, 1),
                             z = (-200, 0),
                             topology = (Periodic, Periodic, Bounded))

produces a BoundsError, if run with julia --check-bounds=yes.

The problem is the worksize specified here:

@inline metric_worksize(grid::XRegularLLG) = length(grid.φᵃᶜᵃ) - 1

I also don't like this code because we cannot read it to understand it. For example, what is length(grid.φᵃᶜᵃ)? Is this Ny + Hy, or Ny + Hy + 1? I think it would be better to be explicit.

It appears that for both Periodic and Bounded in y, then we have

length(grid.φᵃᶜᵃ) = 3

Which looks like Ny + 2Hy.

I think both the worksize and the metric size is wrong in general --- I think we have hardcoded a Bounded y-topology. I think the right thing to do is to go in and use total_length to determine both the correct size of the metrics for any topology, as well as the size of the kernel that is launched to compute them.

@glwagner glwagner added the bug 🐞 Even a perfect program still has bugs label Feb 7, 2024
@glwagner
Copy link
Member Author

glwagner commented Feb 7, 2024

A quick fix is to use

 @inline metric_worksize(grid::XRegularLLG)  = length(grid.φᵃᶠᵃ) - 2

@navidcy
Copy link
Collaborator

navidcy commented Feb 8, 2024

Nice catch!

@navidcy
Copy link
Collaborator

navidcy commented Feb 8, 2024

What's the metric_worksize?

@glwagner
Copy link
Member Author

glwagner commented Feb 8, 2024

I guess it's the size of the kernel that we use to compute the metrics. Basically it has to be the number of faces - 2, beacause we compute metrics using differences.

@glwagner
Copy link
Member Author

Closed by #3450

@navidcy
Copy link
Collaborator

navidcy commented Feb 29, 2024

Closed by #3450

since #3450 includes other things, perhaps you can point out the source code change or the commit the resolved the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Even a perfect program still has bugs grids 🗺️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants