Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(0.95.3) Reset model clock and skip time_step!ing if next actuation time is tiny #3606

Merged
merged 27 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
29709d4
reset model clock and skip time_step if next_actuation_time is really…
tomchor May 24, 2024
ed130ee
move next_actuation_time definition to after IterationInterval is def…
tomchor May 24, 2024
af8e6b2
Merge branch 'main' into tc/timestepping
tomchor Jun 5, 2024
b469a9b
Merge branch 'main' into tc/timestepping
tomchor Jun 18, 2024
d50db47
Merge branch 'main' into tc/timestepping
tomchor Jun 18, 2024
77b3211
Merge branch 'main' into tc/timestepping
tomchor Nov 16, 2024
efc4507
Merge branch 'main' into tc/timestepping
tomchor Nov 18, 2024
d6b0ca4
bugfix
tomchor Nov 18, 2024
c40fa48
Merge branch 'main' into tc/timestepping
tomchor Nov 20, 2024
6aef5b7
Merge branch 'main' into tc/timestepping
tomchor Dec 11, 2024
fcc4a00
Merge branch 'main' into tc/timestepping
tomchor Dec 13, 2024
182bed2
Merge branch 'main' into tc/timestepping
tomchor Dec 13, 2024
218d803
add minimum_relative_step to Simulation
tomchor Dec 13, 2024
e4aabf3
apply logic
tomchor Dec 14, 2024
1879d47
Merge branch 'main' into tc/timestepping
tomchor Dec 14, 2024
8c8285f
bump minor version
tomchor Dec 14, 2024
36a2197
Update src/Simulations/simulation.jl
tomchor Dec 14, 2024
5b062d6
added minimum_time_step to docstring
tomchor Dec 14, 2024
44efaab
better logic
tomchor Dec 15, 2024
80870de
add test
tomchor Dec 15, 2024
6d0202b
Merge branch 'main' into tc/timestepping
tomchor Dec 15, 2024
4fee2b6
fix test
tomchor Dec 15, 2024
eaa200a
update docstring call signature
tomchor Dec 15, 2024
ab1ebad
don't use next_actuation_time for setting next_time
tomchor Dec 16, 2024
459538e
Merge branch 'main' into tc/timestepping
tomchor Dec 16, 2024
c006efd
Update src/Simulations/run.jl
tomchor Dec 16, 2024
d615944
Merge branch 'main' into tc/timestepping
tomchor Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Simulations/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using Oceananigans: AbstractModel, run_diagnostic!, write_output!
import Oceananigans: initialize!
import Oceananigans.OutputWriters: checkpoint_path, set!
import Oceananigans.TimeSteppers: time_step!
import Oceananigans.Utils: schedule_aligned_time_step
import Oceananigans.Utils: schedule_aligned_time_step, next_actuation_time

# Simulations are for running

Expand All @@ -21,6 +21,15 @@ function collect_scheduled_activities(sim)
return tuple(writers..., callbacks...)
end

function next_actuation_time(sim::Simulation)
activities = collect_scheduled_activities(sim)
nearest_next_actuation_time = Inf
for activity in activities
nearest_next_actuation_time = min(nearest_next_actuation_time, next_actuation_time(activity.schedule))
end
return nearest_next_actuation_time
end

function schedule_aligned_time_step(sim, aligned_Δt)
clock = sim.model.clock
activities = collect_scheduled_activities(sim)
Expand Down Expand Up @@ -131,7 +140,13 @@ function time_step!(sim::Simulation)

else # business as usual...
Δt = aligned_time_step(sim, sim.Δt)
time_step!(sim.model, Δt, callbacks=model_callbacks)
if Δt < sim.minimum_relative_step * sim.Δt
next_time = next_actuation_time(sim)
@warn "Reseting clock to $next_time and skipping aligned time step Δt = $Δt"
sim.model.clock.time = next_time
else
time_step!(sim.model, Δt, callbacks=model_callbacks)
end
end

# Callbacks and callback-like things
Expand Down
32 changes: 18 additions & 14 deletions src/Simulations/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import Oceananigans.TimeSteppers: reset!
default_progress(simulation) = nothing

mutable struct Simulation{ML, DT, ST, DI, OW, CB}
model :: ML
Δt :: DT
stop_iteration :: Float64
stop_time :: ST
wall_time_limit :: Float64
diagnostics :: DI
output_writers :: OW
callbacks :: CB
run_wall_time :: Float64
running :: Bool
initialized :: Bool
verbose :: Bool
model :: ML
Δt :: DT
stop_iteration :: Float64
stop_time :: ST
wall_time_limit :: Float64
diagnostics :: DI
output_writers :: OW
callbacks :: CB
run_wall_time :: Float64
running :: Bool
initialized :: Bool
verbose :: Bool
minimum_relative_step :: Float64
end

"""
Expand Down Expand Up @@ -49,7 +50,8 @@ function Simulation(model; Δt,
verbose = true,
stop_iteration = Inf,
stop_time = Inf,
wall_time_limit = Inf)
wall_time_limit = Inf,
minimum_relative_step = 0)
tomchor marked this conversation as resolved.
Show resolved Hide resolved

if stop_iteration == Inf && stop_time == Inf && wall_time_limit == Inf
@warn "This simulation will run forever as stop iteration = stop time " *
Expand Down Expand Up @@ -88,7 +90,8 @@ function Simulation(model; Δt,
0.0,
false,
false,
verbose)
verbose,
Float64(minimum_relative_step))
tomchor marked this conversation as resolved.
Show resolved Hide resolved
end

function Base.show(io::IO, s::Simulation)
Expand All @@ -100,6 +103,7 @@ function Base.show(io::IO, s::Simulation)
"├── Stop time: $(prettytime(s.stop_time))", "\n",
"├── Stop iteration: $(s.stop_iteration)", "\n",
"├── Wall time limit: $(s.wall_time_limit)", "\n",
"├── Minimum relative step: $(s.minimum_relative_step)", "\n",
tomchor marked this conversation as resolved.
Show resolved Hide resolved
"├── Callbacks: $(ordered_dict_show(s.callbacks, "│"))", "\n",
"├── Output writers: $(ordered_dict_show(s.output_writers, "│"))", "\n",
"└── Diagnostics: $(ordered_dict_show(s.diagnostics, "│"))")
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/schedules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ IterationInterval(interval; offset=0) = IterationInterval(interval, offset)

(schedule::IterationInterval)(model) = (model.clock.iteration - schedule.offset) % schedule.interval == 0

next_actuation_time(schedule::IterationInterval) = Inf

#####
##### WallTimeInterval
#####
Expand Down
Loading