Skip to content

Commit

Permalink
Allow outputting of multiple systems for exported_levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Nov 17, 2023
1 parent 6e98867 commit 17f2b6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 1 addition & 4 deletions core/src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,7 @@ end
"""Interpolate the levels and save them to SavedValues"""
function save_exported_levels(u, t, integrator)
update_exporter_levels!(integrator)
# TODO: multiple systems. Although at the point, shouldn't we
# just write to disk instead of using SavedValues?
exporter = first(values(integrator.p.level_exporters))
copy(exporter.level)
return vcat([exporter.level for exporter in values(integrator.p.level_exporters)]...)
end

"Load updates from 'Basin / time' into the parameters"
Expand Down
25 changes: 15 additions & 10 deletions core/src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,22 @@ function exported_levels_table(model::Model)::NamedTuple
(; config, saved, integrator) = model
(; t, saveval) = saved.exported_levels

name, exporter = first(integrator.p.level_exporters)
nelem = length(exporter.basin_index)
unique_elem_id = collect(1:nelem)
ntsteps = length(t)

time = repeat(datetime_since.(t, config.starttime); inner = nelem)
elem_id = repeat(unique_elem_id; outer = ntsteps)
levels = FlatVector(saveval)
names = fill(name, length(time))
# The level exporter may contain multiple named systems, but the
# saved levels are flat.
time = DateTime[]
name = String[]
element_id = Int[]
for (unique_name, exporter) in integrator.p.level_exporters
nelem = length(exporter.basin_index)
unique_elem_id = collect(1:nelem)
ntsteps = length(t)
append!(time, repeat(datetime_since.(t, config.starttime); inner = nelem))
append!(element_id, repeat(unique_elem_id; outer = ntsteps))
append!(name, fill(unique_name, length(time)))
end

return (; time, names, elem_id, levels)
level = FlatVector(saveval)
return (; time, name, element_id, level)
end

"Write a result table to disk as an Arrow file"
Expand Down

0 comments on commit 17f2b6e

Please sign in to comment.