From d66ed9b8b7c4def36260fccf94725c20106029e4 Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Sat, 26 Oct 2024 15:14:33 -0600 Subject: [PATCH] Fix bug calling domain for LatitudeLongitudeGrid (#3871) * Fix bug calling domain for LLG * Bump proj * Clean up * Add test --- Project.toml | 2 +- src/Grids/latitude_longitude_grid.jl | 6 +-- test/test_grids.jl | 55 ++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index b4f5f1d0c9..ca9fc6e487 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/Grids/latitude_longitude_grid.jl b/src/Grids/latitude_longitude_grid.jl index 98dc1bc366..aac94c1d32 100644 --- a/src/Grids/latitude_longitude_grid.jl +++ b/src/Grids/latitude_longitude_grid.jl @@ -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) diff --git a/test/test_grids.jl b/test/test_grids.jl index 4ed536c732..0d94ee3ee1 100644 --- a/test/test_grids.jl +++ b/test/test_grids.jl @@ -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 @@ -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 @@ -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) @@ -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 @@ -1013,3 +1043,4 @@ end end end end +