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

Fix partial cell bottom areas and volumes #3959

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
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
36 changes: 21 additions & 15 deletions src/ImmersedBoundaries/immersed_grid_metrics.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Oceananigans.AbstractOperations: GridMetricOperation

import Oceananigans.Grids: coordinates
import Oceananigans.Operators: Δzᵃᵃᶠ, Δzᵃᵃᶜ, intrinsic_vector, extrinsic_vector
import Oceananigans.Operators: intrinsic_vector, extrinsic_vector

# Grid metrics for ImmersedBoundaryGrid
#
Expand All @@ -10,28 +8,36 @@ 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 dir in (:x, :y, :z), operator in (:Δ, :A)
# We need to extend only the metric explicitly defined in the `spacing_and_areas_and_volumes.jl` file.
# These include all the spacings and the horizontal areas.
# All the other metrics are calculated from these.

x_superscript(dir) = dir == :x ? (:ᶜ, :ᶠ) : (:ᶜ, :ᶠ, :ᵃ)
y_superscript(dir) = dir == :y ? (:ᶜ, :ᶠ) : (:ᶜ, :ᶠ, :ᵃ)
z_superscript(dir) = dir == :z ? (:ᶜ, :ᶠ) : (:ᶜ, :ᶠ, :ᵃ)

metric = Symbol(operator, dir, LX, LY, LZ)
for dir in (:x, :y, :z)
for LX in x_superscript(dir), LY in y_superscript(dir), LZ in z_superscript(dir)
spacing = Symbol(:Δ, dir, LX, LY, LZ)
@eval begin
import Oceananigans.Operators: $metric
@inline $metric(i, j, k, ibg::IBG) = $metric(i, j, k, ibg.underlying_grid)
import Oceananigans.Operators: $spacing
$spacing(i, j, k, ibg::IBG) = $spacing(i, j, k, ibg.underlying_grid)
end
end
end

volume = Symbol(:V, LX, LY, LZ)
@eval begin
import Oceananigans.Operators: $volume
@inline $volume(i, j, k, ibg::IBG) = $volume(i, j, k, ibg.underlying_grid)
for L1 in (:ᶜ, :ᶠ)
for L2 in (:ᶜ, :ᶠ)
zarea2D = Symbol(:Az, L1, L2, :ᵃ)
@eval begin
import Oceananigans.Operators: $zarea2D
$zarea2D(i, j, k, ibg::IBG) = $zarea2D(i, j, k, ibg.underlying_grid)
end
end
end

coordinates(grid::IBG) = coordinates(grid.underlying_grid)

@inline Δzᵃᵃᶠ(i, j, k, ibg::IBG) = Δzᵃᵃᶠ(i, j, k, ibg.underlying_grid)
@inline Δzᵃᵃᶜ(i, j, k, ibg::IBG) = Δzᵃᵃᶜ(i, j, k, ibg.underlying_grid)

# Extend both 2D and 3D methods
@inline intrinsic_vector(i, j, k, ibg::IBG, u, v) = intrinsic_vector(i, j, k, ibg.underlying_grid, u, v)
@inline extrinsic_vector(i, j, k, ibg::IBG, u, v) = extrinsic_vector(i, j, k, ibg.underlying_grid, u, v)
Expand Down