Ribasim
Ribasim copied to clipboard
Refactor allocation code
These refactoring points came out of the knowledge sharing session (which was more of a code review session):
- [x] Use function
is_main_networkhere: https://github.com/Deltares/Ribasim/blob/61b3a173155647b78735a73357908cf8c48ed9ce/core/src/allocation_optim.jl#L1035 - [ ] Introduce a separate
allocation_util.jlfile with allocation utility functions. This might need some discussion though, I'm not sure what counts as a utility function - [ ] The function
allocate!: Dispatch onoptimization_type, so severalifstatements can be removed - [ ] The functions
allocate!andallocate_priority!need to be renamed, maybe simply tooptimize!andoptimize_priority!, as they are not always allocating, depending on theoptimization_type - [ ] For the functions in
allocate_priority - We now only have the
AbstractParameterNodetype for nodes. We can add a more specific abstract node type in between, sayAbstractDemandNode, for nodes that define a demand. - For the
adjust_demands_*functions, loop over theAbstractDemandNodesubtypes and dispatch on them. Alternatively, for all theadjust_*functions, dispatch on the constraint set names.
Hi @SouthEndMusic
You now have one allocate function where you have multiple times and iff statement to see if you need to collect_demands.
In callback.jl (update_allocation) you call allocate multiple times, sometimes to collect_demands, sometimes to allocate_demands.
I would recommend to turn the current allocate function in two functions, one called collect_demands and one called allocate of allocate_demands
[ ] split allocate into collect_demands and allocate_demands function
Steps 1, 3, 4, 5 are finished.
As for step 2, the functions in allocation_optim.jl are utility functions. If we create a new file for utility functions, based on the definition of utility functions in programming, we might move everything from allocation_optim.jl.
I understand that we wanted to split allocation_optim.jl into multiple files, maybe we can come up a different categorization for the functions in there
Hi @Jingru923 , did you also split the current allocate function in two functions, one called collect_demands and one called allocate of allocate_demands ?
Yes @gijsber