Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/mosart/bld/build-namelist
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ else {

add_default($nl, 'paraFile');
add_default($nl, 'demandPath');
add_default($nl, 'RoutingFlag');
add_default($nl, 'ExtractionFlag');
add_default($nl, 'ExtractionMainChannelFlag');
add_default($nl, 'RegulationFlag');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ for the CLM data in the CESM distribution

<paraFile rof_grid="NLDAS" >input_data/runoff/US_reservoir_8th_NLDAS3_c20161220_updated_20170314.nc</paraFile>
<demandPath rof_grid="NLDAS" >input_data/demand/GCAM_waterdemand_nc/RCP8.5_GCAM_water_demand_</demandPath>
<RoutingFlag>1</RoutingFlag>
<ExtractionFlag>1</ExtractionFlag>
<ExtractionMainChannelFlag>1</ExtractionMainChannelFlag>
<RegulationFlag>1</RegulationFlag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ WRM input file
WRM water demand dataset
</entry>

<entry id="RoutingFlag"
type="integer"
category="wrm"
group="wrm_inparm"
valid_values="" >
Routing Flag, 0 = false
</entry>

<entry id="ExtractionFlag"
type="integer"
category="wrm"
Expand Down
24 changes: 24 additions & 0 deletions components/mosart/cime_config/user_nl_mosart
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,42 @@ rtmhist_mfilt = 30
!----------------------------------------------------------------------------------
wrmflag = .true.

!----------------------------------------------------------------------------------
! toggle the kinematic wave component for surface runoff [ 1 / 0 ]
! if set to 1, the runoff becomes available to drain within the subnetwork channel immediately
! this is a reasonable option when running at a daily timestep
!----------------------------------------------------------------------------------
routingflag = 1

!----------------------------------------------------------------------------------
! toggle whether the external demand comes from the demand file or from ELM [ 1 / 0 ]
!----------------------------------------------------------------------------------
externaldemandflag = 1

!----------------------------------------------------------------------------------
! toggle the types of demand read from files:
! - TotalDemandFlag: if set to 1, demand input is defined for irrigation and non-irrigation sectors. If set to 0, demand input is not distinguished between sectors.
! - GroundwaterFlag: if set to 1, demand input is for both surface water and groundwater (proportions defined in gw_irr and gw_nonirr input files). If set to 0, demand input is for surface water only.
! - ReturnFlowFlag: if set to 1, demand input is for withdrawals and model calculates return flows. If set to 0, demand input is for consumptive use and model assumes no return flows.
!
! if any of these flags are 1, demand will be read from files with the following suffixes:
! - TotalDemand: 'nonirr_consumption_{Y}_{M}.nc' & 'irr_consumption_{Y}_{M}.nc', or if ReturnFlowFlag = 1, 'nonirr_withdraw_{Y}_{M}.nc' & 'irr_withdraw_{Y}_{M}.nc'
! - ReturnFlow: 'irr_withdraw_{Y}_{M}.nc', or if TotalDemand = 1 'irr_withdraw_{Y}_{M}.nc' & 'nonirr_withdraw_{Y}_{M}.nc'
! - if the GroundwaterFlag is set to 1, additional 'irr_groundwater_{Y}_{M}.nc' & 'nonirr_groundwater_{Y}_{M}.nc' files will be read in and applied to the demand input files that define a percentage of demand met by gw (nonirr_groundwater is 0 if TotalDemandFlag = 0)
!----------------------------------------------------------------------------------
TotalDemandFlag = 0
GroundwaterFlag = 0
ReturnFlowFlag = 0

!----------------------------------------------------------------------------------
! set the path and prefix for the demand data
!----------------------------------------------------------------------------------
demandpath = '/pic/projects/im3/iwmm/input_data/demand/GCAM_waterdemand_nc/rcp8.5/RCP8.5_GCAM_water_demand_'
!demandpath = '/pic/projects/im3/wm/Jim/USGS_demand/USGS_'

!----------------------------------------------------------------------------------
! set the demand type, corresponding to the variable in the demand files [totalDemand / consDemand / etc. ]
! if reading from multiple types of demand files, this should be the same for all files
!----------------------------------------------------------------------------------
demandvariablename = 'totalDemand'

Expand Down
59 changes: 59 additions & 0 deletions components/mosart/src/riverroute/RtmHistFlds.F90
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,65 @@ subroutine RtmHistFldsInit()
call RtmHistAddfld (fname='WRM_STORAGE', units='m3', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%storageG, default='active')

if ( ctlSubwWRM%ReturnFlowFlag > 0 .OR. ctlSubwWRM%TotalDemandFlag > 0 .OR. ctlSubwWRM%GroundwaterFlag > 0 ) then

call RtmHistAddfld (fname='WRM_SUPPIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%SuppIrrig, default='active')

call RtmHistAddfld (fname='WRM_SUPPNONIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%SuppNonIrrig, default='active')

if ( ctlSubwWRM%ReturnFlowFlag > 0 ) then

call RtmHistAddfld (fname='WRM_WITHDEMANDNONIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%WithDemNonIrrig, default='active')

if ( ctlSubwWRM%TotalDemandFlag > 0 ) then

call RtmHistAddfld (fname='WRM_WITHDEMANDIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%WithDemIrrig, default='active')

endif

else

call RtmHistAddfld (fname='WRM_CONDEMANDNONIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%ConDemNonIrrig, default='active')

if ( ctlSubwWRM%TotalDemandFlag > 0 ) then

call RtmHistAddfld (fname='WRM_CONDEMANDIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%ConDemIrrig, default='active')

endif

endif

if ( ctlSubwWRM%GroundwaterFlag > 0 ) then

call RtmHistAddfld (fname='WRM_GWSHARENONIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%GWShareNonIrrig, default='active')

if ( ctlSubwWRM%TotalDemandFlag > 0 ) then

call RtmHistAddfld (fname='WRM_GWSHAREIRRIG', units='m3/s', &
avgflag='A', long_name='WRM storage ', &
ptr_rof=StorWater%GWShareIrrig, default='active')

endif

endif

endif

endif
#endif

Expand Down
1 change: 1 addition & 0 deletions components/mosart/src/wrm/WRM_modules.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ subroutine Euler_WRM
if (ctlSubwWRM%ExtractionFlag > 0) then
call irrigationExtractionSubNetwork
end if
call UpdateState_subnetwork(iunit)

Trunoff%flow = 0._r8
do m=1,Tctl%DLevelH2R
Expand Down
16 changes: 8 additions & 8 deletions components/mosart/src/wrm/WRM_returnflow.F90
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ subroutine insert_returnflow_soilcolumn()
!irrigation demand by default goes into baseflow
! version 1.0: no lag between application and return
do iunit=rtmCTL%begr,rtmCTL%endr
temp = StorWater%ReturnIrrig(iunit) / ( TUnit%area(iunit) * TUnit%frac(iunit) * Tctl%DATAH ) !m/seconds!
temp = StorWater%ReturnIrrig(iunit) / ( TUnit%area(iunit) * TUnit%frac(iunit) * Tctl%DeltaT ) !m/seconds!
Trunoff%qsub(iunit,nt_nliq) = Trunoff%qsub(iunit,nt_nliq) + temp
StorWater%ReturnIrrig(iunit) = 0._r8
end do
! oput non irrigation back into main channel instead
!if ( (ctlSubwWRM%TotalDemandFlag > 0) ) then
! do iunit=rtmCTL%begr,rtmCTL%endr
! Trunoff%qsur(iunit,nt_nliq) = Trunoff%qsur(iunit,nt_nliq) + StorWater%ReturnNonIrrig(iunit) / (TUnit%area(iunit) * TUnit%frac(iunit))
! StorWater%ReturnNonIrrig(iunit) = 0._r8
! end do
!endif
if ( (ctlSubwWRM%TotalDemandFlag > 0) ) then
do iunit=rtmCTL%begr,rtmCTL%endr
Trunoff%qsur(iunit,nt_nliq) = Trunoff%qsur(iunit,nt_nliq) + StorWater%ReturnNonIrrig(iunit) / (TUnit%area(iunit) * TUnit%frac(iunit))
StorWater%ReturnNonIrrig(iunit) = 0._r8
end do
endif
end subroutine insert_returnflow_soilcolumn
!__________________________________________________________________________________________________
!
Expand All @@ -171,7 +171,7 @@ subroutine insert_returnflow_channel(iunit, TheDeltaT)
! version 1.0: no lag between application and return
!flow_vol = (-Trunoff%erout(iunit,nt_nliq) + (StorWater%ReturnNonIrrig(iunit) / Tctl%DATAH) ) * theDeltaT ! m3 into m3/s
!FIX WR Trunoff%erout(iunit,nt_nliq) = Trunoff%erout(iunit,nt_nliq) - StorWater%ReturnNonIrrig(iunit)/Tctl%DATAH
Trunoff%wr(iunit,nt_nliq) = Trunoff%wr(iunit,nt_nliq) + StorWater%ReturnNonIrrig(iunit)/Tctl%DATAH
Trunoff%wr(iunit,nt_nliq) = Trunoff%wr(iunit,nt_nliq) + StorWater%ReturnNonIrrig(iunit) / Tctl%DeltaT
!Trunoff%erout(iunit,nt_nliq) = -flow_vol / (theDeltaT)
end subroutine insert_returnflow_channel

Expand Down
130 changes: 110 additions & 20 deletions components/mosart/src/wrm/WRM_subw_IO_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ subroutine WRM_init
character(len=256):: nlfilename_wrm

character(len=350) :: paraFile, demandPath, DemandVariableName
integer :: ExtractionFlag, ExtractionMainChannelFlag, RegulationFlag, &
integer :: RoutingFlag, ExtractionFlag, ExtractionMainChannelFlag, RegulationFlag, &
ReturnFlowFlag, TotalDemandFlag, GroundWaterFlag, ExternalDemandFlag

namelist /wrm_inparm/ &
paraFile, demandPath, DemandVariableName, &
paraFile, demandPath, DemandVariableName, RoutingFlag, &
ExtractionFlag, ExtractionMainChannelFlag, RegulationFlag, &
ReturnFlowFlag, TotalDemandFlag, GroundWaterFlag, ExternalDemandFlag

Expand Down Expand Up @@ -124,6 +124,7 @@ subroutine WRM_init
call mpi_bcast(paraFile ,len(paraFile) , MPI_CHARACTER, 0, mpicom_rof, ier)
call mpi_bcast(demandPath ,len(demandPath), MPI_CHARACTER, 0, mpicom_rof, ier)
call mpi_bcast(DemandVariableName ,len(DemandVariableName), MPI_CHARACTER, 0, mpicom_rof, ier)
call mpi_bcast(RoutingFlag, 1, MPI_INTEGER, 0, mpicom_rof, ier)
call mpi_bcast(ExtractionFlag, 1, MPI_INTEGER, 0, mpicom_rof, ier)
call mpi_bcast(ExtractionMainChannelFlag, 1, MPI_INTEGER, 0, mpicom_rof, ier)
call mpi_bcast(RegulationFlag, 1, MPI_INTEGER, 0, mpicom_rof, ier)
Expand All @@ -134,6 +135,7 @@ subroutine WRM_init

ctlSubwWRM%paraFile = paraFile
ctlSubwWRM%demandPath = demandPath
ctlSubwWRM%RoutingFlag = RoutingFlag
ctlSubwWRM%ExtractionFlag = ExtractionFlag
ctlSubwWRM%ExtractionMainChannelFlag = ExtractionMainChannelFlag
ctlSubwWRM%RegulationFlag = RegulationFlag
Expand All @@ -147,6 +149,7 @@ subroutine WRM_init
write(iulog,*) subname," paraFile = ",trim(ctlSubwWRM%paraFile)
write(iulog,*) subname," demandPath = ",trim(ctlSubwWRM%demandPath)
write(iulog,*) subname," DemandVariableName = ",trim(ctlSubwWRM%DemandVariableName)
write(iulog,*) subname," RoutingFlag = ",ctlSubwWRM%RoutingFlag
write(iulog,*) subname," ExtractionFlag = ",ctlSubwWRM%ExtractionFlag
write(iulog,*) subname," ExtractionMainChannelFlag = ",ctlSubwWRM%ExtractionMainChannelFlag
write(iulog,*) subname," RegulationFlag = ",ctlSubwWRM%RegulationFlag
Expand Down Expand Up @@ -866,30 +869,117 @@ subroutine WRM_readDemand
type(var_desc_t) :: vardesc ! netCDF variable description
character(len=*),parameter :: subname='(WRM_readDemand)'

! ExtractionFlag set to 1 means read demand from file(s), otherwise demand comes from coupled models

! TotalDemandFlag set to 1 means demand input is defined for irrigation and non-irrigation sectors, otherwise demand input is not distinguished between sectors
! GroundwaterFlag set to 1 means demand input is for both surface water and groundwater, otherwise demand input is for surface water only
! ReturnFlowFlag set to 1 means demand input is for withdrawals and model calculates return flows, otherwise demand input is for consumptive use and model assumes no return flows

! If any of TotalDemand, Groundwater, or ReturnFlow is enabled, multiple files with the special suffixes will be read; otherwise, just the basic file will be read.

! Extraction ON
if (ctlSubwWRM%ExtractionFlag > 0) then

call get_curr_date(yr, mon, day, tod)
write(iulog,'(2a,4i6)') subname,'at ',yr,mon,day,tod

write(strYear,'(I4.4)') yr
write(strMonth,'(I2.2)') mon
fname = trim(ctlSubwWRM%demandPath)// strYear//'_'//strMonth//'.nc'
call get_curr_date(yr, mon, day, tod)
write(iulog,'(2a,4i6)') subname,'at ',yr,mon,day,tod
write(strYear,'(I4.4)') yr
write(strMonth,'(I2.2)') mon

write(iulog,*) subname, ' reading ',trim(fname)
! Read the usual files
if (( ctlSubwWRM%TotalDemandFlag < 1 ) .AND. ( ctlSubwWRM%GroundwaterFlag < 1 ) .AND. ( ctlSubwWRM%ReturnFlowFlag < 1 )) then

call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%demand0, ier)
call ncd_pio_closefile(ncid)
fname = trim(ctlSubwWRM%demandPath)//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%demand0, ier)
call ncd_pio_closefile(ncid)

do nr=rtmCTL%begr,rtmCTL%endr
if (StorWater%demand0(nr).lt.0._r8) then
StorWater%demand0(nr) = 0._r8
end if
end do
write(iulog,FORMR2) trim(subname),' read totalDemand',iam,minval(StorWater%demand0),maxval(StorWater%demand0)
call shr_sys_flush(iulog)
! Read the suffixed files
else

! consumptive irrigation
fname = trim(ctlSubwWRM%demandPath)//'irr_consumption_'//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%ConDemIrrig, ier)
call ncd_pio_closefile(ncid)

! TotalDemand ON
if ( ctlSubwWRM%TotalDemandFlag > 0 ) then
! consumptive non-irrigation
fname = trim(ctlSubwWRM%demandPath)//'nonirr_consumption_'//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%ConDemNonIrrig, ier)
call ncd_pio_closefile(ncid)
endif

! Groundwater ON
if ( ctlSubwWRM%GroundwaterFlag > 0 ) then
! groundwater irrigation
fname = trim(ctlSubwWRM%demandPath)//'irr_groundwater_'//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%GWShareIrrig, ier)
call ncd_pio_closefile(ncid)
endif

! Groundwater ON and TotalDemand ON
if (( ctlSubwWRM%GroundwaterFlag > 0 ) .AND. ( ctlSubwWRM%TotalDemandFlag > 0 )) then
! groundwater non-irrigation
fname = trim(ctlSubwWRM%demandPath)//'nonirr_groundwater_'//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%GWShareNonIrrig, ier)
call ncd_pio_closefile(ncid)
endif

! ReturnFlow ON
if ( ctlSubwWRM%ReturnFlowFlag > 0 ) then
! return flow irrigation
fname = trim(ctlSubwWRM%demandPath)//'irr_withdraw_'//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%WithDemIrrig, ier)
call ncd_pio_closefile(ncid)
endif

! ReturnFlow ON and TotalDemand ON
if (( ctlSubwWRM%ReturnFlowFlag > 0 ) .AND. ( ctlSubwWRM%TotalDemandFlag > 0 )) then
! return flow non-irrigation
fname = trim(ctlSubwWRM%demandPath)//'nonirr_withdraw_'//strYear//'_'//strMonth//'.nc'
write(iulog,*) subname, ' reading ',trim(fname)
call ncd_pio_openfile(ncid, trim(fname), 0)
ier = pio_inq_varid (ncid, name=ctlSubwWRM%DemandVariableName, vardesc=vardesc) !! need to be consistent with the NC file, Tian Apr 2018
call pio_read_darray(ncid, vardesc, iodesc_dbl_grd2grd , StorWater%WithDemNonIrrig, ier)
call ncd_pio_closefile(ncid)
endif

! Calculate the initial demand based on what is set above
if ( ctlSubwWRM%ReturnFlowFlag > 0 ) then
StorWater%demand0 = StorWater%WithDemIrrig * (1._r8 - StorWater%GWShareIrrig) + StorWater%WithDemNonIrrig * (1._r8 - StorWater%GWShareNonIrrig)
else
StorWater%demand0 = StorWater%ConDemIrrig * (1._r8 - StorWater%GWShareIrrig) + StorWater%ConDemNonIrrig * (1._r8 - StorWater%GWShareNonIrrig)
endif

endif

! Ensure that minimum demand is 0
do nr=rtmCTL%begr,rtmCTL%endr
if (StorWater%demand0(nr).lt.0._r8) then
StorWater%demand0(nr) = 0._r8
end if
end do
write(iulog,FORMR2) trim(subname),' read totalDemand',iam,minval(StorWater%demand0),maxval(StorWater%demand0)
call shr_sys_flush(iulog)

! Extraction OFF
else
do nr=rtmCTL%begr,rtmCTL%endr
StorWater%demand0(nr) = 0._r8
Expand Down
1 change: 1 addition & 0 deletions components/mosart/src/wrm/WRM_type_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ MODULE WRM_type_mod
type WRMcontrol_subw
integer :: NDam ! number of dams
integer :: localNumDam ! number of dams on decomposition
integer :: RoutingFlag ! Flag to toggle the kinematic wave component for surface runoff
integer :: ExtractionFlag ! Flag for whether including Water Demand extraction : 1--> water extraction from each subbasin , uses extraction module ; 0 --> no extraction
integer :: ExtractionMainChannelFlag ! Flag for whether including Water Demand extraction from the main channel, only if unregulated flow ( bells and whistle here based on RegulationFlag is 1, etc)
integer :: RegulationFlag ! Flag whether to use reseervoir regulation or not : 1 --> use reservoir module; 0--> natural flow
Expand Down