Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parameter initialization in core #2133

Open
SouthEndMusic opened this issue Mar 5, 2025 · 0 comments
Open

Refactor parameter initialization in core #2133

SouthEndMusic opened this issue Mar 5, 2025 · 0 comments
Labels
core Issues related to the computational core in Julia

Comments

@SouthEndMusic
Copy link
Collaborator

The function parse_static_and_time is very type unstable, because it does a lot of different things for a lot of different types. I propose the following stages in parameter initializations for nodes:

  • Retrieve the node ids with get_node_ids(db, node_type_string)
  • Initialize the node object making as much use of @kwdef and the zeros(T, length(node_ids)) and otherwise Vector{T}(undef, length(node_ids)) patterns as possible, not caring yet about the actual parameter values
  • Load the relevant tables with load_structvector(db, config, MyTableV1)
  • Per parameter, call
parse_parameter!(
   parameter::Vector{T}, 
   node_ids::Vector{NodeID}; 
   static::Union{StructVector, Nothing} = nothing,
   time::Union{StructVector, Nothing} = nothing,
   default::Union{Nothing, T},
   is_complete::Bool = true
)::Nothing where {T}

which is a trimmed down version of parse_static_and_time. Here the old time_interpolatables and interpolation_type are inferred from T. This for instance allows different fields of the same node type to have different interpolation types.

  • Lastly, call a separate function build_control_mapping! to initialize control states, also split out from parse_static_and_time.

This approach makes the parameter parsing less opaque, and gets rid of the parse_static_and_time versus 'completely custom implementation' divide, for instance in the case of TabulatedRatingCurve. If it makes much more sense to parse certain parameters together, specific methods for that can be written. Another advantage of this approach is that the constructors of the node objects are less likely to bloat up when new features and/or fields are added.

@SouthEndMusic SouthEndMusic added the core Issues related to the computational core in Julia label Mar 5, 2025
@github-project-automation github-project-automation bot moved this to To do in Ribasim Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues related to the computational core in Julia
Projects
Status: To do
Development

No branches or pull requests

1 participant