Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
navidcy committed Jan 20, 2023
1 parent 3f26172 commit 0dc0a8a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
9 changes: 4 additions & 5 deletions src/MultiRegion/cubed_sphere_partitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ struct CubedSpherePartition{M, P} <: AbstractPartition
div :: Int
Rx :: M
Ry :: P
function CubedSpherePartition(div, Rx::M, Ry::P) where {M, P}
return new{M, P}(div, Rx, Ry)
end

CubedSpherePartition(div, Rx::M, Ry::P) where {M, P} = new{M, P}(div, Rx, Ry)
end


Expand Down Expand Up @@ -64,7 +63,7 @@ utilities to get the index of the face the index within the face and the global
@inline rank_from_face_idx(fi, fj, face_idx, p::CubedSpherePartition) = face_idx * div_per_face(face_idx, p) + Rx(face_idx, p) * (fj - 1) + fi

@inline function region_corners(r, p::CubedSpherePartition)

fi = intra_face_index_x(r, p)
fj = intra_face_index_y(r, p)

Expand Down Expand Up @@ -193,7 +192,7 @@ function inject_east_boundary(region, p::CubedSpherePartition, global_bc)
return bc
end

function inject_south_boundary(region, p::CubedSpherePartition, global_bc)
function inject_south_boundary(region, p::CubedSpherePartition, global_bc)

fi = intra_face_index_x(region, p)
fj = intra_face_index_y(region, p)
Expand Down
40 changes: 20 additions & 20 deletions src/MultiRegion/multi_region_boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using Oceananigans.Architectures: arch_array, device_event, device_copy_to!
using Oceananigans.Operators: assumed_field_location
using Oceananigans.Fields: reduced_dimensions

using Oceananigans.BoundaryConditions:
ContinuousBoundaryFunction,
using Oceananigans.BoundaryConditions:
ContinuousBoundaryFunction,
DiscreteBoundaryFunction,
permute_boundary_conditions,
fill_halo_event!,
Expand All @@ -18,8 +18,8 @@ import Oceananigans.BoundaryConditions:
fill_west_and_east_halo!,
fill_south_and_north_halo!,
fill_bottom_and_top_halo!,
fill_west_halo!,
fill_east_halo!,
fill_west_halo!,
fill_east_halo!,
fill_south_halo!,
fill_north_halo!

Expand Down Expand Up @@ -120,7 +120,7 @@ function fill_west_and_east_halo!(c, westbc::CBC, eastbc::CBC, kernel_size, offs
eastsrc = buffers[eastbc.condition.from_rank].west.send
eastsrc .= view(parent(e), H+1:2H, :, :)

switch_device!(getdevice(c))
switch_device!(getdevice(c))
device_copy_to!(westdst, westsrc)
device_copy_to!(eastdst, eastsrc)

Expand Down Expand Up @@ -150,7 +150,7 @@ function fill_south_and_north_halo!(c, southbc::CBC, northbc::CBC, kernel_size,
northsrc = buffers[eastbc.condition.from_rank].north.send
northsrc .= view(parent(n), :, H+1:2H, :)

switch_device!(getdevice(c))
switch_device!(getdevice(c))
device_copy_to!(southdst, southsrc)
device_copy_to!(northdst, northsrc)

Expand All @@ -161,7 +161,7 @@ function fill_south_and_north_halo!(c, southbc::CBC, northbc::CBC, kernel_size,
end

#####
##### Single fill_halo! for Communicating boundary condition
##### Single fill_halo! for Communicating boundary condition
#####

function fill_west_halo!(c, bc::CBC, kernel_size, offset, loc, arch, dep, grid, neighbors, buffers, args...; kwargs...)
Expand Down Expand Up @@ -201,7 +201,7 @@ function fill_east_halo!(c, bc::CBC, kernel_size, offset, loc, arch, dep, grid,
src .= view(parent(e), H+1:2H, :, :)
sync_device!(getdevice(e))

switch_device!(getdevice(c))
switch_device!(getdevice(c))
device_copy_to!(dst, src)

p = view(parent(c), N+H+1:N+2H, :, :)
Expand Down Expand Up @@ -247,7 +247,7 @@ function fill_north_halo!(c, bc::CBC, kernel_size, offset, loc, arch, dep, grid,
src .= view(parent(n), :, H+1:2H, :)
sync_device!(getdevice(n))

switch_device!(getdevice(c))
switch_device!(getdevice(c))
device_copy_to!(dst, src)

p = view(parent(c), :, N+H+1:N+2H, :)
Expand All @@ -261,10 +261,10 @@ end
#####

@inline getregion(fc::FieldBoundaryConditions, i) =
FieldBoundaryConditions(_getregion(fc.west, i),
_getregion(fc.east, i),
_getregion(fc.south, i),
_getregion(fc.north, i),
FieldBoundaryConditions(_getregion(fc.west, i),
_getregion(fc.east, i),
_getregion(fc.south, i),
_getregion(fc.north, i),
_getregion(fc.bottom, i),
_getregion(fc.top, i),
fc.immersed)
Expand All @@ -282,11 +282,11 @@ end
DiscreteBoundaryFunction(df.func, _getregion(df.parameters, i))


@inline _getregion(fc::FieldBoundaryConditions, i) =
FieldBoundaryConditions(getregion(fc.west, i),
getregion(fc.east, i),
getregion(fc.south, i),
getregion(fc.north, i),
@inline _getregion(fc::FieldBoundaryConditions, i) =
FieldBoundaryConditions(getregion(fc.west, i),
getregion(fc.east, i),
getregion(fc.south, i),
getregion(fc.north, i),
getregion(fc.bottom, i),
getregion(fc.top, i),
fc.immersed)
Expand All @@ -304,7 +304,7 @@ ContinuousBoundaryFunction{X, Y, Z, I}(cf.func::F,
DiscreteBoundaryFunction(df.func, getregion(df.parameters, i))

# Everything goes for multi-region BC
validate_boundary_condition_location(::MultiRegionObject, ::Center, side) = nothing
validate_boundary_condition_location(::MultiRegionObject, ::Face, side) = nothing
validate_boundary_condition_location(::MultiRegionObject, ::Center, side) = nothing
validate_boundary_condition_location(::MultiRegionObject, ::Face, side) = nothing
validate_boundary_condition_topology(::MultiRegionObject, topo::Periodic, side) = nothing
validate_boundary_condition_topology(::MultiRegionObject, topo::Flat, side) = nothing
4 changes: 1 addition & 3 deletions src/MultiRegion/multi_region_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ FieldBoundaryBuffers(grid::MultiRegionGrid, args...; kwargs...) =
construct_regionally(FieldBoundaryBuffers, grid, args...; kwargs...)

FieldBoundaryConditions(mrg::MultiRegionGrid, loc, indices; kwargs...) =
construct_regionally(inject_regional_bcs, mrg, Iterate(1:length(mrg)), Reference(mrg.partition), Reference(loc), indices; kwargs...)
construct_regionally(inject_regional_bcs, mrg, Iterate(1:length(mrg)), Reference(mrg.partition), Reference(loc), indices; kwargs...)

function regularize_field_boundary_conditions(bcs::FieldBoundaryConditions,
mrg::MultiRegionGrid,
Expand Down Expand Up @@ -175,5 +175,3 @@ function Base.show(io::IO, field::MultiRegionField)

print(io, prefix, middle, suffix)
end


2 changes: 1 addition & 1 deletion src/MultiRegion/multi_region_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Oceananigans.TurbulenceClosures: implicit_diffusion_solver
const MultiRegionModel = HydrostaticFreeSurfaceModel{<:Any, <:Any, <:AbstractArchitecture, <:Any, <:MultiRegionGrid}

# Utility to generate the inputs to complex `getregion`s
function getregionalproperties(T, inner=true)
function getregionalproperties(T, inner=true)
type = eval(T)
names = fieldnames(type)
args = Vector(undef, length(names))
Expand Down
2 changes: 1 addition & 1 deletion src/MultiRegion/unified_heptadiagonal_iterative_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function UnifiedDiagonalIterativeSolver(coeffs;

return UnifiedDiagonalIterativeSolver(mrg,
devices,
problem_size,
problem_size,
matrix_constructors,
diagonal,
placeholder_matrix,
Expand Down
4 changes: 2 additions & 2 deletions src/MultiRegion/unified_implicit_free_surface_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function compute_regional_rhs!(rhs, grid, g, Δt, ∫ᶻQ, η, region, partition
event = launch!(arch, grid, :xy,
implicit_linearized_unified_free_surface_right_hand_side!,
rhs, grid, g, Δt, ∫ᶻQ, η, region, partition,
dependencies = device_event(arch))
dependencies = device_event(arch))

wait(device(arch), event)
return nothing
Expand Down Expand Up @@ -118,7 +118,7 @@ end
function redistribute_lhs!(η, sol, arch, grid, region, partition)

event = launch!(arch, grid, :xy, _redistribute_lhs!, η, sol, region, grid, partition,
dependencies = device_event(arch))
dependencies = device_event(arch))

wait(device(arch), event)
end
Expand Down
2 changes: 2 additions & 0 deletions src/MultiRegion/x_partitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ using Oceananigans.BoundaryConditions: CBC, PBC

struct XPartition{N} <: AbstractPartition
div :: N

function XPartition(sizes)
if length(sizes) > 1 && all(y -> y == sizes[1], sizes)
sizes = length(sizes)
end

return new{typeof(sizes)}(sizes)
end
end
Expand Down
1 change: 1 addition & 0 deletions src/MultiRegion/y_partitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct YPartition{N} <: AbstractPartition
if length(sizes) > 1 && all(y -> y == sizes[1], sizes)
sizes = length(sizes)
end

return new{typeof(sizes)}(sizes)
end
end
Expand Down

0 comments on commit 0dc0a8a

Please sign in to comment.