Skip to content

Commit

Permalink
(0.87.4) Add missing with_advective_forcing method (#3259)
Browse files Browse the repository at this point in the history
* Add missing method for with_advective_forcing

* Better comment

* Bump minor version

* Expand advective / multiple-forcing tests to test correctness

* Fix test

* Add a test that forcing is correct with mlutiple forcings
  • Loading branch information
glwagner authored Sep 12, 2023
1 parent 754708c commit b99b467
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Forcings/Forcings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions src/Forcings/advective_forcing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@inbounds with_advective_forcing(forcing[1], total_velocities)
29 changes: 24 additions & 5 deletions test/test_forcings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down

2 comments on commit b99b467

@glwagner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/91294

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.87.4 -m "<description of version>" b99b467e163efc64170c2a68398aead6cd5c4478
git push origin v0.87.4

Please sign in to comment.