Replace SimpleDiGraph flowgraph with compact FlowGraph (~320 MB vs ~5 GB for 80M cells)#12
Open
Oddan wants to merge 4 commits into
Open
Replace SimpleDiGraph flowgraph with compact FlowGraph (~320 MB vs ~5 GB for 80M cells)#12Oddan wants to merge 4 commits into
Oddan wants to merge 4 commits into
Conversation
Introduces a custom FlowGraph (src/FlowGraph.jl) that stores forward adjacency
as Vector{Int32} (~320 MB for 80M cells) instead of Graphs.SimpleDiGraph
(~5 GB), with a precomputed topological order and lazy backward adjacency.
- New: src/FlowGraph.jl — struct + downstream_cells, has_downstream,
topological_order, upstream_dfs API
- TrapStructure.flowgraph field changed from Graphs.SimpleDiGraph to FlowGraph
- spillregions.jl: build FlowGraph instead of SimpleDiGraph
- watercourses.jl: use topological_order(g) and downstream_cells(g, cell);
update _update_runoff! signature to accept FlowGraph
- fill_sequence/flow.jl: replace outneighbors calls with has_downstream /
downstream_cells
- utils.jl: update _downstream_cell, upstream_area, reconstruct_spillfield,
and current_upstream_area call sites
- docs/flowgraph-redesign.md: design document with rationale and full details
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
topological_order returns Vector{Int32}, so cur_node is Int32 when
downstream_cells/has_downstream are called from watercourses. Widen
cell argument from ::Int to ::Integer in all three public functions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Test functions in basicTestFuns.jl were calling spillregions(field) without destructuring, receiving the full (regions, flowgraph, bottomcells) tuple instead of just the regions matrix. Add trailing comma to extract only the regions matrix, matching the pattern already used in test_spillregions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents complications, correctness risks, and expected runtime impact
of changing regions::Matrix{Int64} and footprints::Vector{Vector{Int64}}
to Int32, for ~640 MB memory saving on 80M-cell terrains.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FlowGraphstruct (src/FlowGraph.jl) that stores forward adjacency asVector{Int32}instead ofGraphs.SimpleDiGraphSimpleDiGraphtopological_sort_by_dfscalls inwatercoursesupstream_dfs(UI-only path, built on first use)docs/flowgraph-redesign.mdChanged files
src/FlowGraph.jl— struct +downstream_cells,has_downstream,topological_order,upstream_dfssrc/TrapStructure.jl— field typeflowgraph::FlowGraphsrc/spillregions.jl— constructFlowGraphinstead ofSimpleDiGraphsrc/watercourses.jl—topological_order(g),downstream_cells(g, cell), updated_update_runoff!signaturesrc/fill_sequence/flow.jl—has_downstream/downstream_cellsreplaceoutneighborssrc/utils.jl— update_downstream_cell,upstream_area,reconstruct_spillfield,current_upstream_areadocs/flowgraph-redesign.md— design documentTest plan
julia --project test/runtests.jlflow_path_fromand river tracing in the web interfacecurrent_upstream_area(exercises the lazy backward adjacency)🤖 Generated with Claude Code