Skip to content

Commit

Permalink
Revisions part 1 in response to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
slevis-lmwg committed Jan 23, 2021
1 parent 097ff98 commit cb6a840
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
52 changes: 18 additions & 34 deletions src/biogeophys/BalanceCheckMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ end subroutine BeginWaterGridcellBalance
!-----------------------------------------------------------------------
subroutine BeginWaterColumnBalance(bounds, &
num_nolakec, filter_nolakec, num_lakec, filter_lakec, &
water_inst, soilhydrology_inst, lakestate_inst, &
use_aquifer_layer)
water_inst, lakestate_inst)
!
! !DESCRIPTION:
! Initialize column-level water balance at beginning of time step, for bulk water and
Expand All @@ -183,8 +182,6 @@ subroutine BeginWaterColumnBalance(bounds, &
integer , intent(in) :: filter_lakec(:) ! column filter for lake points
type(water_type) , intent(inout) :: water_inst
type(lakestate_type) , intent(in) :: lakestate_inst
type(soilhydrology_type) , intent(in) :: soilhydrology_inst
logical , intent(in) :: use_aquifer_layer ! whether an aquifer layer is used in this run
!
! !LOCAL VARIABLES:
integer :: i
Expand All @@ -196,12 +193,10 @@ subroutine BeginWaterColumnBalance(bounds, &
call BeginWaterColumnBalanceSingle(bounds, &
num_nolakec, filter_nolakec, &
num_lakec, filter_lakec, &
soilhydrology_inst, &
lakestate_inst, &
water_inst%bulk_and_tracers(i)%waterstate_inst, &
water_inst%bulk_and_tracers(i)%waterdiagnostic_inst, &
water_inst%bulk_and_tracers(i)%waterbalance_inst, &
use_aquifer_layer = use_aquifer_layer)
water_inst%bulk_and_tracers(i)%waterbalance_inst)
end do

end subroutine BeginWaterColumnBalance
Expand Down Expand Up @@ -282,8 +277,12 @@ subroutine BeginWaterGridcellBalanceSingle(bounds, &
call c2g(bounds, begwb_col(begc:endc), begwb_grc(begg:endg), &
c2l_scale_type='urbanf', l2g_scale_type='unity')

call waterflux_inst%qflx_liq_dynbal_dribbler%get_amount_left_to_dribble_beg(bounds, qflx_liq_dynbal_left_to_dribble(begg:endg))
call waterflux_inst%qflx_ice_dynbal_dribbler%get_amount_left_to_dribble_beg(bounds, qflx_ice_dynbal_left_to_dribble(begg:endg))
call waterflux_inst%qflx_liq_dynbal_dribbler%get_amount_left_to_dribble_beg( &
bounds, &
qflx_liq_dynbal_left_to_dribble(begg:endg))
call waterflux_inst%qflx_ice_dynbal_dribbler%get_amount_left_to_dribble_beg( &
bounds, &
qflx_ice_dynbal_left_to_dribble(begg:endg))

do g = begg, endg
begwb_grc(g) = begwb_grc(g) - qflx_liq_dynbal_left_to_dribble(g) &
Expand All @@ -297,9 +296,8 @@ end subroutine BeginWaterGridcellBalanceSingle
!-----------------------------------------------------------------------
subroutine BeginWaterColumnBalanceSingle(bounds, &
num_nolakec, filter_nolakec, num_lakec, filter_lakec, &
soilhydrology_inst, lakestate_inst, waterstate_inst, &
waterdiagnostic_inst, waterbalance_inst, &
use_aquifer_layer)
lakestate_inst, waterstate_inst, &
waterdiagnostic_inst, waterbalance_inst)
!
! !DESCRIPTION:
! Initialize column-level water balance at beginning of time step, for bulk or a
Expand All @@ -311,37 +309,19 @@ subroutine BeginWaterColumnBalanceSingle(bounds, &
integer , intent(in) :: filter_nolakec(:) ! column filter for non-lake points
integer , intent(in) :: num_lakec ! number of column lake points in column filter
integer , intent(in) :: filter_lakec(:) ! column filter for lake points
type(soilhydrology_type) , intent(in) :: soilhydrology_inst
type(lakestate_type) , intent(in) :: lakestate_inst
class(waterstate_type) , intent(inout) :: waterstate_inst
class(waterdiagnostic_type), intent(in) :: waterdiagnostic_inst
class(waterbalance_type) , intent(inout) :: waterbalance_inst
logical , intent(in) :: use_aquifer_layer ! whether an aquifer layer is used in this run
!
! !LOCAL VARIABLES:
integer :: c, j, fc ! indices
!-----------------------------------------------------------------------

associate( &
zi => col%zi , & ! Input: [real(r8) (:,:) ] interface level below a "z" level (m)
zwt => soilhydrology_inst%zwt_col , & ! Input: [real(r8) (:) ] water table depth (m)
aquifer_water_baseline => waterstate_inst%aquifer_water_baseline, & ! Input: [real(r8)] baseline value for water in the unconfined aquifer (wa_col) for this bulk / tracer (mm)
wa => waterstate_inst%wa_col , & ! Output: [real(r8) (:) ] water in the unconfined aquifer (mm)
begwb => waterbalance_inst%begwb_col , & ! Output: [real(r8) (:) ] water mass begining of the time step
h2osno_old => waterbalance_inst%h2osno_old_col & ! Output: [real(r8) (:) ] snow water (mm H2O) at previous time step
)

if(use_aquifer_layer) then
do fc = 1, num_nolakec
c = filter_nolakec(fc)
if (col%hydrologically_active(c)) then
if(zwt(c) <= zi(c,nlevsoi)) then
wa(c) = aquifer_water_baseline
end if
end if
end do
endif

call ComputeWaterMassNonLake(bounds, num_nolakec, filter_nolakec, &
waterstate_inst, waterdiagnostic_inst, &
subtract_dynbal_baselines = .false., &
Expand Down Expand Up @@ -413,6 +393,7 @@ subroutine BalanceCheck( bounds, &
integer :: nstep ! time step number
integer :: DAnstep ! time step number since last Data Assimilation (DA)
integer :: indexp,indexc,indexl,indexg ! index of first found in search loop
real(r8) :: errh2o_grc(bounds%begg:bounds%endg) ! grid cell level water conservation error [mm H2O]
real(r8) :: forc_rain_col(bounds%begc:bounds%endc) ! column level rain rate [mm/s]
real(r8) :: forc_snow_col(bounds%begc:bounds%endc) ! column level snow rate [mm/s]
real(r8) :: h2osno_total(bounds%begc:bounds%endc) ! total snow water [mm H2O]
Expand Down Expand Up @@ -450,7 +431,6 @@ subroutine BalanceCheck( bounds, &
snow_depth => waterdiagnosticbulk_inst%snow_depth_col , & ! Input: [real(r8) (:) ] snow height (m)
begwb_grc => waterbalance_inst%begwb_grc , & ! Input: [real(r8) (:) ] grid cell-level water mass begining of the time step
endwb_grc => waterbalance_inst%endwb_grc , & ! Output: [real(r8) (:) ] grid cell-level water mass end of the time step
errh2o_grc => waterbalance_inst%errh2o_grc , & ! Output: [real(r8) (:) ] grid cell-level water conservation error (mm H2O)
begwb_col => waterbalance_inst%begwb_col , & ! Input: [real(r8) (:) ] column-level water mass begining of the time step
endwb_col => waterbalance_inst%endwb_col , & ! Output: [real(r8) (:) ] column-level water mass end of the time step
errh2o_col => waterbalance_inst%errh2o_col , & ! Output: [real(r8) (:) ] column-level water conservation error (mm H2O)
Expand Down Expand Up @@ -642,8 +622,12 @@ subroutine BalanceCheck( bounds, &
qflx_snwcp_discarded_ice_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'urbanf', l2g_scale_type='unity' )

call waterflux_inst%qflx_liq_dynbal_dribbler%get_amount_left_to_dribble_end(bounds, qflx_liq_dynbal_left_to_dribble(bounds%begg:bounds%endg))
call waterflux_inst%qflx_ice_dynbal_dribbler%get_amount_left_to_dribble_end(bounds, qflx_ice_dynbal_left_to_dribble(bounds%begg:bounds%endg))
call waterflux_inst%qflx_liq_dynbal_dribbler%get_amount_left_to_dribble_end( &
bounds, &
qflx_liq_dynbal_left_to_dribble(bounds%begg:bounds%endg))
call waterflux_inst%qflx_ice_dynbal_dribbler%get_amount_left_to_dribble_end( &
bounds, &
qflx_ice_dynbal_left_to_dribble(bounds%begg:bounds%endg))

do g = bounds%begg, bounds%endg
endwb_grc(g) = endwb_grc(g) - qflx_liq_dynbal_left_to_dribble(g) &
Expand Down Expand Up @@ -704,7 +688,7 @@ subroutine BalanceCheck( bounds, &

end if

! Snow balance check at the grid cell level.
! Snow balance check at the column level.
! Beginning snow balance variable h2osno_old is calculated once
! for both the column-level and grid cell-level balance checks.

Expand Down
4 changes: 0 additions & 4 deletions src/biogeophys/WaterBalanceType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module WaterBalanceType
real(r8), pointer :: endwb_col (:) ! column-level water mass end of the time step
real(r8), pointer :: errh2o_patch (:) ! water conservation error (mm H2O)
real(r8), pointer :: errh2o_col (:) ! column-level water conservation error (mm H2O)
real(r8), pointer :: errh2o_grc (:) ! grid cell-level water conservation error (mm H2O)
real(r8), pointer :: errh2osno_col (:) ! snow water conservation error(mm H2O)

contains
Expand Down Expand Up @@ -133,9 +132,6 @@ subroutine InitAllocate(this, bounds, tracer_vars)
call AllocateVar1d(var = this%errh2o_col, name = 'errh2o_col', &
container = tracer_vars, &
bounds = bounds, subgrid_level = BOUNDS_SUBGRID_COLUMN)
call AllocateVar1d(var = this%errh2o_grc, name = 'errh2o_grc', &
container = tracer_vars, &
bounds = bounds, subgrid_level = BOUNDS_SUBGRID_GRIDCELL)
call AllocateVar1d(var = this%errh2osno_col, name = 'errh2osno_col', &
container = tracer_vars, &
bounds = bounds, subgrid_level = BOUNDS_SUBGRID_COLUMN)
Expand Down
3 changes: 1 addition & 2 deletions src/main/clm_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
call BeginWaterColumnBalance(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_lakec, filter(nc)%lakec, &
water_inst, soilhydrology_inst, lakestate_inst, &
use_aquifer_layer = use_aquifer_layer())
water_inst, lakestate_inst)

call t_stopf('begwbal')

Expand Down
21 changes: 15 additions & 6 deletions src/main/lnd2atmMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ subroutine lnd2atm(bounds, &

! qflx_runoff is the sum of a number of terms, including qflx_qrgwl. Since we
! are adjusting qflx_qrgwl above, we need to adjust qflx_runoff analogously.
water_inst%waterfluxbulk_inst%qflx_runoff_col(c) = water_inst%waterfluxbulk_inst%qflx_runoff_col(c) + &
water_inst%waterlnd2atmbulk_inst%qflx_liq_from_ice_col(c)
water_inst%waterfluxbulk_inst%qflx_runoff_col(c) = &
water_inst%waterfluxbulk_inst%qflx_runoff_col(c) + &
water_inst%waterlnd2atmbulk_inst%qflx_liq_from_ice_col(c)
end if
end do

Expand All @@ -374,8 +375,12 @@ subroutine lnd2atm(bounds, &
c2l_scale_type= 'urbanf', l2g_scale_type='unity' )

do g = bounds%begg, bounds%endg
water_inst%waterlnd2atmbulk_inst%qflx_rofliq_qgwl_grc(g) = water_inst%waterlnd2atmbulk_inst%qflx_rofliq_qgwl_grc(g) - water_inst%waterfluxbulk_inst%qflx_liq_dynbal_grc(g)
water_inst%waterlnd2atmbulk_inst%qflx_rofliq_grc(g) = water_inst%waterlnd2atmbulk_inst%qflx_rofliq_grc(g) - water_inst%waterfluxbulk_inst%qflx_liq_dynbal_grc(g)
water_inst%waterlnd2atmbulk_inst%qflx_rofliq_qgwl_grc(g) = &
water_inst%waterlnd2atmbulk_inst%qflx_rofliq_qgwl_grc(g) - &
water_inst%waterfluxbulk_inst%qflx_liq_dynbal_grc(g)
water_inst%waterlnd2atmbulk_inst%qflx_rofliq_grc(g) = &
water_inst%waterlnd2atmbulk_inst%qflx_rofliq_grc(g) - &
water_inst%waterfluxbulk_inst%qflx_liq_dynbal_grc(g)
enddo

call c2g( bounds, &
Expand All @@ -394,7 +399,9 @@ subroutine lnd2atm(bounds, &
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) - water_inst%waterfluxbulk_inst%qflx_ice_dynbal_grc(g)
water_inst%waterlnd2atmbulk_inst%qflx_rofice_grc(g) = &
water_inst%waterlnd2atmbulk_inst%qflx_rofice_grc(g) - &
water_inst%waterfluxbulk_inst%qflx_ice_dynbal_grc(g)
enddo

! calculate total water storage for history files
Expand All @@ -407,7 +414,9 @@ subroutine lnd2atm(bounds, &
water_inst%waterbalancebulk_inst%endwb_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'urbanf', l2g_scale_type='unity' )
do g = bounds%begg, bounds%endg
water_inst%waterdiagnosticbulk_inst%tws_grc(g) = water_inst%waterbalancebulk_inst%endwb_grc(g) + water_inst%wateratm2lndbulk_inst%volr_grc(g) / grc%area(g) * 1.e-3_r8
water_inst%waterdiagnosticbulk_inst%tws_grc(g) = &
water_inst%waterbalancebulk_inst%endwb_grc(g) + &
water_inst%wateratm2lndbulk_inst%volr_grc(g) / grc%area(g) * 1.e-3_r8
enddo

end subroutine lnd2atm
Expand Down

0 comments on commit cb6a840

Please sign in to comment.