To translate data from networks, e.g. the water level output or bed level from 1D hydraulic simulations, to gridded (MODFLOW) input, we need some tooling that's capable of providing this data at the appropriate scale.
An appropriate method is to intersect the network topology with the grid topology, taking the midpoints of the resulting intersecting edges, and adding these as nodes to the original network. Then, we can apply some form of interpolation along the new network based on the connectivity to propagate features to arbitrary locations.
Some implementation ideas. First we search for the new nodes, and remove far away vertices. Next, we need to create a new edge_node_connectivity. Since we're refining, we're just replacing original edges by refined smaller ones. The ones to refine can identified by their count.
We should probably also check for uniques of the old and new vertices.
Anyway, to set up the new edge node connectivity, we need to set the right order. E.g. 0 -> 1 may become 0 -> 3 -> 2 -> 1.
To find the appropriate order, we just need to compute the distance from the first vertex of the original edges.
This potentially includes nodes that are tied "to themselves" (since they are the end of on edge, and the start of the next).
We can easily remove those and insert them into the original edge_node_connectivity to construct a new grid.
After discussion with @JoerivanEngelen:
To translate data from networks, e.g. the water level output or bed level from 1D hydraulic simulations, to gridded (MODFLOW) input, we need some tooling that's capable of providing this data at the appropriate scale.
An appropriate method is to intersect the network topology with the grid topology, taking the midpoints of the resulting intersecting edges, and adding these as nodes to the original network. Then, we can apply some form of interpolation along the new network based on the connectivity to propagate features to arbitrary locations.
Some changes in numba_celltree will allow us to build a tree for 1D networks and search for edges efficiently. https://github.com/Deltares/numba_celltree/issues/11
Some implementation ideas. First we search for the new nodes, and remove far away vertices. Next, we need to create a new edge_node_connectivity. Since we're refining, we're just replacing original edges by refined smaller ones. The ones to refine can identified by their count.
We should probably also check for uniques of the old and new vertices. Anyway, to set up the new edge node connectivity, we need to set the right order. E.g. 0 -> 1 may become 0 -> 3 -> 2 -> 1. To find the appropriate order, we just need to compute the distance from the first vertex of the original edges.
Then we use a lexsort to first sort by edge_index, then distance. To make things a little easier, we add the original network vertices as well.
This puts everything in order. Now we just need to tie the nodes together to form the (sub-)edges.
This potentially includes nodes that are tied "to themselves" (since they are the end of on edge, and the start of the next). We can easily remove those and insert them into the original edge_node_connectivity to construct a new grid.