management_external_supply Subroutine

public subroutine management_external_supply(sub, day, ida, iyr)

if destination subbasin receives water from external source


TSub (current subbasin)

add external supply to destination subbasin inflow


TWU (current water user)

calculate volume delivered to water user


Water user type: IRRIGATION, unlimited external source, from input file

Put on the field what is provided by external source

TWU (current water user)


TSub (current subbasin)

!! pWU%supplied should not be added to %inflow, because the irrigation supply is added in hydrotope !! %inflow is added to sda or varoute in "subbasin" and/or "add"


Water user type: IRRIGATION, unlimited external source, demand from plant deficit

assuming an unlimited source providing exactly the required irrigation demand

TWU (current water user)


TSub (current subbasin)

!! pWU%supplied should not be added to %inflow, because the irrigation supply is added in hydrotope !! %inflow is added to sda or varoute in "subbasin" and/or "add"

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: sub
integer, intent(in) :: day
integer, intent(in) :: ida
integer, intent(in) :: iyr

Calls

proc~~management_external_supply~~CallsGraph proc~management_external_supply management_external_supply proc~management_subbasin_pointer management_subbasin_pointer proc~management_external_supply->proc~management_subbasin_pointer proc~management_user_pointer management_user_pointer proc~management_external_supply->proc~management_user_pointer proc~management_is_transfer_subbasin management_is_transfer_subbasin proc~management_external_supply->proc~management_is_transfer_subbasin proc~management_is_active_period management_is_active_period proc~management_external_supply->proc~management_is_active_period proc~log_warn log_warn proc~management_external_supply->proc~log_warn proc~log_error log_error proc~management_user_pointer->proc~log_error proc~log_message log_message proc~log_warn->proc~log_message proc~log_write log_write proc~log_message->proc~log_write proc~log_format_message log_format_message proc~log_message->proc~log_format_message proc~log_error->proc~log_message proc~to_string to_string proc~log_write->proc~to_string proc~date_time_str date_time_str proc~log_format_message->proc~date_time_str proc~colourise colourise proc~log_format_message->proc~colourise proc~string_index string_index proc~colourise->proc~string_index

Called by

proc~~management_external_supply~~CalledByGraph proc~management_external_supply management_external_supply proc~time_process_day time_process_day proc~time_process_day->proc~management_external_supply proc~time_process_month time_process_month proc~time_process_month->proc~time_process_day proc~time_process_years time_process_years proc~time_process_years->proc~time_process_month program~swim swim program~swim->proc~time_process_years

Contents


Source Code

  subroutine management_external_supply(sub, day, ida, iyr)
    integer, intent(in) :: ida
    integer, intent(in) :: iyr
    ! calculate total inputs from external source(s) where this subbain is a destination subbasin
    ! external supply is true, if source subbasin number == 0 .AND. destination subbasin number >=1 .AND. <=mb
    !  this condition is true if TWU(sub)%wu_opt == 3
    ! CALLED FROM MONTHLY (in daily SUBBASIN command)
    ! current subbasin number
    integer, intent(in) :: sub
    ! current day of simulation
    integer, intent(in) :: day
    integer :: i
    ! pointer on actual subbasin (TSub)
    TYPE (TSubbasin), POINTER :: pS, pSd
    ! pointer on actual water user (TWU)
    TYPE (TWaterUser), POINTER :: pWU

    ! NOTE: If subbasin receives water from another subbasin, this supply volume
    ! is added later on in subroutine wam_withdraw_Transfer_Out
    if (management_is_transfer_subbasin(sub) ) then
      pS => management_subbasin_pointer(sub)
      if (pS % nWUin > 0) then
        do i = 1, pS % nWU ! loop over water users in subbasin
          pWU => management_user_pointer(pS % pos(i)) ! pointer on current water user

          !-----------------------------------------------------------------
          ! if destination subbasin receives water from external source
          !-----------------------------------------------------------------
          if (pWU % wu_opt == 3 .AND. management_is_active_period(iyr, ida, pWU) ) then
            !-----------------------------------------------------------------
            ! TSub (current subbasin)
            !-----------------------------------------------------------------
            ! add external supply to destination subbasin inflow
            pS % inflow(day) = pS % inflow(day) & ! [m3 / s]
                                 + pWU % data(day) & ! add supply from external source (daily time series input file)
                                 * pWU % tr_eff ! subtract losses

            ! add losses to destination subbasin
            pS % tr_losses_in(day) = pS % tr_losses_in(day) &
                                + pWU % data(day) * (1. - pWU % tr_eff) ! summarise losses [m3 / s]
            !-----------------------------------------------------------------

            !-----------------------------------------------------------------
            ! TWU (current water user)
            !-----------------------------------------------------------------
            ! calculate volume delivered to water user
            pWU % supplied(day) = pWU % data(day) * pWU % tr_eff ! [m3 / s]

            ! calculate losses during transfer
            pWU % tr_losses(day) = pWU % data(day) * (1. - pWU % tr_eff) ! [m3 / s]
            !-----------------------------------------------------------------
          end if

          !-----------------------------------------------------------------
          ! Water user type: IRRIGATION, unlimited external source, from input file
          !-----------------------------------------------------------------
          ! Put on the field what is provided by external source
          if (pWU % wu_opt == 4 .AND. pWU % subs == 0 .AND. pWU % irr_opt == 1 &
                .AND. management_is_active_period(iyr, ida, pWU) .AND. pWU % data(day) > 0. ) then
            pSd => management_subbasin_pointer(pWU % subd)
            !-----------------------------------------------------------------
            ! TWU (current water user)
            !-----------------------------------------------------------------
            pWU % supplied(day) = pWU % data(day) * pWU % tr_eff ! [m3 / s]
            wam_supplied_summary(day) = wam_supplied_summary(day) + pWU % supplied(day) ! [m3 / s]
            pWU % tr_losses(day) = pWU % data(day) * (1. - pWU % tr_eff) ! [m3 / s]
            !-----------------------------------------------------------------
            ! TSub (current subbasin)
            !-----------------------------------------------------------------
            !!!! pWU%supplied should not be added to %inflow, because the irrigation supply is added in hydrotope
            !!!! %inflow is added to sda or varoute in "subbasin" and/or "add"
            !pSd%inflow(day) = pSd%inflow(day) + pWU%supplied(day)
            pSd % tr_losses_in(day) = pSd % tr_losses_in(day) + pWU % tr_losses(day)
          end if

          !-----------------------------------------------------------------
          ! Water user type: IRRIGATION, unlimited external source, demand from plant deficit
          !-----------------------------------------------------------------
          ! assuming an unlimited source providing exactly the required irrigation demand
          if (day > 1) then
          if (pWU % wu_opt == 4 .AND. pWU % subs == 0 .AND. pWU % irr_opt == 2 &
                .AND. management_is_active_period(iyr, ida, pWU) .AND. pWU % irrigationDemand(day - 1) > 0. ) then ! .AND. pWU % supplied(day - 1) > 0. ) then
            pSd => management_subbasin_pointer(pWU % subd)
            !-----------------------------------------------------------------
            ! TWU (current water user)
            !-----------------------------------------------------------------
            pWU % data(day) = pWU % irrigationDemand(day - 1) ! [m3 / s]
            pWU % supplied(day) = pWU % irrigationDemand(day - 1) ! [m3 / s]
            wam_supplied_summary(day) = wam_supplied_summary(day) + pWU % supplied(day) ! [m3 / s]
            pWU % tr_losses(day) = pWU % supplied(day - 1) * (1. - pWU % tr_eff) ! [m3 / s]
            !-----------------------------------------------------------------
            ! TSub (current subbasin)
            !-----------------------------------------------------------------
            pSd % irrDemand(day) = pSd % irrDemand(day) + pWU % irrigationDemand(day - 1)
            !!!! pWU%supplied should not be added to %inflow, because the irrigation supply is added in hydrotope
            !!!! %inflow is added to sda or varoute in "subbasin" and/or "add"
            !pSd%inflow(day) = pSd%inflow(day) + pWU%supplied(day)
            pSd % tr_losses_in(day) = pWU % tr_losses(day)
          end if
          end if ! ( day > 1 )
        end do
      end if
    else
      call log_warn("wam", "Water allocation module was called for (subbasin) "// &
        "although it has no water users !!!", i1=sub)
    end if

  end subroutine management_external_supply