Skip to content

Commit

Permalink
Merge branch 'bishtgautam/lnd/fix-cnp-budget' (PR E3SM-Project#6233)
Browse files Browse the repository at this point in the history
The following updates are made to fix the CNP budget in ELM.

- The value for three fluxes used in the monthly CNP budget is now initialized.
- An MPI_Allreduce (instead of an MPI_Reduce) is used when budgets are computed.
- An additional field is written out in the ELM restart file.
- Long names and units of a few variables in the restart files are corrected.

Fixes E3SM-Project#6230
[BFB] (except a new field is added in the ELM restart file)
  • Loading branch information
bishtgautam committed Feb 28, 2024
2 parents cea78cb + 6767fe7 commit c0a7395
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
18 changes: 10 additions & 8 deletions components/elm/src/biogeochem/CNPBudgetMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ subroutine Reset(mode, budg_fluxL, budg_fluxG, budg_fluxN, budg_stateL, budg_sta
!
integer :: year, mon, day, sec
integer :: ip
character(*),parameter :: subName = '(WaterBudget_Reset) '
character(*),parameter :: subName = '(Reset) '

if (.not.present(mode)) then
call get_curr_date(year, mon, day, sec)
Expand Down Expand Up @@ -470,7 +470,7 @@ subroutine CNPBudget_Restart(bounds, ncid, flag)
type(file_desc_t), intent(inout) :: ncid ! netcdf id
character(len=*) , intent(in) :: flag ! 'read' or 'write'
!
character(len=*),parameter :: subname = 'WaterBudget_Restart'
character(len=*),parameter :: subname = 'CNPBudget_Restart'

select case (trim(flag))
case ('define')
Expand Down Expand Up @@ -718,8 +718,8 @@ subroutine Sum0(f_size, s_size, budg_fluxL, budg_fluxG, budg_stateL, budg_stateG
budg_fluxGtmp = 0._r8
budg_stateGtmp = 0._r8

call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName)
call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName, all=.true.)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName, all=.true.)


budg_fluxG = budg_fluxG + budg_fluxGtmp
Expand Down Expand Up @@ -946,15 +946,17 @@ subroutine Restart_Define(bounds, ncid, name)

call ncd_defvar(varname=trim(name)//'_budg_fluxG', xtype=ncd_double, &
dim1name=trim(name)//'_budg_flux', &
long_name=trim(name)//'_budg_fluxG', units='mm', ncid=ncid)
long_name=trim(name)//'_budg_fluxG', &
units='g'//trim(name)//'/m2/s', ncid=ncid)

call ncd_defvar(varname=trim(name)//'_budg_fluxN', xtype=ncd_double, &
dim1name=trim(name)//'_budg_flux', &
long_name=trim(name)//'_budg_fluxN', units='-', ncid=ncid)

call ncd_defvar(varname=trim(name)//'_budg_stateG', xtype=ncd_double, &
dim1name=trim(name)//'_budg_state', &
long_name=trim(name)//'_budg_stateG', units='-', ncid=ncid)
long_name=trim(name)//'_budg_stateG', &
units='g'//trim(name)//'/m2', ncid=ncid)

end subroutine Restart_Define

Expand Down Expand Up @@ -990,8 +992,8 @@ subroutine Restart_Write(bounds, ncid, flag, name, f_size, s_size, &
budg_fluxGtmp = 0._r8
budg_stateGtmp = 0._r8

call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName)
call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName, all=.true.)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName, all=.true.)

! Copy data from 2D into 1D array
count = 0
Expand Down
12 changes: 6 additions & 6 deletions components/elm/src/biogeophys/WaterBudgetMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ subroutine WaterBudget_Sum0()
budg_fluxGtmp = 0._r8
budg_stateGtmp = 0._r8

call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName)
call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName, all=.true. )
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName, all=.true. )

budg_fluxG = budg_fluxG + budg_fluxGtmp
budg_stateG = budg_stateGtmp
Expand Down Expand Up @@ -563,15 +563,15 @@ subroutine WaterBudget_Restart_Define(bounds, ncid)

call ncd_defvar(varname='budg_fluxG', xtype=ncd_double, &
dim1name='budg_flux', &
long_name='budg_fluxG', units='mm', ncid=ncid)
long_name='budg_fluxG', units='kg/m2/s', ncid=ncid)

call ncd_defvar(varname='budg_fluxN', xtype=ncd_double, &
dim1name='budg_flux', &
long_name='budg_fluxN', units='-', ncid=ncid)

call ncd_defvar(varname='budg_stateG', xtype=ncd_double, &
dim1name='budg_state', &
long_name='budg_stateG', units='mm', ncid=ncid)
long_name='budg_stateG', units='kg/m2', ncid=ncid)

end subroutine WaterBudget_Restart_Define

Expand Down Expand Up @@ -601,8 +601,8 @@ subroutine WaterBudget_Restart_Write(bounds, ncid, flag)
budg_fluxGtmp = 0._r8
budg_stateGtmp = 0._r8

call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName)
call shr_mpi_sum(budg_fluxL, budg_fluxGtmp, mpicom, subName, all=.true.)
call shr_mpi_sum(budg_stateL, budg_stateGtmp, mpicom, subName, all=.true. )

! Copy data from 2D into 1D array
count = 0
Expand Down
12 changes: 12 additions & 0 deletions components/elm/src/data_types/ColumnDataType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,8 @@ subroutine col_cs_restart ( this, bounds, ncid, flag, carbon_type, c12_carbonst
! !DESCRIPTION:
! Read/Write column carbon state information to/from restart file.
!
use elm_varctl, only : do_budgets
!
! !ARGUMENTS:
class(column_carbon_state) :: this
type(bounds_type), intent(in) :: bounds
Expand Down Expand Up @@ -2544,6 +2546,13 @@ subroutine col_cs_restart ( this, bounds, ncid, flag, carbon_type, c12_carbonst
integer :: decomp_cascade_state, restart_file_decomp_cascade_state
!-----------------------------------------------------------------------

if (do_budgets) then
call restartvar(ncid=ncid, flag=flag, varname='ENDCB', xtype=ncd_double, &
dim1name='column', &
long_name='carbon balance at end of timestep', units='gC/m2', &
interpinic_flag='interp', readvar=readvar, data=this%endcb)
endif

if (carbon_type == 'c13' .or. carbon_type == 'c14') then
if (.not. present(c12_carbonstate_vars)) then
call endrun(msg=' ERROR: for C14 must pass in c12_carbonstate_vars as argument' //&
Expand Down Expand Up @@ -7755,6 +7764,9 @@ subroutine col_cf_setvalues ( this, num_column, filter_column, value_column)
this%prod1c_loss(i) = value_column
this%prod10c_loss(i) = value_column
this%prod100c_loss(i) = value_column
this%er(i) = value_column
this%som_c_leached(i) = value_column
this%somc_yield(i) = value_column
this%somhr(i) = value_column ! REVISIT
this%lithr(i) = value_column ! REVISIT
this%hr(i) = value_column
Expand Down
8 changes: 4 additions & 4 deletions components/elm/src/data_types/GridcellDataType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ subroutine grc_ws_restart(this, bounds, ncid, flag)
!-----------------------------------------------------------------------
call restartvar(ncid=ncid, flag=flag, varname='TWS_MONTH_BEGIN', xtype=ncd_double, &
dim1name='gridcell', &
long_name='surface watertotal water storage at the beginning of a month', units='mm', &
long_name='total water storage at the beginning of a month', units='mm', &
interpinic_flag='interp', readvar=readvar, data=this%tws_month_beg)

end subroutine grc_ws_restart
Expand Down Expand Up @@ -603,12 +603,12 @@ subroutine grc_cs_init(this, begg, endg,carbon_type)
end if

this%tcs_month_beg(begg:endg) = spval
call hist_addfld1d (fname='TCS_MONTH_BEGIN', units='mm', &
call hist_addfld1d (fname='TCS_MONTH_BEGIN', units='gC/m^2', &
avgflag='I', long_name='total carbon storage at the beginning of a month', &
ptr_lnd=this%tcs_month_beg)

this%tcs_month_end(begg:endg) = spval
call hist_addfld1d (fname='TCS_MONTH_END', units='mm', &
call hist_addfld1d (fname='TCS_MONTH_END', units='gC/m^2', &
avgflag='I', long_name='total carbon storage at the end of a month', &
ptr_lnd=this%tcs_month_end)

Expand Down Expand Up @@ -644,7 +644,7 @@ subroutine grc_cs_restart(this, bounds, ncid, flag)
!-----------------------------------------------------------------------
call restartvar(ncid=ncid, flag=flag, varname='TCS_MONTH_BEGIN', xtype=ncd_double, &
dim1name='gridcell', &
long_name='surface watertotal carbon storage at the beginning of a month', units='mm', &
long_name='total carbon storage at the beginning of a month', units='gC/m^2', &
interpinic_flag='interp', readvar=readvar, data=this%tcs_month_beg)

end subroutine grc_cs_restart
Expand Down

0 comments on commit c0a7395

Please sign in to comment.