Skip to content

Commit

Permalink
Add constructor for SDTime from SDIterations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Sep 6, 2023
1 parent 552f70f commit cd042ee
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/diagnostics/Diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,37 @@ function ScheduledDiagnosticIterations(
)
end

"""
ScheduledDiagnosticTime(sd_time::ScheduledDiagnosticIterations, Δt)
Create a `ScheduledDiagnosticTime` given a `ScheduledDiagnosticIterations` and a timestep
`Δt`.
"""
function ScheduledDiagnosticTime(
sd_time::ScheduledDiagnosticIterations,
Δt::T,
) where {T}

# If we have the timestep, we can convert time in iterations to seconds

# if compute_every is :timestep, then we want to compute after every iterations
compute_every =
sd_time.compute_every == 1 ? :timestep : sd_time.compute_every * Δt
output_every = sd_time.output_every * Δt

ScheduledDiagnosticTime(;
sd_time.variable,
output_every,
sd_time.output_writer,
sd_time.reduction_time_func,
sd_time.reduction_space_func,
compute_every,
sd_time.pre_output_hook!,
)
end

# We provide also a companion constructor for ScheduledDiagnosticIterations which returns
# itself (without copy) when called with a timestep.
#
Expand Down

0 comments on commit cd042ee

Please sign in to comment.