Skip to content

Commit

Permalink
Reorganize code among files in core (#1101)
Browse files Browse the repository at this point in the history
Apologies for the huge diff and the conflicts this will create, but a
reorganization of the core code was overdue. This only moves code, there
are no other changes.

A rough overview of the changes:

- validation.jl: split out schemas.jl, and moved all validation
functions in
- solve.jl: split out parameter structs to parameter.jl
- create.jl and io.jl: split out into read.jl and write.jl
- const.jl: move single const to write.jl
- add callback.jl for solver callback related code
- add graph.jl for graph related code
- bmi.jl: split out all non-BMI functions, moved large function bodies
elsewhere
- utils.jl: split out add sparsity.jl for Jacobian sparsity generation
  • Loading branch information
visr authored Feb 9, 2024
1 parent 6c6969f commit 94a02aa
Show file tree
Hide file tree
Showing 18 changed files with 3,064 additions and 3,068 deletions.
20 changes: 12 additions & 8 deletions core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For more granular access, see:
- [`Config`](@ref)
- [`Model`](@ref)
- [`solve!`](@ref)
- [`BMI.finalize`](@ref)
- [`write_results`](@ref)
"""
module Ribasim

Expand Down Expand Up @@ -75,18 +75,22 @@ export libribasim
const to = TimerOutput()
TimerOutputs.complement!()

include("validation.jl")
include("solve.jl")
include("schema.jl")
include("config.jl")
using .config
include("parameter.jl")
include("validation.jl")
include("solve.jl")
include("logging.jl")
include("allocation.jl")
include("utils.jl")
include("lib.jl")
include("io.jl")
include("create.jl")
include("util.jl")
include("sparsity.jl")
include("graph.jl")
include("model.jl")
include("read.jl")
include("write.jl")
include("bmi.jl")
include("consts.jl")
include("callback.jl")
include("main.jl")
include("libribasim.jl")

Expand Down
33 changes: 0 additions & 33 deletions core/src/allocation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,39 +283,6 @@ end

const allocation_source_nodetypes = Set{Symbol}([:level_boundary, :flow_boundary])

"""
The source nodes must only have one allocation outneighbor and no allocation inneighbors.
"""
function valid_sources(p::Parameters, allocation_network_id::Int)::Bool
(; graph) = p

edge_ids = graph[].edge_ids[allocation_network_id]

errors = false

for edge in edge_ids
(id_source, id_dst) = edge
if graph[id_source, id_dst].allocation_network_id_source == allocation_network_id
from_source_node = graph[id_source].type in allocation_source_nodetypes

if is_main_network(allocation_network_id)
if !from_source_node
errors = true
@error "The source node of source edge $edge in the main network must be one of $allocation_source_nodetypes."
end
else
from_main_network = is_main_network(graph[id_source].allocation_network_id)

if !from_source_node && !from_main_network
errors = true
@error "The source node of source edge $edge for subnetwork $allocation_network_id is neither a source node nor is it coming from the main network."
end
end
end
end
return !errors
end

"""
Remove allocation user return flow edges that are upstream of the user itself.
"""
Expand Down
Loading

0 comments on commit 94a02aa

Please sign in to comment.