Skip to content

Commit

Permalink
Compute third stage time-step for RK3 in a way that reduces the accum…
Browse files Browse the repository at this point in the history
…ulation of error (#3617)

* Change TimeInterval to avoid roundoff error issue plus some cleanup

* fix typo

* Import fix

* Potentially address overflow problem

* Recompute new third stage time-step to reduce error accumulation

* Make schedule work even with fake models

* Fix tests for TimeInterval

* Fix JLD2 output writer tests

* Fix NetCDF writer test?
  • Loading branch information
glwagner authored Jun 13, 2024
1 parent f3d874c commit 9a23b06
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/TimeSteppers/runge_kutta_3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac
second_stage_Δt = (γ² + ζ²) * Δt
third_stage_Δt = (γ³ + ζ³) * Δt

# Compute the next time step a priori to reduce floating point error accumulation
tⁿ⁺¹ = next_time(model.clock, Δt)

#
# First stage
#
Expand Down Expand Up @@ -132,7 +135,10 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac
calculate_pressure_correction!(model, third_stage_Δt)
pressure_correct_velocities!(model, third_stage_Δt)

tick!(model.clock, third_stage_Δt)
# This formulation of the final time-step reduces the accumulation of round-off error when Δt
# is added to model.clock.time.
corrected_third_stage_Δt = tⁿ⁺¹ - model.clock.time
tick!(model.clock, corrected_third_stage_Δt)
update_state!(model, callbacks; compute_tendencies)
step_lagrangian_particles!(model, third_stage_Δt)

Expand Down

0 comments on commit 9a23b06

Please sign in to comment.