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

Remove tendency computation at model construction #3741

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Update peripheral aspects of the model (auxiliary fields, halo regions, diffusiv
hydrostatic pressure) to the current model state. If `callbacks` are provided (in an array),
they are called in the end.
"""
update_state!(model::HydrostaticFreeSurfaceModel, callbacks=[]; compute_tendencies = true) =
update_state!(model::HydrostaticFreeSurfaceModel, callbacks=[]; compute_tendencies = false) =
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved
update_state!(model, model.grid, callbacks; compute_tendencies)

function update_state!(model::HydrostaticFreeSurfaceModel, grid, callbacks; compute_tendencies = true)
function update_state!(model::HydrostaticFreeSurfaceModel, grid, callbacks; compute_tendencies = false)
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved
@apply_regionally mask_immersed_model_fields!(model, grid)

# Update possible FieldTimeSeries used in the model
Expand Down
2 changes: 1 addition & 1 deletion src/Models/NonhydrostaticModels/nonhydrostatic_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function NonhydrostaticModel(; grid,
auxiliary_fields)

update_state!(model)

return model
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Update peripheral aspects of the model (halo regions, diffusivities, hydrostatic
pressure) to the current model state. If `callbacks` are provided (in an array),
they are called in the end.
"""
function update_state!(model::NonhydrostaticModel, callbacks=[]; compute_tendencies = true)
function update_state!(model::NonhydrostaticModel, callbacks=[]; compute_tendencies = false)
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved

# Mask immersed tracers
foreach(model.tracers) do tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Next, `callbacks` are executed.

Finally, tendencies are computed if `compute_tendencies=true`.
"""
function update_state!(model::ShallowWaterModel, callbacks=[]; compute_tendencies=true)
function update_state!(model::ShallowWaterModel, callbacks=[]; compute_tendencies=false)
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved

# Mask immersed fields
foreach(mask_immersed_field!, merge(model.solution, model.tracers))
Expand Down
12 changes: 4 additions & 8 deletions src/TimeSteppers/quasi_adams_bashforth_2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ reset!(timestepper::QuasiAdamsBashforth2TimeStepper) = nothing
#####

"""
time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt; euler=false, compute_tendencies=true)
time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt; euler=false)

Step forward `model` one time step `Δt` with a 2nd-order Adams-Bashforth method and
pressure-correction substep. Setting `euler=true` will take a forward Euler time step.
Expand All @@ -71,11 +71,7 @@ The steps of the Quasi-Adams-Bashforth second-order (AB2) algorithm are:
4. Correct the velocities based on the results of step 3.
5. Store the old tendencies.
6. Update the model state.
7. If `compute_tendencies == true`, compute the tendencies for the next time step.

!!! warning "`compute_tendencies` kwarg"
If `compute_tendencies == false` then the new tendencies at the last step are _not_ calculated!
Setting `compute_tendencies == false` is not recommended _except_ for debugging purposes.
7. Compute tendencies for the next time step
"""
function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt;
callbacks=[], euler=false, compute_tendencies=true)
Expand Down Expand Up @@ -113,7 +109,7 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt
end

# Be paranoid and update state at iteration 0
model.clock.iteration == 0 && update_state!(model, callbacks)
model.clock.iteration == 0 && update_state!(model, callbacks; compute_tendencies=true)

ab2_step!(model, Δt) # full step for tracers, fractional step for velocities.

Expand All @@ -124,7 +120,7 @@ function time_step!(model::AbstractModel{<:QuasiAdamsBashforth2TimeStepper}, Δt
calculate_pressure_correction!(model, Δt)
@apply_regionally correct_velocities_and_store_tendencies!(model, Δt)

update_state!(model, callbacks; compute_tendencies)
update_state!(model, callbacks; compute_tendencies=true)
step_lagrangian_particles!(model, Δt)

# Return χ to initial value
Expand Down
10 changes: 5 additions & 5 deletions src/TimeSteppers/runge_kutta_3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ The 3rd-order Runge-Kutta method takes three intermediate substep stages to
achieve a single timestep. A pressure correction step is applied at each intermediate
stage.
"""
function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbacks=[], compute_tendencies = true)
function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbacks=[])
Δt == 0 && @warn "Δt == 0 may cause model blowup!"

# Be paranoid and update state at iteration 0, in case run! is not used:
model.clock.iteration == 0 && update_state!(model, callbacks)
model.clock.iteration == 0 && update_state!(model, callbacks; compute_tendencies = true)

γ¹ = model.timestepper.γ¹
γ² = model.timestepper.γ²
Expand Down Expand Up @@ -111,7 +111,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac
pressure_correct_velocities!(model, first_stage_Δt)

store_tendencies!(model)
update_state!(model, callbacks)
update_state!(model, callbacks; compute_tendencies = true)
step_lagrangian_particles!(model, first_stage_Δt)

#
Expand All @@ -127,7 +127,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac
pressure_correct_velocities!(model, second_stage_Δt)

store_tendencies!(model)
update_state!(model, callbacks)
update_state!(model, callbacks; compute_tendencies = true)
step_lagrangian_particles!(model, second_stage_Δt)

#
Expand All @@ -148,7 +148,7 @@ function time_step!(model::AbstractModel{<:RungeKutta3TimeStepper}, Δt; callbac
calculate_pressure_correction!(model, third_stage_Δt)
pressure_correct_velocities!(model, third_stage_Δt)

update_state!(model, callbacks; compute_tendencies)
update_state!(model, callbacks; compute_tendencies = true)
step_lagrangian_particles!(model, third_stage_Δt)

return nothing
Expand Down