Skip to content

Commit 1d83f4b

Browse files
tomchorTomas Chor
and
Tomas Chor
authored
(0.96.32) Fix zspacing() for PartialCellBottom immersed boundaries and add tests for ImmersedGrids (#4572)
* Add missing Δz methods for PartialCellBottom immersed boundaries - Add all Δz function combinations for VSPCBIBG - Each Δz method maps to corresponding Δr method for vertically-static grids - Fixes zspacing() not adjusting for PartialCellBottom immersed boundaries * bugfix * add better tests for immersed boundaries * add tests for gridFittedBoundary * add rspacings and a test for it * standardize notation * leanup * fix tests on GPU * add test for mutableVerticalDiscretization * bump patch release --------- Co-authored-by: Tomas Chor <tomchor@login19.chn.perlmutter.nersc.gov>
1 parent b772f73 commit 1d83f4b

File tree

5 files changed

+514
-33
lines changed

5 files changed

+514
-33
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Oceananigans"
22
uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
33
authors = ["Climate Modeling Alliance and contributors"]
4-
version = "0.96.31"
4+
version = "0.96.32"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/AbstractOperations/grid_metrics.jl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ using Adapt
22
using Oceananigans.Operators
33
using Oceananigans.Grids: AbstractGrid
44
using Oceananigans.Fields: AbstractField, default_indices, location
5-
using Oceananigans.Operators: Δx, Δy, Δz, Ax, Δλ, Δφ, Ay, Az, volume
5+
using Oceananigans.Operators: Δx, Δy, Δz, Δr, Ax, Δλ, Δφ, Ay, Az, volume
66

7-
import Oceananigans.Grids: xspacings, yspacings, zspacings, λspacings, φspacings
7+
import Oceananigans.Grids: xspacings, yspacings, zspacings, rspacings, λspacings, φspacings
88

99
const AbstractGridMetric = Union{typeof(Δx),
1010
typeof(Δy),
@@ -159,6 +159,32 @@ function zspacings(grid, ℓx, ℓy, ℓz)
159159
return Δz_op
160160
end
161161

162+
"""
163+
rspacings(grid, ℓx, ℓy, ℓz)
164+
165+
Return a `KernelFunctionOperation` that computes the grid spacings for `grid`
166+
in the ``r`` direction at location `ℓx, ℓy, ℓz`.
167+
168+
Examples
169+
========
170+
```jldoctest
171+
julia> using Oceananigans
172+
173+
julia> grid = RectilinearGrid(size=(2, 4, 8), extent=(1, 1, 1));
174+
175+
julia> rspacings(grid, Center(), Center(), Face())
176+
KernelFunctionOperation at (Center, Center, Face)
177+
├── grid: 2×4×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×3×3 halo
178+
├── kernel_function: Δr (generic function with 28 methods)
179+
└── arguments: ("Center", "Center", "Face")
180+
```
181+
"""
182+
function rspacings(grid, ℓx, ℓy, ℓz)
183+
LX, LY, LZ = map(typeof, (ℓx, ℓy, ℓz))
184+
Δr_op = KernelFunctionOperation{LX, LY, LZ}(Δr, grid, ℓx, ℓy, ℓz)
185+
return Δr_op
186+
end
187+
162188
"""
163189
λspacings(grid, ℓx, ℓy, ℓz)
164190

src/ImmersedBoundaries/grid_fitted_bottom.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Base.summary(ib::GridFittedBottom{<:Function}) = @sprintf("GridFittedBottom(%s)"
7272

7373
function Base.show(io::IO, ib::GridFittedBottom)
7474
print(io, summary(ib), '\n')
75-
print(io, "── bottom_height: ", prettysummary(ib.bottom_height), '\n')
75+
print(io, "── bottom_height: ", prettysummary(ib.bottom_height), '\n')
7676
end
7777

7878
on_architecture(arch, ib::GridFittedBottom) = GridFittedBottom(on_architecture(arch, ib.bottom_height), ib.immersed_condition)

src/ImmersedBoundaries/partial_cell_bottom.jl

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using Oceananigans.Utils: prettysummary
22
using Oceananigans.Fields: fill_halo_regions!
3-
using Oceananigans.Grids: bottommost_active_node
3+
using Oceananigans.Grids: bottommost_active_node, AbstractStaticGrid
44
using Printf
55

6-
import Oceananigans.Operators: Δrᶜᶜᶜ, Δrᶜᶜᶠ, Δrᶜᶠᶜ, Δrᶜᶠᶠ, Δrᶠᶜᶜ, Δrᶠᶜᶠ, Δrᶠᶠᶜ, Δrᶠᶠᶠ
6+
import Oceananigans.Operators: Δrᶜᶜᶜ, Δrᶜᶜᶠ, Δrᶜᶠᶜ, Δrᶜᶠᶠ, Δrᶠᶜᶜ, Δrᶠᶜᶠ, Δrᶠᶠᶜ, Δrᶠᶠᶠ,
7+
Δzᶜᶜᶜ, Δzᶜᶜᶠ, Δzᶜᶠᶜ, Δzᶜᶠᶠ, Δzᶠᶜᶜ, Δzᶠᶜᶠ, Δzᶠᶠᶜ, Δzᶠᶠᶠ
78

89
#####
910
##### PartialCellBottom
@@ -137,20 +138,20 @@ Criterion is zb ≥ z - ϵ Δz
137138
138139
"""
139140
@inline function _immersed_cell(i, j, k, underlying_grid, ib::PartialCellBottom)
140-
z= rnode(i, j, k+1, underlying_grid, c, c, f)
141+
r= rnode(i, j, k + 1, underlying_grid, c, c, f)
141142
ϵ = ib.minimum_fractional_cell_height
142-
Δz = Δrᶜᶜᶜ(i, j, k, underlying_grid)
143-
z= z- Δz * ϵ
144-
zb = @inbounds ib.bottom_height[i, j, 1]
145-
return z< zb
143+
Δr = Δrᶜᶜᶜ(i, j, k, underlying_grid)
144+
r= r- Δr * ϵ
145+
rᵇ = @inbounds ib.bottom_height[i, j, 1]
146+
return r< rᵇ
146147
end
147148

148149
@inline function Δrᶜᶜᶜ(i, j, k, ibg::PCBIBG)
149150
underlying_grid = ibg.underlying_grid
150151
ib = ibg.immersed_boundary
151152

152153
# Get node at face above and defining nodes on c,c,f
153-
rᶜᶜᶠₖ₊₁ = rnode(i, j, k+1, underlying_grid, c, c, f)
154+
r⁺ = rnode(i, j, k + 1, underlying_grid, c, c, f)
154155

155156
# Get bottom r-coordinate and fractional Δr parameter
156157
rᵇ = @inbounds ib.bottom_height[i, j, 1]
@@ -159,13 +160,13 @@ end
159160
at_the_bottom = bottommost_active_node(i, j, k, ibg, c, c, c)
160161

161162
full_Δr = Δrᶜᶜᶜ(i, j, k, ibg.underlying_grid)
162-
partial_Δr = rᶜᶜᶠₖ₊₁ - rᵇ
163+
partial_Δr = r⁺ - rᵇ
163164

164165
return ifelse(at_the_bottom, partial_Δr, full_Δr)
165166
end
166167

167168
@inline function Δrᶜᶜᶠ(i, j, k, ibg::PCBIBG)
168-
just_above_bottom = bottommost_active_node(i, j, k, c, c, f)
169+
just_above_bottom = bottommost_active_node(i, j, k, ibg, c, c, f)
169170
rᶜ = rnode(i, j, k, ibg.underlying_grid, c, c, c)
170171
rᶠ = rnode(i, j, k, ibg.underlying_grid, c, c, f)
171172

@@ -195,3 +196,14 @@ YFlatPCBIBG = ImmersedBoundaryGrid{<:Any, <:Any, <:Flat, <:Any, <:Any, <:Partial
195196
@inline Δrᶜᶠᶠ(i, j, k, ibg::YFlatPCBIBG) = Δrᶜᶜᶠ(i, j, k, ibg)
196197
@inline Δrᶠᶠᶜ(i, j, k, ibg::XFlatPCBIBG) = Δrᶜᶠᶜ(i, j, k, ibg)
197198
@inline Δrᶠᶠᶜ(i, j, k, ibg::YFlatPCBIBG) = Δrᶠᶜᶜ(i, j, k, ibg)
199+
200+
# Vertically-static, partial cell bottom, immergsed boundary grid
201+
VSPCBIBG = ImmersedBoundaryGrid{<:Any, <:Any, <:Any, <:Any, <:AbstractStaticGrid, <:PartialCellBottom}
202+
@inline Δzᶜᶜᶜ(i, j, k, ibg::VSPCBIBG) = Δrᶜᶜᶜ(i, j, k, ibg)
203+
@inline Δzᶠᶜᶜ(i, j, k, ibg::VSPCBIBG) = Δrᶠᶜᶜ(i, j, k, ibg)
204+
@inline Δzᶜᶠᶜ(i, j, k, ibg::VSPCBIBG) = Δrᶜᶠᶜ(i, j, k, ibg)
205+
@inline Δzᶜᶜᶠ(i, j, k, ibg::VSPCBIBG) = Δrᶜᶜᶠ(i, j, k, ibg)
206+
@inline Δzᶠᶠᶜ(i, j, k, ibg::VSPCBIBG) = Δrᶠᶠᶜ(i, j, k, ibg)
207+
@inline Δzᶜᶠᶠ(i, j, k, ibg::VSPCBIBG) = Δrᶜᶠᶠ(i, j, k, ibg)
208+
@inline Δzᶠᶜᶠ(i, j, k, ibg::VSPCBIBG) = Δrᶠᶜᶠ(i, j, k, ibg)
209+
@inline Δzᶠᶠᶠ(i, j, k, ibg::VSPCBIBG) = Δrᶠᶠᶠ(i, j, k, ibg)

0 commit comments

Comments
 (0)