From be5059964c36c00bf2bd89eb3d68a15e4b9956da Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 2 Sep 2024 12:08:10 -0400 Subject: [PATCH 01/20] start adding a test infrastructure --- Project.toml | 2 +- test/runtests.jl | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 6f9c21e..e9e1262 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ Adapt = "4" JLD2 = "0.4" KernelAbstractions = "0.9" MPI = "0.20" -Oceananigans = "0.91.3" +Oceananigans = "0.91.11" OffsetArrays = "1" julia = "1" diff --git a/test/runtests.jl b/test/runtests.jl index 3a8c9b0..cf4a1f2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using OrthogonalSphericalShellGrids -using OrthogonalSphericalShellGrids.Oceananigans +using Oceananigans using Oceananigans: GPU, CPU +using Oceananigans.BoundaryConditions using Oceananigans.CUDA using Test @@ -13,4 +14,17 @@ arch = CUDA.has_cuda_gpu() ? GPU() : CPU() grid = TripolarGrid(arch; size = (10, 10, 1)) # Test boundary conditions? + u = XFaceField(grid) + v = YFaceField(grid) + c = CenterField(grid) + + set!(u, 1.0) + set!(v, 1.0) + set!(c, 1.0) + + fill_halo_regions!(u) + fill_halo_regions!(v) + fill_halo_regions!(c) + + @test all(u.data .== 1.0) end From 5b4960a0c213e388b0b590bd130b1c3738b1c95b Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 13:35:15 -0400 Subject: [PATCH 02/20] add correct areas --- src/grid_utils.jl | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/grid_utils.jl b/src/grid_utils.jl index bed6ff3..45405f1 100644 --- a/src/grid_utils.jl +++ b/src/grid_utils.jl @@ -38,26 +38,12 @@ end d = lat_lon_to_cartesian(φᶠᶠᵃ[ i , j+1], λᶠᶠᵃ[ i , j+1], 1) Azᶜᶜᵃ[i, j] = spherical_area_quadrilateral(a, b, c, d) * radius^2 - - a = lat_lon_to_cartesian(φᶜᶠᵃ[i-1, j ], λᶜᶠᵃ[i-1, j ], 1) - b = lat_lon_to_cartesian(φᶜᶠᵃ[ i , j ], λᶜᶠᵃ[ i , j ], 1) - c = lat_lon_to_cartesian(φᶜᶠᵃ[ i , j+1], λᶜᶠᵃ[ i , j+1], 1) - d = lat_lon_to_cartesian(φᶜᶠᵃ[i-1, j+1], λᶜᶠᵃ[i-1, j+1], 1) - - Azᶠᶜᵃ[i, j] = spherical_area_quadrilateral(a, b, c, d) * radius^2 - - a = lat_lon_to_cartesian(φᶠᶜᵃ[ i , j-1], λᶠᶜᵃ[ i , j-1], 1) - b = lat_lon_to_cartesian(φᶠᶜᵃ[i+1, j-1], λᶠᶜᵃ[i+1, j-1], 1) - c = lat_lon_to_cartesian(φᶠᶜᵃ[i+1, j ], λᶠᶜᵃ[i+1, j ], 1) - d = lat_lon_to_cartesian(φᶠᶜᵃ[ i , j ], λᶠᶜᵃ[ i , j ], 1) - - Azᶜᶠᵃ[i, j] = spherical_area_quadrilateral(a, b, c, d) * radius^2 - - a = lat_lon_to_cartesian(φᶜᶜᵃ[i-1, j-1], λᶜᶜᵃ[i-1, j-1], 1) - b = lat_lon_to_cartesian(φᶜᶜᵃ[ i , j-1], λᶜᶜᵃ[ i , j-1], 1) - c = lat_lon_to_cartesian(φᶜᶜᵃ[ i , j ], λᶜᶜᵃ[ i , j ], 1) - d = lat_lon_to_cartesian(φᶜᶜᵃ[i-1, j ], λᶜᶜᵃ[i-1, j ], 1) - - Azᶠᶠᵃ[i, j] = spherical_area_quadrilateral(a, b, c, d) * radius^2 + + # To be consistent it is better to define the face areas as products of the edge lengths + # rather than using the spherical area of the face (cit JMC). + # TODO: find a reference to support this statement + Azᶠᶜᵃ[i, j] = Δyᶠᶜᵃ[i, j] * Δxᶠᶜᵃ[i, j] + Azᶜᶠᵃ[i, j] = Δyᶜᶠᵃ[i, j] * Δxᶜᶠᵃ[i, j] + Azᶠᶠᵃ[i, j] = Δyᶠᶠᵃ[i, j] * Δxᶠᶠᵃ[i, j] end end From ec57daaae402333b884227febc6c7f7eee02cc00 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 14:04:59 -0400 Subject: [PATCH 03/20] change some stuff --- Project.toml | 2 +- test/dependencies_for_runtests.jl | 9 +++++++++ test/runtests.jl | 20 ++------------------ test/test_tripolar_grid.jl | 29 +++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 test/dependencies_for_runtests.jl create mode 100644 test/test_tripolar_grid.jl diff --git a/Project.toml b/Project.toml index e9e1262..e7c9f52 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ Adapt = "4" JLD2 = "0.4" KernelAbstractions = "0.9" MPI = "0.20" -Oceananigans = "0.91.11" +Oceananigans = "0.91.13" OffsetArrays = "1" julia = "1" diff --git a/test/dependencies_for_runtests.jl b/test/dependencies_for_runtests.jl new file mode 100644 index 0000000..1d5303f --- /dev/null +++ b/test/dependencies_for_runtests.jl @@ -0,0 +1,9 @@ +using OrthogonalSphericalShellGrids +using Oceananigans +using Oceananigans: GPU, CPU +using Oceananigans.BoundaryConditions +using OrthogonalSphericalShellGrids: get_cartesian_nodes_and_vertices +using Oceananigans.CUDA +using Test + +arch = CUDA.has_cuda_gpu() ? GPU() : CPU() diff --git a/test/runtests.jl b/test/runtests.jl index cf4a1f2..595f895 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,30 +1,14 @@ -using OrthogonalSphericalShellGrids -using Oceananigans -using Oceananigans: GPU, CPU -using Oceananigans.BoundaryConditions -using Oceananigans.CUDA -using Test - -arch = CUDA.has_cuda_gpu() ? GPU() : CPU() +include("dependencies_for_runtests.jl") @testset "OrthogonalSphericalShellGrids.jl" begin - # We probably do not need any unit tests. - # Test the grid? grid = TripolarGrid(arch; size = (10, 10, 1)) # Test boundary conditions? - u = XFaceField(grid) - v = YFaceField(grid) c = CenterField(grid) - set!(u, 1.0) - set!(v, 1.0) set!(c, 1.0) - - fill_halo_regions!(u) - fill_halo_regions!(v) fill_halo_regions!(c) - @test all(u.data .== 1.0) + @test all(c.data .== 1.0) end diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl new file mode 100644 index 0000000..c6db56c --- /dev/null +++ b/test/test_tripolar_grid.jl @@ -0,0 +1,29 @@ +include("dependencies_for_runtests.jl") + +@testset "Orthogonality of family of ellipses and hyperbolae..." begin + # Test the grid? + grid = TripolarGrid(size = (50, 50, 1); radius = 1) + + + # Get the cartesian nodes on the faces + cartesian_nodes, _ = get_cartesian_nodes_and_vertices(grid, Face(), Face(), Center()) + xF, yF, zF = cartesian_nodes + + o = zeros(49, 49) + + for i in 1:49, j in 1:49 + x⁻ = xF[i, j] + y⁻ = yF[i, j] + + x⁺¹ = xF[i + 1, j] + y⁺¹ = yF[i + 1, j] + x⁺² = xF[i, j + 1] + y⁺² = yF[i, j + 1] + + v1 = (x⁺¹ - x⁻, y⁺¹ - y⁻) + v2 = (x⁺² - x⁻, y⁺² - y⁻) + + # Check orthogonality by computing scalar products: + o[i, j] = dot(v1, v2) + end +end \ No newline at end of file From 9705bc9c5341e5022f44a8d6cff9a872e871092d Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 15:15:18 -0400 Subject: [PATCH 04/20] adding some tests --- test/test_tripolar_grid.jl | 76 ++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl index c6db56c..f1bcc9b 100644 --- a/test/test_tripolar_grid.jl +++ b/test/test_tripolar_grid.jl @@ -1,29 +1,75 @@ include("dependencies_for_runtests.jl") -@testset "Orthogonality of family of ellipses and hyperbolae..." begin - # Test the grid? - grid = TripolarGrid(size = (50, 50, 1); radius = 1) - - - # Get the cartesian nodes on the faces - cartesian_nodes, _ = get_cartesian_nodes_and_vertices(grid, Face(), Face(), Center()) - xF, yF, zF = cartesian_nodes - - o = zeros(49, 49) +using Oceananigans +using Oceananigans.ImmersedBoundaries: immersed_cell +using KernelAbstractions: @kernel, @index - for i in 1:49, j in 1:49 +@kernel function compute_angle!(angle, grid, xF, yF, zF) + i, j = @index(Global, NTuple) + + @inbounds begin x⁻ = xF[i, j] y⁻ = yF[i, j] + z⁻ = zF[i, j] x⁺¹ = xF[i + 1, j] y⁺¹ = yF[i + 1, j] + z⁺¹ = zF[i + 1, j] x⁺² = xF[i, j + 1] y⁺² = yF[i, j + 1] + z⁺² = zF[i, j + 1] + + v1 = (x⁺¹ - x⁻, y⁺¹ - y⁻, z⁺¹ - z⁻) + v2 = (x⁺² - x⁻, y⁺² - y⁻, z⁺² - z⁻) - v1 = (x⁺¹ - x⁻, y⁺¹ - y⁻) - v2 = (x⁺² - x⁻, y⁺² - y⁻) + # Check orthogonality by computing the angle between the vectors + cosθ = dot(v1, v2) / (norm(v1) * norm(v2)) + immersed = immersed_cell(i, j, 1, grid) + angle[i, j] = ifelse(immersed, π / 2, acos(cosθ)) - π / 2 - # Check orthogonality by computing scalar products: - o[i, j] = dot(v1, v2) + # convert to degrees + angle[i, j] = rad2deg(angle[i, j]) end +end + +@testset "Orthogonality of family of ellipses and hyperbolae..." begin + + # Test the orthogonality of a tripolar grid based on the orthogonality of a + # cubed sphere of the same size (1ᵒ in latitude and longitude) + cubed_sphere_grid = ConformalCubedSphereGrid(panel_size = (90, 90, 1), z = (0, 1)) + cubed_sphere_panel = getregion(cubed_sphere_grid, 1) + + angle_cubed_sphere = zeros(size(cubed_sphere_panel)...) + cartesian_nodes, _ = get_cartesian_nodes_and_vertices(cubed_sphere_panel, Face(), Face(), Center()) + xF, yF, zF = cartesian_nodes + Nx, Ny, _ = size(cubed_sphere_panel) + + # Exclude the corners from the computation! (They are definitely orthogonal) + params = KernelParameters((Nx-10, Ny-10), (5, 5)) + + launch!(CPU(), cubed_sphere_panel, params, compute_angle!, angle_cubed_sphere, cubed_sphere_panel, xF, yF, zF) + + first_pole_longitude = λ¹ₚ = 75 + north_poles_latitude = φₚ = 35 + + λ²ₚ = λ¹ₚ + 180 + + # Build a tripolar grid at 1ᵒ + underlying_grid = TripolarGrid(; size = (360, 180, 1), first_pole_longitude, north_poles_latitude) + + # We need a bottom height field that ``masks'' the singularities + bottom_height(λ, φ) = ((abs(λ - λ¹ₚ) < 5) & (abs(φₚ - φ) < 5)) | + ((abs(λ - λ²ₚ) < 5) & (abs(φₚ - φ) < 5)) | (φ < -78) ? 1 : 0 + + # Exclude the singularities from the computation! (They are definitely orthogonal) + tripolar_grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom_height)) + angle_tripolar = zeros(size(tripolar_grid)...) + cartesian_nodes, _ = get_cartesian_nodes_and_vertices(tripolar_grid.underlying_grid, Face(), Face(), Center()) + xF, yF, zF = cartesian_nodes + Nx, Ny, _ = size(tripolar_grid) + + launch!(CPU(), tripolar_grid, (Nx-1, Ny-1), compute_angle!, angle_tripolar, tripolar_grid, xF, yF, zF) + + @test maximum(angle_tripolar) < maximum(angle_cubed_sphere) + @test minimum(angle_tripolar) > minimum(angle_cubed_sphere) end \ No newline at end of file From 14f4bfb662b427ffdda2bb038cb525c5f8dc5e75 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 15:19:19 -0400 Subject: [PATCH 05/20] better comment --- Project.toml | 1 + test/test_tripolar_grid.jl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index e7c9f52..f0b3faf 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.1.3" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl index f1bcc9b..918833a 100644 --- a/test/test_tripolar_grid.jl +++ b/test/test_tripolar_grid.jl @@ -44,7 +44,7 @@ end xF, yF, zF = cartesian_nodes Nx, Ny, _ = size(cubed_sphere_panel) - # Exclude the corners from the computation! (They are definitely orthogonal) + # Exclude the corners from the computation! (They are definitely not orthogonal) params = KernelParameters((Nx-10, Ny-10), (5, 5)) launch!(CPU(), cubed_sphere_panel, params, compute_angle!, angle_cubed_sphere, cubed_sphere_panel, xF, yF, zF) @@ -61,7 +61,7 @@ end bottom_height(λ, φ) = ((abs(λ - λ¹ₚ) < 5) & (abs(φₚ - φ) < 5)) | ((abs(λ - λ²ₚ) < 5) & (abs(φₚ - φ) < 5)) | (φ < -78) ? 1 : 0 - # Exclude the singularities from the computation! (They are definitely orthogonal) + # Exclude the singularities from the computation! (They are definitely not orthogonal) tripolar_grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom_height)) angle_tripolar = zeros(size(tripolar_grid)...) cartesian_nodes, _ = get_cartesian_nodes_and_vertices(tripolar_grid.underlying_grid, Face(), Face(), Center()) From 19a41bd2d9c563f5a678ac323c998afc80ef8bfa Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 15:41:19 -0400 Subject: [PATCH 06/20] test zipper boundary conditions --- src/zipper_boundary_condition.jl | 2 +- test/dependencies_for_runtests.jl | 1 + test/runtests.jl | 6 +++- test/test_zipper_boundary_conditions.jl | 43 +++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/test_zipper_boundary_conditions.jl diff --git a/src/zipper_boundary_condition.jl b/src/zipper_boundary_condition.jl index 06811b1..76efb25 100644 --- a/src/zipper_boundary_condition.jl +++ b/src/zipper_boundary_condition.jl @@ -86,7 +86,7 @@ end Nx, Ny, _ = size(grid) i′ = Nx - i + 2 # Remember! element Nx + 1 does not exist! - s = ifelse(i′ > Nx , abs(sign), sign) # for periodic elements we change the sign + s = ifelse(i > Nx , abs(sign), sign) # for periodic elements we change the sign i′ = ifelse(i′ > Nx, i′ - Nx, i′) # Periodicity is hardcoded in the x-direction!! Hy = grid.Hy diff --git a/test/dependencies_for_runtests.jl b/test/dependencies_for_runtests.jl index 1d5303f..48baf15 100644 --- a/test/dependencies_for_runtests.jl +++ b/test/dependencies_for_runtests.jl @@ -1,6 +1,7 @@ using OrthogonalSphericalShellGrids using Oceananigans using Oceananigans: GPU, CPU +using Oceananigans.Grids: halo_size using Oceananigans.BoundaryConditions using OrthogonalSphericalShellGrids: get_cartesian_nodes_and_vertices using Oceananigans.CUDA diff --git a/test/runtests.jl b/test/runtests.jl index 595f895..97ee66d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,8 +7,12 @@ include("dependencies_for_runtests.jl") # Test boundary conditions? c = CenterField(grid) - set!(c, 1.0) + fill!(c, 1.0) fill_halo_regions!(c) @test all(c.data .== 1.0) end + +include("test_tripolar_grid.jl") +include("test_zipper_boundary_conditions.jl") + diff --git a/test/test_zipper_boundary_conditions.jl b/test/test_zipper_boundary_conditions.jl new file mode 100644 index 0000000..2a1709b --- /dev/null +++ b/test/test_zipper_boundary_conditions.jl @@ -0,0 +1,43 @@ +include("dependencies_for_runtests.jl") + +using OrthogonalSphericalShellGrids: Zipper + +@testset "Zipper boundary conditions..." begin + grid = TripolarGrid(size = (10, 10, 1)) + Nx, Ny, _ = size(grid) + Hx, Hy, _ = halo_size(grid) + + c = CenterField(grid) + u = XFaceField(grid) + v = YFaceField(grid) + + @test c.boundary_conditions.north.classification isa Zipper + @test u.boundary_conditions.north.classification isa Zipper + @test v.boundary_conditions.north.classification isa Zipper + + @test c.boundary_conditions.north.condition == 1 + @test u.boundary_conditions.north.condition == -1 + @test v.boundary_conditions.north.condition == -1 + + set!(c, 1.0) + set!(u, 1.0) + set!(v, 1.0) + + fill_halo_regions!(c) + fill_halo_regions!(u) + fill_halo_regions!(v) + + north_boundary_c = view(c.data, :, Ny+1:Ny+Hy, 1) + north_boundary_v = view(v.data, :, Ny+1:Ny+Hy, 1) + @test all(north_boundary_c .== 1.0) + @test all(north_boundary_v .== -1.0) + + # U is special, because periodicity is hardcoded in the x-direction + north_interior_boundary_u = view(u.data, 2:Nx-1, Ny+1:Ny+Hy, 1) + @test all(north_interior_boundary_u .== -1.0) + + north_boundary_u_left = view(u.data, 1, Ny+1:Ny+Hy, 1) + north_boundary_u_right = view(u.data, Nx+1, Ny+1:Ny+Hy, 1) + @test all(north_boundary_u_left .== 1.0) + @test all(north_boundary_u_right .== 1.0) +end \ No newline at end of file From 170a2ef5c900290d10b2f3c977c0b25e9866af4b Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 15:42:06 -0400 Subject: [PATCH 07/20] remove initial test --- test/runtests.jl | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 97ee66d..06b146f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,18 +1,5 @@ include("dependencies_for_runtests.jl") -@testset "OrthogonalSphericalShellGrids.jl" begin - # Test the grid? - grid = TripolarGrid(arch; size = (10, 10, 1)) - - # Test boundary conditions? - c = CenterField(grid) - - fill!(c, 1.0) - fill_halo_regions!(c) - - @test all(c.data .== 1.0) -end - include("test_tripolar_grid.jl") include("test_zipper_boundary_conditions.jl") From 2b0abe1ae8816b1e332a32f163c809b428307455 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 15:55:41 -0400 Subject: [PATCH 08/20] add correct dependencies --- test/dependencies_for_runtests.jl | 4 +++- test/test_tripolar_grid.jl | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/dependencies_for_runtests.jl b/test/dependencies_for_runtests.jl index 48baf15..cd72b1e 100644 --- a/test/dependencies_for_runtests.jl +++ b/test/dependencies_for_runtests.jl @@ -1,10 +1,12 @@ using OrthogonalSphericalShellGrids using Oceananigans -using Oceananigans: GPU, CPU using Oceananigans.Grids: halo_size +using Oceananigans.Utils using Oceananigans.BoundaryConditions using OrthogonalSphericalShellGrids: get_cartesian_nodes_and_vertices using Oceananigans.CUDA using Test +using KernelAbstractions: @kernel, @index + arch = CUDA.has_cuda_gpu() ? GPU() : CPU() diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl index 918833a..3b2be87 100644 --- a/test/test_tripolar_grid.jl +++ b/test/test_tripolar_grid.jl @@ -1,8 +1,7 @@ include("dependencies_for_runtests.jl") -using Oceananigans +using Oceananigans.Utils: getregion using Oceananigans.ImmersedBoundaries: immersed_cell -using KernelAbstractions: @kernel, @index @kernel function compute_angle!(angle, grid, xF, yF, zF) i, j = @index(Global, NTuple) From 3ddc94098c47aa648717d0f02e0aa8a61a01d6ec Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 14:48:10 -0600 Subject: [PATCH 09/20] import statistics --- test/test_tripolar_grid.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl index 3b2be87..f57be19 100644 --- a/test/test_tripolar_grid.jl +++ b/test/test_tripolar_grid.jl @@ -1,5 +1,6 @@ include("dependencies_for_runtests.jl") +using Statistics: dot, norm using Oceananigans.Utils: getregion using Oceananigans.ImmersedBoundaries: immersed_cell From 18d85dbbfd8bed88a673225faa99a98a2501292d Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 18:11:52 -0400 Subject: [PATCH 10/20] add statistics --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index f0b3faf..6b52b4d 100644 --- a/Project.toml +++ b/Project.toml @@ -11,6 +11,7 @@ KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] Adapt = "4" From a8f2214a13a4f45c0631029eccffeadcffbfad64 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 17:11:19 -0600 Subject: [PATCH 11/20] revert a mistake --- src/zipper_boundary_condition.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zipper_boundary_condition.jl b/src/zipper_boundary_condition.jl index 76efb25..06811b1 100644 --- a/src/zipper_boundary_condition.jl +++ b/src/zipper_boundary_condition.jl @@ -86,7 +86,7 @@ end Nx, Ny, _ = size(grid) i′ = Nx - i + 2 # Remember! element Nx + 1 does not exist! - s = ifelse(i > Nx , abs(sign), sign) # for periodic elements we change the sign + s = ifelse(i′ > Nx , abs(sign), sign) # for periodic elements we change the sign i′ = ifelse(i′ > Nx, i′ - Nx, i′) # Periodicity is hardcoded in the x-direction!! Hy = grid.Hy From 0bf617dbf604a12526ff74b920ddfdb388b7d860 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 19:12:12 -0400 Subject: [PATCH 12/20] clean up Project.toml --- Project.toml | 3 +-- test/distributed_tests.jl | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/distributed_tests.jl diff --git a/Project.toml b/Project.toml index 6b52b4d..6a15197 100644 --- a/Project.toml +++ b/Project.toml @@ -5,13 +5,11 @@ version = "0.1.3" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] Adapt = "4" @@ -24,6 +22,7 @@ julia = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [targets] test = ["Test"] diff --git a/test/distributed_tests.jl b/test/distributed_tests.jl new file mode 100644 index 0000000..0594704 --- /dev/null +++ b/test/distributed_tests.jl @@ -0,0 +1,7 @@ + using Oceananigans + using MPI + MPI.Init() + + include("distributed_tests_utils.jl") + arch = Distributed(CPU(), partition = Partition(1, 4)) + run_distributed_tripolar_grid(arch, "distributed_slab_tripolar.jld2") From 152569b5d92f32cf6217a68edf4542aa257c7513 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 17:14:37 -0600 Subject: [PATCH 13/20] revert to previous face - face metrics --- src/grid_utils.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/grid_utils.jl b/src/grid_utils.jl index 45405f1..b4a8eea 100644 --- a/src/grid_utils.jl +++ b/src/grid_utils.jl @@ -44,6 +44,13 @@ end # TODO: find a reference to support this statement Azᶠᶜᵃ[i, j] = Δyᶠᶜᵃ[i, j] * Δxᶠᶜᵃ[i, j] Azᶜᶠᵃ[i, j] = Δyᶜᶠᵃ[i, j] * Δxᶜᶠᵃ[i, j] - Azᶠᶠᵃ[i, j] = Δyᶠᶠᵃ[i, j] * Δxᶠᶠᵃ[i, j] + + # Face - Face areas are calculated as the Center - Center ones + a = lat_lon_to_cartesian(φᶜᶜᵃ[i-1, j-1], λᶜᶜᵃ[i-1, j-1], 1) + b = lat_lon_to_cartesian(φᶜᶜᵃ[ i , j-1], λᶜᶜᵃ[ i , j-1], 1) + c = lat_lon_to_cartesian(φᶜᶜᵃ[ i , j ], λᶜᶜᵃ[ i , j ], 1) + d = lat_lon_to_cartesian(φᶜᶜᵃ[i-1, j ], λᶜᶜᵃ[i-1, j ], 1) + + Azᶠᶠᵃ[i, j] = spherical_area_quadrilateral(a, b, c, d) * radius^2 end end From c1400fd12e75f25e35bf990055514dc8496de9c1 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 16 Sep 2024 17:27:09 -0600 Subject: [PATCH 14/20] check if this was the problem --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6a15197..54b1a5a 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] Adapt = "4" @@ -22,7 +23,6 @@ julia = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [targets] test = ["Test"] From b737237fdc563b72a46cb6110d70b17915b2a2de Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Tue, 17 Sep 2024 14:23:48 -0400 Subject: [PATCH 15/20] better comment --- src/grid_utils.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/grid_utils.jl b/src/grid_utils.jl index b4a8eea..9b136e1 100644 --- a/src/grid_utils.jl +++ b/src/grid_utils.jl @@ -39,8 +39,9 @@ end Azᶜᶜᵃ[i, j] = spherical_area_quadrilateral(a, b, c, d) * radius^2 - # To be consistent it is better to define the face areas as products of the edge lengths - # rather than using the spherical area of the face (cit JMC). + # To be able to conserve kinetic energy specifically the momentum equation, + # it is better to define the face areas as products of + # the edge lengths rather than using the spherical area of the face (cit JMC). # TODO: find a reference to support this statement Azᶠᶜᵃ[i, j] = Δyᶠᶜᵃ[i, j] * Δxᶠᶜᵃ[i, j] Azᶜᶠᵃ[i, j] = Δyᶜᶠᵃ[i, j] * Δxᶜᶠᵃ[i, j] From 341690509c9a72e37d500eaa3176248a32bd14be Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Tue, 17 Sep 2024 14:39:00 -0400 Subject: [PATCH 16/20] Update test/test_zipper_boundary_conditions.jl Co-authored-by: Gregory L. Wagner --- test/test_zipper_boundary_conditions.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_zipper_boundary_conditions.jl b/test/test_zipper_boundary_conditions.jl index 2a1709b..2adbbe8 100644 --- a/test/test_zipper_boundary_conditions.jl +++ b/test/test_zipper_boundary_conditions.jl @@ -19,9 +19,9 @@ using OrthogonalSphericalShellGrids: Zipper @test u.boundary_conditions.north.condition == -1 @test v.boundary_conditions.north.condition == -1 - set!(c, 1.0) - set!(u, 1.0) - set!(v, 1.0) + set!(c, 1) + set!(u, 1) + set!(v, 1) fill_halo_regions!(c) fill_halo_regions!(u) From 203b3da284abd86f188d2fba6b2bc8edd18ed2dd Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Tue, 17 Sep 2024 14:39:37 -0400 Subject: [PATCH 17/20] Update test/test_zipper_boundary_conditions.jl Co-authored-by: Gregory L. Wagner --- test/test_zipper_boundary_conditions.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_zipper_boundary_conditions.jl b/test/test_zipper_boundary_conditions.jl index 2adbbe8..4d1aac9 100644 --- a/test/test_zipper_boundary_conditions.jl +++ b/test/test_zipper_boundary_conditions.jl @@ -29,8 +29,8 @@ using OrthogonalSphericalShellGrids: Zipper north_boundary_c = view(c.data, :, Ny+1:Ny+Hy, 1) north_boundary_v = view(v.data, :, Ny+1:Ny+Hy, 1) - @test all(north_boundary_c .== 1.0) - @test all(north_boundary_v .== -1.0) + @test all(north_boundary_c .== 1) + @test all(north_boundary_v .== -1) # U is special, because periodicity is hardcoded in the x-direction north_interior_boundary_u = view(u.data, 2:Nx-1, Ny+1:Ny+Hy, 1) From c172878749959c8a5e66aeec103d144aa5a59c15 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Tue, 17 Sep 2024 14:44:23 -0400 Subject: [PATCH 18/20] fixes --- test/distributed_tests.jl | 7 ------- test/test_tripolar_grid.jl | 8 ++++---- test/test_zipper_boundary_conditions.jl | 6 +++--- 3 files changed, 7 insertions(+), 14 deletions(-) delete mode 100644 test/distributed_tests.jl diff --git a/test/distributed_tests.jl b/test/distributed_tests.jl deleted file mode 100644 index 0594704..0000000 --- a/test/distributed_tests.jl +++ /dev/null @@ -1,7 +0,0 @@ - using Oceananigans - using MPI - MPI.Init() - - include("distributed_tests_utils.jl") - arch = Distributed(CPU(), partition = Partition(1, 4)) - run_distributed_tripolar_grid(arch, "distributed_slab_tripolar.jld2") diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl index f57be19..4aa51d5 100644 --- a/test/test_tripolar_grid.jl +++ b/test/test_tripolar_grid.jl @@ -4,7 +4,7 @@ using Statistics: dot, norm using Oceananigans.Utils: getregion using Oceananigans.ImmersedBoundaries: immersed_cell -@kernel function compute_angle!(angle, grid, xF, yF, zF) +@kernel function compute_nonorthogonality_angle!(angle, grid, xF, yF, zF) i, j = @index(Global, NTuple) @inbounds begin @@ -45,9 +45,9 @@ end Nx, Ny, _ = size(cubed_sphere_panel) # Exclude the corners from the computation! (They are definitely not orthogonal) - params = KernelParameters((Nx-10, Ny-10), (5, 5)) + params = KernelParameters(5:Nx-10, 5:Ny-10) - launch!(CPU(), cubed_sphere_panel, params, compute_angle!, angle_cubed_sphere, cubed_sphere_panel, xF, yF, zF) + launch!(CPU(), cubed_sphere_panel, params, compute_nonorthogonality_angle!, angle_cubed_sphere, cubed_sphere_panel, xF, yF, zF) first_pole_longitude = λ¹ₚ = 75 north_poles_latitude = φₚ = 35 @@ -68,7 +68,7 @@ end xF, yF, zF = cartesian_nodes Nx, Ny, _ = size(tripolar_grid) - launch!(CPU(), tripolar_grid, (Nx-1, Ny-1), compute_angle!, angle_tripolar, tripolar_grid, xF, yF, zF) + launch!(CPU(), tripolar_grid, (Nx-1, Ny-1), compute_nonorthogonality_angle!, angle_tripolar, tripolar_grid, xF, yF, zF) @test maximum(angle_tripolar) < maximum(angle_cubed_sphere) @test minimum(angle_tripolar) > minimum(angle_cubed_sphere) diff --git a/test/test_zipper_boundary_conditions.jl b/test/test_zipper_boundary_conditions.jl index 4d1aac9..20b7c49 100644 --- a/test/test_zipper_boundary_conditions.jl +++ b/test/test_zipper_boundary_conditions.jl @@ -34,10 +34,10 @@ using OrthogonalSphericalShellGrids: Zipper # U is special, because periodicity is hardcoded in the x-direction north_interior_boundary_u = view(u.data, 2:Nx-1, Ny+1:Ny+Hy, 1) - @test all(north_interior_boundary_u .== -1.0) + @test all(north_interior_boundary_u .== -1) north_boundary_u_left = view(u.data, 1, Ny+1:Ny+Hy, 1) north_boundary_u_right = view(u.data, Nx+1, Ny+1:Ny+Hy, 1) - @test all(north_boundary_u_left .== 1.0) - @test all(north_boundary_u_right .== 1.0) + @test all(north_boundary_u_left .== 1) + @test all(north_boundary_u_right .== 1) end \ No newline at end of file From 58f7c23a25c396864bb8c90a660d81e833ff0aa8 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Tue, 17 Sep 2024 14:49:53 -0400 Subject: [PATCH 19/20] updating file names --- src/OrthogonalSphericalShellGrids.jl | 4 ++-- src/{grid_extensions.jl => tripolar_grid_extensions.jl} | 0 src/{grid_utils.jl => tripolar_grid_utils.jl} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{grid_extensions.jl => tripolar_grid_extensions.jl} (100%) rename src/{grid_utils.jl => tripolar_grid_utils.jl} (100%) diff --git a/src/OrthogonalSphericalShellGrids.jl b/src/OrthogonalSphericalShellGrids.jl index 6679e1b..a4cc920 100644 --- a/src/OrthogonalSphericalShellGrids.jl +++ b/src/OrthogonalSphericalShellGrids.jl @@ -22,11 +22,11 @@ using OffsetArrays @inline convert_to_0_360(x) = ((x % 360) + 360) % 360 -include("grid_utils.jl") +include("tripolar_grid_utils.jl") include("zipper_boundary_condition.jl") include("generate_tripolar_coordinates.jl") include("tripolar_grid.jl") -include("grid_extensions.jl") +include("tripolar_grid_extensions.jl") include("distributed_tripolar_grid.jl") include("with_halo.jl") include("split_explicit_free_surface.jl") diff --git a/src/grid_extensions.jl b/src/tripolar_grid_extensions.jl similarity index 100% rename from src/grid_extensions.jl rename to src/tripolar_grid_extensions.jl diff --git a/src/grid_utils.jl b/src/tripolar_grid_utils.jl similarity index 100% rename from src/grid_utils.jl rename to src/tripolar_grid_utils.jl From 5f72faaf45c81c6071109305fdbd7622c756a3a4 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Tue, 17 Sep 2024 14:50:31 -0400 Subject: [PATCH 20/20] new kernel parameters --- test/test_tripolar_grid.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_tripolar_grid.jl b/test/test_tripolar_grid.jl index 4aa51d5..88bd5b8 100644 --- a/test/test_tripolar_grid.jl +++ b/test/test_tripolar_grid.jl @@ -45,7 +45,7 @@ end Nx, Ny, _ = size(cubed_sphere_panel) # Exclude the corners from the computation! (They are definitely not orthogonal) - params = KernelParameters(5:Nx-10, 5:Ny-10) + params = KernelParameters(5:Nx-5, 5:Ny-5) launch!(CPU(), cubed_sphere_panel, params, compute_nonorthogonality_angle!, angle_cubed_sphere, cubed_sphere_panel, xF, yF, zF)