Skip to content

Commit

Permalink
test flow_to_storage_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Oct 10, 2024
1 parent 0e417ec commit bae7ff4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions core/test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,39 @@ end
end
end
end

@testitem "flow_to_storage matrix" begin
using ComponentArrays: ComponentArray, Axis, getaxes
using LinearAlgebra: I
toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml")
@test ispath(toml_path)
model = Ribasim.Model(toml_path)
(; u, p) = model.integrator
n_basins = length(u.evaporation)
(; flow_to_storage) = p
flow_to_storage =
ComponentArray(flow_to_storage, (Axis(; basins = 1:n_basins), only(getaxes(u))))

@test flow_to_storage[:, :evaporation] == -I
@test flow_to_storage[:, :infiltration] == -I

for node_name in
[:tabulated_rating_curve, :pump, :outlet, :linear_resistance, :manning_resistance]
flow_to_storage_node = flow_to_storage[:, node_name]
# In every column there is either 0 or 1 instance of 1.0 (flow into a basin)
@test all(
i -> i (0, 1),
count(==(1.0), collect(flow_to_storage[:, :tabulated_rating_curve]); dims = 1),
)

# In every column there is either 0 or 1 instance of -1.0 (flow out of a basin)
@test all(
i -> i (0, 1),
count(
==(1 - 0.0),
collect(flow_to_storage[:, :tabulated_rating_curve]);
dims = 1,
),
)
end
end

0 comments on commit bae7ff4

Please sign in to comment.