Skip to content

Commit

Permalink
Expose only AbstractVector{Float64} via BMI
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Apr 9, 2024
1 parent ef7b43e commit eefced0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function BMI.update_until(model::Model, time)::Model
return model
end

function BMI.get_value_ptr(model::Model, name::AbstractString)
function BMI.get_value_ptr(model::Model, name::AbstractString)::AbstractVector{Float64}
if name == "basin.storage"
model.integrator.u.storage
elseif name == "basin.level"
Expand All @@ -47,7 +47,7 @@ function BMI.get_value_ptr(model::Model, name::AbstractString)
elseif name == "basin.subgrid_level"
model.integrator.p.subgrid.level
elseif name == "user_demand.demand"
model.integrator.p.user_demand.demand
vec(model.integrator.p.user_demand.demand)
elseif name == "user_demand.realized"
model.integrator.p.user_demand.realized_bmi
else
Expand Down
4 changes: 2 additions & 2 deletions core/test/bmi_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end
@testitem "get_value_ptr_all_values" begin
import BasicModelInterface as BMI

toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml")
toml_path = normpath(@__DIR__, "../../generated_testmodels/subnetwork/ribasim.toml")
model = BMI.initialize(Ribasim.Model, toml_path)

for name in [
Expand All @@ -73,7 +73,7 @@ end
BMI.update_until(model, 86400.0)
value_second = BMI.get_value_ptr(model, name)
# get_value_ptr does not copy
@test value_first === value_second
@test value_first === value_second || pointer(value_first) == pointer(value_second)
end
end

Expand Down

0 comments on commit eefced0

Please sign in to comment.