swb2 icon indicating copy to clipboard operation
swb2 copied to clipboard

Routing sequencing out of order

Open smwesten-usgs opened this issue 1 year ago • 0 comments

Glen Champion writes:

Based on what I can tell, I don’t think there are differences in the routing between different versions of SWB2. I think there is the same bug in the routing in all versions. I got the same results using the executable provided with the swb2_examples (which you updated on 2/2/2018), version 2.0.2, version 2.2.0, and my own compilation of version 2.3. I provided examples of errors in the output from the simple routing example in the email. Since the example is so small, you can also just extract ASCII grids of runoff and runon, look at them side by side with the D8 grid, and see, for example, that there are cells that should have runon that have none.

There is no problem with the information in the routing table, the problem is that the routing isn’t sequenced according to the sort order (See key code snippets below).

        Module daily_calculation
28  subroutine perform_daily_calculation(cells)
. . .
82    do jndx=1, ubound( cells%sort_order, 1 )
. . .
86      indx = cells%sort_order( jndx )
. . .
222       ! rejected net_infiltration + runoff will be routed downslope if routing option is turned on
223        call cells%calc_routing( index=indx )

Ok, the index passed to the calc_routing process is the cell_index that corresponds to jndx sort order.

        Module model_domain
1736  subroutine model_calculate_routing_D8( this, indx )
. . .
1750    cell_index    = get_cell_index( indx )
1751    target_index  = get_target_index( indx )

This is looking up the cell_index and target_index using the cell_index, but the sort-order index is what these procedures should use (i.e., jndx in perform_daily_calculation). So, the cell_index and target_index variables will not be the cells that you want to be computing right now, except if the cell_index is a headwater cell or other special circumstances in the routing table. Now, when calculating the runon to the target index, the runoff and rejected infiltration may not have yet been computed for the cell_index.

1765           this%runon( target_index ) =                                               &
1766              this%runon( target_index )                                          &
1767            + this%runoff( cell_index )                                           &
1768            + this%rejected_net_infiltration( cell_index )

The fix is to change indx to jndx in line 223 of the daily_calculation module. When I made that change, the runon for each cell is what it should be.

smwesten-usgs avatar Apr 07 '23 20:04 smwesten-usgs