Skip to content

Commit f582f25

Browse files
Merge branch 'main' into ncc-ss/distributed-reduction
2 parents 3689e07 + d1e9b46 commit f582f25

18 files changed

+288
-171
lines changed

src/BoundaryConditions/boundary_condition.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,15 @@ DistributedCommunicationBoundaryCondition(val; kwargs...) = BoundaryCondition(Di
109109
# * additional arguments to `fill_halo_regions` enter `getbc` after the `grid` argument:
110110
# so `fill_halo_regions!(c, clock, fields)` translates to `getbc(bc, i, j, grid, clock, fields)`, etc.
111111

112-
@inline getbc(bc, args...) = bc.condition(args...) # fallback!
112+
@inline getbc(bc::BoundaryCondition, args...) = getbc(bc.condition, args...) # unwrap
113+
@inline getbc(condition, args...) = condition(args...) # fallback!
113114

114-
@inline getbc(::BC{<:Open, Nothing}, ::Integer, ::Integer, grid::AbstractGrid, args...) = zero(grid)
115-
@inline getbc(::BC{<:Flux, Nothing}, ::Integer, ::Integer, grid::AbstractGrid, args...) = zero(grid)
116-
@inline getbc(::Nothing, ::Integer, ::Integer, grid::AbstractGrid, args...) = zero(grid)
115+
@inline getbc(::Nothing, ::Integer, ::Integer, grid::AbstractGrid, args...) = zero(grid)
117116

118-
@inline getbc(bc::BC{<:Any, <:Number}, args...) = bc.condition
119-
@inline getbc(bc::BC{<:Any, <:AbstractArray}, i::Integer, j::Integer, grid::AbstractGrid, args...) = @inbounds bc.condition[i, j]
120-
121-
# Support for Ref boundary conditions
122117
const NumberRef = Base.RefValue{<:Number}
123-
@inline getbc(bc::BC{<:Any, <:NumberRef}, args...) = bc.condition[]
118+
@inline getbc(condition::NumberRef, args...) = condition[]
119+
@inline getbc(condition::Number, args...) = condition
120+
@inline getbc(condition::AbstractArray, i::Integer, j::Integer, grid::AbstractGrid, args...) = @inbounds condition[i, j]
124121

125122
#####
126123
##### Validation with topology

src/BoundaryConditions/continuous_boundary_function.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,14 @@ end
116116
@inline z_boundary_node(i, j, k, grid::YFlatGrid, ℓx, ℓy) = tuple(ξnode(i, j, k, grid, ℓx, nothing, Face()))
117117
@inline z_boundary_node(i, j, k, grid::XYFlatGrid, ℓx, ℓy) = tuple()
118118

119-
const XBoundaryFunction{LY, LZ, S} = BoundaryCondition{<:Any, <:ContinuousBoundaryFunction{Nothing, LY, LZ, S}} where {LY, LZ, S}
120-
const YBoundaryFunction{LX, LZ, S} = BoundaryCondition{<:Any, <:ContinuousBoundaryFunction{LX, Nothing, LZ, S}} where {LX, LZ, S}
121-
const ZBoundaryFunction{LX, LY, S} = BoundaryCondition{<:Any, <:ContinuousBoundaryFunction{LX, LY, Nothing, S}} where {LX, LY, S}
119+
const XBoundaryFunction{LY, LZ, S} = ContinuousBoundaryFunction{Nothing, LY, LZ, S} where {LY, LZ, S}
120+
const YBoundaryFunction{LX, LZ, S} = ContinuousBoundaryFunction{LX, Nothing, LZ, S} where {LX, LZ, S}
121+
const ZBoundaryFunction{LX, LY, S} = ContinuousBoundaryFunction{LX, LY, Nothing, S} where {LX, LY, S}
122122

123123
# Return ContinuousBoundaryFunction on east or west boundaries.
124-
@inline function getbc(bc::XBoundaryFunction{LY, LZ, S}, j::Integer, k::Integer,
124+
@inline function getbc(cbf::XBoundaryFunction{LY, LZ, S}, j::Integer, k::Integer,
125125
grid::AbstractGrid, clock, model_fields, args...) where {LY, LZ, S}
126126

127-
cbf = bc.condition
128127
i, i′ = domain_boundary_indices(S(), grid.Nx)
129128
args = user_function_arguments(i, j, k, grid, model_fields, cbf.parameters, cbf)
130129
X = x_boundary_node(i′, j, k, grid, LY(), LZ())
@@ -133,10 +132,9 @@ const ZBoundaryFunction{LX, LY, S} = BoundaryCondition{<:Any, <:ContinuousBounda
133132
end
134133

135134
# Return ContinuousBoundaryFunction on south or north boundaries.
136-
@inline function getbc(bc::YBoundaryFunction{LX, LZ, S}, i::Integer, k::Integer,
135+
@inline function getbc(cbf::YBoundaryFunction{LX, LZ, S}, i::Integer, k::Integer,
137136
grid::AbstractGrid, clock, model_fields, args...) where {LX, LZ, S}
138137

139-
cbf = bc.condition
140138
j, j′ = domain_boundary_indices(S(), grid.Ny)
141139
args = user_function_arguments(i, j, k, grid, model_fields, cbf.parameters, cbf)
142140
X = y_boundary_node(i, j′, k, grid, LX(), LZ())
@@ -145,10 +143,9 @@ end
145143
end
146144

147145
# Return ContinuousBoundaryFunction on bottom or top boundaries.
148-
@inline function getbc(bc::ZBoundaryFunction{LX, LY, S}, i::Integer, j::Integer,
146+
@inline function getbc(cbf::ZBoundaryFunction{LX, LY, S}, i::Integer, j::Integer,
149147
grid::AbstractGrid, clock, model_fields, args...) where {LX, LY, S}
150148

151-
cbf = bc.condition
152149
k, k′ = domain_boundary_indices(S(), grid.Nz)
153150
args = user_function_arguments(i, j, k, grid, model_fields, cbf.parameters, cbf)
154151
X = z_boundary_node(i, j, k′, grid, LX(), LY())
@@ -161,10 +158,9 @@ end
161158
#####
162159

163160
# Return ContinuousBoundaryFunction on the east or west interface of a cell adjacent to an immersed boundary
164-
@inline function getbc(bc::XBoundaryFunction{LY, LZ, S}, i::Integer, j::Integer, k::Integer,
161+
@inline function getbc(cbf::XBoundaryFunction{LY, LZ, S}, i::Integer, j::Integer, k::Integer,
165162
grid::AbstractGrid, clock, model_fields, args...) where {LY, LZ, S}
166163

167-
cbf = bc.condition
168164
i′ = cell_boundary_index(S(), i)
169165
args = user_function_arguments(i, j, k, grid, model_fields, cbf.parameters, cbf)
170166
X = node(i′, j, k, grid, Face(), LY(), LZ())
@@ -173,10 +169,9 @@ end
173169
end
174170

175171
# Return ContinuousBoundaryFunction on the south or north interface of a cell adjacent to an immersed boundary
176-
@inline function getbc(bc::YBoundaryFunction{LX, LZ, S}, i::Integer, j::Integer, k::Integer,
172+
@inline function getbc(cbf::YBoundaryFunction{LX, LZ, S}, i::Integer, j::Integer, k::Integer,
177173
grid::AbstractGrid, clock, model_fields, args...) where {LX, LZ, S}
178174

179-
cbf = bc.condition
180175
j′ = cell_boundary_index(S(), j)
181176
args = user_function_arguments(i, j, k, grid, model_fields, cbf.parameters, cbf)
182177
X = node(i, j′, k, grid, LX(), Face(), LZ())
@@ -185,10 +180,9 @@ end
185180
end
186181

187182
# Return ContinuousBoundaryFunction on the bottom or top interface of a cell adjacent to an immersed boundary
188-
@inline function getbc(bc::ZBoundaryFunction{LX, LY, S}, i::Integer, j::Integer, k::Integer,
183+
@inline function getbc(cbf::ZBoundaryFunction{LX, LY, S}, i::Integer, j::Integer, k::Integer,
189184
grid::AbstractGrid, clock, model_fields, args...) where {LX, LY, S}
190185

191-
cbf = bc.condition
192186
k′ = cell_boundary_index(S(), k)
193187
args = user_function_arguments(i, j, k, grid, model_fields, cbf.parameters, cbf)
194188
X = node(i, j, k′, grid, LX(), LY(), Face())

src/BoundaryConditions/discrete_boundary_function.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@ struct DiscreteBoundaryFunction{P, F}
3232
end
3333

3434
const UnparameterizedDBF = DiscreteBoundaryFunction{<:Nothing}
35-
const UnparameterizedDBFBC = BoundaryCondition{<:Any, <:UnparameterizedDBF}
36-
const DBFBC = BoundaryCondition{<:Any, <:DiscreteBoundaryFunction}
3735

38-
@inline getbc(bc::UnparameterizedDBFBC, i::Integer, j::Integer, grid::AbstractGrid, clock, model_fields, args...) =
39-
bc.condition.func(i, j, grid, clock, model_fields)
36+
@inline getbc(condition::UnparameterizedDBF, i::Integer, j::Integer, grid::AbstractGrid, clock, model_fields, args...) =
37+
condition.func(i, j, grid, clock, model_fields)
4038

41-
@inline getbc(bc::DBFBC, i::Integer, j::Integer, grid::AbstractGrid, clock, model_fields, args...) =
42-
bc.condition.func(i, j, grid, clock, model_fields, bc.condition.parameters)
39+
@inline getbc(condition::DiscreteBoundaryFunction, i::Integer, j::Integer, grid::AbstractGrid, clock, model_fields, args...) =
40+
condition.func(i, j, grid, clock, model_fields, condition.parameters)
4341

4442
# 3D function for immersed boundary conditions
45-
@inline getbc(bc::UnparameterizedDBFBC, i::Integer, j::Integer, k::Integer, grid::AbstractGrid, clock, model_fields, args...) =
46-
bc.condition.func(i, j, k, grid, clock, model_fields)
43+
@inline getbc(condition::UnparameterizedDBF, i::Integer, j::Integer, k::Integer, grid::AbstractGrid, clock, model_fields, args...) =
44+
condition.func(i, j, k, grid, clock, model_fields)
4745

48-
@inline getbc(bc::DBFBC, i::Integer, j::Integer, k::Integer, grid::AbstractGrid, clock, model_fields, args...) =
49-
bc.condition.func(i, j, k, grid, clock, model_fields, bc.condition.parameters)
46+
@inline getbc(condition::DiscreteBoundaryFunction, i::Integer, j::Integer, k::Integer, grid::AbstractGrid, clock, model_fields, args...) =
47+
condition.func(i, j, k, grid, clock, model_fields, condition.parameters)
5048

5149
# Don't re-convert DiscreteBoundaryFunctions passed to BoundaryCondition constructor
5250
BoundaryCondition(Classification::DataType, condition::DiscreteBoundaryFunction) = BoundaryCondition(Classification(), condition)

src/BoundaryConditions/perturbation_advection_open_boundary_matching_scheme.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,19 @@ end
116116
@inline function step_right_boundary!(bc::FPAOBC, l, m, boundary_indices, boundary_adjacent_indices,
117117
grid, u, clock, model_fields, ΔX)
118118
Δt = clock.last_stage_Δt
119-
120119
Δt = ifelse(isinf(Δt), 0, Δt)
121120

122121
ūⁿ⁺¹ = getbc(bc, l, m, grid, clock, model_fields)
123-
124122
uᵢⁿ = @inbounds getindex(u, boundary_indices...)
125123
uᵢ₋₁ⁿ⁺¹ = @inbounds getindex(u, boundary_adjacent_indices...)
126124

127125
U = max(0, min(1, Δt / ΔX * ūⁿ⁺¹))
128-
129126
pa = bc.classification.matching_scheme
130127

131128
τ = ifelse(ūⁿ⁺¹ >= 0, pa.outflow_timescale, pa.inflow_timescale)
132-
133129
τ̃ = Δt / τ
134130

135131
uᵢⁿ⁺¹ = uᵢⁿ + U * (uᵢ₋₁ⁿ⁺¹ - ūⁿ⁺¹) + (ūⁿ⁺¹ - uᵢⁿ) * τ̃
136-
137132
@inbounds setindex!(u, uᵢⁿ⁺¹, boundary_indices...)
138133

139134
return nothing
@@ -142,24 +137,19 @@ end
142137
@inline function step_left_boundary!(bc::FPAOBC, l, m, boundary_indices, boundary_adjacent_indices, boundary_secret_storage_indices,
143138
grid, u, clock, model_fields, ΔX)
144139
Δt = clock.last_stage_Δt
145-
146140
Δt = ifelse(isinf(Δt), 0, Δt)
147141

148142
ūⁿ⁺¹ = getbc(bc, l, m, grid, clock, model_fields)
149-
150143
uᵢⁿ = @inbounds getindex(u, boundary_secret_storage_indices...)
151144
uᵢ₋₁ⁿ⁺¹ = @inbounds getindex(u, boundary_adjacent_indices...)
152145

153146
U = min(0, max(-1, Δt / ΔX * ūⁿ⁺¹))
154-
155147
pa = bc.classification.matching_scheme
156148

157149
τ = ifelse(ūⁿ⁺¹ <= 0, pa.outflow_timescale, pa.inflow_timescale)
158-
159150
τ̃ = Δt / τ
160151

161152
u₁ⁿ⁺¹ = uᵢⁿ - U * (uᵢ₋₁ⁿ⁺¹ - ūⁿ⁺¹) + (ūⁿ⁺¹ - uᵢⁿ) * τ̃
162-
163153
@inbounds setindex!(u, u₁ⁿ⁺¹, boundary_indices...)
164154
@inbounds setindex!(u, u₁ⁿ⁺¹, boundary_secret_storage_indices...)
165155

@@ -168,7 +158,6 @@ end
168158

169159
@inline function _fill_east_halo!(j, k, grid, u, bc::PAOBC, ::Tuple{Face, Any, Any}, clock, model_fields)
170160
i = grid.Nx + 1
171-
172161
boundary_indices = (i, j, k)
173162
boundary_adjacent_indices = (i-1, j, k)
174163

@@ -193,7 +182,6 @@ end
193182

194183
@inline function _fill_north_halo!(i, k, grid, u, bc::PAOBC, ::Tuple{Any, Face, Any}, clock, model_fields)
195184
j = grid.Ny + 1
196-
197185
boundary_indices = (i, j, k)
198186
boundary_adjacent_indices = (i, j-1, k)
199187

@@ -218,7 +206,6 @@ end
218206

219207
@inline function _fill_top_halo!(i, j, grid, u, bc::PAOBC, ::Tuple{Any, Any, Face}, clock, model_fields)
220208
k = grid.Nz + 1
221-
222209
boundary_indices = (i, j, k)
223210
boundary_adjacent_indices = (i, j, k-1)
224211

src/BoundaryConditions/polar_boundary_condition.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ maybe_polar_boundary_condition(grid, side, ::Type{Center}, LZ) = PolarValueBoun
3131
maybe_polar_boundary_condition(grid, side, ::Type{Face}, LZ) = PolarOpenBoundaryCondition(grid, side, LZ)
3232

3333
# Just a column
34-
@inline getbc(pv::BC{<:Any, <:PolarValue}, i, k, args...) = @inbounds pv.condition.data[1, 1, k]
34+
@inline getbc(pv::PolarValue, i, k, args...) = @inbounds pv.data[1, 1, k]
3535

3636
@kernel function _average_pole_value!(data, c, j, grid, loc)
3737
i′, j′, k = @index(Global, NTuple)

src/Fields/Fields.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ include("field_indices.jl")
3030
include("scans.jl")
3131
include("regridding_fields.jl")
3232
include("field_tuples.jl")
33-
include("background_fields.jl")
3433
include("interpolate.jl")
3534
include("show_fields.jl")
3635
include("broadcasting_abstract_fields.jl")

src/Fields/background_fields.jl

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

src/Fields/field.jl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -544,20 +544,15 @@ const ReducedField = Union{XReducedField,
544544
@propagate_inbounds Base.getindex(r::XYZReducedField, i, j, k) = getindex(r.data, 1, 1, 1)
545545
@propagate_inbounds Base.setindex!(r::XYZReducedField, v, i, j, k) = setindex!(r.data, v, 1, 1, 1)
546546

547-
const XFieldBC = BoundaryCondition{<:Any, XReducedField}
548-
const YFieldBC = BoundaryCondition{<:Any, YReducedField}
549-
const ZFieldBC = BoundaryCondition{<:Any, ZReducedField}
550-
551547
# Boundary conditions reduced in one direction --- drop boundary-normal index
552-
@inline getbc(bc::XFieldBC, j::Integer, k::Integer, grid::AbstractGrid, args...) = @inbounds bc.condition[1, j, k]
553-
@inline getbc(bc::YFieldBC, i::Integer, k::Integer, grid::AbstractGrid, args...) = @inbounds bc.condition[i, 1, k]
554-
@inline getbc(bc::ZFieldBC, i::Integer, j::Integer, grid::AbstractGrid, args...) = @inbounds bc.condition[i, j, 1]
548+
@inline getbc(condition::XReducedField, j::Integer, k::Integer, grid::AbstractGrid, args...) = @inbounds condition[1, j, k]
549+
@inline getbc(condition::YReducedField, i::Integer, k::Integer, grid::AbstractGrid, args...) = @inbounds condition[i, 1, k]
550+
@inline getbc(condition::ZReducedField, i::Integer, j::Integer, grid::AbstractGrid, args...) = @inbounds condition[i, j, 1]
555551

556552
# Boundary conditions reduced in two directions are ambiguous, so that's hard...
557553

558554
# 0D boundary conditions --- easy case
559-
const XYZFieldBC = BoundaryCondition{<:Any, XYZReducedField}
560-
@inline getbc(bc::XYZFieldBC, ::Integer, ::Integer, ::AbstractGrid, args...) = @inbounds bc.condition[1, 1, 1]
555+
@inline getbc(condition::XYZReducedField, ::Integer, ::Integer, ::AbstractGrid, args...) = @inbounds condition[1, 1, 1]
561556

562557
# Preserve location when adapting fields reduced on one or more dimensions
563558
function Adapt.adapt_structure(to, reduced_field::ReducedField)

src/Models/Models.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Models
22

33
export
4-
NonhydrostaticModel,
4+
NonhydrostaticModel, BackgroundField, BackgroundFields,
55
ShallowWaterModel, ConservativeFormulation, VectorInvariantFormulation,
66
HydrostaticFreeSurfaceModel, ZStar, ZCoordinate,
77
ExplicitFreeSurface, ImplicitFreeSurface, SplitExplicitFreeSurface,
@@ -101,7 +101,7 @@ include("HydrostaticFreeSurfaceModels/HydrostaticFreeSurfaceModels.jl")
101101
include("ShallowWaterModels/ShallowWaterModels.jl")
102102
include("LagrangianParticleTracking/LagrangianParticleTracking.jl")
103103

104-
using .NonhydrostaticModels: NonhydrostaticModel, PressureField
104+
using .NonhydrostaticModels: NonhydrostaticModel, PressureField, BackgroundField, BackgroundFields
105105

106106
using .HydrostaticFreeSurfaceModels:
107107
HydrostaticFreeSurfaceModel,

src/Models/NonhydrostaticModels/NonhydrostaticModels.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module NonhydrostaticModels
22

3-
export NonhydrostaticModel
3+
export NonhydrostaticModel, BackgroundField, BackgroundFields
44

55
using DocStringExtensions
66

@@ -65,6 +65,7 @@ nonhydrostatic_pressure_solver(grid) = nonhydrostatic_pressure_solver(architectu
6565
##### NonhydrostaticModel definition
6666
#####
6767

68+
include("background_fields.jl")
6869
include("nonhydrostatic_model.jl")
6970
include("pressure_field.jl")
7071
include("show_nonhydrostatic_model.jl")

0 commit comments

Comments
 (0)