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

Refactor of spacings and correction of spacings-connected bugs #3955

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b19461b
small correction
simone-silvestri Nov 23, 2024
73b9b4a
correction
simone-silvestri Nov 23, 2024
1c1dea3
add a test
simone-silvestri Nov 23, 2024
7e5b287
weird
simone-silvestri Nov 23, 2024
b578440
introduce an error for dz
simone-silvestri Nov 23, 2024
63c374f
bugfix
simone-silvestri Nov 23, 2024
9d29ac6
Merge branch 'main' into ss/correct-spacing
simone-silvestri Nov 23, 2024
93e6305
improve grid metrics
simone-silvestri Nov 25, 2024
da88ed2
remove ψspacing...
simone-silvestri Nov 25, 2024
e129e21
remove `AbstractMetric`
simone-silvestri Nov 25, 2024
11ac809
better formatting
simone-silvestri Nov 25, 2024
ed636bc
continue with the spacings
simone-silvestri Nov 25, 2024
20c94d6
a bit of cleanup in the operators
simone-silvestri Nov 25, 2024
c495dd0
comment
simone-silvestri Nov 25, 2024
5f04304
fixes
simone-silvestri Nov 25, 2024
81db44b
last one
simone-silvestri Nov 25, 2024
3c37ee4
simplification
simone-silvestri Nov 25, 2024
235948a
Merge branch 'main' into ss/correct-spacing
simone-silvestri Nov 25, 2024
ae6ddeb
coorect import
simone-silvestri Nov 25, 2024
e1453f5
Merge branch 'ss/correct-spacing' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Nov 25, 2024
ed5ef27
correct areas
simone-silvestri Nov 25, 2024
57890ec
better naming
simone-silvestri Nov 25, 2024
64235b9
correct grid metric
simone-silvestri Nov 25, 2024
5d030f1
space
simone-silvestri Nov 25, 2024
33ad600
bugfix
simone-silvestri Nov 25, 2024
5941eb6
correct 3D vertical areas
simone-silvestri Nov 25, 2024
35a8504
another bugfix
simone-silvestri Nov 25, 2024
75b5a13
remove all spacing functions
simone-silvestri Nov 25, 2024
cdaf207
tests should pass now
simone-silvestri Nov 25, 2024
2f924f8
correct bottom height
simone-silvestri Nov 25, 2024
b7a7971
fix tests
simone-silvestri Nov 25, 2024
9d2df2f
fix example
simone-silvestri Nov 26, 2024
70f0bbf
export the verbose versions
simone-silvestri Nov 27, 2024
da22227
revert partial cell bottom
simone-silvestri Nov 27, 2024
8cb1fc1
bugfix
simone-silvestri Nov 27, 2024
6d7f435
fix tests
simone-silvestri Nov 28, 2024
653b672
Update spacings_and_areas_and_volumes.jl
simone-silvestri Nov 29, 2024
01c0e4a
fix docstrings
navidcy Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/Grids/nodes_and_spacings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ function φspacings end
destantiate(::Face) = Face
destantiate(::Center) = Center

spacings_function(::Val{:x}) = xspacings
spacings_function(::Val{:y}) = yspacings
spacings_function(::Val{:z}) = zspacings
spacings_function(::Val{:λ}) = λspacings
spacings_function(::Val{:φ}) = φspacings

function minimum_spacing(s, grid, ℓx, ℓy, ℓz)
spacings = spacings_function(s)
return minimum(spacings(grid, ℓx, ℓy, ℓz))
end

"""
minimum_xspacing(grid, ℓx, ℓy, ℓz)

Expand Down
28 changes: 25 additions & 3 deletions src/ImmersedBoundaries/immersed_boundary_nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ rname(ibg::IBG) = rname(ibg.underlying_grid)
@inline fractional_y_index(x, locs, grid::ImmersedBoundaryGrid) = fractional_y_index(x, locs, grid.underlying_grid)
@inline fractional_z_index(x, locs, grid::ImmersedBoundaryGrid) = fractional_z_index(x, locs, grid.underlying_grid)

xspacings(ibg::ImmersedBoundaryGrid, ℓ...) = xspacings(ibg.underlying_grid, ℓ...)
yspacings(ibg::ImmersedBoundaryGrid, ℓ...) = yspacings(ibg.underlying_grid, ℓ...)
zspacings(ibg::ImmersedBoundaryGrid, ℓ...) = zspacings(ibg.underlying_grid, ℓ...)
#####
##### Grid-specific grid spacings
#####

const RGIBG{F, X, Y, Z} = ImmersedBoundaryGrid{F, X, Y, Z, <:RectilinearGrid}
const LLIBG{F, X, Y, Z} = ImmersedBoundaryGrid{F, X, Y, Z, <:LatitudeLongitudeGrid}
const OSIBG{F, X, Y, Z} = ImmersedBoundaryGrid{F, X, Y, Z, <:OrthogonalSphericalShellGrid}

@inline xspacings(grid::RGIBG, ℓx) = xspacings(grid, ℓx, nothing, nothing)
@inline yspacings(grid::RGIBG, ℓy) = yspacings(grid, nothing, ℓy, nothing)
@inline zspacings(grid::RGIBG, ℓz) = zspacings(grid, nothing, nothing, ℓz)

@inline xspacings(grid::LLIBG, ℓx, ℓy) = xspacings(grid, ℓx, ℓy, nothing)
@inline yspacings(grid::LLIBG, ℓx, ℓy) = yspacings(grid, ℓx, ℓy, nothing)
@inline zspacings(grid::LLIBG, ℓz) = zspacings(grid, nothing, nothing, ℓz)

@inline xspacings(grid::OSIBG, ℓx, ℓy) = xspacings(grid, ℓx, ℓy, nothing)
@inline yspacings(grid::OSIBG, ℓx, ℓy) = yspacings(grid, ℓx, ℓy, nothing)
@inline zspacings(grid::OSIBG, ℓz) = zspacings(grid, nothing, nothing, ℓz)

@inline λspacings(grid::LLIBG, ℓx) = λspacings(grid, ℓx, nothing, nothing)
@inline φspacings(grid::LLIBG, ℓy) = φspacings(grid, nothing, ℓy, nothing)

@inline λspacings(grid::OSIBG, ℓx, ℓy) = λspacings(grid, ℓx, ℓy, nothing)
@inline φspacings(grid::OSIBG, ℓx, ℓy) = φspacings(grid, ℓx, ℓy, nothing)
2 changes: 1 addition & 1 deletion src/ImmersedBoundaries/immersed_grid_metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Oceananigans.Operators: Δzᵃᵃᶠ, Δzᵃᵃᶜ, intrinsic_vector, ext
# For non "full-cell" immersed boundaries, grid metric functions
# must be extended for the specific immersed boundary grid in question.

for LX in (:ᶜ, :ᶠ), LY in (:ᶜ, :ᶠ), LZ in (:ᶜ, :ᶠ)
for LX in (:ᶜ, :ᶠ, :ᵃ), LY in (:ᶜ, :ᶠ, :ᵃ), LZ in (:ᶜ, :ᶠ, :ᵃ)
for dir in (:x, :y, :z), operator in (:Δ, :A)

metric = Symbol(operator, dir, LX, LY, LZ)
Expand Down
7 changes: 7 additions & 0 deletions src/ImmersedBoundaries/partial_cell_bottom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,10 @@ YFlatPCBIBG = ImmersedBoundaryGrid{<:Any, <:Any, <:Flat, <:Any, <:Any, <:Partial
@inline Δzᶜᶠᶠ(i, j, k, ibg::YFlatPCBIBG) = Δzᶜᶜᶠ(i, j, k, ibg)
@inline Δzᶠᶠᶜ(i, j, k, ibg::XFlatPCBIBG) = Δzᶜᶠᶜ(i, j, k, ibg)
@inline Δzᶠᶠᶜ(i, j, k, ibg::YFlatPCBIBG) = Δzᶠᶜᶜ(i, j, k, ibg)

# Make sure a PartialCellBottom grid cannot use :ᵃ for the z-spacings
# in the z-direction
for LX in (:ᶜ, :ᶠ, :ᵃ), LY in (:ᶜ, :ᶠ, :ᵃ)
metric = Symbol(operator, dir, LX, LY, :ᵃ)
@eval @inline $metric(i, j, k, ibg::PCBIBG) = throw(ArgumentError("PartialCellBottom grids cannot use `:ᵃ` for spacings in the z-direction"))
end
5 changes: 1 addition & 4 deletions src/MultiRegion/multi_region_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Oceananigans.ImmersedBoundaries: GridFittedBottom, PartialCellBottom, Grid

import Oceananigans.Grids: architecture, size, new_data, halo_size
import Oceananigans.Grids: with_halo, on_architecture
import Oceananigans.Grids: minimum_spacing, destantiate
import Oceananigans.Grids: destantiate
import Oceananigans.Grids: minimum_xspacing, minimum_yspacing, minimum_zspacing
import Oceananigans.Models.HydrostaticFreeSurfaceModels: default_free_surface
import Oceananigans.DistributedComputations: reconstruct_global_grid
Expand Down Expand Up @@ -39,9 +39,6 @@ const MultiRegionGrids = Union{MultiRegionGrid, ImmersedMultiRegionGrid}
@inline Base.lastindex(mrg::MultiRegionGrids) = length(mrg)
number_of_regions(mrg::MultiRegionGrids) = lastindex(mrg)

minimum_spacing(dir, grid::MultiRegionGrid, ℓx, ℓy, ℓz) =
minimum(minimum_spacing(dir, grid[r], ℓx, ℓy, ℓz) for r in 1:number_of_regions(grid))

minimum_xspacing(grid::MultiRegionGrid, ℓx, ℓy, ℓz) =
minimum(minimum_xspacing(grid[r], ℓx, ℓy, ℓz) for r in 1:number_of_regions(grid))

Expand Down
5 changes: 5 additions & 0 deletions test/test_grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,11 @@ function test_lat_lon_xyzλφ_node_nodes(FT, arch)
@test minimum_yspacing(grid) / grid.radius ≈ FT(π/6)
@test minimum_zspacing(grid) ≈ 5

grid = ImmersedBoundaryGrid(grid, GridFittedBottom((x, y) -> y < 20 && y > -20))

@test minimum_xspacing(grid, Face(), Face(), Face()) / grid.radius ≈ π/6 * cosd(15)
@test minimum_xspacing(grid) / grid.radius ≈ π/6 * cosd(15)

return nothing
end

Expand Down