-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
607 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Oceananigans.BoundaryConditions: fill_open_boundary_regions!, | ||
permute_boundary_conditions, | ||
fill_halo_event!, | ||
DistributedCommunication | ||
|
||
using Oceananigans.DistributedComputations: cooperative_waitall!, | ||
recv_from_buffers!, | ||
fill_corners!, | ||
loc_id, | ||
DCBCT | ||
|
||
import Oceananigans.BoundaryConditions: fill_halo_regions! | ||
import Oceananigans.DistributedComputations: synchronize_communication! | ||
|
||
@inline instantiate(T::DataType) = T() | ||
@inline instantiate(T) = T | ||
|
||
const DistributedZipper = BoundaryCondition{<:DistributedCommunication, <:ZipperHaloCommunicationRanks} | ||
|
||
switch_north_halos!(c, north_bc, grid, loc) = nothing | ||
|
||
function switch_north_halos!(c, north_bc::DistributedZipper, grid, loc) | ||
sign = north_bc.condition.sign | ||
hz = halo_size(grid) | ||
sz = size(grid) | ||
|
||
_switch_north_halos!(parent(c), loc, sign, sz, hz) | ||
|
||
return nothing | ||
end | ||
|
||
@inline reversed_halos(::Tuple{<:Any, <:Center, <:Any}, Ny, Hy) = Ny+2Hy:-1:Ny+Hy+2 | ||
@inline reversed_halos(::Tuple{<:Any, <:Face, <:Any}, Ny, Hy) = Ny+2Hy-1:-1:Ny+Hy+1 | ||
|
||
@inline west_corner_halos(::Tuple{<:Face, <:Any, <:Any}, Hx) = 2:Hx | ||
@inline west_corner_halos(::Tuple{<:Center, <:Any, <:Any}, Hx) = 1:Hx | ||
|
||
# We throw away the first point! | ||
@inline function _switch_north_halos!(c, loc, sign, (Nx, Ny, Nz), (Hx, Hy, Hz)) | ||
|
||
# Domain indices common for all locations | ||
north_halos = Ny+Hy+1:Ny+2Hy-1 | ||
east_corner = Nx+Hx+1:Nx+2Hx | ||
interior = Hx+1:Nx+Hx | ||
|
||
# Location - dependent halo indices | ||
reversed_north_halos = reversed_halos(loc, Ny, Hy) | ||
west_corner = west_corner_halos(loc, Hx) | ||
|
||
view(c, west_corner, north_halos, :) .= sign .* reverse(view(c, west_corner, reversed_north_halos, :), dims = 1) | ||
view(c, east_corner, north_halos, :) .= sign .* reverse(view(c, east_corner, reversed_north_halos, :), dims = 1) | ||
view(c, interior, north_halos, :) .= sign .* reverse(view(c, interior, reversed_north_halos, :), dims = 1) | ||
|
||
return nothing | ||
end | ||
|
||
function fill_halo_regions!(c::OffsetArray, bcs, indices, loc, grid::DTRG, buffers, args...; only_local_halos = false, fill_boundary_normal_velocities = true, kwargs...) | ||
if fill_boundary_normal_velocities | ||
fill_open_boundary_regions!(c, bcs, indices, loc, grid, args...; kwargs...) | ||
end | ||
|
||
north_bc = bcs.north | ||
|
||
arch = architecture(grid) | ||
fill_halos!, bcs = permute_boundary_conditions(bcs) | ||
|
||
number_of_tasks = length(fill_halos!) | ||
|
||
for task = 1:number_of_tasks | ||
fill_halo_event!(c, fill_halos![task], bcs[task], indices, loc, arch, grid, buffers, args...; only_local_halos, kwargs...) | ||
end | ||
|
||
fill_corners!(c, arch.connectivity, indices, loc, arch, grid, buffers, args...; only_local_halos, kwargs...) | ||
|
||
# We increment the tag counter only if we have actually initiated the MPI communication. | ||
# This is the case only if at least one of the boundary conditions is a distributed communication | ||
# boundary condition (DCBCT) _and_ the `only_local_halos` keyword argument is false. | ||
increment_tag = any(isa.(bcs, DCBCT)) && !only_local_halos | ||
|
||
if increment_tag | ||
arch.mpi_tag[] += 1 | ||
end | ||
|
||
switch_north_halos!(c, north_bc, grid, loc) | ||
|
||
return nothing | ||
end | ||
|
||
function synchronize_communication!(field::Field{<:Any, <:Any, <:Any, <:Any, <:DTRG}) | ||
arch = architecture(field.grid) | ||
|
||
# Wait for outstanding requests | ||
if !isempty(arch.mpi_requests) | ||
cooperative_waitall!(arch.mpi_requests) | ||
|
||
# Reset MPI tag | ||
arch.mpi_tag[] = 0 | ||
|
||
# Reset MPI requests | ||
empty!(arch.mpi_requests) | ||
end | ||
|
||
recv_from_buffers!(field.data, field.boundary_buffers, field.grid) | ||
|
||
north_bc = field.boundary_conditions.north | ||
instantiated_location = map(instantiate, location(field)) | ||
|
||
switch_north_halos!(field, north_bc, field.grid, instantiated_location) | ||
|
||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Oceananigans.DistributedComputations: north_recv_tag, | ||
north_send_tag, | ||
northwest_recv_tag, | ||
northwest_send_tag, | ||
northeast_recv_tag, | ||
northeast_send_tag | ||
|
||
ID_DIGITS = 2 | ||
|
||
sides = (:west, :east, :south, :north, :southwest, :southeast, :northwest, :northeast) | ||
side_id = Dict(side => n-1 for (n, side) in enumerate(sides)) | ||
|
||
# Change these and we are golden! | ||
function north_recv_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "8" : string(side_id[:south]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function north_send_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "8" : string(side_id[:north]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northwest_recv_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "9" : string(side_id[:southeast]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northwest_send_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "9" : string(side_id[:northwest]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northeast_recv_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "10" : string(side_id[:southwest]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northeast_send_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "10" : string(side_id[:northeast]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using OrthogonalSphericalShellGrids | ||
using Oceananigans | ||
using Oceananigans.Grids: halo_size | ||
using Oceananigans.Utils | ||
using Oceananigans.Units | ||
using Oceananigans.BoundaryConditions | ||
using OrthogonalSphericalShellGrids: get_cartesian_nodes_and_vertices | ||
using Oceananigans.CUDA | ||
using Test | ||
|
||
using KernelAbstractions: @kernel, @index | ||
|
||
arch = CUDA.has_cuda_gpu() ? GPU() : CPU() | ||
|
||
# Mask the singularity of the grid in a region of | ||
# 5 degrees radius around the singularities | ||
function mask_singularities(underlying_grid::TripolarGrid) | ||
λp = underlying_grid.conformal_mapping.first_pole_longitude | ||
φp = underlying_grid.conformal_mapping.north_poles_latitude | ||
|
||
# We need a bottom height field that ``masks'' the singularities | ||
bottom_height(λ, φ) = ((abs(λ - λp) < 5) & (abs(φp - φ) < 5)) | | ||
((abs(λ - λp - 180) < 5) & (abs(φp - φ) < 5)) | (φ < -80) ? 0 : - 1000 | ||
|
||
grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom_height)) | ||
|
||
return grid | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using JLD2 | ||
using MPI | ||
using Oceananigans.DistributedComputations: reconstruct_global_field | ||
|
||
include("dependencies_for_runtests.jl") | ||
|
||
# Run the distributed grid simulation and save down reconstructed results | ||
function run_distributed_tripolar_grid(arch, filename) | ||
distributed_grid = TripolarGrid(arch; size = (100, 100, 1), z = (-1000, 0), halo = (5, 5, 5)) | ||
distributed_grid = mask_singularities(distributed_grid) | ||
simulation = run_tripolar_simulation(distributed_grid) | ||
|
||
η = reconstruct_global_field(simulation.model.free_surface.η) | ||
u = reconstruct_global_field(simulation.model.velocities.u) | ||
v = reconstruct_global_field(simulation.model.velocities.v) | ||
c = reconstruct_global_field(simulation.model.tracers.c) | ||
|
||
fill_halo_regions!(η) | ||
fill_halo_regions!(u) | ||
fill_halo_regions!(v) | ||
fill_halo_regions!(c) | ||
|
||
if arch.local_rank == 0 | ||
jldsave(filename; η = interior(η, :, :, 1), | ||
u = interior(u, :, :, 1), | ||
v = interior(v, :, :, 1), | ||
c = interior(c, :, :, 1)) | ||
end | ||
|
||
MPI.Barrier(MPI.COMM_WORLD) | ||
MPI.Finalize() | ||
|
||
return nothing | ||
end | ||
|
||
# Just a random simulation on a tripolar grid | ||
function run_tripolar_simulation(grid) | ||
|
||
model = HydrostaticFreeSurfaceModel(; grid = grid, | ||
free_surface = SplitExplicitFreeSurface(grid; substeps = 20), | ||
tracers = :c, | ||
buoyancy = nothing, | ||
tracer_advection = WENO(), | ||
momentum_advection = VectorInvariant(), | ||
coriolis = HydrostaticSphericalCoriolis()) | ||
|
||
# Setup the model with a gaussian sea surface height | ||
# near the physical north poles and one near the equator | ||
ηᵢ(λ, φ, z) = exp(- (φ - 90)^2 / 10^2) + exp(- φ^2 / 10^2) | ||
|
||
set!(model, η = ηᵢ, c = ηᵢ) | ||
|
||
simulation = Simulation(model, Δt = 5minutes, stop_iteration = 100) | ||
|
||
run!(simulation) | ||
|
||
return simulation | ||
end |
Oops, something went wrong.