Skip to content

Commit

Permalink
first netcdf time step from clock
Browse files Browse the repository at this point in the history
  • Loading branch information
milankl committed Sep 18, 2023
1 parent 58bb703 commit 86da8b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
15 changes: 4 additions & 11 deletions src/dynamics/time_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,19 @@ function first_timesteps!(
clock.n_timesteps == 0 && return time # exit immediately for no time steps

# FIRST TIME STEP (EULER FORWARD with dt=Δt/2)
i = 1 # time step index
lf1 = 1 # without Robert+Williams filter
lf2 = 1 # evaluates all tendencies at t=0,
# the first leapfrog index (=>Euler forward)
initialize!(implicit,Δt/2,diagn,model) # update precomputed implicit terms with time step Δt/2
timestep!(progn,diagn,Δt/2,i,model,lf1,lf2)
timestep!(progn,diagn,Δt/2,model,lf1,lf2)
clock.time += Dates.Second(Δt_sec÷2) # update by half the leapfrog time step Δt used here

# SECOND TIME STEP (UNFILTERED LEAPFROG with dt=Δt, leapfrogging from t=0 over t=Δt/2 to t=Δt)
initialize!(implicit,Δt,diagn,model) # update precomputed implicit terms with time step Δt
lf1 = 1 # without Robert+Williams filter
lf2 = 2 # evaluate all tendencies at t=dt/2,
# the 2nd leapfrog index (=>Leapfrog)
timestep!(progn,diagn,Δt,i,model,lf1,lf2)
timestep!(progn,diagn,Δt,model,lf1,lf2)
clock.time += Dates.Second(Δt_sec÷2) # now 2nd leapfrog step is at t=Δt
write_output!(output,clock.time,diagn)

Expand All @@ -151,7 +150,6 @@ Calculate a single time step for the `model <: Barotropic`."""
function timestep!( progn::PrognosticVariables, # all prognostic variables
diagn::DiagnosticVariables, # all pre-allocated diagnostic variables
dt::Real, # time step (mostly =2Δt, but for init steps =Δt,Δt/2)
i::Integer, # time step index
model::Barotropic, # everything that's constant at runtime
lf1::Int=2, # leapfrog index 1 (dis/enables Robert+Williams filter)
lf2::Int=2) # leapfrog index 2 (time step used for tendencies)
Expand All @@ -175,7 +173,6 @@ Calculate a single time step for the `model <: ShallowWater`."""
function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables
diagn::DiagnosticVariables{NF}, # all pre-allocated diagnostic variables
dt::Real, # time step (mostly =2Δt, but for init steps =Δt,Δt/2)
i::Integer, # time step index
model::ShallowWater, # everything that's constant at runtime
lf1::Int=2, # leapfrog index 1 (dis/enables Robert+Williams filter)
lf2::Int=2 # leapfrog index 2 (time step used for tendencies)
Expand Down Expand Up @@ -216,7 +213,6 @@ Calculate a single time step for the `model<:PrimitiveEquation`"""
function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables
diagn::DiagnosticVariables{NF}, # all pre-allocated diagnostic variables
dt::Real, # time step (mostly =2Δt, but for init steps =Δt,Δt/2)
i::Integer, # time step index
model::PrimitiveEquation, # everything that's constant at runtime
lf1::Int=2, # leapfrog index 1 (dis/enables Robert+Williams filter)
lf2::Int=2 # leapfrog index 2 (time step used for tendencies)
Expand All @@ -229,9 +225,6 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables
model.physics && parameterization_tendencies!(diagn,time,model)
model.physics || zero_tendencies!(diagn) # set tendencies to zero otherwise

# occasionally reinitialize the implicit solver with new temperature profile
# initialize!(model.implicit,i,dt,diagn,model.geometry,model.constants)

dynamics_tendencies!(diagn,progn,model,lf2) # dynamical core
implicit_correction!(diagn,model.implicit,progn) # semi-implicit time stepping corrections

Expand Down Expand Up @@ -278,7 +271,7 @@ function time_stepping!(
(;output,feedback) = model
lf = 1 # use first leapfrog index
gridded!(diagn,progn,lf,model)
initialize!(output,feedback,time_stepping,diagn,model)
initialize!(output,feedback,time_stepping,clock,diagn,model)
initialize!(feedback,clock,model)

# FIRST TIMESTEPS: EULER FORWARD THEN 1x LEAPFROG
Expand All @@ -288,7 +281,7 @@ function time_stepping!(
for i in 2:clock.n_timesteps # start at 2 as first Δt in first_timesteps!

# calculate tendencies and leapfrog forward
timestep!(progn,diagn,2Δt,i,model)
timestep!(progn,diagn,2Δt,model)
clock.time += Dates.Second(Δt_sec) # time of lf=2 and diagn after timestep!

progress!(feedback,progn) # updates the progress meter bar
Expand Down
3 changes: 2 additions & 1 deletion src/output/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function initialize!(
output::OutputWriter{output_NF,Model},
feedback::AbstractFeedback,
time_stepping::TimeStepper,
clock::Clock,
diagn::DiagnosticVariables,
model::Model
) where {output_NF,Model}
Expand Down Expand Up @@ -285,7 +286,7 @@ function initialize!(

# WRITE INITIAL CONDITIONS TO FILE
write_netcdf_variables!(output,diagn)
write_netcdf_time!(output,startdate)
write_netcdf_time!(output,clock.time)

# also export parameters into run????/parameters.txt
parameters_txt = open(joinpath(output.run_path,"parameters.txt"),"w")
Expand Down
9 changes: 6 additions & 3 deletions src/run_speedy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ function run!( simulation::Simulation;
output::Bool = false)

(;prognostic_variables, diagnostic_variables, model) = simulation
(;clock) = prognostic_variables

# set the clock
if typeof(startdate) == DateTime prognostic_variables.clock.time = startdate end
prognostic_variables.clock.n_days = n_days
initialize!(prognostic_variables.clock,model.time_stepping)
if typeof(startdate) == DateTime
clock.time = startdate
end
clock.n_days = n_days
initialize!(clock,model.time_stepping)

model.output.output = output # enable/disable output
initialize && initialize!(model) # initialize again?
Expand Down

0 comments on commit 86da8b9

Please sign in to comment.