Skip to content

Commit

Permalink
Merge branch 'main' into jsw/pertubation-advection-obc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchor authored Feb 19, 2025
2 parents ad198cf + 76c5f29 commit ad5b837
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .buildkite/distributed/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
agents:
queue: new-central
slurm_mem: 8G # Note that the tests run on shared nodes, so limiting the memory usage might help in avoiding long queues
modules: climacommon/2024_10_08
modules: climacommon/2024_10_10

env:
JULIA_LOAD_PATH: "${JULIA_LOAD_PATH}:${BUILDKITE_BUILD_CHECKOUT_PATH}/.buildkite/distributed"
Expand Down
5 changes: 2 additions & 3 deletions 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.95.10"
version = "0.95.12"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down Expand Up @@ -44,7 +44,7 @@ Reactant = "3c362404-f566-11ee-1572-e11a4b42c853"
[extensions]
OceananigansEnzymeExt = "Enzyme"
OceananigansMakieExt = ["MakieCore", "Makie"]
OceananigansReactantExt = "Reactant"
OceananigansReactantExt = ["Reactant", "KernelAbstractions"]

[compat]
Adapt = "4.1.1"
Expand Down Expand Up @@ -86,7 +86,6 @@ julia = "1.9"
CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2"
DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
Reactant = "3c362404-f566-11ee-1572-e11a4b42c853"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Expand Down
2 changes: 1 addition & 1 deletion examples/internal_tide.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# # Internal tide by a seamount
# # Internal tide over a seamount
#
# In this example, we show how internal tide is generated from a barotropic tidal flow
# sloshing back and forth over a sea mount.
Expand Down
11 changes: 10 additions & 1 deletion src/Fields/interpolate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ end
return fractional_index(x, xn, Nx)
end

@inline convert_to_0_360(x) = ((x % 360) + 360) % 360
# Because of precision errors with numbers close to 0,
# we need to make sure we approach the correct limit also from the left.
@inline function convert_to_0_360(x::FT) where FT
x₀ = ((x % 360) + 360) % 360
x⁻ = - eps(convert(FT, 360))
return ifelse(x⁻ x < 0, 360 + x, x₀)
end

# No need to check precision for integers
@inline convert_to_0_360(x::Integer) = ((x % 360) + 360) % 360

# Find n for which 360 * n ≤ λ ≤ 360 * (n + 1)
@inline find_λ_range(λ) = ifelse((λ < 0) & (mod(λ, 360) != 0), λ ÷ 360 - 1, λ ÷ 360)
Expand Down
1 change: 0 additions & 1 deletion src/ImmersedBoundaries/immersed_boundary_condition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function ImmersedBoundaryCondition(; west = nothing,
bottom = nothing,
top = nothing)

@warn "`ImmersedBoundaryCondition` is experimental."
return ImmersedBoundaryCondition(west, east, south, north, bottom, top)
end

Expand Down
33 changes: 22 additions & 11 deletions src/Utils/schedules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ end
Callable `TimeInterval` schedule for periodic output or diagnostic evaluation
according to `model.clock.time`.
"""
mutable struct TimeInterval <: AbstractSchedule
interval :: Float64
first_actuation_time :: Float64
mutable struct TimeInterval{FT} <: AbstractSchedule
interval :: FT
first_actuation_time :: FT
actuations :: Int
end

Expand All @@ -45,7 +45,11 @@ end
Return a callable `TimeInterval` that schedules periodic output or diagnostic evaluation
on a `interval` of simulation time, as kept by `model.clock`.
"""
TimeInterval(interval) = TimeInterval(convert(Float64, interval), 0.0, 0)
function TimeInterval(interval)
FT = Oceananigans.defaults.FloatType
interval = convert(FT, interval)
return TimeInterval(interval, zero(FT), 0)
end

function initialize!(schedule::TimeInterval, first_actuation_time::Number)
schedule.first_actuation_time = first_actuation_time
Expand Down Expand Up @@ -114,9 +118,9 @@ next_actuation_time(schedule::IterationInterval) = Inf
##### WallTimeInterval
#####

mutable struct WallTimeInterval <: AbstractSchedule
interval :: Float64
previous_actuation_time :: Float64
mutable struct WallTimeInterval{FT} <: AbstractSchedule
interval :: FT
previous_actuation_time :: FT
end

"""
Expand All @@ -131,7 +135,10 @@ or hypothetical clock hanging on your wall.
The keyword argument `start_time` can be used to specify a starting wall time
other than the moment `WallTimeInterval` is constructed.
"""
WallTimeInterval(interval; start_time = time_ns() * 1e-9) = WallTimeInterval(Float64(interval), Float64(start_time))
function WallTimeInterval(interval; start_time = time_ns() * 1e-9)
FT = Oceananigans.defaults.FloatType
return WallTimeInterval(convert(FT, interval), convert(FT, interval))
end

function (schedule::WallTimeInterval)(model)
wall_time = time_ns() * 1e-9
Expand All @@ -149,8 +156,8 @@ end
##### SpecifiedTimes
#####

mutable struct SpecifiedTimes <: AbstractSchedule
times :: Vector{Float64}
mutable struct SpecifiedTimes{FT} <: AbstractSchedule
times :: Vector{FT}
previous_actuation :: Int
end

Expand All @@ -166,7 +173,11 @@ whenever the model's clock equals the specified values in `times`. For example,
The specified `times` need not be ordered as the `SpecifiedTimes` constructor
will check and order them in ascending order if needed.
"""
SpecifiedTimes(times::Vararg{T}) where T<:Number = SpecifiedTimes(sort([Float64(t) for t in times]), 0)
function SpecifiedTimes(times::Vararg{T}) where T<:Number
FT = Oceananigans.defaults.FloatType
return SpecifiedTimes(sort([convert(FT, t) for t in times]), 0)
end

SpecifiedTimes(times) = SpecifiedTimes(times...)

function next_actuation_time(st::SpecifiedTimes)
Expand Down
20 changes: 19 additions & 1 deletion test/test_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Oceananigans.Fields: ReducedField, has_velocities
using Oceananigans.Fields: VelocityFields, TracerFields, interpolate, interpolate!
using Oceananigans.Fields: reduced_location
using Oceananigans.Fields: fractional_indices, interpolator
using Oceananigans.Fields: convert_to_0_360
using Oceananigans.Fields: convert_to_0_360, convert_to_λ₀_λ₀_plus360
using Oceananigans.Grids: ξnode, ηnode, rnode
using Oceananigans.Grids: total_length
using Oceananigans.Grids: λnode
Expand Down Expand Up @@ -186,6 +186,24 @@ function run_field_interpolation_tests(grid)
end
end

@info "Testing the convert functions"
for n in 1:30
@test convert_to_0_360(- 10.e0^(-n)) > 359
@test convert_to_0_360(- 10.f0^(-n)) > 359
@test convert_to_0_360(10.e0^(-n)) < 1
@test convert_to_0_360(10.f0^(-n)) < 1
end

# Generating a random longitude left bound between -1000 and 1000
λs₀ = rand(1000) .* 2000 .- 1000

# Generating a random interpolation longitude
λsᵢ = rand(1000) .* 2000 .- 1000

for λ₀ in λs₀, λᵢ in λsᵢ
@test λ₀ convert_to_λ₀_λ₀_plus360(λᵢ, λ₀) λ₀ + 360
end

# Check interpolation on Windowed fields
wf = ZFaceField(grid; indices=(:, :, grid.Nz+1))
If = Field{Center, Center, Nothing}(grid)
Expand Down

0 comments on commit ad5b837

Please sign in to comment.