Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
a667e16
Refactor water balance and flow handling in Ribasim
verheem Apr 16, 2026
bf9a2d1
bart + claude's proposal: find trapezoidal average flow that satisfie…
verheem Apr 16, 2026
c1cc628
fix
verheem Apr 16, 2026
04a8bdc
double maximum storage
verheem Apr 17, 2026
b56e026
revert doubling the storage and change test model
verheem Apr 17, 2026
1b48699
Add convergence back
verheem Apr 17, 2026
3492fc5
reduce vibe
verheem Apr 17, 2026
b880ae4
more cleanup
verheem Apr 17, 2026
72adc24
fix some tests
verheem Apr 17, 2026
c8f74e1
fix test and lower level difference threshold
verheem Apr 17, 2026
7eddcbe
fix convergence test
verheem Apr 17, 2026
4d57ef6
fix tests
verheem Apr 17, 2026
ae58587
revert level diff thres
verheem Apr 20, 2026
63f050e
use sparse cholesky
verheem Apr 20, 2026
82f0c2c
Rosenbrock 2.5x performance increase
verheem Apr 20, 2026
497f532
loosen abs tol to 100 L for solver
verheem Apr 20, 2026
9d8ae36
fix some bmi tests and lp
verheem Apr 21, 2026
cc9acda
add constrained flow solve
verheem Apr 21, 2026
875780b
Add backtracking back
verheem May 4, 2026
5e85546
temp comment out extra contrained solve
verheem May 4, 2026
7693c72
add threading to sync flow rates
verheem May 7, 2026
d4a435b
fast lookup with precomputed mapping. Almost another 2x speedup
verheem May 7, 2026
0e84cb8
remove threading again
verheem May 7, 2026
4df8df0
remove threading better
verheem May 7, 2026
50ac52c
update default solver algorithm from Rosenbrock23 to QNDF
verheem May 15, 2026
2c6e690
Merge remote-tracking branch 'origin/main' into basin-storage-states
verheem May 15, 2026
bd62c2c
Set abstol to 1e-4
visr May 15, 2026
4181bca
improve performance with ldiv, combine ingoing link with outgoing and…
verheem May 18, 2026
fb4656e
working new formulation with cosmetic storage
verheem May 18, 2026
400b82a
temporarily turn off water balance check. It is not meaningfull with …
verheem May 18, 2026
2342551
Fix initialization of flow callback and UserDemand
visr May 19, 2026
351936b
Remove cosmetic storage
visr May 19, 2026
3ce03cd
Update Manifest.toml / OrdinaryDiffEq v7 (#3082)
visr May 18, 2026
4c9b766
Connection added (TeamCity change in 'Ribasim' project)
May 18, 2026
5096b05
Resolve
visr May 19, 2026
5692bd4
fixt tests
verheem Jun 4, 2026
d861135
fix continuity holds between 99-101%
verheem Jun 4, 2026
7a1c395
fix continuity tests
verheem Jun 4, 2026
4de48df
Merge branch 'main' into basin-storage-states
verheem Jun 4, 2026
d78c24f
fix undefined du
visr Jun 5, 2026
a01ca2c
fix the last tests
verheem Jun 8, 2026
dae0b3d
remove old comment
verheem Jun 8, 2026
43d5fec
use simpsons rule for integrating flows
verheem Jun 8, 2026
aba5b06
Merge branch 'main' into basin-storage-states
verheem Jun 8, 2026
4f67114
fix alloc error
verheem Jun 11, 2026
7a9157d
fix transient test
verheem Jun 11, 2026
c78909f
Remove unused `unsafe_array`
visr Jun 11, 2026
3b8d2b9
some docs and test fixes
verheem Jun 11, 2026
3fd59b2
Merge branch 'basin-storage-states' of https://github.com/Deltares/Ri…
verheem Jun 11, 2026
a6ec9fa
tighten tolerances and small fixes
verheem Jun 11, 2026
13dd924
loosen tol a bit
verheem Jun 12, 2026
e32b1ba
Fable's flow correcrion idea
verheem Jun 12, 2026
8493ae0
Bump the all-actions group with 2 updates (#3101)
dependabot[bot] Jun 9, 2026
25d5b8f
QGIS plot and guide improvements (#3102)
visr Jun 9, 2026
e4c905b
QGIS guide: add spatial results and topology (#3104)
visr Jun 9, 2026
422b462
Use QGIS DevTools debugging and add QGIS Pytest plugin (#3106)
deltamarnix Jun 11, 2026
d77789e
Simplify `NodeType.T(s::Symbol)` (#3109)
visr Jun 15, 2026
50835ec
Fix newlines in docs' `run_ribasim` output (#3112)
visr Jun 15, 2026
0d23ece
[delwaq] Drop required graph and substance state variables (#3110)
evetion Jun 16, 2026
196f05d
Add Observation support to QGIS plot widget (#3115)
visr Jun 16, 2026
e617075
Prepare release v2026.1.2 (#3116)
visr Jun 16, 2026
4c1e977
Update version numbers in docs
visr Jun 16, 2026
8bd9bc7
Don't use string interpolation in query
visr Jun 16, 2026
66c5d56
Free SQLite
visr Jun 17, 2026
2ea78f0
Bump actions/checkout from 6.0.3 to 7.0.0 in the all-actions group (#…
dependabot[bot] Jun 23, 2026
0452a4f
Merge branch 'main' into basin-storage-states
visr Jun 23, 2026
2d06950
runic formatting
visr Jun 23, 2026
d82e39c
Bring back specialize for ODEFunction and ODEProblem
visr Jun 23, 2026
be61f3a
Align documented abstol and reltol
visr Jun 23, 2026
79545f8
Resolve some of my own comments
SouthEndMusic Jun 25, 2026
4072dd4
Restore chunksize
visr Jun 26, 2026
5d79f06
Update numerics.qmd
visr Jun 26, 2026
019c13b
Merge branch 'main' into basin-storage-states
SouthEndMusic Jun 29, 2026
02c5ecd
Some fixes
SouthEndMusic Jun 29, 2026
ed58f45
Refactor all the things
SouthEndMusic Jul 2, 2026
0a4b0e3
many fixes
SouthEndMusic Jul 6, 2026
cd039de
Reset manifest
visr Jul 7, 2026
c0dc0a1
Merge branch 'main' into basin-storage-states
visr Jul 7, 2026
a4384bb
Reset core/Project.toml to main
visr Jul 7, 2026
908bad9
Introduce new state vector
SouthEndMusic Jul 7, 2026
f5ed0cb
CArrays offset nested axes fix
SouthEndMusic Jul 10, 2026
3b00397
Better CArrays -> CVectors fix
SouthEndMusic Jul 10, 2026
a5ba106
Refactor all the things
SouthEndMusic Jul 14, 2026
9155f17
Many fixes
SouthEndMusic Jul 14, 2026
da0ee30
More fixes
SouthEndMusic Jul 15, 2026
28788ec
More fixes again
SouthEndMusic Jul 15, 2026
a5650bb
More fixes again would you believe it
SouthEndMusic Jul 15, 2026
aaa0007
Remove backtracking code
SouthEndMusic Jul 15, 2026
1c0c121
Yet more fixes
SouthEndMusic Jul 16, 2026
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
6 changes: 3 additions & 3 deletions Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ projects = ["core"]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
BasicModelInterface = "59605e27-edc0-445a-b93d-c09a3a50b330"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
2 changes: 2 additions & 0 deletions core/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ projects = ["test"]
[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
BasicModelInterface = "59605e27-edc0-445a-b93d-c09a3a50b330"
Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d"
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"
Expand Down Expand Up @@ -60,6 +61,7 @@ TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
[compat]
ADTypes = "1.13"
Accessors = "0.1"
ArrayInterface = "7.27.0"
BasicModelInterface = "0.1"
Configurations = "0.17"
DBInterface = "2.4"
Expand Down
39 changes: 24 additions & 15 deletions core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@ using PrecompileTools: @setup_workload, @compile_workload
using DifferentiationInterface:
AutoSparse,
Constant,
Cache,
prepare_jacobian,
value_and_jacobian!,
jacobian!,
prepare_derivative,
derivative!,
second_derivative

using ForwardDiff: derivative as forward_diff
using ForwardDiff: ForwardDiff, Dual, Partials, seed!, partials, valtype, derivative as forward_diff

using ArrayInterface: ArrayInterface

# Algorithms for solving ODEs.
using OrdinaryDiffEqCore: OrdinaryDiffEqCore, get_du
using OrdinaryDiffEqDifferentiation:
OrdinaryDiffEqDifferentiation, dolinsolve, jacobian2W!
using SciMLOperators: WOperator, MatrixOperator
using OrdinaryDiffEqCore:
OrdinaryDiffEqCore,
OrdinaryDiffEqAdaptiveImplicitAlgorithm,
OrdinaryDiffEqImplicitAlgorithm,
get_du
using DiffEqBase: DiffEqBase
import ADTypes
using ADTypes: AutoForwardDiff
import ForwardDiff
import NaNMath
import OrdinaryDiffEqBDF

# Interface for defining and solving the ODE problem of the physical layer.
Expand All @@ -54,21 +59,22 @@ using SciMLBase:
DEIntegrator,
FullSpecialize,
NoSpecialize,
SciMLOperators,
AbstractSciMLOperator,
LinearProblem,
LinearSolution

using OrdinaryDiffEqDifferentiation:
OrdinaryDiffEqDifferentiation, do_newJW, jacobian2W!, dolinsolve

# Automatically detecting the sparsity pattern of the Jacobian of water_balance!
# through operator overloading
using SparseConnectivityTracer: GradientTracer, TracerSparsityDetector
using SparseConnectivityTracer: TracerSparsityDetector
using SparseMatrixColorings: GreedyColoringAlgorithm, sparsity_pattern

# For efficient sparse computations
using SparseArrays: SparseMatrixCSC, sparse, nzrange
using SparseArrays: SparseMatrixCSC, spzeros, sparse, findnz

# Linear algebra
using LinearAlgebra: LinearAlgebra, mul!, UniformScaling
using LinearAlgebra: LinearAlgebra, mul!, dot, I

# Interpolation functionality, used for e.g.
# basin profiles and TabulatedRatingCurve. See also the node
Expand Down Expand Up @@ -108,7 +114,7 @@ import BasicModelInterface as BMI
using DelimitedFiles: writedlm

# Reading GeoPackage files, which are SQLite databases with spatial data
using SQLite: SQLite, DB, Query, esc_id
using SQLite: SQLite, DB, esc_id
using DBInterface: execute, prepare

# Logging to both the console and a file
Expand Down Expand Up @@ -169,13 +175,17 @@ using Printf: @sprintf

using Base.Threads: nthreads

include("carrays.jl")
using .CArrays: CVector, getaxes, getdata
using SciMLOperators: SciMLOperators, WOperator, AbstractSciMLOperator

include("cvectors.jl")
using .CVectors: CVector, getaxes, getdata
include("schema.jl")
include("config.jl")
using .config
using .config: with_mass_matrix
include("parameter.jl")
include("validation.jl")
include("formulate_flows.jl")
include("solve.jl")
include("logo.jl")
include("logging.jl")
Expand All @@ -184,7 +194,6 @@ include("allocation_init.jl")
include("allocation_optim.jl")
include("util.jl")
include("graph.jl")
include("differentiation.jl")
include("model.jl")
include("read.jl")
include("write.jl")
Expand Down
29 changes: 8 additions & 21 deletions core/src/allocation_init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function add_user_demand!(
allocation_model::AllocationModel,
p_independent::ParametersIndependent,
)::Nothing
(; problem, cumulative_supplied_volume, node_ids_in_subnetwork) = allocation_model
(; problem, node_ids_in_subnetwork) = allocation_model
(; user_demand_ids_subnetwork) = node_ids_in_subnetwork
(; user_demand) = p_independent
(; inflow_links, outflow_link) = user_demand
Expand Down Expand Up @@ -235,14 +235,6 @@ function add_user_demand!(
return_factor * sum(flow[lm.link] for lm in inflow_links[node_id.idx]),
base_name = "user_demand_return_flow"
)

# Add the links for which the supplied volume is required for output
for node_id in user_demand_ids_subnetwork
for link_metadata in inflow_links[node_id.idx]
cumulative_supplied_volume[link_metadata.link] = 0.0
end
end

return nothing
end

Expand All @@ -253,11 +245,11 @@ function add_flow_demand!(
allocation_model::AllocationModel,
p_independent::ParametersIndependent,
)::Nothing
(; problem, cumulative_supplied_volume, scaling, node_ids_in_subnetwork) =
(; problem, scaling, node_ids_in_subnetwork) =
allocation_model
(; node_ids_subnetwork_with_flow_demand, flow_demand_ids_subnetwork) =
(; node_ids_subnetwork_with_flow_demand) =
node_ids_in_subnetwork
(; graph, flow_demand) = p_independent
(; graph) = p_independent
flow = problem[:flow]

# Define decision variables: flow allocated to FlowDemand node per demand priority
Expand Down Expand Up @@ -327,11 +319,6 @@ function add_flow_demand!(
d - flow_demand_allocated[node_id, demand_priority],
base_name = "flow_demand_relative_error_constraint"
)

# Add the links for which the supplied volume is required for output
for node_id in flow_demand_ids_subnetwork
cumulative_supplied_volume[flow_demand.inflow_link[node_id.idx].link] = 0.0
end
return nothing
end

Expand Down Expand Up @@ -433,15 +420,15 @@ function add_linearized_connector_node!(

# Only linearize if the level comes from a Basin
upstream_node = inflow_link[node_id.idx].link[1]
if upstream_node.type == NodeType.Basin
if upstream_node.is_basin
JuMP.add_to_expression!(
linearization,
∂q∂h_upstream * storage_change[upstream_node] / A,
)
end

downstream_node = outflow_link[node_id.idx].link[2]
if downstream_node.type == NodeType.Basin
if downstream_node.is_basin
JuMP.add_to_expression!(
linearization,
∂q∂h_downstream * storage_change[downstream_node] / A,
Expand Down Expand Up @@ -926,13 +913,13 @@ function NodeIDsInSubnetwork(
# basin_ids_subnetwork_with_level_demand
get_nodes(
node_id ->
node_id.type == NodeType.Basin &&
node_id.is_basin &&
!isnothing(get_external_demand_id(p_independent, node_id)),
),
# node_ids_subnetwork_with_flow_demand
get_nodes(
node_id ->
node_id.type != NodeType.Basin &&
!node_id.is_basin &&
!isnothing(get_external_demand_id(p_independent, node_id)),
),
)
Expand Down
Loading
Loading