Skip to content

Commit

Permalink
Fix bug calling domain for LatitudeLongitudeGrid (#3871)
Browse files Browse the repository at this point in the history
* Fix bug calling domain for LLG

* Bump proj

* Clean up

* Add test
  • Loading branch information
glwagner authored Oct 26, 2024
1 parent 0c1f4fd commit d66ed9b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Oceananigans"
uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
authors = ["Climate Modeling Alliance and contributors"]
version = "0.93.0"
version = "0.93.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
6 changes: 3 additions & 3 deletions src/Grids/latitude_longitude_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ function Base.show(io::IO, grid::LatitudeLongitudeGrid, withsummary=true)
"└── ", z_summary)
end

@inline x_domain(grid::LLG{FT, TX, TY, TZ}) where {FT, TX, TY, TZ} = domain(TX, grid.Nx, grid.λᶠᵃᵃ)
@inline y_domain(grid::LLG{FT, TX, TY, TZ}) where {FT, TX, TY, TZ} = domain(TY, grid.Ny, grid.φᵃᶠᵃ)
@inline z_domain(grid::LLG{FT, TX, TY, TZ}) where {FT, TX, TY, TZ} = domain(TZ, grid.Nz, grid.zᵃᵃᶠ)
@inline x_domain(grid::LLG) = domain(topology(grid, 1)(), grid.Nx, grid.λᶠᵃᵃ)
@inline y_domain(grid::LLG) = domain(topology(grid, 2)(), grid.Ny, grid.φᵃᶠᵃ)
@inline z_domain(grid::LLG) = domain(topology(grid, 3)(), grid.Nz, grid.zᵃᵃᶠ)

@inline cpu_face_constructor_x(grid::XRegularLLG) = x_domain(grid)
@inline cpu_face_constructor_y(grid::YRegularLLG) = y_domain(grid)
Expand Down
55 changes: 43 additions & 12 deletions test/test_grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ end
function test_grid_equality_over_architectures()
grid_cpu = RectilinearGrid(CPU(), topology=(Periodic, Periodic, Bounded), size=(3, 7, 9), x=(0, 1), y=(-1, 1), z=0:9)
grid_gpu = RectilinearGrid(GPU(), topology=(Periodic, Periodic, Bounded), size=(3, 7, 9), x=(0, 1), y=(-1, 1), z=0:9)

return grid_cpu == grid_gpu
end

Expand Down Expand Up @@ -872,6 +871,16 @@ end

@test grid isa RectilinearGrid
end

for arch in archs
@info " Testing on_architecture for RectilinearGrid..."
cpu_grid = RectilinearGrid(CPU(), size=(1, 1, 4), x=(0, 1), y=(0, 1), z=collect(0:4).^2)
grid = on_architecture(arch, cpu_grid)
@test grid isa RectilinearGrid
@test architecture(grid) == arch
cpu_grid_again = on_architecture(CPU(), grid)
@test cpu_grid_again == cpu_grid
end
end

@testset "Latitude-longitude grid" begin
Expand All @@ -884,7 +893,7 @@ end
test_lat_lon_areas(FT)
end

@info " Testing precomputed metrics on latitude-longitude grid..."
@info " Testing precomputed metrics on LatitudeLongitudeGrid..."
for arch in archs, FT in float_types
test_lat_lon_precomputed_metrics(FT, arch)
test_lat_lon_xyzλφ_node_nodes(FT, arch)
Expand All @@ -904,19 +913,40 @@ end

@test grid isa LatitudeLongitudeGrid

# Testing show function for stretched grid
grid = LatitudeLongitudeGrid(CPU(), size=(36, 32, 10), longitude=(-180, 180), latitude=(-80, 80), z=collect(0:10))
for arch in archs
@info " Testing show for vertically-stretched LatitudeLongitudeGrid..."
grid = LatitudeLongitudeGrid(arch,
size = (36, 32, 10),
longitude = (-180, 180),
latitude = (-80, 80),
z = collect(0:10))

@test try
show(grid); println()
true
catch err
println("error in show(::LatitudeLongitudeGrid)")
println(sprint(showerror, err))
false
@test try
show(grid); println()
true
catch err
println("error in show(::LatitudeLongitudeGrid)")
println(sprint(showerror, err))
false
end

@test grid isa LatitudeLongitudeGrid
end

@test grid isa LatitudeLongitudeGrid
for arch in archs
@info " Testing on_architecture for LatitudeLongitudeGrid..."
cpu_grid = LatitudeLongitudeGrid(CPU(),
size = (36, 32, 10),
longitude = (-180, 180),
latitude = (-80, 80),
z = collect(0:10))
grid = on_architecture(arch, cpu_grid)
@test grid isa LatitudeLongitudeGrid
@test architecture(grid) == arch

cpu_grid_again = on_architecture(CPU(), grid)
@test cpu_grid_again == cpu_grid
end
end

@testset "Single column grids" begin
Expand Down Expand Up @@ -1013,3 +1043,4 @@ end
end
end
end

2 comments on commit d66ed9b

@navidcy
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/118140

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.93.1 -m "<description of version>" d66ed9b8b7c4def36260fccf94725c20106029e4
git push origin v0.93.1

Please sign in to comment.