From 1da00b2b7ee889bc0f9d874908d87a527b59fffe Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Mon, 20 Feb 2023 22:07:54 -0600 Subject: [PATCH 1/3] Clean up ImmersedBoundaries module --- .../grid_fitted_immersed_boundaries.jl | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl b/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl index b665f8e5f0..60826b2f57 100644 --- a/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl +++ b/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl @@ -2,6 +2,7 @@ using Adapt using CUDA: CuArray using OffsetArrays: OffsetArray using Oceananigans.Utils: getnamewrapper +using Oceananigans.Grids: total_size using Oceananigans.Fields: fill_halo_regions! using Oceananigans.Architectures: arch_array using Oceananigans.BoundaryConditions: FBC @@ -86,10 +87,7 @@ function ImmersedBoundaryGrid(grid, ib::AbstractGridFittedBottom{<:OffsetArray}) end function validate_ib_size(grid, ib) - Nx, Ny, _ = size(grid) - Hx, Hy, _ = halo_size(grid) - - bottom_height_size = (Nx, Ny) .+ 2 .* (Hx, Hy) + bottom_height_size = total_size((Center, Center, Nothing), grid)[1:2] # Check that the size of a bottom field are # consistent with the size of the field @@ -118,12 +116,12 @@ Adapt.adapt_structure(to, ib::GridFittedBottom) = GridFittedBottom(adapt(to, ib. ##### Implicit vertical diffusion ##### -#### -#### For a center solver we have to check the interface "solidity" at faces k+1 in both the -#### Upper diagonal and the Lower diagonal -#### (because of tridiagonal convention where lower_diagonal on row k is found at k-1) -#### Same goes for the face solver, where we check at centers k in both Upper and lower diagonal -#### +##### +##### For a center solver we have to check the interface "solidity" at faces k+1 in both the +##### Upper diagonal and the Lower diagonal +##### (because of tridiagonal convention where lower_diagonal on row k is found at k-1) +##### Same goes for the face solver, where we check at centers k in both Upper and lower diagonal +##### @inline immersed_ivd_peripheral_node(i, j, k, ibg, LX, LY, ::Center) = immersed_peripheral_node(i, j, k+1, ibg, LX, LY, Face()) @inline immersed_ivd_peripheral_node(i, j, k, ibg, LX, LY, ::Face) = immersed_peripheral_node(i, j, k, ibg, LX, LY, Center()) @@ -199,15 +197,15 @@ immersed_cell(i, j, k, grid, ib) = _immersed_cell(i, j, k, grid, ib) # support for Flat grids using Oceananigans.Grids: AbstractGrid -for ImmBoundary in [:GridFittedBottom, :GridFittedBoundary] +for IB in [:GridFittedBottom, :GridFittedBoundary] @eval begin - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, <:Any, <:Any}, ib::$ImmBoundary) = _immersed_cell(1, j, k, grid, ib) - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, <:Any, Flat, <:Any}, ib::$ImmBoundary) = _immersed_cell(i, 1, k, grid, ib) - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, <:Any, <:Any, Flat}, ib::$ImmBoundary) = _immersed_cell(i, j, 1, grid, ib) - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, Flat, <:Any}, ib::$ImmBoundary) = _immersed_cell(1, 1, k, grid, ib) - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, <:Any, Flat}, ib::$ImmBoundary) = _immersed_cell(1, j, 1, grid, ib) - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, <:Any, Flat, Flat}, ib::$ImmBoundary) = _immersed_cell(i, 1, 1, grid, ib) - @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, Flat, Flat}, ib::$ImmBoundary) = _immersed_cell(1, 1, 1, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, <:Any, <:Any}, ib::$IB) = _immersed_cell(1, j, k, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, <:Any, Flat, <:Any}, ib::$IB) = _immersed_cell(i, 1, k, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, <:Any, <:Any, Flat}, ib::$IB) = _immersed_cell(i, j, 1, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, Flat, <:Any}, ib::$IB) = _immersed_cell(1, 1, k, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, <:Any, Flat}, ib::$IB) = _immersed_cell(1, j, 1, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, <:Any, Flat, Flat}, ib::$IB) = _immersed_cell(i, 1, 1, grid, ib) + @inline immersed_cell(i, j, k, grid::AbstractGrid{<:Any, Flat, Flat, Flat}, ib::$IB) = _immersed_cell(1, 1, 1, grid, ib) end end From 9b9fc721edcfa8ccccd4eb4a8affe6628eaabce5 Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Mon, 20 Feb 2023 22:10:38 -0600 Subject: [PATCH 2/3] Update grid_fitted_immersed_boundaries.jl --- src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl b/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl index 60826b2f57..5487e64038 100644 --- a/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl +++ b/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl @@ -89,10 +89,11 @@ end function validate_ib_size(grid, ib) bottom_height_size = total_size((Center, Center, Nothing), grid)[1:2] - # Check that the size of a bottom field are - # consistent with the size of the field + # Why do we use `any` here? Is this a bug? any(size(ib.bottom_height) .!= bottom_height_size) && throw(ArgumentError("The dimensions of the immersed boundary $(size(ib.bottom_height)) do not match the grid size $(bottom_height_size)")) + + return nothing end @inline function _immersed_cell(i, j, k, underlying_grid, ib::GridFittedBottom{<:Any, <:InterfaceImmersedCondition}) From c7419220c67cc32edb99db12dbf37a8a178c1aa4 Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Mon, 20 Feb 2023 22:42:29 -0600 Subject: [PATCH 3/3] Update grid_fitted_immersed_boundaries.jl --- src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl b/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl index 5487e64038..4ed58af0bd 100644 --- a/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl +++ b/src/ImmersedBoundaries/grid_fitted_immersed_boundaries.jl @@ -89,8 +89,7 @@ end function validate_ib_size(grid, ib) bottom_height_size = total_size((Center, Center, Nothing), grid)[1:2] - # Why do we use `any` here? Is this a bug? - any(size(ib.bottom_height) .!= bottom_height_size) && + size(ib.bottom_height) != bottom_height_size && throw(ArgumentError("The dimensions of the immersed boundary $(size(ib.bottom_height)) do not match the grid size $(bottom_height_size)")) return nothing