From 79b49a058fb56b11562307fae91ad8cfef9cd20b Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 9 May 2024 13:25:10 -0600 Subject: [PATCH 01/15] =?UTF-8?q?Remove=20instances=20of=20previous=5F?= =?UTF-8?q?=CE=94t=20and=20fix=20a=20bug=20in=20RK3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prescribed_hydrostatic_velocity_fields.jl | 2 +- src/OutputWriters/checkpointer.jl | 7 +++---- src/OutputWriters/output_writer_utils.jl | 1 - src/Simulations/time_step_wizard.jl | 2 +- src/Solvers/heptadiagonal_iterative_solver.jl | 8 ++++---- src/TimeSteppers/clock.jl | 2 -- src/TimeSteppers/quasi_adams_bashforth_2.jl | 11 +++-------- src/TimeSteppers/runge_kutta_3.jl | 1 + 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Models/HydrostaticFreeSurfaceModels/prescribed_hydrostatic_velocity_fields.jl b/src/Models/HydrostaticFreeSurfaceModels/prescribed_hydrostatic_velocity_fields.jl index 471f5468f2..7a34bad052 100644 --- a/src/Models/HydrostaticFreeSurfaceModels/prescribed_hydrostatic_velocity_fields.jl +++ b/src/Models/HydrostaticFreeSurfaceModels/prescribed_hydrostatic_velocity_fields.jl @@ -124,8 +124,8 @@ const OnlyParticleTrackingModel = HydrostaticFreeSurfaceModel{TS, E, A, S, G, T, {TS, E, A, S, G, T, V, B, R, F, P<:AbstractLagrangianParticles, U<:PrescribedVelocityFields, C<:NamedTuple{(), Tuple{}}} function time_step!(model::OnlyParticleTrackingModel, Δt; callbacks = [], kwargs...) - model.timestepper.previous_Δt = Δt tick!(model.clock, Δt) + model.clock.last_Δt = Δt step_lagrangian_particles!(model, Δt) update_state!(model, callbacks) end diff --git a/src/OutputWriters/checkpointer.jl b/src/OutputWriters/checkpointer.jl index b70577c7a3..d2da594e08 100644 --- a/src/OutputWriters/checkpointer.jl +++ b/src/OutputWriters/checkpointer.jl @@ -230,6 +230,7 @@ function set!(model, filepath::AbstractString) # Update model clock model.clock.iteration = checkpointed_clock.iteration model.clock.time = checkpointed_clock.time + model.clock.last_Δt = checkpointed_clock.last_Δt end return nothing @@ -260,8 +261,6 @@ end set_time_stepper!(timestepper::RungeKutta3TimeStepper, file, model_fields) = set_time_stepper_tendencies!(timestepper, file, model_fields) -function set_time_stepper!(timestepper::QuasiAdamsBashforth2TimeStepper, file, model_fields) +set_time_stepper!(timestepper::QuasiAdamsBashforth2TimeStepper, file, model_fields) = set_time_stepper_tendencies!(timestepper, file, model_fields) - timestepper.previous_Δt = file["timestepper/previous_Δt"] - return nothing -end + diff --git a/src/OutputWriters/output_writer_utils.jl b/src/OutputWriters/output_writer_utils.jl index 9218e44d58..24f6d1fd92 100644 --- a/src/OutputWriters/output_writer_utils.jl +++ b/src/OutputWriters/output_writer_utils.jl @@ -160,7 +160,6 @@ end function serializeproperty!(file, address, ts::QuasiAdamsBashforth2TimeStepper) serializeproperty!(file, address * "/Gⁿ", ts.Gⁿ) serializeproperty!(file, address * "/G⁻", ts.G⁻) - serializeproperty!(file, address * "/previous_Δt", ts.previous_Δt) return nothing end diff --git a/src/Simulations/time_step_wizard.jl b/src/Simulations/time_step_wizard.jl index 18ec2b86fb..d8773d5e7f 100644 --- a/src/Simulations/time_step_wizard.jl +++ b/src/Simulations/time_step_wizard.jl @@ -35,7 +35,7 @@ for advective and diffusive Courant-Friedrichs-Lewy (CFL) numbers (`cfl` and `di subject to the limits ```julia -max(min_Δt, min_change * previous_Δt) ≤ new_Δt ≤ min(max_Δt, max_change * previous_Δt) +max(min_Δt, min_change * last_Δt) ≤ new_Δt ≤ min(max_Δt, max_change * last_Δt) ``` where `new_Δt` is the new time step calculated by the `TimeStepWizard`. diff --git a/src/Solvers/heptadiagonal_iterative_solver.jl b/src/Solvers/heptadiagonal_iterative_solver.jl index d3fb92f86a..c67a500ef9 100644 --- a/src/Solvers/heptadiagonal_iterative_solver.jl +++ b/src/Solvers/heptadiagonal_iterative_solver.jl @@ -21,7 +21,7 @@ mutable struct HeptadiagonalIterativeSolver{G, R, L, D, M, P, PM, PS, I, ST, T, iterative_solver :: I state_vars :: ST tolerance :: T - previous_Δt :: F + last_Δt :: F maximum_iterations :: Int verbose :: Bool end @@ -70,7 +70,7 @@ The matrix constructors are calculated based on the pentadiagonal coeffients pas to `matrix_from_coefficients` function. To allow for variable time step, the diagonal term `- Az / (g * Δt²)` is only added later on -and it is updated only when the previous time step changes (`previous_Δt != Δt`). +and it is updated only when the previous time step changes (`last_Δt != Δt`). Preconditioning is done through the various methods implemented in `Solvers/sparse_preconditioners.jl`. @@ -296,7 +296,7 @@ function solve!(x, solver::HeptadiagonalIterativeSolver, b, Δt) arch = architecture(solver.matrix) # update matrix and preconditioner if time step changes - if Δt != solver.previous_Δt + if Δt != solver.last_Δt constructors = deepcopy(solver.matrix_constructors) M = prod(solver.problem_size) update_diag!(constructors, arch, M, M, solver.diagonal, Δt, 0) @@ -308,7 +308,7 @@ function solve!(x, solver::HeptadiagonalIterativeSolver, b, Δt) solver.matrix, solver.preconditioner_settings) - solver.previous_Δt = Δt + solver.last_Δt = Δt end solver.iterative_solver(x, solver.matrix, b, diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index b1b8da173b..eef886b858 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -61,8 +61,6 @@ function tick!(clock, Δt; stage=false) tick_time!(clock, Δt) - clock.last_Δt = Δt - if stage # tick a stage update clock.stage += 1 else # tick an iteration and reset stage diff --git a/src/TimeSteppers/quasi_adams_bashforth_2.jl b/src/TimeSteppers/quasi_adams_bashforth_2.jl index 780df779b6..5db8ba2d66 100644 --- a/src/TimeSteppers/quasi_adams_bashforth_2.jl +++ b/src/TimeSteppers/quasi_adams_bashforth_2.jl @@ -5,7 +5,6 @@ using Oceananigans.ImmersedBoundaries: ActiveCellsIBG, active_linear_index_to_tu mutable struct QuasiAdamsBashforth2TimeStepper{FT, GT, IT} <: AbstractTimeStepper χ :: FT - previous_Δt :: FT Gⁿ :: GT G⁻ :: GT implicit_solver :: IT @@ -53,10 +52,7 @@ function QuasiAdamsBashforth2TimeStepper(grid, tracers, return QuasiAdamsBashforth2TimeStepper{FT, GT, IT}(χ, Inf, Gⁿ, G⁻, implicit_solver) end -function reset!(timestepper::QuasiAdamsBashforth2TimeStepper) - timestepper.previous_Δt = Inf - return nothing -end +reset!(timestepper::QuasiAdamsBashforth2TimeStepper) = nothing ##### ##### Time steppping @@ -73,7 +69,7 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt Δt == 0 && @warn "Δt == 0 may cause model blowup!" # Shenanigans for properly starting the AB2 loop with an Euler step - euler = euler || (Δt != model.timestepper.previous_Δt) + euler = euler || (Δt != model.clock.last_Δt) χ = ifelse(euler, convert(eltype(model.grid), -0.5), model.timestepper.χ) @@ -86,8 +82,6 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt end end - model.timestepper.previous_Δt = Δt - # Be paranoid and update state at iteration 0 model.clock.iteration == 0 && update_state!(model, callbacks) @@ -97,6 +91,7 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt @apply_regionally correct_velocities_and_store_tendecies!(model, Δt) tick!(model.clock, Δt) + clock.last_Δt = Δt update_state!(model, callbacks; compute_tendencies) step_lagrangian_particles!(model, Δt) diff --git a/src/TimeSteppers/runge_kutta_3.jl b/src/TimeSteppers/runge_kutta_3.jl index 9c706c88ff..8f4c2d3315 100644 --- a/src/TimeSteppers/runge_kutta_3.jl +++ b/src/TimeSteppers/runge_kutta_3.jl @@ -133,6 +133,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, third_stage_Δt) tick!(model.clock, third_stage_Δt) + clock.last_Δt = Δt update_state!(model, callbacks; compute_tendencies) step_lagrangian_particles!(model, third_stage_Δt) From 845bc07b9410f1a7631a5379594905146e44760b Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Mon, 13 May 2024 14:53:46 -0600 Subject: [PATCH 02/15] Add the "stage" time step to Clock --- src/TimeSteppers/clock.jl | 50 +++++++++++++++++++++++-------- src/TimeSteppers/runge_kutta_3.jl | 3 ++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index eef886b858..dd2d095d72 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -13,19 +13,31 @@ The `stage` is updated only for multi-stage time-stepping methods. The `time::T` either a number or a `DateTime` object. """ mutable struct Clock{TT, DT} - time :: TT - last_Δt :: DT + time :: TT + last_Δt :: DT + last_stage_Δt :: DT iteration :: Int - stage :: Int + stage :: Int end """ - Clock(; time, last_Δt = Inf, iteration=0, stage=1) + Clock(; time, last_Δt=Inf, last_stage_Δt=Inf, iteration=0, stage=1) Returns a `Clock` object. By default, `Clock` is initialized to the zeroth `iteration` -and first time step `stage` with `last_Δt`. +and first time step `stage` with `last_Δt=last_stage_Δt=Inf`. """ -Clock(; time::TT, last_Δt::DT=Inf, iteration=0, stage=1) where {TT, DT} = Clock{TT, DT}(time, last_Δt, iteration, stage) +function Clock(; time, + last_Δt = Inf, + last_stage_Δt = Inf, + iteration = 0, + stage = 1) + + TT = typeof(time) + DT = typeof(last_Δt) + last_stage_Δt = convert(DT, last_Δt) + return Clock{TT, DT}(time, last_Δt, last_stage_Δt, iteration, stage) +end + # TODO: when supporting DateTime, this function will have to be extended time_step_type(TT) = TT @@ -35,10 +47,20 @@ function Clock{TT}(; time, last_Δt=Inf, iteration=0, stage=1) where TT 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)))") +function Base.summary(clock::Clock) + TT = typeof(clock.time) + DT = typeof(clock.last_Δt) + return string("Clock{", TT, ", ", DT, "}", + "(time=", prettytime(clock.time), + " iteration=", clock.iteration, + " last_Δt=", prettytime(clock.last_Δt), ")") +end -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)") +function Base.show(io::IO, clock::Clock) + return print(io, summary(clock), '\n', + "├── stage: ", clock.stage, '\n', + "└── last_stage_Δt: ", prettytime(clock.last_stage_Δt)) +end next_time(clock, Δt) = clock.time + Δt next_time(clock::Clock{<:AbstractTime}, Δt) = clock.time + Nanosecond(round(Int, 1e9 * Δt)) @@ -71,7 +93,11 @@ function tick!(clock, Δt; stage=false) return nothing 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 `Clock` for GPU.""" +Adapt.adapt_structure(to, clock::Clock) = (time = clock.time, + last_Δt = clock.last_Δt, + last_stage_Δt = clock.last_stage_Δt, + iteration = clock.iteration, + stage = clock.stage) + diff --git a/src/TimeSteppers/runge_kutta_3.jl b/src/TimeSteppers/runge_kutta_3.jl index 8f4c2d3315..1e4a54c12c 100644 --- a/src/TimeSteppers/runge_kutta_3.jl +++ b/src/TimeSteppers/runge_kutta_3.jl @@ -105,6 +105,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, first_stage_Δt) tick!(model.clock, first_stage_Δt; stage=true) + clock.last_stage_Δt = first_stage_Δt store_tendencies!(model) update_state!(model, callbacks) step_lagrangian_particles!(model, first_stage_Δt) @@ -119,6 +120,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, second_stage_Δt) tick!(model.clock, second_stage_Δt; stage=true) + clock.last_stage_Δt = second_stage_Δt store_tendencies!(model) update_state!(model, callbacks) step_lagrangian_particles!(model, second_stage_Δt) @@ -133,6 +135,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, third_stage_Δt) tick!(model.clock, third_stage_Δt) + clock.last_stage_Δt = third_stage_Δt clock.last_Δt = Δt update_state!(model, callbacks; compute_tendencies) step_lagrangian_particles!(model, third_stage_Δt) From 8a25326fd402e49d6d12d445156018b53f8939e0 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Tue, 14 May 2024 11:06:41 -0600 Subject: [PATCH 03/15] Update the other constructor --- src/TimeSteppers/clock.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index dd2d095d72..b710ea21ef 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -41,10 +41,17 @@ end # 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 +function Clock{TT}(; time, + last_Δt = Inf, + last_stage_Δt = Inf, + iteration = 0, + stage = 1) + DT = time_step_type(TT) last_Δt = convert(DT, last_Δt) - return Clock{TT, DT}(time, last_Δt, iteration, stage) + last_stage_Δt = convert(DT, last_stage_Δt) + + return Clock{TT, DT}(time, last_Δt, last_stage_Δt, iteration, stage) end function Base.summary(clock::Clock) From da1c8249bff48efd36dee87c2b80e3a16a1a4b5a Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Tue, 14 May 2024 11:24:53 -0600 Subject: [PATCH 04/15] Bugfix --- 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 b710ea21ef..57463f136b 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -45,7 +45,7 @@ function Clock{TT}(; time, last_Δt = Inf, last_stage_Δt = Inf, iteration = 0, - stage = 1) + stage = 1) where TT DT = time_step_type(TT) last_Δt = convert(DT, last_Δt) From 18282adfff39b5c910f4b76344b9199269b3bf23 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 16 May 2024 06:53:31 -0600 Subject: [PATCH 05/15] Also set the stage dt in AB2 --- src/TimeSteppers/quasi_adams_bashforth_2.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TimeSteppers/quasi_adams_bashforth_2.jl b/src/TimeSteppers/quasi_adams_bashforth_2.jl index 5db8ba2d66..0a8cc786dd 100644 --- a/src/TimeSteppers/quasi_adams_bashforth_2.jl +++ b/src/TimeSteppers/quasi_adams_bashforth_2.jl @@ -92,6 +92,7 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt tick!(model.clock, Δt) clock.last_Δt = Δt + clock.last_stage_Δt = Δt # just one stage update_state!(model, callbacks; compute_tendencies) step_lagrangian_particles!(model, Δt) From 3bfd4da5b35255a977c746e32a51ff73b03aa70d Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 16 May 2024 10:30:54 -0600 Subject: [PATCH 06/15] Fix constructor for AB2 --- src/TimeSteppers/quasi_adams_bashforth_2.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/TimeSteppers/quasi_adams_bashforth_2.jl b/src/TimeSteppers/quasi_adams_bashforth_2.jl index 0a8cc786dd..6be8f799bd 100644 --- a/src/TimeSteppers/quasi_adams_bashforth_2.jl +++ b/src/TimeSteppers/quasi_adams_bashforth_2.jl @@ -49,7 +49,7 @@ function QuasiAdamsBashforth2TimeStepper(grid, tracers, GT = typeof(Gⁿ) χ = convert(FT, χ) - return QuasiAdamsBashforth2TimeStepper{FT, GT, IT}(χ, Inf, Gⁿ, G⁻, implicit_solver) + return QuasiAdamsBashforth2TimeStepper{FT, GT, IT}(χ, Gⁿ, G⁻, implicit_solver) end reset!(timestepper::QuasiAdamsBashforth2TimeStepper) = nothing @@ -65,7 +65,9 @@ Step forward `model` one time step `Δt` with a 2nd-order Adams-Bashforth method pressure-correction substep. Setting `euler=true` will take a forward Euler time step. Setting `compute_tendencies=false` will not calculate new tendencies """ -function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt; callbacks=[], euler=false, compute_tendencies=true) +function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt; + callbacks=[], euler=false, compute_tendencies=true) + Δt == 0 && @warn "Δt == 0 may cause model blowup!" # Shenanigans for properly starting the AB2 loop with an Euler step @@ -155,3 +157,4 @@ Time step velocity fields via the 2nd-order quasi Adams-Bashforth method end @kernel ab2_step_field!(::FunctionField, Δt, χ, Gⁿ, G⁻) = nothing + From dd3e5b532a55e2eaca2f549fae48f7f50aa5be2d Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 16 May 2024 10:31:19 -0600 Subject: [PATCH 07/15] Bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 552bfcb4b8..c56b10d0c9 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.91.0" +version = "0.91.1" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From ae8d9eb2394a14794e662f41fee13786a7cb0065 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Mon, 20 May 2024 09:16:16 -0600 Subject: [PATCH 08/15] Fix simple bug --- src/TimeSteppers/quasi_adams_bashforth_2.jl | 4 ++-- src/TimeSteppers/runge_kutta_3.jl | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TimeSteppers/quasi_adams_bashforth_2.jl b/src/TimeSteppers/quasi_adams_bashforth_2.jl index 6be8f799bd..7d02d9eb59 100644 --- a/src/TimeSteppers/quasi_adams_bashforth_2.jl +++ b/src/TimeSteppers/quasi_adams_bashforth_2.jl @@ -93,8 +93,8 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt @apply_regionally correct_velocities_and_store_tendecies!(model, Δt) tick!(model.clock, Δt) - clock.last_Δt = Δt - clock.last_stage_Δt = Δt # just one stage + model.clock.last_Δt = Δt + model.clock.last_stage_Δt = Δt # just one stage update_state!(model, callbacks; compute_tendencies) step_lagrangian_particles!(model, Δt) diff --git a/src/TimeSteppers/runge_kutta_3.jl b/src/TimeSteppers/runge_kutta_3.jl index 1e4a54c12c..533caa2f6e 100644 --- a/src/TimeSteppers/runge_kutta_3.jl +++ b/src/TimeSteppers/runge_kutta_3.jl @@ -105,7 +105,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, first_stage_Δt) tick!(model.clock, first_stage_Δt; stage=true) - clock.last_stage_Δt = first_stage_Δt + model.clock.last_stage_Δt = first_stage_Δt store_tendencies!(model) update_state!(model, callbacks) step_lagrangian_particles!(model, first_stage_Δt) @@ -120,7 +120,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, second_stage_Δt) tick!(model.clock, second_stage_Δt; stage=true) - clock.last_stage_Δt = second_stage_Δt + model.clock.last_stage_Δt = second_stage_Δt store_tendencies!(model) update_state!(model, callbacks) step_lagrangian_particles!(model, second_stage_Δt) @@ -135,8 +135,8 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac pressure_correct_velocities!(model, third_stage_Δt) tick!(model.clock, third_stage_Δt) - clock.last_stage_Δt = third_stage_Δt - clock.last_Δt = Δt + model.clock.last_stage_Δt = third_stage_Δt + model.clock.last_Δt = Δt update_state!(model, callbacks; compute_tendencies) step_lagrangian_particles!(model, third_stage_Δt) From 8552570f5748d4e25f978ed2a199064b7a630636 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Wed, 22 May 2024 09:07:55 -0600 Subject: [PATCH 09/15] =?UTF-8?q?Fix=20tests=20that=20used=20previous=5F?= =?UTF-8?q?=CE=94t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ocean_large_eddy_simulation_regression_test.jl | 2 +- test/regression_tests/rayleigh_benard_regression_test.jl | 2 +- test/test_checkpointer.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/regression_tests/ocean_large_eddy_simulation_regression_test.jl b/test/regression_tests/ocean_large_eddy_simulation_regression_test.jl index 395d8ecb60..543c96b1bc 100644 --- a/test/regression_tests/ocean_large_eddy_simulation_regression_test.jl +++ b/test/regression_tests/ocean_large_eddy_simulation_regression_test.jl @@ -102,7 +102,7 @@ function run_ocean_large_eddy_simulation_regression_test(arch, grid_type, closur model.clock.iteration = spinup_steps update_state!(model; compute_tendencies = true) - model.timestepper.previous_Δt = Δt + model.clock.last_Δt = Δt for n in 1:test_steps time_step!(model, Δt, euler=false) diff --git a/test/regression_tests/rayleigh_benard_regression_test.jl b/test/regression_tests/rayleigh_benard_regression_test.jl index 2f64eb30aa..ac86333ad4 100644 --- a/test/regression_tests/rayleigh_benard_regression_test.jl +++ b/test/regression_tests/rayleigh_benard_regression_test.jl @@ -125,7 +125,7 @@ function run_rayleigh_benard_regression_test(arch, grid_type) # Step the model forward and perform the regression test update_state!(model) - model.timestepper.previous_Δt = Δt + model.clock.last_Δt = Δt for n in 1:test_steps time_step!(model, Δt, euler=false) diff --git a/test/test_checkpointer.jl b/test/test_checkpointer.jl index 234bd590ef..66e8f6b5b5 100644 --- a/test/test_checkpointer.jl +++ b/test/test_checkpointer.jl @@ -102,7 +102,7 @@ function run_checkpointer_tests(true_model, test_model, Δt) test_model_equality(test_model, checkpointed_model) # This only applies to QuasiAdamsBashforthTimeStepper: - @test test_model.timestepper.previous_Δt == checkpointed_model.timestepper.previous_Δt + @test test_model.clock.last_Δt == checkpointed_model.clock.last_Δt ##### ##### Test pickup from explicit checkpoint path From 03ae2469b7bfdf0391ac937a85efcc13b1f51751 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Wed, 22 May 2024 09:09:22 -0600 Subject: [PATCH 10/15] Fix shallow water model constructor --- src/Models/ShallowWaterModels/shallow_water_model.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/ShallowWaterModels/shallow_water_model.jl b/src/Models/ShallowWaterModels/shallow_water_model.jl index bd46367ba9..9c5778ac14 100644 --- a/src/Models/ShallowWaterModels/shallow_water_model.jl +++ b/src/Models/ShallowWaterModels/shallow_water_model.jl @@ -112,7 +112,7 @@ Keyword arguments function 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(), From d37d429d61785f93cab9ae13a97b4079bee560d3 Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Thu, 6 Jun 2024 20:55:39 +0200 Subject: [PATCH 11/15] Update clock.md --- docs/src/model_setup/clock.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/src/model_setup/clock.md b/docs/src/model_setup/clock.md index c2d2a2eb2b..de42741bd3 100644 --- a/docs/src/model_setup/clock.md +++ b/docs/src/model_setup/clock.md @@ -14,7 +14,9 @@ end ```jldoctest julia> clock = Clock(time=0.0) -Clock{Float64, Float64}: time = 0 seconds, last_Δt = Inf days, iteration = 0, stage = 1 +Clock{Float64, Float64}(time=0 seconds iteration=0 last_Δt=Inf days) +├── stage: 1 +└── last_stage_Δt: Inf days ``` but can be modified to start the model clock at some other time. @@ -22,7 +24,9 @@ For example, passing ```jldoctest julia> clock = Clock(time=3600.0) -Clock{Float64, Float64}: time = 1 hour, last_Δt = Inf days, iteration = 0, stage = 1 +Clock{Float64, Float64}(time=1 hour iteration=0 last_Δt=Inf days) +├── stage: 1 +└── last_stage_Δt: Inf days ``` to the constructor for `NonhydrostaticModel` causes the simulation @@ -37,7 +41,9 @@ for example, pass julia> using TimesDates julia> clock = Clock(time=TimeDate(2020)) -Clock{TimesDates.TimeDate, Float64}: time = 2020-01-01T00:00:00, last_Δt = Inf days, iteration = 0, stage = 1 +Clock{TimesDates.TimeDate, Float64}(time=2020-01-01T00:00:00 iteration=0 last_Δt=Inf days) +├── stage: 1 +└── last_stage_Δt: Inf days ``` to `NonhydrostaticModel`. `TimesDates.TimeDate` supports nanosecond resolution and is thus recommended From c506e5054b07c6731b30a7215367fa8de6660798 Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Fri, 7 Jun 2024 06:27:54 -0600 Subject: [PATCH 12/15] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c56b10d0c9..5d2eb1405e 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.91.1" +version = "0.91.2" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From c76188ced3dbcdebdeaa43a76a150e4eea10fda5 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Fri, 7 Jun 2024 09:31:15 -0600 Subject: [PATCH 13/15] Bugfix --- src/TimeSteppers/quasi_adams_bashforth_2.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TimeSteppers/quasi_adams_bashforth_2.jl b/src/TimeSteppers/quasi_adams_bashforth_2.jl index 68e50682cb..ff8e3e7203 100644 --- a/src/TimeSteppers/quasi_adams_bashforth_2.jl +++ b/src/TimeSteppers/quasi_adams_bashforth_2.jl @@ -79,14 +79,14 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt # need to take an euler step. Note that model.clock.last_Δt is # initialized as Inf # * The user has passed euler=true to time_step! - χ₀ = ab2_timestepper.χ - euler = euler || (Δt != ab2_timestepper.previous_Δt) + euler = euler || (Δt != model.clock.last_Δt) # If euler, then set χ = -0.5 minus_point_five = convert(eltype(model.grid), -0.5) χ = ifelse(euler, minus_point_five, ab2_timestepper.χ) # Set time-stepper χ (this is used in ab2_step!, but may also be used elsewhere) + χ₀ = ab2_timestepper.χ # Save initial value ab2_timestepper.χ = χ ab2_timestepper.previous_Δt = Δt From f00fd58a838bb4363d88bba0dec58d54318d170c Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Fri, 7 Jun 2024 10:02:25 -0600 Subject: [PATCH 14/15] Another bugbix --- src/TimeSteppers/quasi_adams_bashforth_2.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TimeSteppers/quasi_adams_bashforth_2.jl b/src/TimeSteppers/quasi_adams_bashforth_2.jl index ff8e3e7203..77fa882702 100644 --- a/src/TimeSteppers/quasi_adams_bashforth_2.jl +++ b/src/TimeSteppers/quasi_adams_bashforth_2.jl @@ -88,7 +88,6 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt # Set time-stepper χ (this is used in ab2_step!, but may also be used elsewhere) χ₀ = ab2_timestepper.χ # Save initial value ab2_timestepper.χ = χ - ab2_timestepper.previous_Δt = Δt # Ensure zeroing out all previous tendency fields to avoid errors in # case G⁻ includes NaNs. See https://github.com/CliMA/Oceananigans.jl/issues/2259 From 0ad6f7741eed567d0665f62843f1758ace7b39f9 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 13 Jun 2024 17:01:15 -0600 Subject: [PATCH 15/15] Fix summary and doctests --- docs/src/model_setup/background_fields.md | 4 ++-- docs/src/model_setup/clock.md | 6 +++--- src/TimeSteppers/clock.jl | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/model_setup/background_fields.md b/docs/src/model_setup/background_fields.md index d9cbac2493..428ce03599 100644 --- a/docs/src/model_setup/background_fields.md +++ b/docs/src/model_setup/background_fields.md @@ -59,7 +59,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 1×1×1 halo -├── clock: Clock(time=0 seconds, iteration=0, last_Δt=Inf days) +├── clock: Clock{Float64, Float64}(time=0 seconds, iteration=0, last_Δt=Inf days) └── parameters: nothing ``` @@ -102,6 +102,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 1×1×1 halo -├── clock: Clock(time=0 seconds, iteration=0, last_Δt=Inf days) +├── clock: Clock{Float64, Float64}(time=0 seconds, iteration=0, last_Δt=Inf days) └── parameters: (α = 3.14, N = 1.0, f = 0.1) ``` diff --git a/docs/src/model_setup/clock.md b/docs/src/model_setup/clock.md index de42741bd3..8a8b7c388b 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, Float64}(time=0 seconds iteration=0 last_Δt=Inf days) +Clock{Float64, Float64}(time=0 seconds, iteration=0, last_Δt=Inf days) ├── stage: 1 └── last_stage_Δt: Inf days ``` @@ -24,7 +24,7 @@ For example, passing ```jldoctest julia> clock = Clock(time=3600.0) -Clock{Float64, Float64}(time=1 hour iteration=0 last_Δt=Inf days) +Clock{Float64, Float64}(time=1 hour, iteration=0, last_Δt=Inf days) ├── stage: 1 └── last_stage_Δt: Inf days ``` @@ -41,7 +41,7 @@ for example, pass julia> using TimesDates julia> clock = Clock(time=TimeDate(2020)) -Clock{TimesDates.TimeDate, Float64}(time=2020-01-01T00:00:00 iteration=0 last_Δt=Inf days) +Clock{TimesDates.TimeDate, Float64}(time=2020-01-01T00:00:00, iteration=0, last_Δt=Inf days) ├── stage: 1 └── last_stage_Δt: Inf days ``` diff --git a/src/TimeSteppers/clock.jl b/src/TimeSteppers/clock.jl index 57463f136b..48d8e5172f 100644 --- a/src/TimeSteppers/clock.jl +++ b/src/TimeSteppers/clock.jl @@ -59,8 +59,8 @@ function Base.summary(clock::Clock) DT = typeof(clock.last_Δt) return string("Clock{", TT, ", ", DT, "}", "(time=", prettytime(clock.time), - " iteration=", clock.iteration, - " last_Δt=", prettytime(clock.last_Δt), ")") + ", iteration=", clock.iteration, + ", last_Δt=", prettytime(clock.last_Δt), ")") end function Base.show(io::IO, clock::Clock)