Skip to content

Commit

Permalink
Merge branch 'main' into flow_condition_on_flow_boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Aug 7, 2023
2 parents 4b8a92a + d026761 commit bac4dbe
Show file tree
Hide file tree
Showing 17 changed files with 826 additions and 88 deletions.
2 changes: 1 addition & 1 deletion build/ribasim_cli/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.3.0"

[[deps.Ribasim]]
deps = ["Arrow", "BasicModelInterface", "ComponentArrays", "Configurations", "DBInterface", "DataInterpolations", "DataStructures", "Dates", "Dictionaries", "DiffEqCallbacks", "Graphs", "IterTools", "Legolas", "OrdinaryDiffEq", "SQLite", "SciMLBase", "SparseArrays", "StructArrays", "Tables", "TimerOutputs"]
deps = ["Arrow", "BasicModelInterface", "ComponentArrays", "Configurations", "DBInterface", "DataInterpolations", "DataStructures", "Dates", "Dictionaries", "DiffEqCallbacks", "FiniteDiff", "Graphs", "IterTools", "Legolas", "Logging", "OrdinaryDiffEq", "SQLite", "SciMLBase", "SparseArrays", "StructArrays", "Tables", "TerminalLoggers", "TimerOutputs"]
path = "../../core"
uuid = "aac5e3d9-0b8f-4d4f-8241-b1a7a9632635"
version = "0.1.0"
Expand Down
5 changes: 5 additions & 0 deletions core/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
Legolas = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[compat]
Expand All @@ -35,6 +38,7 @@ DataInterpolations = "3.7, 4"
DataStructures = "0.18"
Dictionaries = "0.3.25"
DiffEqCallbacks = "2.23"
FiniteDiff = "2.21"
Graphs = "1.6"
IterTools = "1.4"
Legolas = "0.5"
Expand All @@ -43,6 +47,7 @@ SQLite = "1.5.1"
SciMLBase = "1.60"
StructArrays = "0.6.13"
Tables = "1"
TerminalLoggers = "0.1.7"
TimerOutputs = "0.5"
julia = "1.9"

Expand Down
2 changes: 2 additions & 0 deletions core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ using SparseArrays
using SQLite: SQLite, DB, Query, esc_id
using StructArrays: StructVector
using Tables: Tables, AbstractRow, columntable, getcolumn
using TerminalLoggers: TerminalLogger
using TimerOutputs

const to = TimerOutput()
TimerOutputs.complement!()

include("validation.jl")
include("solve.jl")
include("jac.jl")
include("config.jl")
using .config: Config, Solver, algorithm, snake_case, zstd, lz4
include("utils.jl")
Expand Down
13 changes: 4 additions & 9 deletions core/src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function BMI.initialize(T::Type{Model}, config::Config)::Model
timespan = (zero(t_end), t_end)

jac_prototype = get_jac_prototype(parameters)
RHS = ODEFunction(water_balance!; jac_prototype)
RHS = ODEFunction(water_balance!; jac_prototype, jac = water_balance_jac!)

@timeit_debug to "Setup ODEProblem" begin
prob = ODEProblem(RHS, u0, timespan, parameters)
Expand Down Expand Up @@ -209,13 +209,8 @@ function get_value(
(; basin, flow_boundary) = p

if variable == "level"
has_index, basin_idx = id_index(basin.node_id, feature_id)

if !has_index
error("Level condition node #$feature_id is not a basin.")
end

_, level = get_area_and_level(basin, basin_idx, storage[basin_idx])
hasindex, basin_idx = id_index(basin.node_id, feature_id)
_, level, _ = get_area_and_level(basin, basin_idx, storage[basin_idx])
value = level

elseif variable == "flow_rate"
Expand All @@ -227,7 +222,7 @@ function get_value(

value = flow_boundary.flow_rate[flow_boundary_idx](t)
else
throw(ValueError("Unsupported condition variable $variable."))
error("Unsupported condition variable $variable.")
end

return value
Expand Down
2 changes: 2 additions & 0 deletions core/src/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function Basin(db::DB, config::Config)::Basin
n = length(node_id)
current_level = zeros(n)
current_area = zeros(n)
current_darea = zeros(n)

precipitation = fill(NaN, length(node_id))
potential_evaporation = fill(NaN, length(node_id))
Expand Down Expand Up @@ -326,6 +327,7 @@ function Basin(db::DB, config::Config)::Basin
infiltration,
current_level,
current_area,
current_darea,
area,
level,
storage,
Expand Down
Loading

0 comments on commit bac4dbe

Please sign in to comment.