-
Notifications
You must be signed in to change notification settings - Fork 250
Enable AveragedSpecifiedTimes to be used in output writers
#4876
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
5fcbcfa
5457bc5
96872aa
61d29ac
c20c9b0
35c41a5
6d16825
6ea30f5
56e6e55
b3f1541
ed15fd6
0efdbc8
3ab8e0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ using Oceananigans.Diagnostics: AbstractDiagnostic | |||||||||||||||||||||||||||||||
| using Oceananigans.OutputWriters: fetch_output | ||||||||||||||||||||||||||||||||
| using Oceananigans.Utils: AbstractSchedule, prettytime | ||||||||||||||||||||||||||||||||
| using Oceananigans.TimeSteppers: Clock | ||||||||||||||||||||||||||||||||
| using Dates: Period | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import Oceananigans: run_diagnostic! | ||||||||||||||||||||||||||||||||
| import Oceananigans.Utils: TimeInterval, SpecifiedTimes | ||||||||||||||||||||||||||||||||
|
|
@@ -102,63 +103,54 @@ Base.copy(sch::AveragedTimeInterval) = AveragedTimeInterval(sch.interval, window | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| A schedule for averaging over windows that precede SpecifiedTimes. | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| mutable struct AveragedSpecifiedTimes{W <: Union{Float64, Vector{Float64}}} <: AbstractSchedule | ||||||||||||||||||||||||||||||||
| mutable struct AveragedSpecifiedTimes{W} <: AbstractSchedule | ||||||||||||||||||||||||||||||||
| specified_times :: SpecifiedTimes | ||||||||||||||||||||||||||||||||
| window :: W | ||||||||||||||||||||||||||||||||
| stride :: Int | ||||||||||||||||||||||||||||||||
| collecting :: Bool | ||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const VaryingWindowAveragedSpecifiedTimes = AveragedSpecifiedTimes{Vector{Float64}} | ||||||||||||||||||||||||||||||||
| const VaryingWindowAveragedSpecifiedTimes = AveragedSpecifiedTimes{<:Vector} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| AveragedSpecifiedTimes(specified_times::SpecifiedTimes; window, stride=1) = | ||||||||||||||||||||||||||||||||
| AveragedSpecifiedTimes(specified_times, window, stride, false) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| AveragedSpecifiedTimes(times; window, kw...) = AveragedSpecifiedTimes(times, window; kw...) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| function AveragedSpecifiedTimes(times, window::Vector{Float64}; kw...) | ||||||||||||||||||||||||||||||||
| function determine_epsilon(eltype) | ||||||||||||||||||||||||||||||||
| if eltype <: AbstractFloat | ||||||||||||||||||||||||||||||||
| return eps(eltype) | ||||||||||||||||||||||||||||||||
| elseif eltype <: Period | ||||||||||||||||||||||||||||||||
| return Second(0) | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| function determine_epsilon(eltype) | |
| if eltype <: AbstractFloat | |
| return eps(eltype) | |
| elseif eltype <: Period | |
| return Second(0) | |
| else | |
| return 0 | |
| end | |
| end | |
| determine_epsilon(eltype) = 0 | |
| determine_epsilon(eltype::AbstractType) = eps(eltype) | |
| determine_epsilon(::Period) = Second(0) |
the name of the function is slightly problematic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you meant
Oceananigans.jl/src/OutputWriters/windowed_time_average.jl
Lines 120 to 122 in 0efdbc8
| determine_epsilon(eltype) = 0 | |
| determine_epsilon(::Type{T}) where T <: AbstractFloat = eps(T) | |
| determine_epsilon(::Period) = Second(0) |
right?
I agree the name is terrible, but I haven't figured out a better alternative...
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| function AveragedSpecifiedTimes(times, window::Union{<:Number, <:Period}; kw...) | |
| function AveragedSpecifiedTimes(times, window; kw...) |
can this be the fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
SpecifiedTimesis not a concrete type, this should also be a type parameter