diff --git a/Project.toml b/Project.toml index cc1748392b..cf13b97b67 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Oceananigans" uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09" authors = ["Climate Modeling Alliance and contributors"] -version = "0.87.3" +version = "0.87.4" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/Forcings/Forcings.jl b/src/Forcings/Forcings.jl index 832bcfa581..c0d99c2a8c 100644 --- a/src/Forcings/Forcings.jl +++ b/src/Forcings/Forcings.jl @@ -4,12 +4,12 @@ export Forcing, ContinuousForcing, DiscreteForcing, Relaxation, GaussianMask, Li using Oceananigans.Fields +include("multiple_forcings.jl") include("continuous_forcing.jl") include("discrete_forcing.jl") include("relaxation.jl") include("advective_forcing.jl") include("forcing.jl") include("model_forcing.jl") -include("multiple_forcings.jl") end # module diff --git a/src/Forcings/advective_forcing.jl b/src/Forcings/advective_forcing.jl index c6db2bfe71..d1ba1a0394 100644 --- a/src/Forcings/advective_forcing.jl +++ b/src/Forcings/advective_forcing.jl @@ -77,9 +77,14 @@ Adapt.adapt_structure(to, af::AdvectiveForcing) = v = SumOfArrays{2}(forcing.v, total_velocities.v), w = SumOfArrays{2}(forcing.w, total_velocities.w)) +# Unwrap the tuple within MultipleForcings +@inline with_advective_forcing(mf::MultipleForcings, total_velocities) = + with_advective_forcing(mf.forcings, total_velocities) + +# Recurse over forcing tuples @inline with_advective_forcing(forcing::Tuple, total_velocities) = @inbounds with_advective_forcing(forcing[2:end], with_advective_forcing(forcing[1], total_velocities)) -# terminates recursion +# Terminate recursion @inline with_advective_forcing(forcing::NTuple{1}, total_velocities) = - @inbounds with_advective_forcing(forcing[1], total_velocities) \ No newline at end of file + @inbounds with_advective_forcing(forcing[1], total_velocities) diff --git a/test/test_forcings.jl b/test/test_forcings.jl index 751a337942..5c9900e595 100644 --- a/test/test_forcings.jl +++ b/test/test_forcings.jl @@ -119,19 +119,38 @@ function advective_and_multiple_forcing(arch) grid = RectilinearGrid(arch, size=(2, 2, 3), extent=(1, 1, 1), halo=(4, 4, 4)) constant_slip = AdvectiveForcing(w=1) - + zero_slip = AdvectiveForcing(w=0) no_penetration = ImpenetrableBoundaryCondition() slip_bcs = FieldBoundaryConditions(grid, (Center, Center, Face), top=no_penetration, bottom=no_penetration) slip_velocity = ZFaceField(grid, boundary_conditions=slip_bcs) + set!(slip_velocity, 1) velocity_field_slip = AdvectiveForcing(w=slip_velocity) - simple_forcing(x, y, z, t) = 1 + zero_forcing(x, y, z, t) = 0 + one_forcing(x, y, z, t) = 1 + + model = NonhydrostaticModel(; grid, + tracers = (:a, :b, :c), + forcing = (a = constant_slip, + b = (zero_forcing, velocity_field_slip), + c = (one_forcing, zero_slip))) - model = NonhydrostaticModel(; grid, tracers=(:a, :b), forcing=(a=constant_slip, b=(simple_forcing, velocity_field_slip))) + a₀ = rand(size(grid)...) + b₀ = rand(size(grid)...) + set!(model, a=a₀, b=b₀, c=0) + + # Time-step without an error? time_step!(model, 1, euler=true) - return true -end + a₁ = Array(interior(model.tracers.a)) + b₁ = Array(interior(model.tracers.b)) + c₁ = Array(interior(model.tracers.c)) + + a_changed = a₁ ≠ a₀ + b_changed = b₁ ≠ b₀ + c_correct = all(c₁ .== model.clock.time) + return a_changed & b_changed & c_correct +end @testset "Forcings" begin @info "Testing forcings..."