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

Deal with x ⇆ y, λ ⇆ φ, etc when filling halos for metrics/coords in ConformalCubedSphereGrid #3256

Merged
merged 6 commits into from
Sep 11, 2023

Conversation

navidcy
Copy link
Collaborator

@navidcy navidcy commented Sep 8, 2023

I found that the issue #3254 was because while filling the metrics at the halo regions, we didn't took into consideration that Δx ⇆ Δy in non-trivial cubed sphere connections East ⇆ North.

This PR deals with that.

Closes #3254

@navidcy navidcy added bug 🐞 Even a perfect program still has bugs grids 🗺️ cubed sphere 🧊🌎 labels Sep 8, 2023
@navidcy
Copy link
Collaborator Author

navidcy commented Sep 8, 2023

using Oceananigans
using Oceananigans.MultiRegion: getregion
using GLMakie

Nx, Ny = 5, 5
H = 3

range_with_offset(N, H, offset::Int) = (-H + 1 + offset*N):(N + H + offset*N)

grid = ConformalCubedSphereGrid(panel_size = (Nx, Ny, 1), z = (0, 1), horizontal_direction_halo = H)

j_index = 2
i_index = Nx+1 - j_index

fig = Figure(resolution=(2200, 600), fontsize=30)
ax = Axis(fig[1, 1])
lines!(ax, range_with_offset(Nx, H, 0), parent(getregion(grid, 1).Δxᶜᶜᵃ)[:, j_index+H], linewidth=4, color = (:green, 0.9), label="panel 1")
lines!(ax, range_with_offset(Nx, H, 1), parent(getregion(grid, 2).Δxᶜᶜᵃ)[:, j_index+H], linewidth=8, color = (:red, 0.5), label="panel 2")
lines!(ax, range_with_offset(Ny, H, 2), parent(getregion(grid, 4).Δyᶜᶜᵃ)[i_index+H, :], linewidth=4, color = (:blue, 0.5), label="panel 4")
vlines!(ax, [1, Nx+1, 2Nx+1, 3Nx+1], linewidth=8, color=(:black, 0.3))
fig[1, 2] = Legend(fig, ax, framevisible = false)
fig
save("metrictest.png", fig)

metrictest

while BEFORE THIS PR:

metrictest

@navidcy navidcy changed the title Deal with x->y, λ->φ, etc when filling halos for metrics/coords in ConformalCubedSphereGrid Deal with x <-> y, λ <->φ, etc when filling halos for metrics/coords in ConformalCubedSphereGrid Sep 10, 2023
@navidcy navidcy changed the title Deal with x <-> y, λ <->φ, etc when filling halos for metrics/coords in ConformalCubedSphereGrid Deal with x ⇆ y, λ ⇆ φ, etc when filling halos for metrics/coords in ConformalCubedSphereGrid Sep 10, 2023
@navidcy
Copy link
Collaborator Author

navidcy commented Sep 10, 2023

I wanted to add tests but the current test functionality is difficult to adjust to work for 2D arrays.

function get_range_of_indices(operation, index, Nx, Ny)
if operation == :endpoint && index == :first
range_x = 1
range_y = 1
elseif operation == :endpoint && index == :last
range_x = Nx
range_y = Ny
elseif operation == :subset && index == :first # here index is the index to skip
range_x = 2:Nx
range_y = 2:Ny
elseif operation == :subset && index == :last # here index is the index to skip
range_x = 1:Nx-1
range_y = 1:Ny-1
else
range_x = 1:Nx
range_y = 1:Ny
end
return range_x, range_y
end
function get_halo_data(field, side, k_index=1; operation=nothing, index=:all)
Nx, Ny, _ = size(field)
Hx, Hy, _ = halo_size(field.grid)
range_x, range_y = get_range_of_indices(operation, index, Nx, Ny)
if side == :west
return field.data[-Hx+1:0, range_y, k_index]
elseif side == :east
return field.data[Nx+1:Nx+Hx, range_y, k_index]
elseif side == :south
return field.data[range_x, -Hy+1:0, k_index]
elseif side == :north
return field.data[range_x, Ny+1:Ny+Hy, k_index]
end
end
function get_boundary_indices(Nx, Ny, Hx, Hy, side; operation=nothing, index=:all)
range_x, range_y = get_range_of_indices(operation, index, Nx, Ny)
if side == :west
return 1:Hx, range_y
elseif side == :south
return range_x, 1:Hy
elseif side == :east
return Nx-Hx+1:Nx, range_y
elseif side == :north
return range_x, Ny-Hy+1:Ny
end
end

I'd like to rewrite those to use the connectivity property of the ConformalCubedSphereGrid rather than a series of if statements. Also address ##3242. But I wasn't planning to do this on this PR.

Copy link
Member

@glwagner glwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the problem is across panel 2 and 4? And there is also a problem across panel 1 and 2, but oddly the coordinates were still continuous originally.

@navidcy navidcy merged commit 74ce1ef into main Sep 11, 2023
@navidcy navidcy deleted the ncc/halos-conformal-cubed-sphere branch September 11, 2023 17:07
siddharthabishnu pushed a commit that referenced this pull request Sep 11, 2023
…`ConformalCubedSphereGrid` (#3256)

* deal with Δx <-> Δy, etc for nontrivial connections

* two halo filling pases

* ommit coords/metric halo test as deprecated

* add TODO for coords/metric tests that include the halo regions

* bit more julian-like

* make sides types instead of symbols
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 cubed sphere 🧊🌎 grids 🗺️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics across ConformalCubedSphereGrid panels
2 participants