-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
188 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using OrthogonalSphericalShellGrids | ||
using Oceananigans | ||
using Oceananigans.Grids: halo_size, φnodes, λnodes | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
using OrthogonalSphericalShellGrids | ||
using OrthogonalSphericalShellGrids.Oceananigans | ||
using Oceananigans: GPU, CPU | ||
using Oceananigans.CUDA | ||
using Test | ||
include("dependencies_for_runtests.jl") | ||
|
||
arch = CUDA.has_cuda_gpu() ? GPU() : CPU() | ||
@testset "Unit tests..." begin | ||
grid = TripolarGrid(size = (4, 5, 1), z = (0, 1), | ||
first_pole_longitude = 75, | ||
north_poles_latitude = 35, | ||
southernmost_latitude = -80) | ||
|
||
@testset "OrthogonalSphericalShellGrids.jl" begin | ||
# We probably do not need any unit tests. | ||
@test grid isa TripolarGrid | ||
|
||
# Test the grid? | ||
grid = TripolarGrid(arch; size = (10, 10, 1)) | ||
@test grid.Nx == 4 | ||
@test grid.Ny == 5 | ||
@test grid.Nz == 1 | ||
|
||
# Test boundary conditions? | ||
@test grid.conformal_mapping.first_pole_longitude == 75 | ||
@test grid.conformal_mapping.north_poles_latitude == 35 | ||
@test grid.conformal_mapping.southernmost_latitude == -80 | ||
|
||
λᶜᶜᵃ = λnodes(grid, Center(), Center()) | ||
φᶜᶜᵃ = φnodes(grid, Center(), Center()) | ||
|
||
min_Δφ = minimum(φᶜᶜᵃ[:, 2] .- φᶜᶜᵃ[:, 1]) | ||
|
||
@test minimum(λᶜᶜᵃ) ≥ 0 | ||
@test maximum(λᶜᶜᵃ) ≤ 360 | ||
@test maximum(φᶜᶜᵃ) ≤ 90 | ||
|
||
# The minimum latitude is not exactly the southermost latitude because the grid | ||
# undulates slightly to maintain the same analytical description in the whole sphere | ||
# (i.e. constant latitude lines do not exist anywhere in this grid) | ||
@test minimum(φᶜᶜᶜ .+ min_Δφ / 10) ≥ grid.conformal_mapping.southernmost_latitude | ||
end | ||
|
||
include("test_tripolar_grid.jl") | ||
include("test_zipper_boundary_conditions.jl") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
include("dependencies_for_runtests.jl") | ||
|
||
using Statistics: dot, norm | ||
using Oceananigans.Utils: getregion | ||
using Oceananigans.ImmersedBoundaries: immersed_cell | ||
|
||
@kernel function compute_nonorthogonality_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⁻) | ||
|
||
# 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 | ||
|
||
# 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 not orthogonal) | ||
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) | ||
|
||
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 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()) | ||
xF, yF, zF = cartesian_nodes | ||
Nx, Ny, _ = size(tripolar_grid) | ||
|
||
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) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
set!(u, 1) | ||
set!(v, 1) | ||
|
||
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) | ||
@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) | ||
@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) | ||
@test all(north_boundary_u_right .== 1) | ||
end |