@@ -389,7 +389,9 @@ SUBROUTINE route_run(rstwr)
389389 flush(iulog)
390390
391391 associate(nt_liq = > ctl% nt_liq, &
392- nt_ice = > ctl% nt_ice)
392+ nt_ice = > ctl% nt_ice, &
393+ begr = > ctl% begr, &
394+ endr = > ctl% endr)
393395
394396 !- ------------------------------------------------------
395397 ! Initialize mizuRoute history handler and fields
@@ -435,20 +437,23 @@ SUBROUTINE route_run(rstwr)
435437 ! 2. direct_to_outlet: send negative flow to an outlet of the reach and subtract the flow from the outlet reach
436438 call t_startf(' mizuRoute_bypass_route' )
437439
440+ allocate (qSend(ctl% lnumr))
441+ qSend = 0._r8
442+
438443 select case (trim (bypass_routing_option))
439444 case (' direct_in_place' )
440445 ctl% direct = 0._r8
441- do nr = ctl % begr,ctl % endr
442- ! --- Transfer qgwl [mm/s] to ocean
443- if ( trim (qgwl_runoff_option ) == ' all ' ) then ! send all qgwl flow to ocean
444- ctl% direct (nr, nt_liq) = ctl % qgwl(nr,nt_liq)
445- ctl % qgwl(nr,nt_liq ) = 0._r8
446- else if ( trim (qgwl_runoff_option) == ' negative ' ) then ! send only negative qgwl flow to ocean
447- if ( ctl% qgwl(nr, nt_liq) < 0._r8 ) then
448- ctl% direct (nr, nt_liq) = ctl % qgwl(nr,nt_liq)
449- ctl % qgwl(nr,nt_liq) = 0._r8
450- endif
451- else if ( trim (qgwl_runoff_option) == ' threshold ' ) then
446+ ! --- Transfer qgwl [mm/s] to ocean
447+ if ( trim (qgwl_runoff_option) == ' all ' ) then ! send all qgwl flow to ocean
448+ ctl % direct (begr:endr, nt_liq ) = ctl % direct (begr:endr, nt_liq) + ctl % qgwl(begr:endr, nt_liq)
449+ ctl% qgwl(begr:endr, nt_liq) = 0._r8
450+ else if ( trim (qgwl_runoff_option ) == ' negative ' ) then ! send only negative qgwl flow to ocean
451+ where (ctl % qgwl(begr:endr, nt_liq) < 0._r8 )
452+ ctl% direct (begr:endr, nt_liq) = ctl % direct (begr:endr, nt_liq) + ctl % qgwl(begr:endr, nt_liq)
453+ ctl% qgwl(begr:endr, nt_liq) = 0._r8
454+ end where
455+ else if ( trim (qgwl_runoff_option) == ' threshold ' ) then
456+ do nr = begr,endr
452457 ! if qgwl is negative, and adding it to the main channel
453458 ! would bring main channel storage below a threshold,
454459 ! send qgwl directly to ocean
@@ -462,26 +467,38 @@ SUBROUTINE route_run(rstwr)
462467 ctl% direct (nr,nt_liq) = ctl% qgwl(nr,nt_liq)
463468 ctl% qgwl(nr,nt_liq) = 0._r8
464469 end if
465- end if
466- ! --- Transfer qsub to ocean [mm/s]
467- if (ctl% qsub(nr,nt_liq) < 0._r8 ) then
468- ctl% direct (nr,nt_liq) = ctl% direct (nr,nt_liq)+ ctl% qsub(nr,nt_liq)
469- ctl% qsub(nr,nt_liq) = 0._r8
470- endif
471- end do
470+ end do
471+ end if
472+ ! --- Transfer negative qsub to ocean [mm/s]
473+ where (ctl% qsub(begr:endr, nt_liq) < 0._r8 )
474+ ctl% direct (begr:endr, nt_liq) = ctl% direct (begr:endr, nt_liq) + ctl% qsub(begr:endr, nt_liq)
475+ ctl% qsub(begr:endr, nt_liq) = 0._r8
476+ end where
477+
478+ ! --- Transfer negative qsur to ocean [mm/s]
479+ where (ctl% qsur(begr:endr, nt_liq) < 0._r8 )
480+ ctl% direct (begr:endr, nt_liq) = ctl% direct (begr:endr, nt_liq) + ctl% qsur(begr:endr, nt_liq)
481+ ctl% qsur(begr:endr, nt_liq) = 0._r8
482+ end where
483+
472484 case (' direct_to_outlet' )
473- allocate (qSend(ctl% lnumr))
474- qSend(:) = 0._r8 ! total negative q [mm/s] to be sent to the outlet (converted to +)
475- do nr = ctl% begr,ctl% endr
476- if (ctl% qgwl(nr,nt_liq) < 0._r8 ) then
477- qSend(nr) = ctl% qgwl(nr,nt_liq)
478- ctl% qgwl(nr,nt_liq) = 0._r8
479- end if
480- if (ctl% qsub(nr,nt_liq) < 0._r8 ) then
481- qSend(nr) = qSend(nr) + ctl% qsub(nr,nt_liq)
482- ctl% qsub(nr,nt_liq) = 0._r8
483- end if
484- end do
485+ ! ---- qgwl [mm/s]
486+ select case (trim (qgwl_runoff_option))
487+ case (' all' ) ! send all qgwl flow to the outlet
488+ qSend(begr:endr) = qSend(begr:endr) + ctl% qgwl(begr:endr, nt_liq)
489+ ctl% qgwl(begr:endr, nt_liq) = 0._r8
490+ case (' negative' ) ! send negative qgwl flow to the outlet
491+ where (ctl% qgwl(begr:endr, nt_liq) < 0._r8 )
492+ qSend(begr:endr) = qSend(begr:endr) + ctl% qgwl(begr:endr, nt_liq)
493+ ctl% qgwl(begr:endr, nt_liq) = 0._r8
494+ end where
495+ case default ; call shr_sys_abort(trim (subname)// ' unexpected qgwl_runoff_option for direct_to_outlet' )
496+ end select
497+ ! ---- qsub [mm/s]
498+ where (ctl% qsub(begr:endr, nt_liq) < 0._r8 )
499+ qSend(begr:endr) = qSend(begr:endr) + ctl% qsub(begr:endr, nt_liq)
500+ ctl% qsub(begr:endr, nt_liq) = 0._r8
501+ end where
485502
486503 ! Distribute "direct runoff to ocean" to targe reach (i.e., outlet of river network)
487504 call shr_mpi_sparse_distribute(qSend, commRch(:)% destTask, commRch(:)% destIndex, ctl% direct (:,nt_liq), fillvalue= 0._r8 )
@@ -495,10 +512,8 @@ SUBROUTINE route_run(rstwr)
495512
496513 call t_startf(' mizuRoute_direct_to_outlet_land_ice' )
497514
498- qSend(:) = 0._r8 ! total negative q [mm/s] to be sent to the outlet (converted to +)
499- do nr = ctl% begr,ctl% endr
500- qSend(nr) = ctl% qsur(nr,nt_ice) + ctl% qsub(nr,nt_ice) + ctl% qgwl(nr,nt_ice)
501- end do
515+ qSend(:) = 0._r8
516+ qSend(begr:endr) = qSend(begr:endr) + ctl% qsur(begr:endr, nt_ice) + ctl% qsub(begr:endr, nt_ice) + ctl% qgwl(begr:endr, nt_ice)
502517
503518 ! Distribute "direct runoff to ocean" to targe reach (i.e., outlet of river network)
504519 call shr_mpi_sparse_distribute(qSend, commRch(:)% destTask, commRch(:)% destIndex, ctl% direct (:,nt_ice), fillvalue= 0._r8 )
0 commit comments