Skip to content

Commit 2ae1cbb

Browse files
authored
New default size for FaceFields (#644)
New default size for FaceFields
2 parents 705158b + c627f48 commit 2ae1cbb

17 files changed

+428
-213
lines changed

src/AbstractOperations/computations.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using Oceananigans.Utils: @loop_xyz
2+
import Oceananigans.Fields: location, total_size
3+
14
"""
2-
Computation{R, T, O, G}
5+
Computation{T, R, O, G}
36
47
Represents an operation performed over the elements of a field.
58
"""
6-
struct Computation{R, T, O, G}
9+
struct Computation{T, R, O, G}
710
operation :: O
811
result :: R
912
grid :: G
@@ -20,8 +23,11 @@ Returns a `Computation` representing an `operation` performed over the elements
2023
Computation(operation, result; return_type=Array) =
2124
Computation(operation, result, operation.grid, return_type)
2225

26+
# Utilities for limited field-like behavior
2327
architecture(comp::Computation) = architecture(comp.result)
2428
Base.parent(comp::Computation) = comp # this enables taking a "horizontal average" of a computation
29+
location(comp::Computation) = location(comp.operation)
30+
total_size(comp::Computation) = total_size(comp.result)
2531

2632
"""
2733
compute!(computation::Computation)
@@ -38,12 +44,8 @@ end
3844

3945
"""Compute an `operation` over `grid` and store in `result`."""
4046
function _compute!(result, grid, operation)
41-
@loop for k in (1:grid.Nz; (blockIdx().z - 1) * blockDim().z + threadIdx().z)
42-
@loop for j in (1:grid.Ny; (blockIdx().y - 1) * blockDim().y + threadIdx().y)
43-
@loop for i in (1:grid.Nx; (blockIdx().x - 1) * blockDim().x + threadIdx().x)
44-
@inbounds result[i, j, k] = operation[i, j, k]
45-
end
46-
end
47+
@loop_xyz i j k grid begin
48+
@inbounds result[i, j, k] = operation[i, j, k]
4749
end
4850
return nothing
4951
end

src/BoundaryConditions/BoundaryConditions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ include("fill_halo_regions.jl")
3030
include("zero_halo_regions.jl")
3131

3232
include("apply_flux_bcs.jl")
33-
include("apply_flux_periodic_no_penetration_bcs.jl")
3433
include("apply_value_gradient_bcs.jl")
3534

3635
end

src/BoundaryConditions/apply_flux_periodic_no_penetration_bcs.jl

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/BoundaryConditions/fill_halo_regions.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,55 @@ function fill_halo_regions!(c::AbstractArray, fieldbcs, arch, grid, args...)
3030
fill_top_halo!(c, fieldbcs.z.top, arch, grid, args...)
3131
return nothing
3232
end
33+
34+
#####
35+
##### Halo filling for flux, periodic, and no-penetration boundary conditions.
36+
#####
37+
38+
# For flux boundary conditions we fill halos as for a *no-flux* boundary condition, and add the
39+
# flux divergence associated with the flux boundary condition in a separate step. Note that
40+
# ranges are used to reference the data copied into halos, as this produces views of the correct
41+
# dimension (eg size = (1, Ny, Nz) for the west halos).
42+
43+
_fill_west_halo!(c, ::FBC, H, N) = @views @. c.parent[1:H, :, :] = c.parent[1+H:1+H, :, :]
44+
_fill_south_halo!(c, ::FBC, H, N) = @views @. c.parent[:, 1:H, :] = c.parent[:, 1+H:1+H, :]
45+
_fill_bottom_halo!(c, ::FBC, H, N) = @views @. c.parent[:, :, 1:H] = c.parent[:, :, 1+H:1+H]
46+
47+
_fill_east_halo!(c, ::FBC, H, N) = @views @. c.parent[N+H+1:N+2H, :, :] = c.parent[N+H:N+H, :, :]
48+
_fill_north_halo!(c, ::FBC, H, N) = @views @. c.parent[:, N+H+1:N+2H, :] = c.parent[:, N+H:N+H, :]
49+
_fill_top_halo!(c, ::FBC, H, N) = @views @. c.parent[:, :, N+H+1:N+2H] = c.parent[:, :, N+H:N+H]
50+
51+
# Periodic boundary conditions
52+
_fill_west_halo!(c, ::PBC, H, N) = @views @. c.parent[1:H, :, :] = c.parent[N+1:N+H, :, :]
53+
_fill_south_halo!(c, ::PBC, H, N) = @views @. c.parent[:, 1:H, :] = c.parent[:, N+1:N+H, :]
54+
_fill_bottom_halo!(c, ::PBC, H, N) = @views @. c.parent[:, :, 1:H] = c.parent[:, :, N+1:N+H]
55+
56+
_fill_east_halo!(c, ::PBC, H, N) = @views @. c.parent[N+H+1:N+2H, :, :] = c.parent[1+H:2H, :, :]
57+
_fill_north_halo!(c, ::PBC, H, N) = @views @. c.parent[:, N+H+1:N+2H, :] = c.parent[:, 1+H:2H, :]
58+
_fill_top_halo!(c, ::PBC, H, N) = @views @. c.parent[:, :, N+H+1:N+2H] = c.parent[:, :, 1+H:2H]
59+
60+
# Recall that, by convention, the first grid point (k=1) in an array with a no-penetration boundary
61+
# condition lies on the boundary, where as the last grid point (k=Nz) lies in the domain.
62+
63+
_fill_west_halo!(c, ::NPBC, H, N) = @views @. c.parent[1:1+H, :, :] = 0
64+
_fill_south_halo!(c, ::NPBC, H, N) = @views @. c.parent[:, 1:1+H, :] = 0
65+
_fill_bottom_halo!(c, ::NPBC, H, N) = @views @. c.parent[:, :, 1:1+H] = 0
66+
67+
_fill_east_halo!(c, ::NPBC, H, N) = @views @. c.parent[N+H+1:N+2H, :, :] = 0
68+
_fill_north_halo!(c, ::NPBC, H, N) = @views @. c.parent[:, N+H+1:N+2H, :] = 0
69+
_fill_top_halo!(c, ::NPBC, H, N) = @views @. c.parent[:, :, N+H+1:N+2H] = 0
70+
71+
# Generate functions that implement flux, periodic, and no-penetration boundary conditions
72+
sides = (:west, :east, :south, :north, :top, :bottom)
73+
coords = (:x, :x, :y, :y, :z, :z)
74+
75+
for (x, side) in zip(coords, sides)
76+
outername = Symbol(:fill_, side, :_halo!)
77+
innername = Symbol(:_fill_, side, :_halo!)
78+
H = Symbol(:H, x)
79+
N = Symbol(:N, x)
80+
@eval begin
81+
$outername(c, bc::Union{FBC, PBC, NPBC}, arch, grid, args...) =
82+
$innername(c, bc, grid.$(H), grid.$(N))
83+
end
84+
end

src/Diagnostics/horizontal_average.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Oceananigans.Architectures
22
using Oceananigans.BoundaryConditions
33
using Oceananigans.Utils
4+
using Oceananigans.Grids: total_size
45

56
"""
67
HorizontalAverage{F, R, P, I, Ω} <: AbstractDiagnostic
@@ -37,7 +38,7 @@ model and you want to save the output to disk by passing it to an output writer.
3738
"""
3839
function HorizontalAverage(field; frequency=nothing, interval=nothing, return_type=Array)
3940
arch = architecture(field)
40-
result = zeros(arch, field.grid, 1, 1, field.grid.Nz + 2field.grid.Hz)
41+
result = zeros(arch, field.grid, 1, 1, total_size(parent(field))[3])
4142
return HorizontalAverage(field, result, frequency, interval, 0.0, return_type, field.grid)
4243
end
4344

0 commit comments

Comments
 (0)