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 2 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
18 changes: 16 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: aligned_time_step
import Oceananigans.Utils: 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_Δt(sim, aligned_Δt)
clock = sim.model.clock
activities = collect_scheduled_activities(sim)
Expand Down Expand Up @@ -131,7 +140,12 @@ 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.Δt / 1e10)
tomchor marked this conversation as resolved.
Show resolved Hide resolved
time_step!(sim.model, Δt, callbacks=model_callbacks)
else
println("Skipping aligned time step, which is of ", Δt)
sim.model.clock.time = next_actuation_time(sim)
Copy link
Member

Choose a reason for hiding this comment

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

Could this also be

Suggested change
sim.model.clock.time = next_actuation_time(sim)
sim.model.clock.time += Δt

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this works when we're almost at next_actuation_time since it would skip that actuation time, no?

Copy link
Member

Choose a reason for hiding this comment

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

What is

sim.model.clock.time + Δt

vs

next_actuation_time(sim)

?

Copy link
Member

Choose a reason for hiding this comment

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

@tomchor still have this question

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, sorry I missed this. It's been so long that I forgot the details, but looking at the code for both, it's possible they end up calculating the same thing since Δt is calculated with aligned_time_step().

end
end

# Callbacks and callback-like things
Expand Down
7 changes: 5 additions & 2 deletions src/Utils/schedules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ function (schedule::TimeInterval)(model)
end
end

next_actuation_time(schedule::TimeInterval) = schedule.previous_actuation_time + schedule.interval

function aligned_time_step(schedule::TimeInterval, clock, Δt)
next_actuation_time = schedule.previous_actuation_time + schedule.interval
return min(Δt, next_actuation_time - clock.time)
return min(Δt, next_actuation_time(schedule::TimeInterval) - clock.time)
end

#####
Expand All @@ -90,6 +91,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