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

set! for time step #650

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- set! for time step [#650](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/650)
- Bug: ZonalWind had sqrt of negative for uncommon resolutions [#649](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/649)
- Spectral Gradients are now differentiable, with correctness check in extended CI [#638](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/638)[#651](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/651)
- Tracer advection [#579](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/579)
Expand Down
25 changes: 24 additions & 1 deletion src/dynamics/time_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,37 @@ function initialize!(L::Leapfrog, model::AbstractModel)
L.Δt = L.Δt_sec/L.radius
end

# check how time stepping time step and output time step align
# check how time steps from time integration and output align
n = round(Int, Millisecond(output_dt).value/L.Δt_millisec.value)
nΔt = n*L.Δt_millisec
if nΔt != output_dt
@warn "$n steps of Δt = $(L.Δt_millisec.value)ms yield output every $(nΔt.value)ms (=$(nΔt.value/1000)s), but output_dt = $(output_dt.value)s"
end
end

"""$(TYPEDSIGNATURES)
Change time step of timestepper `L` to `Δt` (unscaled)
and disables adjustment to output frequency."""
function set!(
L::AbstractTimeStepper,
Δt::Period, # unscaled time step in Second, Minute, ...
)
L.Δt_millisec = Millisecond(Δt) # recalculate all Δt fields
L.Δt_sec = L.Δt_millisec.value/1000
L.Δt = L.Δt_sec/L.radius

# recalculate the default time step at resolution T31 to be consistent
resolution_factor = (L.trunc+1)/(DEFAULT_TRUNC+1)
L.Δt_at_T31 = Second(round(Int, L.Δt_sec*resolution_factor))

# given Δt was manually set disallow adjustment to output frequency
L.adjust_with_output = false
return L
end

# also allow for keyword arguments
set!(L::AbstractTimeStepper; Δt::Period) = set!(L, Δt)

"""
$(TYPEDSIGNATURES)
Performs one leapfrog time step with (`lf=2`) or without (`lf=1`) Robert+Williams filter
Expand Down
12 changes: 12 additions & 0 deletions test/time_stepping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,16 @@ end
@test M_Ronly < 1
@test M_Ronly <= M_RAW
end
end

@testset "Set timestep manually" begin
@testset for trunc in (31, 63, 127)
spectral_grid = SpectralGrid(; trunc)
time_stepping = Leapfrog(spectral_grid)
set!(time_stepping, Minute(10))
@test time_stepping.Δt_sec == 10*60

set!(time_stepping, Δt=Minute(20))
@test time_stepping.Δt_sec == 20*60
end
end
Loading