From f1788d2bd80d1e1188c96c1156756b00fd49bbad Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:16:07 -0600 Subject: [PATCH 01/11] Comment typo fixes. --- src/biogeophys/HydrologyNoDrainageMod.F90 | 4 ++-- src/cpl/lilac/lnd_import_export.F90 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/biogeophys/HydrologyNoDrainageMod.F90 b/src/biogeophys/HydrologyNoDrainageMod.F90 index 300ed96ce3..d1ad7c1473 100644 --- a/src/biogeophys/HydrologyNoDrainageMod.F90 +++ b/src/biogeophys/HydrologyNoDrainageMod.F90 @@ -40,7 +40,7 @@ Module HydrologyNoDrainageMod save ! ! !PUBLIC MEMBER FUNCTIONS: - public :: CalcAndWithdrawSectorWaterFluxes ! Calculates sectorwal water withdrawal, consumption and return flow fluxes; update the fields which are sent to the routing model through the coupler; + public :: CalcAndWithdrawSectorWaterFluxes ! Calculates sectoral water withdrawal, consumption and return flow fluxes; update the fields which are sent to the routing model through the coupler; public :: CalcAndWithdrawIrrigationFluxes ! Calculates irrigation withdrawal fluxes and withdraws from groundwater public :: HandleNewSnow ! Handle new snow falling on the ground public :: HydrologyNoDrainage ! Calculates soil/snow hydrology without drainage @@ -52,7 +52,7 @@ Module HydrologyNoDrainageMod subroutine CalcAndWithdrawSectorWaterFluxes(bounds, soilhydrology_inst, sectorwater_inst, water_inst, volr, rof_prognostic) ! ! !DESCRIPTION: - ! Calculates sectorwal water withdrawal, consumption and return flow fluxes; + ! Calculates sectoral water withdrawal, consumption and return flow fluxes; ! Updates the fields which are sent to the routing model through the coupler; ! ! !USES: diff --git a/src/cpl/lilac/lnd_import_export.F90 b/src/cpl/lilac/lnd_import_export.F90 index d2b88a54e7..34c18ed2e6 100644 --- a/src/cpl/lilac/lnd_import_export.F90 +++ b/src/cpl/lilac/lnd_import_export.F90 @@ -504,7 +504,7 @@ subroutine export_fields(exportState, bounds, rc) input=water_inst%waterlnd2atmbulk_inst%qdom_rf_grc, minus=.false., rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - ! livestock wihtdrawal flux to be removed from main channel storage (negative) + ! livestock withdrawal flux to be removed from main channel storage (negative) call state_setexport(exportState, 'l2c_fb_rof', 'Flrl_liv_withd', bounds, & input=water_inst%waterlnd2atmbulk_inst%qliv_withd_grc, minus=.true., rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return From b4d96135366a8a0989956577f8f47ba3ab68a42e Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:20:21 -0600 Subject: [PATCH 02/11] Reverted some whitespace-only changes. --- src/biogeophys/IrrigationMod.F90 | 4 ++-- src/main/lnd2atmMod.F90 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/biogeophys/IrrigationMod.F90 b/src/biogeophys/IrrigationMod.F90 index 4e86912f49..e31900f06e 100644 --- a/src/biogeophys/IrrigationMod.F90 +++ b/src/biogeophys/IrrigationMod.F90 @@ -179,7 +179,7 @@ module IrrigationMod real(r8), pointer :: irrig_rate_demand_patch (:) ! current irrigation rate, neglecting surface water source limitation [mm/s] integer , pointer :: n_irrig_steps_left_patch (:) ! number of time steps for which we still need to irrigate today (if 0, ignore) real(r8), pointer :: qflx_irrig_demand_patch (:) ! irrigation flux neglecting surface water source limitation [mm/s] - + contains ! Public routines ! COMPILER_BUG(wjs, 2014-10-15, pgi 14.7) Add an "Irrigation" prefix to some generic routines like "Init" @@ -448,7 +448,7 @@ subroutine ReadNamelist(this, NLFilename, use_aquifer_layer) limit_irrigation_if_rof_enabled = limit_irrigation_if_rof_enabled, & use_groundwater_irrigation = use_groundwater_irrigation, & irrig_method_default = irrig_method_default_int) - + if (masterproc) then write(iulog,*) ' ' write(iulog,*) nmlname//' settings:' diff --git a/src/main/lnd2atmMod.F90 b/src/main/lnd2atmMod.F90 index d8d1873240..fd72d24766 100644 --- a/src/main/lnd2atmMod.F90 +++ b/src/main/lnd2atmMod.F90 @@ -388,6 +388,7 @@ subroutine lnd2atm(bounds, & water_inst%waterlnd2atmbulk_inst%qflx_rofliq_drain_perched_grc(bounds%begg:bounds%endg), & c2l_scale_type= 'urbanf', l2g_scale_type='unity' ) + call c2g( bounds, & water_inst%waterfluxbulk_inst%qflx_sfc_irrig_col (bounds%begc:bounds%endc), & water_inst%waterlnd2atmbulk_inst%qirrig_grc(bounds%begg:bounds%endg), & @@ -402,7 +403,6 @@ subroutine lnd2atm(bounds, & water_inst%waterlnd2atmbulk_inst%qflx_ice_runoff_col(bounds%begc:bounds%endc), & water_inst%waterlnd2atmbulk_inst%qflx_rofice_grc(bounds%begg:bounds%endg), & c2l_scale_type= 'urbanf', l2g_scale_type='unity' ) - do g = bounds%begg, bounds%endg water_inst%waterlnd2atmbulk_inst%qflx_rofice_grc(g) = & water_inst%waterlnd2atmbulk_inst%qflx_rofice_grc(g) - & From 0a238ab39eeb81f7e66b5ea75500121ab374f310 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:21:11 -0600 Subject: [PATCH 03/11] Corrected indentation. --- src/cpl/lilac/lnd_import_export.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpl/lilac/lnd_import_export.F90 b/src/cpl/lilac/lnd_import_export.F90 index 34c18ed2e6..0a02ff6bdc 100644 --- a/src/cpl/lilac/lnd_import_export.F90 +++ b/src/cpl/lilac/lnd_import_export.F90 @@ -494,7 +494,7 @@ subroutine export_fields(exportState, bounds, rc) input=water_inst%waterlnd2atmbulk_inst%qirrig_grc, minus=.true., rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - ! domestic withdrawal flux to be removed from main channel storage (negative) + ! domestic withdrawal flux to be removed from main channel storage (negative) call state_setexport(exportState, 'l2c_fb_rof', 'Flrl_dom_withd', bounds, & input=water_inst%waterlnd2atmbulk_inst%qdom_withd_grc, minus=.true., rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return From e0482dd0865e4fad9bcd4ddf79dd5af44a624f02 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:24:08 -0600 Subject: [PATCH 04/11] Deleted some end-of-line whitespace. --- src/biogeophys/SectorWaterMod.F90 | 402 ++++++++++++++-------------- src/cpl/lilac/lnd_import_export.F90 | 4 +- 2 files changed, 203 insertions(+), 203 deletions(-) diff --git a/src/biogeophys/SectorWaterMod.F90 b/src/biogeophys/SectorWaterMod.F90 index 15002a9321..d28bc0b462 100644 --- a/src/biogeophys/SectorWaterMod.F90 +++ b/src/biogeophys/SectorWaterMod.F90 @@ -8,30 +8,30 @@ module SectorWaterMod use clm_varctl , only : iulog use clm_time_manager , only : get_curr_date use WaterType , only : water_type - use GridcellType , only : grc - use clm_time_manager , only : get_step_size + use GridcellType , only : grc + use clm_time_manager , only : get_step_size use ncdio_pio - - + + implicit none private - + ! !PUBLIC TYPES: - + ! This type is public (and its components are public, too) to aid unit testing type, public :: sectorwater_params_type - ! Threshold for how much of the current river water can be used to satisfy sectoral demand, + ! Threshold for how much of the current river water can be used to satisfy sectoral demand, ! if limit_sectorwater is .true. (fraction of available river water). A threshold of 0 ! means allow all current river water to be used; a threshold of 0.1 means allow 90% of the current ! river volume to be used; etc. ! This is done to protect against negative runoff, caused by extracting more water than currently available. real(r8) :: sectorwater_river_volume_threshold - + ! Whether sectorwater usage is limited based on river storage. This only applies if ROF is ! enabled (i.e., rof_prognostic is .true.) - otherwise we don't limit sectorwater usage, ! regardless of the value of this flag. - logical :: limit_sectorwater_if_rof_enabled - + logical :: limit_sectorwater_if_rof_enabled + ! The sectoral water usage is computed based on the provided input data ! path_sectorwater_input_data is the path to a .txt file containing the paths to each year .nc file with sectoral withdrawal and consumption data ! The right format of the .txt file is: @@ -43,20 +43,20 @@ module SectorWaterMod ! N.B. Make sure that there is no NaN values in your input files for the sector water usage variables. Instead of NaN values, use 0. character(len=256) :: path_sectorwater_input_data end type sectorwater_params_type - - + + type, public :: sectorwater_type ! private ! Private data members; set in initialization: - + type(sectorwater_params_type) :: params integer :: dtime ! land model time step (sec) - + ! Private data members; time-varying: ! naming: dom = domestic, liv = livestock, elec = thermoelectric, mfc = manufacturing, min = mining ! naming: withd = withdrawal, cons = consumption, rf = return flow - + real(r8), pointer :: input_mon_dom_withd_grc (:) ! input expected withdrawal for current month real(r8), pointer :: input_mon_dom_cons_grc (:) ! input expected consumption for current month real(r8), pointer :: dom_withd_grc (:) ! expected withdrawal flux for the day [mm/s] @@ -64,7 +64,7 @@ module SectorWaterMod real(r8), pointer :: dom_withd_actual_grc (:) ! actual withdrawal flux for the day [mm/s] real(r8), pointer :: dom_cons_actual_grc (:) ! actual consumption flux for the day [mm/s] real(r8), pointer :: dom_rf_actual_grc (:) ! actual return flow flux for the day [mm/s] - + real(r8), pointer :: input_mon_liv_withd_grc (:) ! input expected withdrawal for current month real(r8), pointer :: input_mon_liv_cons_grc (:) ! input expected consumption for current month real(r8), pointer :: liv_withd_grc (:) ! expected withdrawal flux for the day [mm/s] @@ -72,7 +72,7 @@ module SectorWaterMod real(r8), pointer :: liv_withd_actual_grc (:) ! actual withdrawal flux for the day [mm/s] real(r8), pointer :: liv_cons_actual_grc (:) ! actual consumption flux for the day [mm/s] real(r8), pointer :: liv_rf_actual_grc (:) ! actual return flow flux for the day [mm/s] - + real(r8), pointer :: input_mon_elec_withd_grc (:) ! input expected withdrawal for current month real(r8), pointer :: input_mon_elec_cons_grc (:) ! input expected consumption for current month real(r8), pointer :: elec_withd_grc (:) ! expected withdrawal flux for the day [mm/s] @@ -80,7 +80,7 @@ module SectorWaterMod real(r8), pointer :: elec_withd_actual_grc (:) ! actual withdrawal flux for the day [mm/s] real(r8), pointer :: elec_cons_actual_grc (:) ! actual consumption flux for the day [mm/s] real(r8), pointer :: elec_rf_actual_grc (:) ! actual return flow flux for the day [mm/s] - + real(r8), pointer :: input_mon_mfc_withd_grc (:) ! input expected withdrawal for current month real(r8), pointer :: input_mon_mfc_cons_grc (:) ! input expected consumption for current month real(r8), pointer :: mfc_withd_grc (:) ! expected withdrawal flux for the day [mm/s] @@ -88,7 +88,7 @@ module SectorWaterMod real(r8), pointer :: mfc_withd_actual_grc (:) ! actual withdrawal flux for the day [mm/s] real(r8), pointer :: mfc_cons_actual_grc (:) ! actual consumption flux for the day [mm/s] real(r8), pointer :: mfc_rf_actual_grc (:) ! actual return flow flux for the day [mm/s] - + real(r8), pointer :: input_mon_min_withd_grc (:) ! input expected withdrawal for current month real(r8), pointer :: input_mon_min_cons_grc (:) ! input expected consumption for current month real(r8), pointer :: min_withd_grc (:) ! expected withdrawal flux for the day [mm/s] @@ -99,8 +99,8 @@ module SectorWaterMod real(r8), pointer :: sectorwater_total_actual_withd (:) ! total actual water withdrawal for all sectors (except irrigation) during current day [m3] - - + + contains ! Public routines procedure, public :: Init => SectorWaterInit @@ -110,7 +110,7 @@ module SectorWaterMod ! Public routines to be added: ! procedure, public :: Restart - + ! Private routines procedure, private :: ReadNamelist procedure, private :: CheckNamelistValidity ! Check for validity of input parameters @@ -119,23 +119,23 @@ module SectorWaterMod procedure, private :: InitCold => SectorWaterInitCold procedure, private :: CalcSectorDemandVolrLimited ! calculate actual sectoral abstractions limited by river volume end type sectorwater_type - + interface sectorwater_params_type module procedure sectorwater_params_constructor end interface sectorwater_params_type - + real(r8), parameter :: m3_over_km2_to_mm = 1.e-3_r8 real(r8), parameter :: mm_to_m3_over_km2 = 1.0/m3_over_km2_to_mm character(len=*), parameter, private :: sourcefile = & __FILE__ - + contains - + ! ======================================================================== ! Constructors ! ======================================================================== - + !----------------------------------------------------------------------- function sectorwater_params_constructor(sectorwater_river_volume_threshold, & limit_sectorwater_if_rof_enabled, path_sectorwater_input_data) & @@ -153,7 +153,7 @@ function sectorwater_params_constructor(sectorwater_river_volume_threshold, & character(len=256), intent(in) :: path_sectorwater_input_data ! ! !LOCAL VARIABLES: - + character(len=*), parameter :: subname = 'sectorwater_params_constructor' !----------------------------------------------------------------------- this%sectorwater_river_volume_threshold = sectorwater_river_volume_threshold @@ -161,11 +161,11 @@ function sectorwater_params_constructor(sectorwater_river_volume_threshold, & this%path_sectorwater_input_data = path_sectorwater_input_data end function sectorwater_params_constructor - + ! ======================================================================== ! Infrastructure routines (initialization, restart, etc.) ! ======================================================================== - + !------------------------------------------------------------------------ subroutine SectorWaterInit(this, bounds, NLFilename) class(sectorwater_type) , intent(inout) :: this @@ -176,7 +176,7 @@ subroutine SectorWaterInit(this, bounds, NLFilename) call this%InitHistory(bounds) call this%InitCold(bounds) end subroutine SectorWaterInit - + !----------------------------------------------------------------------- subroutine ReadNamelist(this, NLFilename) ! @@ -195,7 +195,7 @@ subroutine ReadNamelist(this, NLFilename) character(len=*), intent(in) :: NLFilename ! Namelist filename ! !!LOCAL VARIABLES: - + ! temporary variables corresponding to the components of sectorwater_params_type real(r8) :: sectorwater_river_volume_threshold logical :: limit_sectorwater_if_rof_enabled @@ -206,24 +206,24 @@ subroutine ReadNamelist(this, NLFilename) character(len=*), parameter :: nmlname_sectorwater = 'sectorwater_inparm' character(len=*), parameter :: subname = 'ReadNamelist' !----------------------------------------------------------------------- - + namelist /sectorwater_inparm/ sectorwater_river_volume_threshold, limit_sectorwater_if_rof_enabled, path_sectorwater_input_data - + ! Initialize options to garbage defaults, forcing all to be specified explicitly in ! order to get reasonable results sectorwater_river_volume_threshold = nan limit_sectorwater_if_rof_enabled = .false. path_sectorwater_input_data = ' ' - + if (masterproc) then unitn = getavu() write(iulog,*) 'Read in '//nmlname_sectorwater//' namelist' call opnfil (NLFilename, unitn, 'F') call shr_nl_find_group_name(unitn, nmlname_sectorwater, status=ierr) - + if (ierr == 0) then read(unitn, nml=sectorwater_inparm, iostat=ierr) - + if (ierr /= 0) then call endrun(msg="ERROR reading "//nmlname_sectorwater//"namelist"//errmsg(sourcefile, __LINE__)) end if @@ -242,7 +242,7 @@ subroutine ReadNamelist(this, NLFilename) this%params = sectorwater_params_type(sectorwater_river_volume_threshold = sectorwater_river_volume_threshold, & limit_sectorwater_if_rof_enabled = limit_sectorwater_if_rof_enabled, & path_sectorwater_input_data = path_sectorwater_input_data) - + if (masterproc) then write(iulog,*) ' ' write(iulog,*) nmlname_sectorwater//' settings:' @@ -255,9 +255,9 @@ subroutine ReadNamelist(this, NLFilename) write(iulog,*) 'path_sectorwater_input_data = ', path_sectorwater_input_data write(iulog,*) ' ' end if - + end subroutine ReadNamelist - + !----------------------------------------------------------------------- subroutine CheckNamelistValidity(this) ! @@ -273,14 +273,14 @@ subroutine CheckNamelistValidity(this) class(sectorwater_type), intent(in) :: this ! ! !LOCAL VARIABLES: - + character(len=*), parameter :: subname = 'CheckNamelistValidity' !----------------------------------------------------------------------- - + associate( & sectorwater_river_volume_threshold => this%params%sectorwater_river_volume_threshold, & limit_sectorwater_if_rof_enabled => this%params%limit_sectorwater_if_rof_enabled) - + if (limit_sectorwater_if_rof_enabled) then if (sectorwater_river_volume_threshold < 0._r8 .or. sectorwater_river_volume_threshold > 1._r8) then write(iulog,*) ' ERROR: sectorwater_river_volume_threshold must be between 0 and 1' @@ -290,9 +290,9 @@ subroutine CheckNamelistValidity(this) end if end if end associate - + end subroutine CheckNamelistValidity - + !----------------------------------------------------------------------- subroutine SectorWaterInitAllocate(this, bounds) ! @@ -308,12 +308,12 @@ subroutine SectorWaterInitAllocate(this, bounds) ! ! !LOCAL VARIABLES: integer :: begg, endg - + character(len=*), parameter :: subname = 'InitAllocate' !----------------------------------------------------------------------- - - begg = bounds%begg; endg= bounds%endg - + + begg = bounds%begg; endg= bounds%endg + allocate(this%input_mon_dom_withd_grc (begg:endg)) ; this%input_mon_dom_withd_grc (:) = 0 allocate(this%input_mon_dom_cons_grc (begg:endg)) ; this%input_mon_dom_cons_grc (:) = 0 allocate(this%dom_withd_grc (begg:endg)) ; this%dom_withd_grc (:) = 0 @@ -321,7 +321,7 @@ subroutine SectorWaterInitAllocate(this, bounds) allocate(this%dom_withd_actual_grc (begg:endg)) ; this%dom_withd_actual_grc (:) = 0 allocate(this%dom_cons_actual_grc (begg:endg)) ; this%dom_cons_actual_grc (:) = 0 allocate(this%dom_rf_actual_grc (begg:endg)) ; this%dom_rf_actual_grc (:) = 0 - + allocate(this%input_mon_liv_withd_grc (begg:endg)) ; this%input_mon_liv_withd_grc (:) = 0 allocate(this%input_mon_liv_cons_grc (begg:endg)) ; this%input_mon_liv_cons_grc (:) = 0 allocate(this%liv_withd_grc (begg:endg)) ; this%liv_withd_grc (:) = 0 @@ -329,7 +329,7 @@ subroutine SectorWaterInitAllocate(this, bounds) allocate(this%liv_withd_actual_grc (begg:endg)) ; this%liv_withd_actual_grc (:) = 0 allocate(this%liv_cons_actual_grc (begg:endg)) ; this%liv_cons_actual_grc (:) = 0 allocate(this%liv_rf_actual_grc (begg:endg)) ; this%liv_rf_actual_grc (:) = 0 - + allocate(this%input_mon_elec_withd_grc (begg:endg)) ; this%input_mon_elec_withd_grc (:) = 0 allocate(this%input_mon_elec_cons_grc (begg:endg)) ; this%input_mon_elec_cons_grc (:) = 0 allocate(this%elec_withd_grc (begg:endg)) ; this%elec_withd_grc (:) = 0 @@ -337,7 +337,7 @@ subroutine SectorWaterInitAllocate(this, bounds) allocate(this%elec_withd_actual_grc (begg:endg)) ; this%elec_withd_actual_grc (:) = 0 allocate(this%elec_cons_actual_grc (begg:endg)) ; this%elec_cons_actual_grc (:) = 0 allocate(this%elec_rf_actual_grc (begg:endg)) ; this%elec_rf_actual_grc (:) = 0 - + allocate(this%input_mon_mfc_withd_grc (begg:endg)) ; this%input_mon_mfc_withd_grc (:) = 0 allocate(this%input_mon_mfc_cons_grc (begg:endg)) ; this%input_mon_mfc_cons_grc (:) = 0 allocate(this%mfc_withd_grc (begg:endg)) ; this%mfc_withd_grc (:) = 0 @@ -345,7 +345,7 @@ subroutine SectorWaterInitAllocate(this, bounds) allocate(this%mfc_withd_actual_grc (begg:endg)) ; this%mfc_withd_actual_grc (:) = 0 allocate(this%mfc_cons_actual_grc (begg:endg)) ; this%mfc_cons_actual_grc (:) = 0 allocate(this%mfc_rf_actual_grc (begg:endg)) ; this%mfc_rf_actual_grc (:) = 0 - + allocate(this%input_mon_min_withd_grc (begg:endg)) ; this%input_mon_min_withd_grc (:) = 0 allocate(this%input_mon_min_cons_grc (begg:endg)) ; this%input_mon_min_cons_grc (:) = 0 allocate(this%min_withd_grc (begg:endg)) ; this%min_withd_grc (:) = 0 @@ -357,8 +357,8 @@ subroutine SectorWaterInitAllocate(this, bounds) allocate(this%sectorwater_total_actual_withd (begg:endg)) ; this%sectorwater_total_actual_withd (:) = 0 end subroutine SectorWaterInitAllocate - - + + !----------------------------------------------------------------------- subroutine SectorWaterInitHistory(this, bounds) ! @@ -374,10 +374,10 @@ subroutine SectorWaterInitHistory(this, bounds) ! ! !LOCAL VARIABLES: integer :: begg, endg - + character(len=*), parameter :: subname = 'InitHistory' !----------------------------------------------------------------------- - + begg = bounds%begg; endg= bounds%endg ! Add output variables @@ -386,7 +386,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='INPUT_MON_DOM_WITHD', units='mm', & avgflag='A', long_name='input monthly domestic withdrawal', & ptr_gcell=this%input_mon_dom_withd_grc, default='inactive') - + this%input_mon_dom_cons_grc(begg:endg) = 0 call hist_addfld1d (fname='INPUT_MON_DOM_CONS', units='mm', & avgflag='A', long_name='input monthly domestic consumption', & @@ -401,7 +401,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='DOM_ACTUAL_CONS', units='mm/s', & avgflag='A', long_name='domestic actual consumption flux', & ptr_gcell=this%dom_cons_actual_grc, default='inactive') - + this%dom_withd_actual_grc(begg:endg) = 0 call hist_addfld1d (fname='DOM_ACTUAL_WITHD', units='mm/s', & avgflag='A', long_name='domestic actual withdrawal flux', & @@ -416,13 +416,13 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='DOM_ACTUAL_RF', units='mm/s', & avgflag='A', long_name='domestic actual return flow flux', & ptr_gcell=this%dom_rf_actual_grc, default='inactive') - + ! Livestock this%input_mon_liv_withd_grc(begg:endg) = 0 call hist_addfld1d (fname='INPUT_MON_LIV_WITHD', units='mm', & avgflag='A', long_name='input monthly livestock withdrawal', & ptr_gcell=this%input_mon_liv_withd_grc, default='inactive') - + this%input_mon_liv_cons_grc(begg:endg) = 0 call hist_addfld1d (fname='INPUT_MON_LIV_CONS', units='mm', & avgflag='A', long_name='input monthly livestock consumption', & @@ -437,7 +437,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='LIV_ACTUAL_CONS', units='mm/s', & avgflag='A', long_name='livestock actual consumption flux', & ptr_gcell=this%liv_cons_actual_grc, default='inactive') - + this%liv_withd_actual_grc(begg:endg) = 0 call hist_addfld1d (fname='LIV_ACTUAL_WITHD', units='mm/s', & avgflag='A', long_name='livestock actual withdrawal flux', & @@ -458,7 +458,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='INPUT_MON_ELEC_WITHD', units='mm', & avgflag='A', long_name='input monthly thermoelectric withdrawal', & ptr_gcell=this%input_mon_elec_withd_grc, default='inactive') - + this%input_mon_elec_cons_grc(begg:endg) = 0 call hist_addfld1d (fname='INPUT_MON_ELEC_CONS', units='mm', & avgflag='A', long_name='input monthly thermoelectric consumption', & @@ -473,7 +473,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='ELEC_ACTUAL_CONS', units='mm/s', & avgflag='A', long_name='thermoelectric actual consumption flux', & ptr_gcell=this%elec_cons_actual_grc, default='inactive') - + this%elec_withd_actual_grc(begg:endg) = 0 call hist_addfld1d (fname='ELEC_ACTUAL_WITHD', units='mm/s', & avgflag='A', long_name='thermoelectric actual withdrawal flux', & @@ -494,7 +494,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='INPUT_MON_MFC_WITHD', units='mm', & avgflag='A', long_name='input monthly manufacturing withdrawal', & ptr_gcell=this%input_mon_mfc_withd_grc, default='inactive') - + this%input_mon_mfc_cons_grc(begg:endg) = 0 call hist_addfld1d (fname='INPUT_MON_MFC_CONS', units='mm', & avgflag='A', long_name='input monthly manufacturing consumption', & @@ -509,7 +509,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='MFC_ACTUAL_CONS', units='mm/s', & avgflag='A', long_name='manufacturing actual consumption flux', & ptr_gcell=this%mfc_cons_actual_grc, default='inactive') - + this%mfc_withd_actual_grc(begg:endg) = 0 call hist_addfld1d (fname='MFC_ACTUAL_WITHD', units='mm/s', & avgflag='A', long_name='manufacturing actual withdrawal flux', & @@ -530,7 +530,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='INPUT_MON_MIN_WITHD', units='mm', & avgflag='A', long_name='input monthly mining withdrawal', & ptr_gcell=this%input_mon_min_withd_grc, default='inactive') - + this%input_mon_min_cons_grc(begg:endg) = 0 call hist_addfld1d (fname='INPUT_MON_MIN_CONS', units='mm', & avgflag='A', long_name='input monthly mining consumption', & @@ -545,7 +545,7 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='MIN_ACTUAL_CONS', units='mm/s', & avgflag='A', long_name='mining actual consumption flux', & ptr_gcell=this%min_cons_actual_grc, default='inactive') - + this%min_withd_actual_grc(begg:endg) = 0 call hist_addfld1d (fname='MIN_ACTUAL_WITHD', units='mm/s', & avgflag='A', long_name='mining actual withdrawal flux', & @@ -560,9 +560,9 @@ subroutine SectorWaterInitHistory(this, bounds) call hist_addfld1d (fname='MIN_ACTUAL_RF', units='mm/s', & avgflag='A', long_name='mining actual return flow flux', & ptr_gcell=this%min_rf_actual_grc, default='inactive') - + end subroutine SectorWaterInitHistory - + !----------------------------------------------------------------------- subroutine SectorWaterInitCold(this, bounds) ! @@ -572,10 +572,10 @@ subroutine SectorWaterInitCold(this, bounds) ! !ARGUMENTS: class(sectorwater_type) , intent(inout) :: this type(bounds_type) , intent(in) :: bounds - + character(len=*), parameter :: subname = 'InitCold' - !----------------------------------------------------------------------- - + !----------------------------------------------------------------------- + this%dtime = get_step_size() this%input_mon_dom_withd_grc(bounds%begg:bounds%endg) = 0._r8 this%input_mon_liv_withd_grc(bounds%begg:bounds%endg) = 0._r8 @@ -606,13 +606,13 @@ subroutine SectorWaterInitCold(this, bounds) this%elec_withd_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%mfc_withd_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%min_withd_actual_grc(bounds%begg:bounds%endg) = 0._r8 - + this%dom_cons_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%liv_cons_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%elec_cons_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%mfc_cons_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%min_cons_actual_grc(bounds%begg:bounds%endg) = 0._r8 - + this%dom_rf_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%liv_rf_actual_grc(bounds%begg:bounds%endg) = 0._r8 this%elec_rf_actual_grc(bounds%begg:bounds%endg) = 0._r8 @@ -621,9 +621,9 @@ subroutine SectorWaterInitCold(this, bounds) this%sectorwater_total_actual_withd(bounds%begg:bounds%endg) = 0._r8 - + end subroutine SectorWaterInitCold - + !----------------------------------------------------------------------- subroutine SectorWaterClean(this) ! @@ -634,10 +634,10 @@ subroutine SectorWaterClean(this) class(sectorwater_type), intent(inout) :: this ! ! !LOCAL VARIABLES: - + character(len=*), parameter :: subname = 'Clean' !----------------------------------------------------------------------- - + deallocate(this%input_mon_dom_withd_grc) deallocate(this%input_mon_dom_cons_grc) deallocate(this%dom_withd_grc) @@ -645,7 +645,7 @@ subroutine SectorWaterClean(this) deallocate(this%dom_withd_actual_grc) deallocate(this%dom_cons_actual_grc) deallocate(this%dom_rf_actual_grc) - + deallocate(this%input_mon_liv_withd_grc) deallocate(this%input_mon_liv_cons_grc) deallocate(this%liv_withd_grc) @@ -653,7 +653,7 @@ subroutine SectorWaterClean(this) deallocate(this%liv_withd_actual_grc) deallocate(this%liv_cons_actual_grc) deallocate(this%liv_rf_actual_grc) - + deallocate(this%input_mon_elec_withd_grc) deallocate(this%input_mon_elec_cons_grc) deallocate(this%elec_withd_grc) @@ -661,7 +661,7 @@ subroutine SectorWaterClean(this) deallocate(this%elec_withd_actual_grc) deallocate(this%elec_cons_actual_grc) deallocate(this%elec_rf_actual_grc) - + deallocate(this%input_mon_mfc_withd_grc) deallocate(this%input_mon_mfc_cons_grc) deallocate(this%mfc_withd_grc) @@ -669,7 +669,7 @@ subroutine SectorWaterClean(this) deallocate(this%mfc_withd_actual_grc) deallocate(this%mfc_cons_actual_grc) deallocate(this%mfc_rf_actual_grc) - + deallocate(this%input_mon_min_withd_grc) deallocate(this%input_mon_min_cons_grc) deallocate(this%min_withd_grc) @@ -682,16 +682,16 @@ subroutine SectorWaterClean(this) end subroutine sectorWaterClean - - + + ! ======================================================================== ! Science routines ! ======================================================================== - + subroutine ReadSectorWaterData (this, bounds, year, mon) ! ! !DESCRIPTION: - ! read the input data, withdrawal and consumption, for all sectors and for the current month + ! read the input data, withdrawal and consumption, for all sectors and for the current month ! ! !USES: use fileutils , only : getfil @@ -699,13 +699,13 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) use ncdio_pio , only : file_desc_t use spmdMod , only : masterproc use netcdf - + ! !ARGUMENTS: class(sectorwater_type), intent(inout) :: this type(bounds_type) , intent(in) :: bounds integer , intent(in) :: year ! current year (e.g. 2000) integer , intent(in) :: mon ! month (1, ..., 12) for nstep+1 - + ! ! !LOCAL VARIABLES: type(file_desc_t) :: ncid ! netcdf id @@ -724,7 +724,7 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) real(r8), pointer :: mon_mfc_cons(:) ! monthly manufacturing consumption read from input files real(r8), pointer :: mon_min_withd(:) ! monthly mining withdrawal read from input files real(r8), pointer :: mon_min_cons(:) ! monthly mining consumption read from input files - + character(len=256) :: current_line character(len=256) :: current_year_input_data ! path for the sectorwater input data for current year character(len=256) :: locfn ! local file name @@ -732,12 +732,12 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) character(len=20) :: string_year character(len=32) :: subname = 'ReadSectorWaterData' !----------------------------------------------------------------------- - + if (masterproc) then write (iulog,*) 'Attempting to read sectoral water usage data for current month .....' end if - - + + allocate(& mon_dom_withd(bounds%begg:bounds%endg), & mon_dom_cons(bounds%begg:bounds%endg), & @@ -750,7 +750,7 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) mon_min_withd(bounds%begg:bounds%endg), & mon_min_cons(bounds%begg:bounds%endg), & stat=ier) - + ! Open the input .txt file: open(unit=10, file=this%params%path_sectorwater_input_data, status='old') ! Read first line to get start_year_input and end_year_input @@ -759,12 +759,12 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) if (year > end_year_input) then write(yearErrMessage, '(I0)') year yearErrMessage = trim(yearErrMessage) - call endrun(msg='Error: there is no sector water demand data for current year. Please update the sector water input .txt file with the path to water demand inputs for current year '//yearErrMessage//errMsg(sourcefile, __LINE__)) + call endrun(msg='Error: there is no sector water demand data for current year. Please update the sector water input .txt file with the path to water demand inputs for current year '//yearErrMessage//errMsg(sourcefile, __LINE__)) end if if (year < start_year_input) then write(yearErrMessage, '(I0)') year yearErrMessage = trim(yearErrMessage) - call endrun(msg='Error: there is no sector water demand data for current year. Please update the sector water input .txt file with the path to water demand inputs for current year '//yearErrMessage//errMsg(sourcefile, __LINE__)) + call endrun(msg='Error: there is no sector water demand data for current year. Please update the sector water input .txt file with the path to water demand inputs for current year '//yearErrMessage//errMsg(sourcefile, __LINE__)) end if ! Compute the current line number @@ -793,87 +793,87 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) ! Determine necessary indices call getfil(current_year_input_data, locfn, 0) call ncd_pio_openfile (ncid, trim(locfn), 0) - + call ncd_io(ncid=ncid, varname='withd_dom', flag='read', data=mon_dom_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_dom NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_dom NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_dom', flag='read', data=mon_dom_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_dom NOT on surfdata file'//errMsg(sourcefile, __LINE__)) - + if (.not. readvar) call endrun(msg=' ERROR: cons_dom NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + call ncd_io(ncid=ncid, varname='withd_liv', flag='read', data=mon_liv_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_liv NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_liv NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_liv', flag='read', data=mon_liv_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_liv NOT on surfdata file'//errMsg(sourcefile, __LINE__)) - + if (.not. readvar) call endrun(msg=' ERROR: cons_liv NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + call ncd_io(ncid=ncid, varname='withd_elec', flag='read', data=mon_elec_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_elec NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_elec NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_elec', flag='read', data=mon_elec_cons, & - dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_elec NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + dim1name=nameg, nt=mon, readvar=readvar) + if (.not. readvar) call endrun(msg=' ERROR: cons_elec NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='withd_mfc', flag='read', data=mon_mfc_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_mfc NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_mfc NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_mfc', flag='read', data=mon_mfc_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_mfc NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_mfc NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='withd_min', flag='read', data=mon_min_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_min NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_min NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_min', flag='read', data=mon_min_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_min NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_min NOT on surfdata file'//errMsg(sourcefile, __LINE__)) call ncd_pio_closefile(ncid) - + do g = bounds%begg,bounds%endg this%input_mon_dom_withd_grc(g) = mon_dom_withd(g) this%input_mon_dom_cons_grc(g) = mon_dom_cons(g) - + this%input_mon_liv_withd_grc(g) = mon_liv_withd(g) this%input_mon_liv_cons_grc(g) = mon_liv_cons(g) - + this%input_mon_elec_withd_grc(g) = mon_elec_withd(g) this%input_mon_elec_cons_grc(g) = mon_elec_cons(g) - + this%input_mon_mfc_withd_grc(g) = mon_mfc_withd(g) this%input_mon_mfc_cons_grc(g) = mon_mfc_cons(g) - + this%input_mon_min_withd_grc(g) = mon_min_withd(g) this%input_mon_min_cons_grc(g) = mon_min_cons(g) - + end do deallocate(mon_dom_withd, mon_dom_cons, mon_liv_withd, mon_liv_cons, mon_elec_withd, mon_elec_cons, mon_mfc_withd, mon_mfc_cons, mon_min_withd, mon_min_cons) endsubroutine ReadSectorWaterData - + subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) - + use shr_const_mod , only : SHR_CONST_TKFRZ use clm_time_manager , only : get_curr_date, is_end_curr_month, get_curr_days_per_year ! ! !ARGUMENTS: class(sectorwater_type) , intent(inout) :: this type(bounds_type) , intent(in) :: bounds - + ! river water volume (m3) (ignored if rof_prognostic is .false.) real(r8), intent(in) :: volr(bounds%begg:bounds%endg) - + ! whether we're running with a prognostic ROF component; this is needed to determine ! whether we can limit demand based on river volume. logical, intent(in) :: rof_prognostic - + ! ! !LOCAL VARIABLES: integer :: g ! gridcell index @@ -891,52 +891,52 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) real(r8) :: dom_demand(bounds%begg:bounds%endg) real(r8) :: dom_demand_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: dom_consumption(bounds%begg:bounds%endg) real(r8) :: dom_consumption_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: liv_demand(bounds%begg:bounds%endg) real(r8) :: liv_demand_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: liv_consumption(bounds%begg:bounds%endg) real(r8) :: liv_consumption_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: elec_demand(bounds%begg:bounds%endg) real(r8) :: elec_demand_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: elec_consumption(bounds%begg:bounds%endg) real(r8) :: elec_consumption_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: mfc_demand(bounds%begg:bounds%endg) real(r8) :: mfc_demand_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: mfc_consumption(bounds%begg:bounds%endg) real(r8) :: mfc_consumption_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: min_demand(bounds%begg:bounds%endg) real(r8) :: min_demand_volr_limited(bounds%begg:bounds%endg) - + real(r8) :: min_consumption(bounds%begg:bounds%endg) real(r8) :: min_consumption_volr_limited(bounds%begg:bounds%endg) - + ! Whether we should limit deficits by available volr logical :: limit_sectorwater - + character(len=*), parameter :: subname = 'CalcSectorWaterNeeded' !----------------------------------------------------------------------- - + ! Get current date call get_curr_date(year, mon, day, sec) dayspyr = get_curr_days_per_year() dayspm = dayspyr/12._r8 first_read = 1 - + flux_transform_from_monthly_to_second = (1._r8/dayspm)/86400._r8 - - + + ! For the first month of the simulation we need to read the data at the beginning of the month ! But for all the remaining months, the information is updated at the end of the month. - if (first_read == 1) then + if (first_read == 1) then call this%ReadSectorWaterData(bounds, year, mon) first_read = 2 endif @@ -945,42 +945,42 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) if (is_end_curr_month()) then call this%ReadSectorWaterData(bounds, year, mon) endif - + ! Compute demand [mm] ! First initialize demand to 0 everywhere; dom_demand(bounds%begg:bounds%endg) = 0._r8 dom_consumption(bounds%begg:bounds%endg) = 0._r8 - + liv_demand(bounds%begg:bounds%endg) = 0._r8 liv_consumption(bounds%begg:bounds%endg) = 0._r8 - + elec_demand(bounds%begg:bounds%endg) = 0._r8 elec_consumption(bounds%begg:bounds%endg) = 0._r8 - + mfc_demand(bounds%begg:bounds%endg) = 0._r8 mfc_consumption(bounds%begg:bounds%endg) = 0._r8 - + min_demand(bounds%begg:bounds%endg) = 0._r8 min_consumption(bounds%begg:bounds%endg) = 0._r8 - + do g = bounds%begg,bounds%endg dom_demand(g) = this%input_mon_dom_withd_grc(g) *flux_transform_from_monthly_to_second dom_consumption(g) = this%input_mon_dom_cons_grc(g) *flux_transform_from_monthly_to_second - + liv_demand(g) = this%input_mon_liv_withd_grc(g) *flux_transform_from_monthly_to_second liv_consumption(g) = this%input_mon_liv_cons_grc(g) *flux_transform_from_monthly_to_second - + elec_demand(g) = this%input_mon_elec_withd_grc(g)*flux_transform_from_monthly_to_second elec_consumption(g) = this%input_mon_elec_cons_grc(g) *flux_transform_from_monthly_to_second - + mfc_demand(g) = this%input_mon_mfc_withd_grc(g) *flux_transform_from_monthly_to_second mfc_consumption(g) = this%input_mon_mfc_cons_grc(g) *flux_transform_from_monthly_to_second - + min_demand(g) = this%input_mon_min_withd_grc(g) *flux_transform_from_monthly_to_second min_consumption(g) = this%input_mon_min_cons_grc(g) *flux_transform_from_monthly_to_second - + end do ! end loop over gridcels - + ! Limit deficits by available volr, if desired. Note that we cannot do this limiting ! if running without a prognostic river model, since we need river volume to impose the limitation. limit_sectorwater = (this%params%limit_sectorwater_if_rof_enabled .and. rof_prognostic) @@ -1011,66 +1011,66 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) else dom_demand_volr_limited(bounds%begg:bounds%endg) = dom_demand(bounds%begg:bounds%endg) dom_consumption_volr_limited(bounds%begg:bounds%endg) = dom_consumption(bounds%begg:bounds%endg) - + liv_demand_volr_limited(bounds%begg:bounds%endg) = liv_demand(bounds%begg:bounds%endg) liv_consumption_volr_limited(bounds%begg:bounds%endg) = liv_consumption(bounds%begg:bounds%endg) - + elec_demand_volr_limited(bounds%begg:bounds%endg) = elec_demand(bounds%begg:bounds%endg) elec_consumption_volr_limited(bounds%begg:bounds%endg) = elec_consumption(bounds%begg:bounds%endg) - + mfc_demand_volr_limited(bounds%begg:bounds%endg) = mfc_demand(bounds%begg:bounds%endg) mfc_consumption_volr_limited(bounds%begg:bounds%endg) = mfc_consumption(bounds%begg:bounds%endg) - + min_demand_volr_limited(bounds%begg:bounds%endg) = min_demand(bounds%begg:bounds%endg) min_consumption_volr_limited(bounds%begg:bounds%endg) = min_consumption(bounds%begg:bounds%endg) end if - + ! Convert demand to withdrawal rates [mm/s] ! Here it also seems like I could directly operate with the this%arrays instead of generating new ones (to check) do g = bounds%begg,bounds%endg ! Domestic this%dom_withd_grc(g) = dom_demand(g) this%dom_withd_actual_grc(g) = dom_demand_volr_limited(g) - + this%dom_cons_grc(g) = dom_consumption(g) this%dom_cons_actual_grc(g) = dom_consumption_volr_limited(g) - + this%dom_rf_actual_grc(g) = this%dom_withd_actual_grc(g) - this%dom_cons_actual_grc(g) - + ! Livestock this%liv_withd_grc(g) = liv_demand(g) this%liv_withd_actual_grc(g) = liv_demand_volr_limited(g) - + this%liv_cons_grc(g) = liv_consumption(g) this%liv_cons_actual_grc(g) = liv_consumption_volr_limited(g) - + this%liv_rf_actual_grc(g) = this%liv_withd_actual_grc(g) - this%liv_cons_actual_grc(g) - + ! Thermoelectric this%elec_withd_grc(g) = elec_demand(g) this%elec_withd_actual_grc(g) = elec_demand_volr_limited(g) - + this%elec_cons_grc(g) = elec_consumption(g) this%elec_cons_actual_grc(g) = elec_consumption_volr_limited(g) - + this%elec_rf_actual_grc(g) = this%elec_withd_actual_grc(g) - this%elec_cons_actual_grc(g) - + ! Manufacturing this%mfc_withd_grc(g) = mfc_demand(g) this%mfc_withd_actual_grc(g) = mfc_demand_volr_limited(g) - + this%mfc_cons_grc(g) = mfc_consumption(g) this%mfc_cons_actual_grc(g) = mfc_consumption_volr_limited(g) - + this%mfc_rf_actual_grc(g) = this%mfc_withd_actual_grc(g) - this%mfc_cons_actual_grc(g) - + ! Mining this%min_withd_grc(g) = min_demand(g) this%min_withd_actual_grc(g) = min_demand_volr_limited(g) - + this%min_cons_grc(g) = min_consumption(g) this%min_cons_actual_grc(g) = min_consumption_volr_limited(g) - + this%min_rf_actual_grc(g) = this%min_withd_actual_grc(g) - this%min_cons_actual_grc(g) ! Total actual withdrawal volume in m3 for all sectors during the current day @@ -1079,10 +1079,10 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) this%elec_withd_actual_grc(g) + this%mfc_withd_actual_grc(g) + & this%min_withd_actual_grc(g)) * mm_to_m3_over_km2 * grc%area(g) * 86400._r8 end do - + end subroutine CalcSectorWaterNeeded - - + + !----------------------------------------------------------------------- subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption, liv_demand, liv_consumption, elec_demand, elec_consumption, & mfc_demand, mfc_consumption, min_demand, min_consumption, volr, dom_demand_volr_limited, dom_consumption_volr_limited, liv_demand_volr_limited, & @@ -1093,57 +1093,57 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption ! !ARGUMENTS: class(sectorwater_type) , intent(in) :: this type(bounds_type) , intent(in) :: bounds - + real(r8), intent(in) :: dom_demand( bounds%begg:bounds%endg) real(r8), intent(in) :: dom_consumption( bounds%begg:bounds%endg) - + real(r8), intent(in) :: liv_demand( bounds%begg:bounds%endg) real(r8), intent(in) :: liv_consumption( bounds%begg:bounds%endg) - + real(r8), intent(in) :: elec_demand( bounds%begg:bounds%endg) real(r8), intent(in) :: elec_consumption( bounds%begg:bounds%endg) - + real(r8), intent(in) :: mfc_demand( bounds%begg:bounds%endg) real(r8), intent(in) :: mfc_consumption( bounds%begg:bounds%endg) - + real(r8), intent(in) :: min_demand( bounds%begg:bounds%endg) real(r8), intent(in) :: min_consumption( bounds%begg:bounds%endg) - - + + real(r8), intent(in) :: volr( bounds%begg:bounds%endg) ! river water volume [m3] - + real(r8), intent(out) :: dom_demand_volr_limited( bounds%begg:bounds%endg) real(r8), intent(out) :: dom_consumption_volr_limited( bounds%begg:bounds%endg) - + real(r8), intent(out) :: liv_demand_volr_limited( bounds%begg:bounds%endg) real(r8), intent(out) :: liv_consumption_volr_limited( bounds%begg:bounds%endg) - + real(r8), intent(out) :: elec_demand_volr_limited( bounds%begg:bounds%endg) real(r8), intent(out) :: elec_consumption_volr_limited( bounds%begg:bounds%endg) - + real(r8), intent(out) :: mfc_demand_volr_limited( bounds%begg:bounds%endg) real(r8), intent(out) :: mfc_consumption_volr_limited( bounds%begg:bounds%endg) - + real(r8), intent(out) :: min_demand_volr_limited( bounds%begg:bounds%endg) real(r8), intent(out) :: min_consumption_volr_limited( bounds%begg:bounds%endg) - + ! ! !LOCAL VARIABLES: integer :: g ! gridcell index real(r8) :: available_volr ! volr available for withdrawal [m3] real(r8) :: max_demand_supported_by_volr ! [kg/m2] [i.e., mm] - + ! ratio of demand_volr_limited to demand for each grid cell real(r8) :: dom_demand_limited_ratio_grc(bounds%begg:bounds%endg) real(r8) :: liv_demand_limited_ratio_grc(bounds%begg:bounds%endg) real(r8) :: elec_demand_limited_ratio_grc(bounds%begg:bounds%endg) real(r8) :: mfc_demand_limited_ratio_grc(bounds%begg:bounds%endg) real(r8) :: min_demand_limited_ratio_grc(bounds%begg:bounds%endg) - - + + character(len=*), parameter :: subname = 'CalcSectorDemandVolrLimited' !----------------------------------------------------------------------- - + do g = bounds%begg, bounds%endg if (volr(g) > 0._r8) then @@ -1153,14 +1153,14 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption ! Ensure that negative volr is treated the same as 0 volr max_demand_supported_by_volr = 0._r8 end if - + ! I think the algorithm is potentially too conservative ! I will need to check river discharge when there is high amount of unsatisfied demand ! The reason why I am saying this is because we compare the expected demand for the entire day with the current volume available in the river... ! It would make sense to use such an algorithm under the condition that volr does not change much during a day for a given gridcell ! But if this is not the case we maybe underestimate the amount of water available for usage. ! If this would be done once a day, then no problem, but we do it at each time step - ! This means that volr get + ! This means that volr get if (dom_demand(g) * 86400.0 > max_demand_supported_by_volr) then ! inadequate river storage, adjust demand dom_demand_limited_ratio_grc(g) = max_demand_supported_by_volr / (dom_demand(g) * 86400.0) @@ -1168,7 +1168,7 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption elec_demand_limited_ratio_grc(g) = 0._r8 mfc_demand_limited_ratio_grc(g) = 0._r8 min_demand_limited_ratio_grc(g) = 0._r8 - + else if (liv_demand(g) * 86400.0 > (max_demand_supported_by_volr - (dom_demand(g) * 86400.0))) then dom_demand_limited_ratio_grc(g) = 1._r8 liv_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) * 86400.0)) / (liv_demand(g) * 86400.0) @@ -1187,14 +1187,14 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption elec_demand_limited_ratio_grc(g) = 1._r8 mfc_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g)) * 86400.0) / (mfc_demand(g) * 86400.0) min_demand_limited_ratio_grc(g) = 0._r8 - + else if (min_demand(g) * 86400.0 > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g) + mfc_demand(g)) * 86400.0)) then dom_demand_limited_ratio_grc(g) = 1._r8 liv_demand_limited_ratio_grc(g) = 1._r8 elec_demand_limited_ratio_grc(g) = 1._r8 mfc_demand_limited_ratio_grc(g) = 1._r8 min_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g) + mfc_demand(g)) * 86400.0) / (min_demand(g) * 86400.0) - + else dom_demand_limited_ratio_grc(g) = 1._r8 liv_demand_limited_ratio_grc(g) = 1._r8 @@ -1203,7 +1203,7 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption min_demand_limited_ratio_grc(g) = 1._r8 end if end do - + dom_demand_volr_limited(bounds%begg:bounds%endg) = 0._r8 dom_consumption_volr_limited(bounds%begg:bounds%endg) = 0._r8 liv_demand_volr_limited(bounds%begg:bounds%endg) = 0._r8 @@ -1218,21 +1218,21 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption do g = bounds%begg, bounds%endg dom_demand_volr_limited(g) = dom_demand(g) * dom_demand_limited_ratio_grc(g) dom_consumption_volr_limited(g) = dom_consumption(g) * dom_demand_limited_ratio_grc(g) - + liv_demand_volr_limited(g) = liv_demand(g) * liv_demand_limited_ratio_grc(g) liv_consumption_volr_limited(g) = liv_consumption(g) * liv_demand_limited_ratio_grc(g) - + elec_demand_volr_limited(g) = elec_demand(g) * elec_demand_limited_ratio_grc(g) elec_consumption_volr_limited(g) = elec_consumption(g) * elec_demand_limited_ratio_grc(g) - + mfc_demand_volr_limited(g) = mfc_demand(g) * mfc_demand_limited_ratio_grc(g) mfc_consumption_volr_limited(g) = mfc_consumption(g) * mfc_demand_limited_ratio_grc(g) - + min_demand_volr_limited(g) = min_demand(g) * min_demand_limited_ratio_grc(g) min_consumption_volr_limited(g) = min_consumption(g) * min_demand_limited_ratio_grc(g) - + end do - + end subroutine CalcSectorDemandVolrLimited - + end module SectorWaterMod \ No newline at end of file diff --git a/src/cpl/lilac/lnd_import_export.F90 b/src/cpl/lilac/lnd_import_export.F90 index 0a02ff6bdc..681a89c412 100644 --- a/src/cpl/lilac/lnd_import_export.F90 +++ b/src/cpl/lilac/lnd_import_export.F90 @@ -493,7 +493,7 @@ subroutine export_fields(exportState, bounds, rc) call state_setexport(exportState, 'l2c_fb_rof', 'Flrl_irrig', bounds, & input=water_inst%waterlnd2atmbulk_inst%qirrig_grc, minus=.true., rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - + ! domestic withdrawal flux to be removed from main channel storage (negative) call state_setexport(exportState, 'l2c_fb_rof', 'Flrl_dom_withd', bounds, & input=water_inst%waterlnd2atmbulk_inst%qdom_withd_grc, minus=.true., rc=rc) @@ -543,7 +543,7 @@ subroutine export_fields(exportState, bounds, rc) call state_setexport(exportState, 'l2c_fb_rof', 'Flrl_min_rf', bounds, & input=water_inst%waterlnd2atmbulk_inst%qmin_rf_grc, minus=.false., rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - + end subroutine export_fields !=============================================================================== From d5a3c4651afc3a228940cd1794cec05d43e9536c Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:24:52 -0600 Subject: [PATCH 05/11] Added a space in endsubroutine. --- src/biogeophys/SectorWaterMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biogeophys/SectorWaterMod.F90 b/src/biogeophys/SectorWaterMod.F90 index d28bc0b462..b283c343b6 100644 --- a/src/biogeophys/SectorWaterMod.F90 +++ b/src/biogeophys/SectorWaterMod.F90 @@ -856,7 +856,7 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) deallocate(mon_dom_withd, mon_dom_cons, mon_liv_withd, mon_liv_cons, mon_elec_withd, mon_elec_cons, mon_mfc_withd, mon_mfc_cons, mon_min_withd, mon_min_cons) - endsubroutine ReadSectorWaterData + end subroutine ReadSectorWaterData subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) From 9cf43e871e3cc498bf9224d2eb52f581a23db2a8 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:27:11 -0600 Subject: [PATCH 06/11] Deleted some unnecessary/incomplete comments. --- src/biogeophys/HydrologyNoDrainageMod.F90 | 3 --- src/biogeophys/SectorWaterMod.F90 | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/biogeophys/HydrologyNoDrainageMod.F90 b/src/biogeophys/HydrologyNoDrainageMod.F90 index d1ad7c1473..8138ef0392 100644 --- a/src/biogeophys/HydrologyNoDrainageMod.F90 +++ b/src/biogeophys/HydrologyNoDrainageMod.F90 @@ -110,9 +110,6 @@ subroutine CalcAndWithdrawSectorWaterFluxes(bounds, soilhydrology_inst, sectorwa end do ! Update the qflx_sectorwater_col field corresponding to total sectoral consumption (except irrigation) - ! Here I am not sure if it is needed to have loop over all tracers (it seems that the tracers mechanism is not maintained anymore) - ! So I could in principle just use associate : w => water_inst%bulk_and_tracers(1) which correspond to bulk water. - ! To stay in aggreement with the legacy code, I am looping over the tracers. do i = water_inst%bulk_and_tracers_beg, water_inst%bulk_and_tracers_end associate(w => water_inst%bulk_and_tracers(i)) diff --git a/src/biogeophys/SectorWaterMod.F90 b/src/biogeophys/SectorWaterMod.F90 index b283c343b6..1c4448189a 100644 --- a/src/biogeophys/SectorWaterMod.F90 +++ b/src/biogeophys/SectorWaterMod.F90 @@ -882,7 +882,7 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) integer :: day ! day of month (1, ..., 31) for nstep+1 integer :: sec ! seconds into current date for nstep+1 - integer :: first_read ! variable to do first read, in future I may prefer to make a subroutine is_beg_curr_month to avoid exception for first reading + integer :: first_read ! variable to do first read real(r8) :: dayspyr ! days per year real(r8) :: dayspm ! days per month @@ -1160,7 +1160,6 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption ! It would make sense to use such an algorithm under the condition that volr does not change much during a day for a given gridcell ! But if this is not the case we maybe underestimate the amount of water available for usage. ! If this would be done once a day, then no problem, but we do it at each time step - ! This means that volr get if (dom_demand(g) * 86400.0 > max_demand_supported_by_volr) then ! inadequate river storage, adjust demand dom_demand_limited_ratio_grc(g) = max_demand_supported_by_volr / (dom_demand(g) * 86400.0) From edc2aeb48c67e1590534193cd95de1563d3bcf73 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:28:13 -0600 Subject: [PATCH 07/11] Lowercased Close(). --- src/biogeophys/SectorWaterMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biogeophys/SectorWaterMod.F90 b/src/biogeophys/SectorWaterMod.F90 index 1c4448189a..826671f7f6 100644 --- a/src/biogeophys/SectorWaterMod.F90 +++ b/src/biogeophys/SectorWaterMod.F90 @@ -788,7 +788,7 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) ! Assign current line to path_current_year_input_data current_year_input_data = current_line ! Close the input .txt file - Close(10) + close(10) ! Determine necessary indices call getfil(current_year_input_data, locfn, 0) From 9efee0f351508cb56430a6807e78d2cde42b99ae Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:29:15 -0600 Subject: [PATCH 08/11] Missing sector water inputs: error msg now points to correct file. --- src/biogeophys/SectorWaterMod.F90 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/biogeophys/SectorWaterMod.F90 b/src/biogeophys/SectorWaterMod.F90 index 826671f7f6..83b08d65b6 100644 --- a/src/biogeophys/SectorWaterMod.F90 +++ b/src/biogeophys/SectorWaterMod.F90 @@ -796,43 +796,43 @@ subroutine ReadSectorWaterData (this, bounds, year, mon) call ncd_io(ncid=ncid, varname='withd_dom', flag='read', data=mon_dom_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_dom NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_dom NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_dom', flag='read', data=mon_dom_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_dom NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_dom NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='withd_liv', flag='read', data=mon_liv_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_liv NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_liv NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_liv', flag='read', data=mon_liv_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_liv NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_liv NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='withd_elec', flag='read', data=mon_elec_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_elec NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_elec NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_elec', flag='read', data=mon_elec_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_elec NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_elec NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='withd_mfc', flag='read', data=mon_mfc_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_mfc NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_mfc NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_mfc', flag='read', data=mon_mfc_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_mfc NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_mfc NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='withd_min', flag='read', data=mon_min_withd, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: withd_min NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: withd_min NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_io(ncid=ncid, varname='cons_min', flag='read', data=mon_min_cons, & dim1name=nameg, nt=mon, readvar=readvar) - if (.not. readvar) call endrun(msg=' ERROR: cons_min NOT on surfdata file'//errMsg(sourcefile, __LINE__)) + if (.not. readvar) call endrun(msg=' ERROR: cons_min NOT on sector water file'//errMsg(sourcefile, __LINE__)) call ncd_pio_closefile(ncid) From 61e5eaea3509705fd32454a94af96e6cfc56317d Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:31:41 -0600 Subject: [PATCH 09/11] Replace 86400 with SHR_CONST_CDAY. --- src/biogeophys/SectorWaterMod.F90 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/biogeophys/SectorWaterMod.F90 b/src/biogeophys/SectorWaterMod.F90 index 83b08d65b6..07bb241666 100644 --- a/src/biogeophys/SectorWaterMod.F90 +++ b/src/biogeophys/SectorWaterMod.F90 @@ -2,6 +2,7 @@ module SectorWaterMod #include "shr_assert.h" use shr_kind_mod , only : r8 => shr_kind_r8 + use shr_const_mod , only : SHR_CONST_CDAY ! Number of seconds in day; real(r8) use decompMod , only : bounds_type use shr_log_mod , only : errMsg => shr_log_errMsg use abortutils , only : endrun @@ -931,7 +932,7 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) dayspm = dayspyr/12._r8 first_read = 1 - flux_transform_from_monthly_to_second = (1._r8/dayspm)/86400._r8 + flux_transform_from_monthly_to_second = (1._r8/dayspm)/SHR_CONST_CDAY ! For the first month of the simulation we need to read the data at the beginning of the month @@ -1077,7 +1078,7 @@ subroutine CalcSectorWaterNeeded(this, bounds, volr, rof_prognostic) ! Total actual sectoral withdrawal volume will be used to constrain how much water is available for irrigation taking into acount VOLR capacity (if limit on abstractions is active) this%sectorwater_total_actual_withd(g) = (this%dom_withd_actual_grc(g) + this%liv_withd_actual_grc(g) + & this%elec_withd_actual_grc(g) + this%mfc_withd_actual_grc(g) + & - this%min_withd_actual_grc(g)) * mm_to_m3_over_km2 * grc%area(g) * 86400._r8 + this%min_withd_actual_grc(g)) * mm_to_m3_over_km2 * grc%area(g) * SHR_CONST_CDAY end do end subroutine CalcSectorWaterNeeded @@ -1160,39 +1161,39 @@ subroutine CalcSectorDemandVolrLimited(this, bounds, dom_demand, dom_consumption ! It would make sense to use such an algorithm under the condition that volr does not change much during a day for a given gridcell ! But if this is not the case we maybe underestimate the amount of water available for usage. ! If this would be done once a day, then no problem, but we do it at each time step - if (dom_demand(g) * 86400.0 > max_demand_supported_by_volr) then + if (dom_demand(g) * SHR_CONST_CDAY > max_demand_supported_by_volr) then ! inadequate river storage, adjust demand - dom_demand_limited_ratio_grc(g) = max_demand_supported_by_volr / (dom_demand(g) * 86400.0) + dom_demand_limited_ratio_grc(g) = max_demand_supported_by_volr / (dom_demand(g) * SHR_CONST_CDAY) liv_demand_limited_ratio_grc(g) = 0._r8 elec_demand_limited_ratio_grc(g) = 0._r8 mfc_demand_limited_ratio_grc(g) = 0._r8 min_demand_limited_ratio_grc(g) = 0._r8 - else if (liv_demand(g) * 86400.0 > (max_demand_supported_by_volr - (dom_demand(g) * 86400.0))) then + else if (liv_demand(g) * SHR_CONST_CDAY > (max_demand_supported_by_volr - (dom_demand(g) * SHR_CONST_CDAY))) then dom_demand_limited_ratio_grc(g) = 1._r8 - liv_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) * 86400.0)) / (liv_demand(g) * 86400.0) + liv_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) * SHR_CONST_CDAY)) / (liv_demand(g) * SHR_CONST_CDAY) elec_demand_limited_ratio_grc(g) = 0._r8 mfc_demand_limited_ratio_grc(g) = 0._r8 min_demand_limited_ratio_grc(g) = 0._r8 - else if (elec_demand(g) * 86400.0 > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g))* 86400.0 )) then + else if (elec_demand(g) * SHR_CONST_CDAY > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g))* SHR_CONST_CDAY )) then dom_demand_limited_ratio_grc(g) = 1._r8 liv_demand_limited_ratio_grc(g) = 1._r8 - elec_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g))* 86400.0) / (elec_demand(g) * 86400.0) + elec_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g))* SHR_CONST_CDAY) / (elec_demand(g) * SHR_CONST_CDAY) mfc_demand_limited_ratio_grc(g) = 0._r8 min_demand_limited_ratio_grc(g) = 0._r8 - else if (mfc_demand(g) * 86400.0 > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g)) * 86400.0)) then + else if (mfc_demand(g) * SHR_CONST_CDAY > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g)) * SHR_CONST_CDAY)) then dom_demand_limited_ratio_grc(g) = 1._r8 liv_demand_limited_ratio_grc(g) = 1._r8 elec_demand_limited_ratio_grc(g) = 1._r8 - mfc_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g)) * 86400.0) / (mfc_demand(g) * 86400.0) + mfc_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g)) * SHR_CONST_CDAY) / (mfc_demand(g) * SHR_CONST_CDAY) min_demand_limited_ratio_grc(g) = 0._r8 - else if (min_demand(g) * 86400.0 > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g) + mfc_demand(g)) * 86400.0)) then + else if (min_demand(g) * SHR_CONST_CDAY > (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g) + mfc_demand(g)) * SHR_CONST_CDAY)) then dom_demand_limited_ratio_grc(g) = 1._r8 liv_demand_limited_ratio_grc(g) = 1._r8 elec_demand_limited_ratio_grc(g) = 1._r8 mfc_demand_limited_ratio_grc(g) = 1._r8 - min_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g) + mfc_demand(g)) * 86400.0) / (min_demand(g) * 86400.0) + min_demand_limited_ratio_grc(g) = (max_demand_supported_by_volr - (dom_demand(g) + liv_demand(g) + elec_demand(g) + mfc_demand(g)) * SHR_CONST_CDAY) / (min_demand(g) * SHR_CONST_CDAY) else dom_demand_limited_ratio_grc(g) = 1._r8 From eed9bf11951f25c66f48bef41f9038214916f422 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:32:42 -0600 Subject: [PATCH 10/11] Deleted incorrect "sfc" in some comments. --- src/biogeophys/Waterlnd2atmType.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/biogeophys/Waterlnd2atmType.F90 b/src/biogeophys/Waterlnd2atmType.F90 index 17c1abbdb5..28e6dccea4 100644 --- a/src/biogeophys/Waterlnd2atmType.F90 +++ b/src/biogeophys/Waterlnd2atmType.F90 @@ -36,15 +36,15 @@ module Waterlnd2atmType real(r8), pointer :: qflx_rofice_grc (:) ! rof ice forcing, grc level real(r8), pointer :: qflx_liq_from_ice_col(:) ! liquid runoff from converted ice runoff real(r8), pointer :: qirrig_grc (:) ! irrigation flux - real(r8), pointer :: qdom_withd_grc (:) ! sfc domestic actual withdrawal as satisfied by CLM + real(r8), pointer :: qdom_withd_grc (:) ! domestic actual withdrawal as satisfied by CLM real(r8), pointer :: qdom_rf_grc (:) ! domestic return flow - real(r8), pointer :: qliv_withd_grc (:) ! sfc livestock actual withdrawal as satisfied by CLM + real(r8), pointer :: qliv_withd_grc (:) ! livestock actual withdrawal as satisfied by CLM real(r8), pointer :: qliv_rf_grc (:) ! livestock return flow - real(r8), pointer :: qelec_withd_grc (:) ! sfc thermoelectric actual withdrawal as satisfied by CLM + real(r8), pointer :: qelec_withd_grc (:) ! thermoelectric actual withdrawal as satisfied by CLM real(r8), pointer :: qelec_rf_grc (:) ! thermoelectric return flow - real(r8), pointer :: qmfc_withd_grc (:) ! sfc manufacturing actual withdrawal as satisfied by CLM + real(r8), pointer :: qmfc_withd_grc (:) ! manufacturing actual withdrawal as satisfied by CLM real(r8), pointer :: qmfc_rf_grc (:) ! manufacturing return flow - real(r8), pointer :: qmin_withd_grc (:) ! sfc mining actual withdrawal as satisfied by CLM + real(r8), pointer :: qmin_withd_grc (:) ! mining actual withdrawal as satisfied by CLM real(r8), pointer :: qmin_rf_grc (:) ! mining return flow real(r8), pointer :: qsectorwater_grc (:) ! total consumption related to sector water abstractions From 26a7625e3d2deb9c611e058da418077bfd5bdaa0 Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Fri, 8 Sep 2023 14:46:20 -0600 Subject: [PATCH 11/11] CLMBuildNamelist: Changed else{if{ to elsif{. --- bld/CLMBuildNamelist.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bld/CLMBuildNamelist.pm b/bld/CLMBuildNamelist.pm index 5925dc5491..c4dd264cac 100755 --- a/bld/CLMBuildNamelist.pm +++ b/bld/CLMBuildNamelist.pm @@ -3026,10 +3026,8 @@ sub setup_logic_sectorwater_parameters { $var = "sectorwater_river_volume_threshold"; if ( &value_is_true($nl->get_value("limit_sectorwater_if_rof_enabled")) ) { add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, $var); - } else { - if (defined($nl->get_value($var))) { - $log->fatal_error("$var can only be set if limit_sectorwater_if_rof_enabled is true"); - } + } elsif (defined($nl->get_value($var))) { + $log->fatal_error("$var can only be set if limit_sectorwater_if_rof_enabled is true"); } }