Skip to content

Commit 6c2944e

Browse files
siddharthabishnunavidcysimone-silvestri
authored
Integrate cubed sphere functionality with halo filling and core infrastructure updates (#4538)
* Make necessary modifications * Update multi_region_split_explicit_free_surface.jl * Fix bug * Update src/Utils/multi_region_transformation.jl Co-authored-by: Navid C. Constantinou <[email protected]> * Update src/Models/HydrostaticFreeSurfaceModels/pcg_implicit_free_surface_solver.jl Co-authored-by: Simone Silvestri <[email protected]> * Fix bug * Compact code * Specialize difference operators for CCSPanelGrid * Fix bug * Extend tupled_fill_halo_regions! * Fix bug * Remove replace_horizontal_vector_halos! * Add explanatory comments and fix bug * Update src/Models/HydrostaticFreeSurfaceModels/pcg_implicit_free_surface_solver.jl Co-authored-by: Simone Silvestri <[email protected]> * Update src/Models/HydrostaticFreeSurfaceModels/pcg_implicit_free_surface_solver.jl Co-authored-by: Simone Silvestri <[email protected]> * Update src/MultiRegion/unified_implicit_free_surface_solver.jl Co-authored-by: Simone Silvestri <[email protected]> * Fix bug * Remove auxiliary_actions! * Fix bugs * Update src/Models/HydrostaticFreeSurfaceModels/update_hydrostatic_free_surface_model_state.jl * comment the todo * FieldBoundaryBuffers --> CommunicationBuffers * Remove unused parameter in fill_halo_size function * Fix bug * Remove hardcoded situation-specific logic * Incorporate modifications from PR #4566 * Incorporate modifications from PR #4568 * Fix typo * Enhance code * Reinstate unused parameter for consistency * Fix out-of-bounds memory access bug * Fix typo * Fix bug * Remove commented-out line * Fix typo * Fix bug * correct getregion for an immersed boundary grid * fix show for a multiregion grid * active cells map for CSG * add a small test for IBG construction on CSG * including Immersed boundary grids in the PCG solver * Fix out-of-bounds memory allocation error * Update test_multi_region_cubed_sphere.jl * Use ConformalCubedSphereGridOfSomeKind * Fix out-of-bounds error * Update test_multi_region_cubed_sphere.jl * Fix out-of-bounds error * Update test_multi_region_cubed_sphere.jl * Leverage reduced_dimensions for kernel launches * add a function inside apply regionally * Enhance code * Compact code * switch the apply regionally inside the linear operation * revert * Update src/MultiRegion/multi_region_split_explicit_free_surface.jl * Update src/MultiRegion/multi_region_boundary_conditions.jl * Update src/MultiRegion/multi_region_boundary_conditions.jl * Fix GPU error * Define ConformalCubedSpherePanelGridOfSomeKind * Fix GPU kernel type instability bug --------- Co-authored-by: Navid C. Constantinou <[email protected]> Co-authored-by: Simone Silvestri <[email protected]>
1 parent b2a597f commit 6c2944e

22 files changed

+1238
-756
lines changed

src/BoundaryConditions/BoundaryConditions.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ using Oceananigans.Grids
2020

2121
import Adapt: adapt_structure
2222

23-
# Switch around halos for cubed sphere by exchanging buffer informations
24-
replace_horizontal_vector_halos!(velocities, grid::AbstractGrid; signed=true) = nothing
25-
2623
include("boundary_condition_classifications.jl")
2724
include("boundary_condition.jl")
2825
include("discrete_boundary_function.jl")

src/Fields/field_tuples.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ Fill halo regions for all `fields`. The algorithm:
5353
4. In every direction, the halo regions in each of the remaining `Field` tuple
5454
are filled simultaneously.
5555
"""
56-
function fill_halo_regions!(maybe_nested_tuple::Union{NamedTuple, Tuple}, args...; kwargs...)
56+
function fill_halo_regions!(maybe_nested_tuple::Union{NamedTuple, Tuple}, args...;
57+
signed = true, # This kwarg is active only for a `ConformalCubedSphereGrid`, here we discard it.
58+
kwargs...)
59+
5760
flattened = flattened_unique_values(maybe_nested_tuple)
5861

5962
# Look for grid within the flattened field tuple:

src/ImmersedBoundaries/immersed_boundary_grid.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ end
7878
const IBG = ImmersedBoundaryGrid
7979

8080
@inline Base.getproperty(ibg::IBG, property::Symbol) = get_ibg_property(ibg, Val(property))
81-
@inline get_ibg_property(ibg::IBG, ::Val{property}) where property = getfield(getfield(ibg, :underlying_grid), property)
81+
@inline get_ibg_property(ibg::IBG, ::Val{property}) where property = getproperty(getfield(ibg, :underlying_grid), property)
8282
@inline get_ibg_property(ibg::IBG, ::Val{:immersed_boundary}) = getfield(ibg, :immersed_boundary)
8383
@inline get_ibg_property(ibg::IBG, ::Val{:underlying_grid}) = getfield(ibg, :underlying_grid)
8484
@inline get_ibg_property(ibg::IBG, ::Val{:interior_active_cells}) = getfield(ibg, :interior_active_cells)

src/Models/HydrostaticFreeSurfaceModels/SplitExplicitFreeSurfaces/initialize_split_explicit_substepping.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function initialize_free_surface!(sefs::SplitExplicitFreeSurface, grid, velociti
2020
grid, u, v)
2121

2222
fill_halo_regions!((barotropic_velocities.U, barotropic_velocities.V))
23+
fill_halo_regions!(sefs.η)
2324

2425
return nothing
2526
end

src/Models/HydrostaticFreeSurfaceModels/pcg_implicit_free_surface_solver.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Oceananigans.Architectures
55
using Oceananigans.Grids: with_halo, isrectilinear, halo_size
66
using Oceananigans.Architectures: device
77

8-
import Oceananigans.Solvers: solve!, precondition!
8+
import Oceananigans.Solvers: solve!, precondition!, perform_linear_operation!
99
import Oceananigans.Architectures: architecture
1010

1111
"""
@@ -50,7 +50,10 @@ function PCGImplicitFreeSurfaceSolver(grid::AbstractGrid, settings, gravitationa
5050
vertically_integrated_lateral_areas = (xᶠᶜᶜ = ∫ᶻ_Axᶠᶜᶜ, yᶜᶠᶜ = ∫ᶻ_Ayᶜᶠᶜ)
5151

5252
@apply_regionally compute_vertically_integrated_lateral_areas!(vertically_integrated_lateral_areas)
53-
fill_halo_regions!(vertically_integrated_lateral_areas)
53+
54+
Ax = vertically_integrated_lateral_areas.xᶠᶜᶜ
55+
Ay = vertically_integrated_lateral_areas.yᶜᶠᶜ
56+
fill_halo_regions!((Ax, Ay); signed=false)
5457

5558
# Set some defaults
5659
settings = Dict{Symbol, Any}(settings)
@@ -66,8 +69,8 @@ function PCGImplicitFreeSurfaceSolver(grid::AbstractGrid, settings, gravitationa
6669
right_hand_side = ZFaceField(grid, indices = (:, :, size(grid, 3) + 1))
6770

6871
solver = ConjugateGradientSolver(implicit_free_surface_linear_operation!;
69-
template_field = right_hand_side,
70-
settings...)
72+
template_field = right_hand_side,
73+
settings...)
7174

7275
return PCGImplicitFreeSurfaceSolver(vertically_integrated_lateral_areas, solver, right_hand_side)
7376
end
@@ -134,16 +137,19 @@ function implicit_free_surface_linear_operation!(L_ηⁿ⁺¹, ηⁿ⁺¹, ∫
134137
grid = L_ηⁿ⁺¹.grid
135138
arch = architecture(L_ηⁿ⁺¹)
136139

137-
# Note: because of `fill_halo_regions!` below, we cannot use `PCGImplicitFreeSurface` on a
138-
# multi-region grid; `fill_halo_regions!` cannot be used within `@apply_regionally`
139-
fill_halo_regions!(ηⁿ⁺¹)
140-
141140
launch!(arch, grid, :xy, _implicit_free_surface_linear_operation!,
142141
L_ηⁿ⁺¹, grid, ηⁿ⁺¹, ∫ᶻ_Axᶠᶜᶜ, ∫ᶻ_Ayᶜᶠᶜ, g, Δt)
143142

144143
return nothing
145144
end
146145

146+
ImplicitFreeSurfaceOperation = typeof(implicit_free_surface_linear_operation!)
147+
148+
@inline function perform_linear_operation!(linear_operation!::ImplicitFreeSurfaceOperation, q, p, args...)
149+
fill_halo_regions!(p)
150+
@apply_regionally linear_operation!(q, p, args...)
151+
end
152+
147153
# Kernels that act on vertically integrated / surface quantities
148154
@inline ∫ᶻ_Ax_∂x_ηᶠᶜᶜ(i, j, k, grid, ∫ᶻ_Axᶠᶜᶜ, η) = @inbounds ∫ᶻ_Axᶠᶜᶜ[i, j, k] * ∂xᶠᶜᶠ(i, j, k, grid, η)
149155
@inline ∫ᶻ_Ay_∂y_ηᶜᶠᶜ(i, j, k, grid, ∫ᶻ_Ayᶜᶠᶜ, η) = @inbounds ∫ᶻ_Ayᶜᶠᶜ[i, j, k] * ∂yᶜᶠᶠ(i, j, k, grid, η)

src/Models/HydrostaticFreeSurfaceModels/prescribed_hydrostatic_velocity_fields.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ function hydrostatic_velocity_fields(velocities::PrescribedVelocityFields, grid,
6363
v = wrap_prescribed_field(Center, Face, Center, velocities.v, grid; clock, parameters)
6464
w = wrap_prescribed_field(Center, Center, Face, velocities.w, grid; clock, parameters)
6565

66-
fill_halo_regions!(u)
67-
fill_halo_regions!(v)
66+
fill_halo_regions!((u, v))
6867
fill_halo_regions!(w)
69-
prescribed_velocities = (; u, v, w)
70-
@apply_regionally replace_horizontal_vector_halos!(prescribed_velocities, grid)
7168

7269
return PrescribedVelocityFields(u, v, w, parameters)
7370
end

src/Models/HydrostaticFreeSurfaceModels/update_hydrostatic_free_surface_model_state.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Oceananigans.BoundaryConditions
33

44
using Oceananigans: UpdateStateCallsite
55
using Oceananigans.Biogeochemistry: update_biogeochemical_state!
6-
using Oceananigans.BoundaryConditions: update_boundary_conditions!, replace_horizontal_vector_halos!
6+
using Oceananigans.BoundaryConditions: update_boundary_conditions!
77
using Oceananigans.TurbulenceClosures: compute_diffusivities!
88
using Oceananigans.ImmersedBoundaries: mask_immersed_field!, mask_immersed_field_xy!, inactive_node
99
using Oceananigans.Models: update_model_field_time_series!
@@ -39,9 +39,8 @@ function update_state!(model::HydrostaticFreeSurfaceModel, grid, callbacks; comp
3939
# Update the boundary conditions
4040
@apply_regionally update_boundary_conditions!(fields(model), model)
4141

42-
tupled_fill_halo_regions!(prognostic_fields(model), grid, model.clock, fields(model), async=true)
42+
tupled_fill_halo_regions!(prognostic_fields(model), grid, model.clock, fields(model); async=true)
4343

44-
@apply_regionally replace_horizontal_vector_halos!(model.velocities, model.grid)
4544
@apply_regionally compute_auxiliaries!(model)
4645

4746
fill_halo_regions!(model.diffusivity_fields; only_local_halos = true)

0 commit comments

Comments
 (0)