From 360d6cbbffd3be8b78dc9e66e5549ec4272e3d91 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 25 Nov 2024 16:18:53 +0100 Subject: [PATCH 1/2] fix for partial cell bottom --- .../immersed_grid_metrics.jl | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/ImmersedBoundaries/immersed_grid_metrics.jl b/src/ImmersedBoundaries/immersed_grid_metrics.jl index 48cb239768..33b5289cf9 100644 --- a/src/ImmersedBoundaries/immersed_grid_metrics.jl +++ b/src/ImmersedBoundaries/immersed_grid_metrics.jl @@ -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 # @@ -10,28 +8,39 @@ 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 the one-dimensional and two-dimensional (horizontal) spacings and the horizontal areas. - metric = Symbol(operator, dir, LX, LY, LZ) - @eval begin - import Oceananigans.Operators: $metric - @inline $metric(i, j, k, ibg::IBG) = $metric(i, j, k, ibg.underlying_grid) - end - end +for L1 in (:ᶜ, :ᶠ) + xspacing1D = Symbol(:Δx, L1, :ᵃ, :ᵃ) + yspacing1D = Symbol(:Δy, :ᵃ, L1, :ᵃ) + zspacing1D = Symbol(:Δz, :ᵃ, :ᵃ, L1) - 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) + import Oceananigans.Operators: $xspacing1D, $yspacing1D, $zspacing1D + + $xspacing1D(i, j, k, ibg::IBG) = $xspacing1D(i, j, k, ibg.underlying_grid) + $yspacing1D(i, j, k, ibg::IBG) = $yspacing1D(i, j, k, ibg.underlying_grid) + $zspacing1D(i, j, k, ibg::IBG) = $zspacing1D(i, j, k, ibg.underlying_grid) + end + + for L2 in (:ᶜ, :ᶠ) + xspacing2D = Symbol(:Δx, L1, L2, :ᵃ) + yspacing2D = Symbol(:Δy, L2, L1, :ᵃ) + zarea2D = Symbol(:Az, L1, L2, :ᵃ) + + @eval begin + import Oceananigans.Operators: $xspacing2D, $yspacing2D, $zarea2D + + $xspacing2D(i, j, k, ibg::IBG) = $xspacing2D(i, j, k, ibg.underlying_grid) + $yspacing2D(i, j, k, ibg::IBG) = $yspacing2D(i, j, k, ibg.underlying_grid) + $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) From 09db93208af60d393295e3db813c6a74db9d6f0f Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Mon, 25 Nov 2024 16:26:11 +0100 Subject: [PATCH 2/2] fix imports --- .../immersed_grid_metrics.jl | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/ImmersedBoundaries/immersed_grid_metrics.jl b/src/ImmersedBoundaries/immersed_grid_metrics.jl index 33b5289cf9..c51e2fb374 100644 --- a/src/ImmersedBoundaries/immersed_grid_metrics.jl +++ b/src/ImmersedBoundaries/immersed_grid_metrics.jl @@ -9,31 +9,28 @@ import Oceananigans.Operators: intrinsic_vector, extrinsic_vector # must be extended for the specific immersed boundary grid in question. # We need to extend only the metric explicitly defined in the `spacing_and_areas_and_volumes.jl` file. -# These include the one-dimensional and two-dimensional (horizontal) spacings and the horizontal areas. +# These include all the spacings and the horizontal areas. +# All the other metrics are calculated from these. -for L1 in (:ᶜ, :ᶠ) - xspacing1D = Symbol(:Δx, L1, :ᵃ, :ᵃ) - yspacing1D = Symbol(:Δy, :ᵃ, L1, :ᵃ) - zspacing1D = Symbol(:Δz, :ᵃ, :ᵃ, L1) - - @eval begin - import Oceananigans.Operators: $xspacing1D, $yspacing1D, $zspacing1D +x_superscript(dir) = dir == :x ? (:ᶜ, :ᶠ) : (:ᶜ, :ᶠ, :ᵃ) +y_superscript(dir) = dir == :y ? (:ᶜ, :ᶠ) : (:ᶜ, :ᶠ, :ᵃ) +z_superscript(dir) = dir == :z ? (:ᶜ, :ᶠ) : (:ᶜ, :ᶠ, :ᵃ) - $xspacing1D(i, j, k, ibg::IBG) = $xspacing1D(i, j, k, ibg.underlying_grid) - $yspacing1D(i, j, k, ibg::IBG) = $yspacing1D(i, j, k, ibg.underlying_grid) - $zspacing1D(i, j, k, ibg::IBG) = $zspacing1D(i, j, k, ibg.underlying_grid) +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: $spacing + $spacing(i, j, k, ibg::IBG) = $spacing(i, j, k, ibg.underlying_grid) + end end +end +for L1 in (:ᶜ, :ᶠ) for L2 in (:ᶜ, :ᶠ) - xspacing2D = Symbol(:Δx, L1, L2, :ᵃ) - yspacing2D = Symbol(:Δy, L2, L1, :ᵃ) - zarea2D = Symbol(:Az, L1, L2, :ᵃ) - + zarea2D = Symbol(:Az, L1, L2, :ᵃ) @eval begin - import Oceananigans.Operators: $xspacing2D, $yspacing2D, $zarea2D - - $xspacing2D(i, j, k, ibg::IBG) = $xspacing2D(i, j, k, ibg.underlying_grid) - $yspacing2D(i, j, k, ibg::IBG) = $yspacing2D(i, j, k, ibg.underlying_grid) + import Oceananigans.Operators: $zarea2D $zarea2D(i, j, k, ibg::IBG) = $zarea2D(i, j, k, ibg.underlying_grid) end end