Deltares / Ribasim

Water resources modeling
https://deltares.github.io/Ribasim/
MIT License
36 stars 5 forks source link

Use keywords for creating parameter structs #1566

Closed visr closed 1 week ago

visr commented 1 week ago

By putting the kwdef macro in front of our struct definitions we can create them with keywords and set defaults if applicable. This helps with readability and makes it less likely to pass the wrong argument due to a wrong order. E.g. compare this test code before and after:

basin = Ribasim.Basin(
    NodeID.(:Basin, [1], 1),
    [NodeID[]],
    [NodeID[]],
    zeros(1),
    zeros(1),
    zeros(1),
    zeros(1),
    zeros(1),
    zeros(1),
    zeros(1),
    [storage_to_level],
    [level_to_area],
    demand,
    StructVector{Ribasim.BasinTimeV1}(undef, 0),
)

basin = Ribasim.Basin(;
    node_id = NodeID.(:Basin, [1], 1),
    storage_to_level = [storage_to_level],
    level_to_area = [level_to_area],
    demand,
    time = StructVector{Ribasim.BasinTimeV1}(undef, 0),
)```
Jingru923 commented 1 week ago

Looks good to me. In terms of which struct to make use of this macro and to have default parameter, I trust you. For the unit tests, I don't see any unit tests that can make use of this being left out. Approve (I also got your failing test on TC passed)