From ac59cdf47833c57b3ed637ab8fdd270563483a4d Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 11:38:03 -0400 Subject: [PATCH 01/16] =?UTF-8?q?added=20`=CE=94t`=20to=20`Clock`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hydrostatic_free_surface_model.jl | 4 ++-- .../NonhydrostaticModels/nonhydrostatic_model.jl | 4 ++-- src/TimeSteppers/clock.jl | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl b/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl index b268031091..2216490cc9 100644 --- a/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl +++ b/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl @@ -50,7 +50,7 @@ end """ HydrostaticFreeSurfaceModel(; grid, - clock = Clock{eltype(grid)}(0, 0, 1), + clock = Clock{eltype(grid)}(0, Inf, 0, 1), momentum_advection = CenteredSecondOrder(), tracer_advection = CenteredSecondOrder(), buoyancy = SeawaterBuoyancy(eltype(grid)), @@ -94,7 +94,7 @@ Keyword arguments - `auxiliary_fields`: `NamedTuple` of auxiliary fields. Default: `nothing`. """ function HydrostaticFreeSurfaceModel(; grid, - clock = Clock{eltype(grid)}(0, 0, 1), + clock = Clock{eltype(grid)}(0, Inf, 0, 1), momentum_advection = CenteredSecondOrder(), tracer_advection = CenteredSecondOrder(), buoyancy = SeawaterBuoyancy(eltype(grid)), diff --git a/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl b/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl index a5ea3e5197..1ab4b81792 100644 --- a/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl +++ b/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl @@ -52,7 +52,7 @@ end """ NonhydrostaticModel(; grid, - clock = Clock{eltype(grid)}(0, 0, 1), + clock = Clock{eltype(grid)}(0, Inf, 0, 1), advection = CenteredSecondOrder(), buoyancy = nothing, coriolis = nothing, @@ -105,7 +105,7 @@ Keyword arguments - `auxiliary_fields`: `NamedTuple` of auxiliary fields. Default: `nothing` """ function NonhydrostaticModel(; grid, - clock = Clock{eltype(grid)}(0, 0, 1), + clock = Clock{eltype(grid)}(0, Inf, 0, 1), advection = CenteredSecondOrder(), buoyancy = nothing, coriolis = nothing, diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 24b219a603..5644354efa 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -14,6 +14,7 @@ either a number or a `DateTime` object. """ mutable struct Clock{T} time :: T + Δt :: T iteration :: Int stage :: Int end @@ -24,12 +25,12 @@ end Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iteration` and first time step `stage`. """ -Clock(; time::T, iteration=0, stage=1) where T = Clock{T}(time, iteration, stage) +Clock(; time::T, iteration=0, stage=1, Δt = Inf) where T = Clock{T}(time, Δt, iteration, stage) -Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration))") +Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), Δt=$(prettytime(clock.Δt)))") Base.show(io::IO, c::Clock{T}) where T = - println(io, "Clock{$T}: time = $(prettytime(c.time)), iteration = $(c.iteration), stage = $(c.stage)") + println(io, "Clock{$T}: time = $(prettytime(c.time)), Δt = $(prettytime(c.Δt)), iteration = $(c.iteration), stage = $(c.stage)") next_time(clock, Δt) = clock.time + Δt next_time(clock::Clock{<:AbstractTime}, Δt) = clock.time + Nanosecond(round(Int, 1e9 * Δt)) @@ -52,6 +53,8 @@ function tick!(clock, Δt; stage=false) tick_time!(clock, Δt) + clock.Δt = Δt + if stage # tick a stage update clock.stage += 1 else # tick an iteration and reset stage @@ -63,4 +66,4 @@ function tick!(clock, Δt; stage=false) end "Adapt `Clock` to work on the GPU via CUDAnative and CUDAdrv." -Adapt.adapt_structure(to, clock::Clock) = (time=clock.time, iteration=clock.iteration, stage=clock.stage) +Adapt.adapt_structure(to, clock::Clock) = (time=clock.time, Δt=clock.Δt, iteration=clock.iteration, stage=clock.stage) From dfd62df8a7a2e56fa5fa2e9d112646a021a0c7b6 Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 12:04:16 -0400 Subject: [PATCH 02/16] fixed clock to work for DateTime --- .../hydrostatic_free_surface_model.jl | 4 ++-- src/Models/NonhydrostaticModels/nonhydrostatic_model.jl | 4 ++-- src/Models/ShallowWaterModels/shallow_water_model.jl | 4 ++-- src/TimeSteppers/clock.jl | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl b/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl index 2216490cc9..c39ed8af19 100644 --- a/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl +++ b/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl @@ -50,7 +50,7 @@ end """ HydrostaticFreeSurfaceModel(; grid, - clock = Clock{eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), momentum_advection = CenteredSecondOrder(), tracer_advection = CenteredSecondOrder(), buoyancy = SeawaterBuoyancy(eltype(grid)), @@ -94,7 +94,7 @@ Keyword arguments - `auxiliary_fields`: `NamedTuple` of auxiliary fields. Default: `nothing`. """ function HydrostaticFreeSurfaceModel(; grid, - clock = Clock{eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), momentum_advection = CenteredSecondOrder(), tracer_advection = CenteredSecondOrder(), buoyancy = SeawaterBuoyancy(eltype(grid)), diff --git a/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl b/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl index 1ab4b81792..117119ae82 100644 --- a/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl +++ b/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl @@ -52,7 +52,7 @@ end """ NonhydrostaticModel(; grid, - clock = Clock{eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), advection = CenteredSecondOrder(), buoyancy = nothing, coriolis = nothing, @@ -105,7 +105,7 @@ Keyword arguments - `auxiliary_fields`: `NamedTuple` of auxiliary fields. Default: `nothing` """ function NonhydrostaticModel(; grid, - clock = Clock{eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), advection = CenteredSecondOrder(), buoyancy = nothing, coriolis = nothing, diff --git a/src/Models/ShallowWaterModels/shallow_water_model.jl b/src/Models/ShallowWaterModels/shallow_water_model.jl index d18e8eb086..0919a3d09d 100644 --- a/src/Models/ShallowWaterModels/shallow_water_model.jl +++ b/src/Models/ShallowWaterModels/shallow_water_model.jl @@ -61,7 +61,7 @@ struct VectorInvariantFormulation end """ ShallowWaterModel(; grid, gravitational_acceleration, - clock = Clock{eltype(grid)}(0, 0, 1), + clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), momentum_advection = UpwindBiasedFifthOrder(), tracer_advection = WENO(), mass_advection = WENO(), @@ -112,7 +112,7 @@ Keyword arguments function ShallowWaterModel(; grid, gravitational_acceleration, - clock = Clock{eltype(grid)}(0, 0, 1), + clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), momentum_advection = UpwindBiasedFifthOrder(), tracer_advection = WENO(), mass_advection = WENO(), diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 5644354efa..4220544026 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -12,9 +12,9 @@ Keeps track of the current `time`, `iteration` number, and time-stepping `stage` The `stage` is updated only for multi-stage time-stepping methods. The `time::T` is either a number or a `DateTime` object. """ -mutable struct Clock{T} +mutable struct Clock{T, FT} time :: T - Δt :: T + Δt :: FT iteration :: Int stage :: Int end @@ -25,7 +25,7 @@ end Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iteration` and first time step `stage`. """ -Clock(; time::T, iteration=0, stage=1, Δt = Inf) where T = Clock{T}(time, Δt, iteration, stage) +Clock(; time::T, Δt::FT = Inf, iteration=0, stage=1) where {T, FT} = Clock{T, FT}(time, Δt, iteration, stage) Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), Δt=$(prettytime(clock.Δt)))") From 99aacbbaae48c5bdd635f18cd5dd07e381240bae Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 13:06:14 -0400 Subject: [PATCH 03/16] =?UTF-8?q?changed=20name=20to=20`last=5F=CE=94t`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TimeSteppers/clock.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 4220544026..351e960616 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -14,7 +14,7 @@ either a number or a `DateTime` object. """ mutable struct Clock{T, FT} time :: T - Δt :: FT + last_Δt :: FT iteration :: Int stage :: Int end @@ -25,12 +25,12 @@ end Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iteration` and first time step `stage`. """ -Clock(; time::T, Δt::FT = Inf, iteration=0, stage=1) where {T, FT} = Clock{T, FT}(time, Δt, iteration, stage) +Clock(; time::T, last_Δt::FT = Inf, iteration=0, stage=1) where {T, FT} = Clock{T, FT}(time, last_Δt, iteration, stage) -Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), Δt=$(prettytime(clock.Δt)))") +Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), last_Δt=$(prettytime(clock.last_Δt)))") Base.show(io::IO, c::Clock{T}) where T = - println(io, "Clock{$T}: time = $(prettytime(c.time)), Δt = $(prettytime(c.Δt)), iteration = $(c.iteration), stage = $(c.stage)") + println(io, "Clock{$T}: time = $(prettytime(c.time)), last_Δt = $(prettytime(c.last_Δt)), iteration = $(c.iteration), stage = $(c.stage)") next_time(clock, Δt) = clock.time + Δt next_time(clock::Clock{<:AbstractTime}, Δt) = clock.time + Nanosecond(round(Int, 1e9 * Δt)) @@ -53,7 +53,7 @@ function tick!(clock, Δt; stage=false) tick_time!(clock, Δt) - clock.Δt = Δt + clock.last_Δt = Δt if stage # tick a stage update clock.stage += 1 From a68c34a4ba0b5307d34e1ef2b39f3d749f10bbe8 Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 13:06:59 -0400 Subject: [PATCH 04/16] fixed Clock adapt --- src/TimeSteppers/clock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 351e960616..b824cab20d 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -66,4 +66,4 @@ function tick!(clock, Δt; stage=false) end "Adapt `Clock` to work on the GPU via CUDAnative and CUDAdrv." -Adapt.adapt_structure(to, clock::Clock) = (time=clock.time, Δt=clock.Δt, iteration=clock.iteration, stage=clock.stage) +Adapt.adapt_structure(to, clock::Clock) = (time=clock.time, last_Δt=clock.last_Δt, iteration=clock.iteration, stage=clock.stage) From 51f792b65b99b37bcd24346a6078781133c70a52 Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 13:09:06 -0400 Subject: [PATCH 05/16] updated docstring --- src/TimeSteppers/clock.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index b824cab20d..cd12767a0f 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -6,9 +6,9 @@ import Base: show import Oceananigans.Units: Time """ - mutable struct Clock{T<:Number} + mutable struct Clock{T, FT} -Keeps track of the current `time`, `iteration` number, and time-stepping `stage`. +Keeps track of the current `time`, `last_Δt`, `iteration` number, and time-stepping `stage`. The `stage` is updated only for multi-stage time-stepping methods. The `time::T` is either a number or a `DateTime` object. """ @@ -20,10 +20,10 @@ mutable struct Clock{T, FT} end """ - Clock(; time, iteration=0, stage=1) + Clock(; time, last_Δt = Inf, iteration=0, stage=1) Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iteration` -and first time step `stage`. +and first time step `stage` with `last_Δt`. """ Clock(; time::T, last_Δt::FT = Inf, iteration=0, stage=1) where {T, FT} = Clock{T, FT}(time, last_Δt, iteration, stage) From 1852d42fb730f4c6447cea5938f8a7c609a01daa Mon Sep 17 00:00:00 2001 From: Jago Strong-Wright Date: Wed, 13 Mar 2024 15:52:47 -0400 Subject: [PATCH 06/16] Update src/TimeSteppers/clock.jl Co-authored-by: Gregory L. Wagner --- src/TimeSteppers/clock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index cd12767a0f..36b1176382 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -14,7 +14,7 @@ either a number or a `DateTime` object. """ mutable struct Clock{T, FT} time :: T - last_Δt :: FT + last_Δt :: DT iteration :: Int stage :: Int end From a83e3bbd007f60f90744b495e8d24afc832f83c4 Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 16:18:55 -0400 Subject: [PATCH 07/16] fixed constructor --- .../hydrostatic_free_surface_model.jl | 4 ++-- .../NonhydrostaticModels/nonhydrostatic_model.jl | 4 ++-- .../ShallowWaterModels/shallow_water_model.jl | 2 +- src/TimeSteppers/clock.jl | 14 +++++++++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl b/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl index c39ed8af19..213a3ddaf6 100644 --- a/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl +++ b/src/Models/HydrostaticFreeSurfaceModels/hydrostatic_free_surface_model.jl @@ -50,7 +50,7 @@ end """ HydrostaticFreeSurfaceModel(; grid, - clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid)}(time = 0), momentum_advection = CenteredSecondOrder(), tracer_advection = CenteredSecondOrder(), buoyancy = SeawaterBuoyancy(eltype(grid)), @@ -94,7 +94,7 @@ Keyword arguments - `auxiliary_fields`: `NamedTuple` of auxiliary fields. Default: `nothing`. """ function HydrostaticFreeSurfaceModel(; grid, - clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid)}(time = 0), momentum_advection = CenteredSecondOrder(), tracer_advection = CenteredSecondOrder(), buoyancy = SeawaterBuoyancy(eltype(grid)), diff --git a/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl b/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl index 117119ae82..07e0141c1d 100644 --- a/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl +++ b/src/Models/NonhydrostaticModels/nonhydrostatic_model.jl @@ -52,7 +52,7 @@ end """ NonhydrostaticModel(; grid, - clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid)}(time = 0), advection = CenteredSecondOrder(), buoyancy = nothing, coriolis = nothing, @@ -105,7 +105,7 @@ Keyword arguments - `auxiliary_fields`: `NamedTuple` of auxiliary fields. Default: `nothing` """ function NonhydrostaticModel(; grid, - clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid)}(time = 0), advection = CenteredSecondOrder(), buoyancy = nothing, coriolis = nothing, diff --git a/src/Models/ShallowWaterModels/shallow_water_model.jl b/src/Models/ShallowWaterModels/shallow_water_model.jl index 0919a3d09d..bd46367ba9 100644 --- a/src/Models/ShallowWaterModels/shallow_water_model.jl +++ b/src/Models/ShallowWaterModels/shallow_water_model.jl @@ -61,7 +61,7 @@ struct VectorInvariantFormulation end """ ShallowWaterModel(; grid, gravitational_acceleration, - clock = Clock{eltype(grid), eltype(grid)}(0, Inf, 0, 1), + clock = Clock{eltype(grid)}(time = 0), momentum_advection = UpwindBiasedFifthOrder(), tracer_advection = WENO(), mass_advection = WENO(), diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 36b1176382..dc732b48a6 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -12,8 +12,8 @@ Keeps track of the current `time`, `last_Δt`, `iteration` number, and time-step The `stage` is updated only for multi-stage time-stepping methods. The `time::T` is either a number or a `DateTime` object. """ -mutable struct Clock{T, FT} - time :: T +mutable struct Clock{TT, DT} + time :: TT last_Δt :: DT iteration :: Int stage :: Int @@ -25,12 +25,16 @@ end Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iteration` and first time step `stage` with `last_Δt`. """ -Clock(; time::T, last_Δt::FT = Inf, iteration=0, stage=1) where {T, FT} = Clock{T, FT}(time, last_Δt, iteration, stage) +Clock(; time::TT, last_Δt::DT=Inf, iteration=0, stage=1) where {TT, DT} = Clock{TT, DT}(time, last_Δt, iteration, stage) + +Clock{TT}(; time, last_Δt=Inf, iteration=0, stage=1) where TT = Clock{TT, TT}(time, last_Δt, iteration, stage) + +Clock{DT}(; time::AbstractTime, last_Δt=Inf, iteration=0, stage=1) where DT = Clock{AbstractTime, DT}(time, last_Δt, iteration, stage) Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), last_Δt=$(prettytime(clock.last_Δt)))") -Base.show(io::IO, c::Clock{T}) where T = - println(io, "Clock{$T}: time = $(prettytime(c.time)), last_Δt = $(prettytime(c.last_Δt)), iteration = $(c.iteration), stage = $(c.stage)") +Base.show(io::IO, c::Clock{TT, DT}) where {TT, DT} = + println(io, "Clock{$TT, $DT}: time = $(prettytime(c.time)), last_Δt = $(prettytime(c.last_Δt)), iteration = $(c.iteration), stage = $(c.stage)") next_time(clock, Δt) = clock.time + Δt next_time(clock::Clock{<:AbstractTime}, Δt) = clock.time + Nanosecond(round(Int, 1e9 * Δt)) From 40db431c93231dfc85bcc94dbd706ddf48c39c26 Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 16:21:02 -0400 Subject: [PATCH 08/16] updated `reset!` --- src/Simulations/simulation.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Simulations/simulation.jl b/src/Simulations/simulation.jl index 22ccb2ae3d..fc90daf99b 100644 --- a/src/Simulations/simulation.jl +++ b/src/Simulations/simulation.jl @@ -161,7 +161,8 @@ run_wall_time(sim::Simulation) = prettytime(sim.run_wall_time) Reset `sim`ulation, `model.clock`, and `model.timestepper` to their initial state. """ function reset!(sim::Simulation) - sim.model.clock.time = 0.0 + sim.model.clock.time = 0 + sim.model.clock.last_Δt = Inf sim.model.clock.iteration = 0 sim.model.clock.stage = 1 sim.stop_iteration = Inf From 65068f622459b74f63749d6fb5f8f8a9c00cc847 Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Wed, 13 Mar 2024 16:21:54 -0400 Subject: [PATCH 09/16] fixed formatting --- src/TimeSteppers/clock.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index dc732b48a6..0cc9e79a17 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -26,9 +26,7 @@ Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iter and first time step `stage` with `last_Δt`. """ Clock(; time::TT, last_Δt::DT=Inf, iteration=0, stage=1) where {TT, DT} = Clock{TT, DT}(time, last_Δt, iteration, stage) - Clock{TT}(; time, last_Δt=Inf, iteration=0, stage=1) where TT = Clock{TT, TT}(time, last_Δt, iteration, stage) - Clock{DT}(; time::AbstractTime, last_Δt=Inf, iteration=0, stage=1) where DT = Clock{AbstractTime, DT}(time, last_Δt, iteration, stage) Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), last_Δt=$(prettytime(clock.last_Δt)))") From d5f49169d11bf9f0233aed63eed8f92c613d80bc Mon Sep 17 00:00:00 2001 From: Jago Strong-Wright Date: Thu, 14 Mar 2024 14:37:01 -0400 Subject: [PATCH 10/16] Apply suggestions from code review Co-authored-by: Gregory L. Wagner --- src/TimeSteppers/clock.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 0cc9e79a17..1303bf9b29 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -26,8 +26,14 @@ Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iter and first time step `stage` with `last_Δt`. """ Clock(; time::TT, last_Δt::DT=Inf, iteration=0, stage=1) where {TT, DT} = Clock{TT, DT}(time, last_Δt, iteration, stage) -Clock{TT}(; time, last_Δt=Inf, iteration=0, stage=1) where TT = Clock{TT, TT}(time, last_Δt, iteration, stage) -Clock{DT}(; time::AbstractTime, last_Δt=Inf, iteration=0, stage=1) where DT = Clock{AbstractTime, DT}(time, last_Δt, iteration, stage) +# TODO: when supporting DateTime, this function will have to be extended +time_step_type(TT) = TT + +function Clock{TT}(; time, last_Δt=Inf, iteration=0, stage=1) where TT + DT = time_step_type(TT) + last_Δt = convert(DT, last_Δt) + return Clock{TT, DT}(time, last_Δt, iteration, stage) +end Base.summary(clock::Clock) = string("Clock(time=$(prettytime(clock.time)), iteration=$(clock.iteration), last_Δt=$(prettytime(clock.last_Δt)))") From bc3ca25414cc84b1146a60cb53849d0bd12831bf Mon Sep 17 00:00:00 2001 From: Jago Strong-Wright Date: Mon, 18 Mar 2024 09:19:37 -0400 Subject: [PATCH 11/16] Update src/TimeSteppers/clock.jl Co-authored-by: Navid C. Constantinou --- src/TimeSteppers/clock.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 1303bf9b29..b1b8da173b 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -74,4 +74,6 @@ function tick!(clock, Δt; stage=false) end "Adapt `Clock` to work on the GPU via CUDAnative and CUDAdrv." -Adapt.adapt_structure(to, clock::Clock) = (time=clock.time, last_Δt=clock.last_Δt, iteration=clock.iteration, stage=clock.stage) +Adapt.adapt_structure(to, clock::Clock) = + (time=clock.time, last_Δt=clock.last_Δt, iteration=clock.iteration, stage=clock.stage) + From 0170cf097070938a7881be7f899a68a857ed356a Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Wed, 20 Mar 2024 10:27:04 +0200 Subject: [PATCH 12/16] increase size_threshold=1MiB --- docs/make.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 568ffe94ec..556c0ae9d1 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -21,6 +21,7 @@ end CairoMakie.activate!(type = "svg") using Oceananigans + using Oceananigans.Units using Oceananigans.Operators using Oceananigans.Diagnostics using Oceananigans.OutputWriters @@ -174,7 +175,7 @@ format = Documenter.HTML(collapselevel = 1, prettyurls = get(ENV, "CI", nothing) == "true", canonical = "https://clima.github.io/OceananigansDocumentation/stable/", mathengine = MathJax3(), - size_threshold = 819200, + size_threshold = 1MiB, assets = String["assets/citations.css"]) makedocs(sitename = "Oceananigans.jl", From 9820fedd7d466f273d08abafa0be94f3930533b1 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Wed, 20 Mar 2024 10:36:09 +0200 Subject: [PATCH 13/16] fix doctest --- docs/src/model_setup/clock.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/model_setup/clock.md b/docs/src/model_setup/clock.md index 50128ff0bb..c2d2a2eb2b 100644 --- a/docs/src/model_setup/clock.md +++ b/docs/src/model_setup/clock.md @@ -14,7 +14,7 @@ end ```jldoctest julia> clock = Clock(time=0.0) -Clock{Float64}: time = 0 seconds, iteration = 0, stage = 1 +Clock{Float64, Float64}: time = 0 seconds, last_Δt = Inf days, iteration = 0, stage = 1 ``` but can be modified to start the model clock at some other time. @@ -22,7 +22,7 @@ For example, passing ```jldoctest julia> clock = Clock(time=3600.0) -Clock{Float64}: time = 1 hour, iteration = 0, stage = 1 +Clock{Float64, Float64}: time = 1 hour, last_Δt = Inf days, iteration = 0, stage = 1 ``` to the constructor for `NonhydrostaticModel` causes the simulation @@ -37,7 +37,7 @@ for example, pass julia> using TimesDates julia> clock = Clock(time=TimeDate(2020)) -Clock{TimesDates.TimeDate}: time = 2020-01-01T00:00:00, iteration = 0, stage = 1 +Clock{TimesDates.TimeDate, Float64}: time = 2020-01-01T00:00:00, last_Δt = Inf days, iteration = 0, stage = 1 ``` to `NonhydrostaticModel`. `TimesDates.TimeDate` supports nanosecond resolution and is thus recommended From 28cc105946158d30dda0b0d4914ba579d07e53e4 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Wed, 20 Mar 2024 10:37:23 +0200 Subject: [PATCH 14/16] fix doctest --- docs/src/model_setup/background_fields.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/model_setup/background_fields.md b/docs/src/model_setup/background_fields.md index 44bec466e3..fd4a526866 100644 --- a/docs/src/model_setup/background_fields.md +++ b/docs/src/model_setup/background_fields.md @@ -56,7 +56,7 @@ model.background_fields.velocities.u FunctionField located at (Face, Center, Center) ├── func: U (generic function with 1 method) ├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo -├── clock: Clock(time=0 seconds, iteration=0) +├── clock: Clock(time=0 seconds, iteration=0, last_Δt=Inf days) └── parameters: nothing ``` @@ -99,6 +99,6 @@ model.background_fields.tracers.b FunctionField located at (Center, Center, Center) ├── func: B (generic function with 1 method) ├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo -├── clock: Clock(time=0 seconds, iteration=0) +├── clock: Clock(time=0 seconds, iteration=0, last_Δt=Inf days) └── parameters: (α = 3.14, N = 1.0, f = 0.1) ``` From b7d32536b18e7f4a91a9f1de8209d34055855cc6 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Wed, 20 Mar 2024 15:34:57 +0200 Subject: [PATCH 15/16] Update pipeline.yml --- .buildkite/distributed/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/distributed/pipeline.yml b/.buildkite/distributed/pipeline.yml index bc6dd5c456..2d2b59eea0 100644 --- a/.buildkite/distributed/pipeline.yml +++ b/.buildkite/distributed/pipeline.yml @@ -1,7 +1,7 @@ agents: queue: new-central slurm_mem: 8G - modules: climacommon/2024_02_27 + modules: climacommon/2024_03_18 env: From 84c206b6d8becc1b177d9d12300fd13aee4d28b6 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Thu, 21 Mar 2024 13:06:38 +0200 Subject: [PATCH 16/16] fix size_threshold --- docs/make.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 556c0ae9d1..452b1a226f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -21,7 +21,6 @@ end CairoMakie.activate!(type = "svg") using Oceananigans - using Oceananigans.Units using Oceananigans.Operators using Oceananigans.Diagnostics using Oceananigans.OutputWriters @@ -175,7 +174,7 @@ format = Documenter.HTML(collapselevel = 1, prettyurls = get(ENV, "CI", nothing) == "true", canonical = "https://clima.github.io/OceananigansDocumentation/stable/", mathengine = MathJax3(), - size_threshold = 1MiB, + size_threshold = 2^20, assets = String["assets/citations.css"]) makedocs(sitename = "Oceananigans.jl",