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

Interpolated stats #203

Closed
wants to merge 9 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/Output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,23 @@ show(io::IO, o::MemoryOutput) = print(io, "MemoryOutput$(collect(keys(o.data)))"
"""
function (o::MemoryOutput)(y, t, dt, yfun)
save, ts = o.save_cond(y, t, dt, o.saved)
append_stats!(o, o.statsfun(y, t, dt))
!haskey(o.data, o.yname) && initialise(o, y)
while save
ys = yfun(ts)
append_stats!(o, o.statsfun(ys, ts, dt))
s = size(o.data[o.yname])
if s[end] < o.saved+1
o.data[o.yname] = fastcat(o.data[o.yname], yfun(ts))
o.data[o.yname] = fastcat(o.data[o.yname], ys)
push!(o.data[o.tname], ts)
else
idcs = fill(:, ndims(y))
o.data[o.yname][idcs..., o.saved+1] = yfun(ts)
o.data[o.yname][idcs..., o.saved+1] = ys
o.data[o.tname][o.saved+1] = ts
end
o.saved += 1
save, ts = o.save_cond(y, t, dt, o.saved)
end
append_stats!(o, o.statsfun(y, t, dt))
jtravs marked this conversation as resolved.
Show resolved Hide resolved
end

function append_stats!(o::MemoryOutput, d)
Expand Down Expand Up @@ -306,22 +308,27 @@ end
function (o::HDF5Output)(y, t, dt, yfun)
o.readonly && error("Cannot add data to read-only output!")
save, ts = o.save_cond(y, t, dt, o.saved)
push!(o.stats_tmp, o.statsfun(y, t, dt))
if save
@hlock HDF5.h5open(o.fpath, "r+") do file
!HDF5.exists(file, o.yname) && initialise(o, y)
statsnames = sort(collect(keys(o.stats_tmp[end])))
cachehash = hash((statsnames, size(y)))
cachehash == o.cachehash || error(
"the hash for this propagation does not agree with cache in file")
if !HDF5.exists(file, o.yname)
jtravs marked this conversation as resolved.
Show resolved Hide resolved
push!(o.stats_tmp, o.statsfun(y, t, dt))
initialise(o, y)
statsnames = sort(collect(keys(o.stats_tmp[end])))
cachehash = hash((statsnames, size(y)))
cachehash == o.cachehash || error(
"the hash for this propagation does not agree with cache in file")
o.stats_tmp = Vector{Dict{String, Any}}()
end
while save
s = collect(size(file[o.yname]))
idcs = fill(:, length(s)-1)
if s[end] < o.saved+1
s[end] += 1
HDF5.set_dims!(file[o.yname], Tuple(s))
end
file[o.yname][idcs..., o.saved+1] = yfun(ts)
ys = yfun(ts)
push!(o.stats_tmp, o.statsfun(ys, ts, dt))
file[o.yname][idcs..., o.saved+1] = ys
s = collect(size(file[o.tname]))
if s[end] < o.saved+1
s[end] += 1
Expand All @@ -341,6 +348,7 @@ function (o::HDF5Output)(y, t, dt, yfun)
end
end
end
push!(o.stats_tmp, o.statsfun(y, t, dt))
end

function append_stats!(parent, a::Array{Dict{String,Any},1})
Expand Down