From dfb246820e0c3f6accc3b908cc7c34028698c56a Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 4 Dec 2023 09:47:20 +0100 Subject: [PATCH 1/7] period kwarg --- src/SpeedyWeather.jl | 2 +- src/dynamics/prognostic_variables.jl | 13 ++++++++--- src/output/feedback.jl | 5 ++-- src/run_speedy.jl | 14 ++++++++---- test/dates.jl | 13 +++++++++++ test/netcdf_output.jl | 34 ++++++++++++++-------------- test/run_speedy.jl | 8 +++---- test/vertical_advection.jl | 2 +- 8 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/SpeedyWeather.jl b/src/SpeedyWeather.jl index 3bd0878b4..72b9cf97d 100644 --- a/src/SpeedyWeather.jl +++ b/src/SpeedyWeather.jl @@ -18,7 +18,7 @@ import Adapt: Adapt, adapt, adapt_structure # INPUT OUTPUT import TOML -import Dates: Dates, DateTime, Millisecond, Second, Minute, Hour, Day +import Dates: Dates, DateTime, Period, Millisecond, Second, Minute, Hour, Day import Printf: Printf, @sprintf import NCDatasets: NCDatasets, NCDataset, defDim, defVar import JLD2: jldopen diff --git a/src/dynamics/prognostic_variables.jl b/src/dynamics/prognostic_variables.jl index fd55ccd0a..83c65d6ba 100644 --- a/src/dynamics/prognostic_variables.jl +++ b/src/dynamics/prognostic_variables.jl @@ -10,8 +10,8 @@ Base.@kwdef mutable struct Clock "current model time" time::DateTime = DEFAULT_DATE - "number of days to integrate for, set in run!(::Simulation)" - n_days::Float64 = 0 + "period to integrate for, set in set_period!(::Clock, ::Dates.Period)" + period::Second = Second(0) "number of time steps to integrate for, set in initialize!(::Clock,::TimeStepper)" n_timesteps::Int = 0 @@ -28,10 +28,17 @@ end $(TYPEDSIGNATURES) Initialize the clock with the time step `Δt` in the `time_stepping`.""" function initialize!(clock::Clock,time_stepping::TimeStepper) - clock.n_timesteps = ceil(Int,3600*24*clock.n_days/time_stepping.Δt_sec) + clock.n_timesteps = ceil(Int,clock.period.value/time_stepping.Δt_sec) return clock end +""" +$(TYPEDSIGNATURES) +Set the `period` of the clock to a new value. Converts any `Dates.Period` input to `Second`.""" +function set_period!(clock::Clock,period::Period) + clock.period = Second(period) +end + """ $(TYPEDSIGNATURES) Create and initialize a clock from `time_stepping`""" diff --git a/src/output/feedback.jl b/src/output/feedback.jl index 4486d7566..f3396f6dd 100644 --- a/src/output/feedback.jl +++ b/src/output/feedback.jl @@ -86,7 +86,8 @@ function initialize!(feedback::Feedback,clock::Clock,model::ModelSetup) (; run_path, id) = feedback SG = model.spectral_grid L = model.time_stepping - + period = clock.period.value/(3600*24) + # create progress.txt file in run_????/ progress_txt = open(joinpath(run_path,"progress.txt"),"w") s = "Starting SpeedyWeather.jl run $id on "* @@ -94,7 +95,7 @@ function initialize!(feedback::Feedback,clock::Clock,model::ModelSetup) write(progress_txt,s*"\n") write(progress_txt,"Integrating:\n") write(progress_txt,"$SG\n") - write(progress_txt,"Time: $(clock.n_days) days at Δt = $(L.Δt_sec)s\n") + write(progress_txt,"Time: $period days at Δt = $(L.Δt_sec)s\n") write(progress_txt,"\nAll data will be stored in $run_path\n") feedback.progress_txt = progress_txt end diff --git a/src/run_speedy.jl b/src/run_speedy.jl index ff5dafcce..8acb02b71 100644 --- a/src/run_speedy.jl +++ b/src/run_speedy.jl @@ -2,18 +2,24 @@ $(TYPEDSIGNATURES) Run a SpeedyWeather.jl `simulation`. The `simulation.model` is assumed to be initialized.""" function run!( simulation::Simulation; - n_days::Real = 10, - output::Bool = false) + period::Period = Day(10), + output::Bool = false, + n_days::Union{Nothing, Real}=nothing) + if !isnothing(n_days) + @warn "run!: n_days keyword is deprecated, use period = Day(n_days) instead." + period = Day(n_days) + end + (;prognostic_variables, diagnostic_variables, model) = simulation (;clock) = prognostic_variables # set the clock's enddate - clock.n_days = n_days + set_period!(clock,period) initialize!(clock,model.time_stepping) model.output.output = output # enable/disable output # run it, yeah! time_stepping!(prognostic_variables,diagnostic_variables,model) -end \ No newline at end of file +end diff --git a/test/dates.jl b/test/dates.jl index d6e66e96e..e4240719a 100644 --- a/test/dates.jl +++ b/test/dates.jl @@ -24,4 +24,17 @@ L4 = Leapfrog(SG,Δt_at_T31=Minute(60),adjust_with_output=false) L5 = Leapfrog(SG,Δt_at_T31=Hour(1),adjust_with_output=false) @test L4.Δt == L5.Δt + + # clock tests + c1 = SpeedyWeather.Clock() + SG2 = SpectralGrid(trunc=31, nlev=1) + L6 = Leapfrog(SG2,Δt_at_T31=Hour(1),adjust_with_output=false) + + SpeedyWeather.set_period!(c1, Hour(10)) + SpeedyWeather.initialize!(c1, L6) + @test c1.n_timesteps == 10 + + SpeedyWeather.set_period!(c1, Day(2)) + SpeedyWeather.initialize!(c1, L6) + @test c1.n_timesteps == 48 end \ No newline at end of file diff --git a/test/netcdf_output.jl b/test/netcdf_output.jl index 031c6ac1b..2c33794b5 100644 --- a/test/netcdf_output.jl +++ b/test/netcdf_output.jl @@ -2,14 +2,14 @@ using NCDatasets, Dates @testset "Output on various grids" begin tmp_output_path = mktempdir(pwd(), prefix = "tmp_testruns_") # Cleaned up when the process exits - n_days = 1 + period = Day(1) # default grid, Float64, ShallowWater spectral_grid = SpectralGrid(;NF=Float64,nlev=1) output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # default grid, Float32, ShallowWater @@ -17,7 +17,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # FullClenshawGrid, Float32, ShallowWater @@ -25,7 +25,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # OctahedralClenshawGrid, Float32, ShallowWater @@ -33,7 +33,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # HEALPixGrid, Float32, ShallowWater @@ -41,7 +41,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # OctaHEALPixGrid, Float32, ShallowWater @@ -49,7 +49,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # OctahedralClenshawGrid, as matrix, Float32, ShallowWater @@ -57,7 +57,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,ShallowWater,path=tmp_output_path,as_matrix=true) model = ShallowWaterModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # OctaHEALPixGrid, as matrix, Float32, PrimitiveDry @@ -65,7 +65,7 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,as_matrix=true) model = PrimitiveDryModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false # OctaHEALPixGrid, as matrix, Float32, but output Float64 PrimitiveDry @@ -73,18 +73,18 @@ using NCDatasets, Dates output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,as_matrix=true,NF=Float64) model = PrimitiveDryModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true;n_days) + run!(simulation,output=true;period) @test simulation.model.feedback.nars_detected == false end @testset "Restart from output file" begin tmp_output_path = mktempdir(pwd(), prefix = "tmp_testruns_") # Cleaned up when the process exits - + spectral_grid = SpectralGrid() output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,id="restart-test") model = PrimitiveDryModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true,n_days=1) + run!(simulation,output=true;period=Day(1)) initial_conditions = StartFromFile(path=tmp_output_path,id="restart-test") model2 = PrimitiveDryModel(;spectral_grid,initial_conditions) @@ -119,7 +119,7 @@ end output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,id="dense-output-test",output_dt=Hour(0)) model = PrimitiveDryModel(;spectral_grid,output) simulation = initialize!(model) - run!(simulation,output=true,n_days=1) + run!(simulation,output=true;period=Day(1)) progn = simulation.prognostic_variables tmp_read_path = joinpath(model.output.run_path,model.output.filename) @@ -131,7 +131,7 @@ end time_stepping = Leapfrog(spectral_grid, adjust_with_output=true) model = PrimitiveDryModel(;spectral_grid,output,time_stepping) simulation = initialize!(model) - run!(simulation,output=true,n_days=1) + run!(simulation,output=true;period) t = SpeedyWeather.load_trajectory("time", model) @test all(y->y==diff(t)[1], diff(t)) # all elements equal @test diff(t)[1] == Minute(70) @@ -141,11 +141,11 @@ end # at the moment, no error # 1kyrs simulation spectral_grid = SpectralGrid() - time_stepping = Leapfrog(spectral_grid,Δt_at_T31=Minute(60*24*365*10)) - output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,id="long-output-test",output_dt=Hour(24*365*10)) + time_stepping = Leapfrog(spectral_grid,Δt_at_T31=Year(10)) + output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,id="long-output-test",output_dt=Year(10)) model = PrimitiveDryModel(;spectral_grid,output,time_stepping) simulation = initialize!(model) - run!(simulation,output=true,n_days=365000) + run!(simulation,output=true,period=Year(1000)) progn = simulation.prognostic_variables tmp_read_path = joinpath(model.output.run_path,model.output.filename) diff --git a/test/run_speedy.jl b/test/run_speedy.jl index d263d604f..20072df44 100644 --- a/test/run_speedy.jl +++ b/test/run_speedy.jl @@ -3,27 +3,27 @@ spectral_grid = SpectralGrid(nlev=1) model = BarotropicModel(;spectral_grid) simulation = initialize!(model) - run!(simulation,n_days=10) + run!(simulation,period=Day(10)) @test simulation.model.feedback.nars_detected == false # ShallowWater spectral_grid = SpectralGrid(nlev=1) model = ShallowWaterModel(;spectral_grid) simulation = initialize!(model) - run!(simulation,n_days=10) + run!(simulation,period=Day(10)) @test simulation.model.feedback.nars_detected == false # PrimitiveDry spectral_grid = SpectralGrid() model = PrimitiveDryModel(;spectral_grid) simulation = initialize!(model) - run!(simulation,n_days=10) + run!(simulation,period=Day(10)) @test simulation.model.feedback.nars_detected == false # PrimitiveWet spectral_grid = SpectralGrid() model = PrimitiveWetModel(;spectral_grid) simulation = initialize!(model) - run!(simulation,n_days=10) + run!(simulation,period=Day(10)) @test simulation.model.feedback.nars_detected == false end \ No newline at end of file diff --git a/test/vertical_advection.jl b/test/vertical_advection.jl index 52296aaf2..a95efcd68 100644 --- a/test/vertical_advection.jl +++ b/test/vertical_advection.jl @@ -10,7 +10,7 @@ vertical_advection = VerticalAdvection(spectral_grid), physics=false) simulation = initialize!(model) - run!(simulation,n_days=10) + run!(simulation,period=Day(10)) @test simulation.model.feedback.nars_detected == false end end \ No newline at end of file From 2fa8ac9eb2cd9faed76fed0f4b87bf2bee71aaef Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 4 Dec 2023 10:00:52 +0100 Subject: [PATCH 2/7] period kwarg docs --- README.md | 2 +- docs/src/how_to_run_speedy.md | 4 ++-- docs/src/output.md | 4 ++-- docs/src/setups.md | 22 +++++++++++----------- docs/src/speedytransforms.md | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 67b638bb9..ed1e6e25a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ With v0.6 the interface to SpeedyWeather.jl consist of 4 steps: define the grid, spectral_grid = SpectralGrid(trunc=31, Grid=OctahedralGaussianGrid, nlev=8) model = PrimitiveDryModel(;spectral_grid, orography = EarthOrography(spectral_grid)) simulation = initialize!(model) -run!(simulation,n_days=10,output=true) +run!(simulation,period=Day(10),output=true) ``` and you will see diff --git a/docs/src/how_to_run_speedy.md b/docs/src/how_to_run_speedy.md index cbf3fe7c1..0c6895d01 100644 --- a/docs/src/how_to_run_speedy.md +++ b/docs/src/how_to_run_speedy.md @@ -108,7 +108,7 @@ just ignore those. But the `Leapfrog` time stepper comes with `Δt_at_T31` which is the parameter used to scale the time step automatically. This means at a spectral resolution of T31 it would use 30min steps, at T63 it would be ~half that, 15min, etc. Meaning that if you want to have a shorter or longer time step you can create a new -`Leapfrog` time stepper. But remember that every model component depends on a +`Leapfrog` time stepper. All time inputs are supposed to be given with the help of `Dates` (e.g. `Minute()`, `Hour()`, ...). But remember that every model component depends on a `SpectralGrid` as first argument. ```@example howto spectral_grid = SpectralGrid(trunc=63,nlev=1) @@ -206,7 +206,7 @@ By default this runs for 10 days without output. These are the options left to change, so with ```@example howto model.output.id = "test" # hide -run!(simulation,n_days=5,output=true) +run!(simulation,period=Day(5),output=true) ``` You would continue this simulation (the previous `run!` call already integrated 10 days!) for another 5 days and storing default [NetCDF output](@ref). \ No newline at end of file diff --git a/docs/src/output.md b/docs/src/output.md index 9cbd9d14e..bc9de3694 100644 --- a/docs/src/output.md +++ b/docs/src/output.md @@ -68,7 +68,7 @@ The time axis of the NetCDF output will now look like ```@example netcdf using NCDatasets model.feedback.verbose = false # hide -run!(simulation,n_days=1,output=true) +run!(simulation,period=Day(1),output=true) id = model.output.id ds = NCDataset("run_$id/output.nc") ds["time"][:] @@ -79,7 +79,7 @@ time_stepping = Leapfrog(spectral_grid,adjust_with_output=true) output = OutputWriter(spectral_grid, ShallowWater, output_dt=Hour(1)) model = ShallowWaterModel(;spectral_grid, time_stepping, output) simulation = initialize!(model) -run!(simulation,n_days=1,output=true) +run!(simulation,period=Day(1),output=true) id = model.output.id ds = NCDataset("run_$id/output.nc") ds["time"][:] diff --git a/docs/src/setups.md b/docs/src/setups.md index 67fb83087..c870953ee 100644 --- a/docs/src/setups.md +++ b/docs/src/setups.md @@ -14,7 +14,7 @@ complicated setups. initial_conditions = StartWithRandomVorticity() model = BarotropicModel(;spectral_grid, initial_conditions, planet=still_earth) simulation = initialize!(model) - run!(simulation,n_days=20) + run!(simulation,period=Day(20)) ``` We want to use the barotropic model to simulate some free-decaying 2D turbulence @@ -53,11 +53,11 @@ plotted for surface relative vorticity with a unicode plot. The resolution of th is not necessarily representative but it lets us have a quick look at the result ```@example barotropic_setup simulation = initialize!(model) -run!(simulation,n_days=20) +run!(simulation,period=Day(20)) ``` Woohoo! Something is moving! You could pick up where this simulation stopped by simply -doing `run!(simulation,n_days=50)` again. We didn't store any output, which +doing `run!(simulation,period=Day(50))` again. We didn't store any output, which you can do by `run!(simulation,output=true)`, which will switch on NetCDF output with default settings. More options on output in [NetCDF output](@ref). @@ -71,7 +71,7 @@ with default settings. More options on output in [NetCDF output](@ref). initial_conditions = ZonalJet() model = ShallowWaterModel(;spectral_grid, orography, initial_conditions) simulation = initialize!(model) - run!(simulation,n_days=6) + run!(simulation,period=Day(6)) ``` As a second example, let's investigate the Galewsky et al.[^G04] test case for the shallow @@ -97,12 +97,12 @@ Now we construct a model, but this time a `ShallowWaterModel` ```@example galewsky_setup model = ShallowWaterModel(;spectral_grid, orography, initial_conditions) simulation = initialize!(model) -run!(simulation,n_days=6) +run!(simulation,period=Day(6)) ``` Oh yeah. That looks like the wobbly jet in their paper. Let's run it again for another 6 days but this time also store [NetCDF output](@ref). ```@example galewsky_setup -run!(simulation,n_days=6,output=true) +run!(simulation,period=Day(6),output=true) ``` The progress bar tells us that the simulation run got the identification "0001" (which just counts up, so yours might be higher), meaning that @@ -164,7 +164,7 @@ compare with the last plot ```@example galewsky_setup model = ShallowWaterModel(;spectral_grid, orography, initial_conditions) simulation = initialize!(model) -run!(simulation,n_days=12,output=true) +run!(simulation,period=Day(12),output=true) ``` This time the run got a new run id, which you see in the progress bar, but can again always check @@ -207,8 +207,8 @@ output = OutputWriter(spectral_grid,ShallowWater,output_dt=Hour(6),output_vars=[ model = ShallowWaterModel(;spectral_grid,output,drag,forcing) simulation = initialize!(model) model.feedback.verbose = false # hide -run!(simulation,n_days=20) # discard first 20 days -run!(simulation,n_days=20,output=true) +run!(simulation,period=Day(20)) # discard first 20 days +run!(simulation,period=Day(20),output=true) nothing # hide ``` @@ -260,7 +260,7 @@ output = OutputWriter(spectral_grid,ShallowWater,output_dt=Hour(12),output_vars= model = ShallowWaterModel(;spectral_grid,orography,output,initial_conditions,implicit,time_stepping) simulation = initialize!(model) model.feedback.verbose = false # hide -run!(simulation,n_days=2,output=true) +run!(simulation,period=Day(2),output=true) nothing # hide ``` @@ -324,7 +324,7 @@ initial_conditions = ZonalWind() model = PrimitiveDryModel(;spectral_grid,orography,initial_conditions,physics=false) simulation = initialize!(model) model.feedback.verbose = false # hide -run!(simulation,n_days=9,output=true) +run!(simulation,period=Day(9),output=true) nothing # hide ``` diff --git a/docs/src/speedytransforms.md b/docs/src/speedytransforms.md index 0afcaba50..5ce1a135e 100644 --- a/docs/src/speedytransforms.md +++ b/docs/src/speedytransforms.md @@ -324,7 +324,7 @@ drag = QuadraticDrag(spectral_grid) model = ShallowWaterModel(;spectral_grid,forcing,drag) model.feedback.verbose = false # hide simulation = initialize!(model); -run!(simulation,n_days=30) +run!(simulation,period=Day(30)) nothing # hide ``` From 1f357cff3995dfd596c167c48ee6d656f92ca752 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 4 Dec 2023 10:05:13 +0100 Subject: [PATCH 3/7] typo in set_period! --- src/dynamics/prognostic_variables.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamics/prognostic_variables.jl b/src/dynamics/prognostic_variables.jl index 83c65d6ba..9017ab56d 100644 --- a/src/dynamics/prognostic_variables.jl +++ b/src/dynamics/prognostic_variables.jl @@ -34,7 +34,7 @@ end """ $(TYPEDSIGNATURES) -Set the `period` of the clock to a new value. Converts any `Dates.Period` input to `Second`.""" +Set the `period` of the clock to a new value. Converts any `Dates.Period` input `Second`.""" function set_period!(clock::Clock,period::Period) clock.period = Second(period) end From 09ea2f01332091fd7a4cc97aaf09a7ad13188977 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 4 Dec 2023 10:30:32 +0100 Subject: [PATCH 4/7] fix test period kwarg --- src/dynamics/prognostic_variables.jl | 2 +- test/netcdf_output.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dynamics/prognostic_variables.jl b/src/dynamics/prognostic_variables.jl index 9017ab56d..83c65d6ba 100644 --- a/src/dynamics/prognostic_variables.jl +++ b/src/dynamics/prognostic_variables.jl @@ -34,7 +34,7 @@ end """ $(TYPEDSIGNATURES) -Set the `period` of the clock to a new value. Converts any `Dates.Period` input `Second`.""" +Set the `period` of the clock to a new value. Converts any `Dates.Period` input to `Second`.""" function set_period!(clock::Clock,period::Period) clock.period = Second(period) end diff --git a/test/netcdf_output.jl b/test/netcdf_output.jl index 2c33794b5..3ea7c7833 100644 --- a/test/netcdf_output.jl +++ b/test/netcdf_output.jl @@ -131,7 +131,7 @@ end time_stepping = Leapfrog(spectral_grid, adjust_with_output=true) model = PrimitiveDryModel(;spectral_grid,output,time_stepping) simulation = initialize!(model) - run!(simulation,output=true;period) + run!(simulation,output=true;period=Day(1)) t = SpeedyWeather.load_trajectory("time", model) @test all(y->y==diff(t)[1], diff(t)) # all elements equal @test diff(t)[1] == Minute(70) @@ -141,11 +141,11 @@ end # at the moment, no error # 1kyrs simulation spectral_grid = SpectralGrid() - time_stepping = Leapfrog(spectral_grid,Δt_at_T31=Year(10)) - output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,id="long-output-test",output_dt=Year(10)) + time_stepping = Leapfrog(spectral_grid,Δt_at_T31=Day(3650)) + output = OutputWriter(spectral_grid,PrimitiveDry,path=tmp_output_path,id="long-output-test",output_dt=Day(3650)) model = PrimitiveDryModel(;spectral_grid,output,time_stepping) simulation = initialize!(model) - run!(simulation,output=true,period=Year(1000)) + run!(simulation,output=true,period=Day(365000)) progn = simulation.prognostic_variables tmp_read_path = joinpath(model.output.run_path,model.output.filename) From 3bacbdea3e64a90b874877f924834c911526f130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Mon, 4 Dec 2023 17:53:14 +0000 Subject: [PATCH 5/7] allow run!(simulation,period=1.23) --- src/dynamics/prognostic_variables.jl | 8 ++++++++ src/output/feedback.jl | 4 ++-- src/run_speedy.jl | 2 +- test/dates.jl | 8 ++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/dynamics/prognostic_variables.jl b/src/dynamics/prognostic_variables.jl index 83c65d6ba..efe4d4355 100644 --- a/src/dynamics/prognostic_variables.jl +++ b/src/dynamics/prognostic_variables.jl @@ -39,6 +39,14 @@ function set_period!(clock::Clock,period::Period) clock.period = Second(period) end +""" +$(TYPEDSIGNATURES) +Set the `period` of the clock to a new value. Converts any `::Real` input to `Day`.""" +function set_period!(clock::Clock,period::Real) + @info "Input $x assumed to have units of days. Use Week($x), Hour($x), Minute($x) otherwise." + clock.period = Day(period) +end + """ $(TYPEDSIGNATURES) Create and initialize a clock from `time_stepping`""" diff --git a/src/output/feedback.jl b/src/output/feedback.jl index f3396f6dd..3e3a16641 100644 --- a/src/output/feedback.jl +++ b/src/output/feedback.jl @@ -86,7 +86,7 @@ function initialize!(feedback::Feedback,clock::Clock,model::ModelSetup) (; run_path, id) = feedback SG = model.spectral_grid L = model.time_stepping - period = clock.period.value/(3600*24) + days = clock.period.value/(3600*24) # create progress.txt file in run_????/ progress_txt = open(joinpath(run_path,"progress.txt"),"w") @@ -95,7 +95,7 @@ function initialize!(feedback::Feedback,clock::Clock,model::ModelSetup) write(progress_txt,s*"\n") write(progress_txt,"Integrating:\n") write(progress_txt,"$SG\n") - write(progress_txt,"Time: $period days at Δt = $(L.Δt_sec)s\n") + write(progress_txt,"Time: $days days at Δt = $(L.Δt_sec)s\n") write(progress_txt,"\nAll data will be stored in $run_path\n") feedback.progress_txt = progress_txt end diff --git a/src/run_speedy.jl b/src/run_speedy.jl index 8acb02b71..b1ea9919f 100644 --- a/src/run_speedy.jl +++ b/src/run_speedy.jl @@ -2,7 +2,7 @@ $(TYPEDSIGNATURES) Run a SpeedyWeather.jl `simulation`. The `simulation.model` is assumed to be initialized.""" function run!( simulation::Simulation; - period::Period = Day(10), + period = Day(10), output::Bool = false, n_days::Union{Nothing, Real}=nothing) diff --git a/test/dates.jl b/test/dates.jl index e4240719a..4c040b343 100644 --- a/test/dates.jl +++ b/test/dates.jl @@ -34,6 +34,14 @@ SpeedyWeather.initialize!(c1, L6) @test c1.n_timesteps == 10 + SpeedyWeather.set_period!(c1, 10) + SpeedyWeather.initialize!(c1, L6) + @test c1.n_timesteps == 10 + + SpeedyWeather.set_period!(c1, 10.0) + SpeedyWeather.initialize!(c1, L6) + @test c1.n_timesteps == 10 + SpeedyWeather.set_period!(c1, Day(2)) SpeedyWeather.initialize!(c1, L6) @test c1.n_timesteps == 48 From d2d34336685125888cce85e99978b8438138681a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Mon, 4 Dec 2023 18:05:45 +0000 Subject: [PATCH 6/7] x -> period typo --- src/dynamics/prognostic_variables.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamics/prognostic_variables.jl b/src/dynamics/prognostic_variables.jl index efe4d4355..02f69ad50 100644 --- a/src/dynamics/prognostic_variables.jl +++ b/src/dynamics/prognostic_variables.jl @@ -43,7 +43,7 @@ end $(TYPEDSIGNATURES) Set the `period` of the clock to a new value. Converts any `::Real` input to `Day`.""" function set_period!(clock::Clock,period::Real) - @info "Input $x assumed to have units of days. Use Week($x), Hour($x), Minute($x) otherwise." + @info "Input $period assumed to have units of days. Use Week($period), Hour($period), Minute($period) otherwise." clock.period = Day(period) end From 11ce352c6fcf0511641d58d02cab834bda5e1bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Mon, 4 Dec 2023 18:19:56 +0000 Subject: [PATCH 7/7] correct dates.jl tests --- test/dates.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dates.jl b/test/dates.jl index 4c040b343..a92c2122b 100644 --- a/test/dates.jl +++ b/test/dates.jl @@ -34,13 +34,13 @@ SpeedyWeather.initialize!(c1, L6) @test c1.n_timesteps == 10 - SpeedyWeather.set_period!(c1, 10) + SpeedyWeather.set_period!(c1, 10) # assumed to be in days SpeedyWeather.initialize!(c1, L6) - @test c1.n_timesteps == 10 + @test c1.n_timesteps == 24*10 - SpeedyWeather.set_period!(c1, 10.0) + SpeedyWeather.set_period!(c1, 10.0) # also assumed to be in days SpeedyWeather.initialize!(c1, L6) - @test c1.n_timesteps == 10 + @test c1.n_timesteps == 24*10 SpeedyWeather.set_period!(c1, Day(2)) SpeedyWeather.initialize!(c1, L6)