From 5ecb8d264cfb1271343660caafd78b595645f980 Mon Sep 17 00:00:00 2001 From: Gautam Bisht Date: Mon, 12 Feb 2024 21:00:05 -0800 Subject: [PATCH 1/5] Fixes CNP Budget Sets the values for three fluxes that are included in monthly CNP budgets. Fixes #6230 [BFB] --- components/elm/src/data_types/ColumnDataType.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/elm/src/data_types/ColumnDataType.F90 b/components/elm/src/data_types/ColumnDataType.F90 index 32ebf37af051..7a4f37a14649 100644 --- a/components/elm/src/data_types/ColumnDataType.F90 +++ b/components/elm/src/data_types/ColumnDataType.F90 @@ -7755,6 +7755,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 From 96a2d8957d41bc6d3e9627ab22fe65b816d6790c Mon Sep 17 00:00:00 2001 From: Gautam Bisht Date: Tue, 27 Feb 2024 12:44:32 -0800 Subject: [PATCH 2/5] Adds column-level C balance in the restart file --- components/elm/src/data_types/ColumnDataType.F90 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/elm/src/data_types/ColumnDataType.F90 b/components/elm/src/data_types/ColumnDataType.F90 index 7a4f37a14649..bc6c935efa5c 100644 --- a/components/elm/src/data_types/ColumnDataType.F90 +++ b/components/elm/src/data_types/ColumnDataType.F90 @@ -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 @@ -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' //& From 7679eef5701f5769bf1bd6a78ec92f16106edba6 Mon Sep 17 00:00:00 2001 From: Gautam Bisht Date: Tue, 27 Feb 2024 12:48:20 -0800 Subject: [PATCH 3/5] Uses MPI_Allreduce instead of MPI_Reduce --- components/elm/src/biogeochem/CNPBudgetMod.F90 | 8 ++++---- components/elm/src/biogeophys/WaterBudgetMod.F90 | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/elm/src/biogeochem/CNPBudgetMod.F90 b/components/elm/src/biogeochem/CNPBudgetMod.F90 index aeb033a1c257..e15928cc36e3 100644 --- a/components/elm/src/biogeochem/CNPBudgetMod.F90 +++ b/components/elm/src/biogeochem/CNPBudgetMod.F90 @@ -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 @@ -990,8 +990,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 diff --git a/components/elm/src/biogeophys/WaterBudgetMod.F90 b/components/elm/src/biogeophys/WaterBudgetMod.F90 index a1e70e6cd8e4..79ccce565fe5 100644 --- a/components/elm/src/biogeophys/WaterBudgetMod.F90 +++ b/components/elm/src/biogeophys/WaterBudgetMod.F90 @@ -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 @@ -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 From 1662bc01069ec28c57e394a6235a901d1a8d5e8a Mon Sep 17 00:00:00 2001 From: Gautam Bisht Date: Tue, 27 Feb 2024 13:12:14 -0800 Subject: [PATCH 4/5] Fixes variable name and units --- components/elm/src/biogeochem/CNPBudgetMod.F90 | 6 ++++-- components/elm/src/biogeophys/WaterBudgetMod.F90 | 4 ++-- components/elm/src/data_types/GridcellDataType.F90 | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/components/elm/src/biogeochem/CNPBudgetMod.F90 b/components/elm/src/biogeochem/CNPBudgetMod.F90 index e15928cc36e3..7279c01cc90d 100644 --- a/components/elm/src/biogeochem/CNPBudgetMod.F90 +++ b/components/elm/src/biogeochem/CNPBudgetMod.F90 @@ -946,7 +946,8 @@ 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', & @@ -954,7 +955,8 @@ subroutine Restart_Define(bounds, ncid, name) 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 diff --git a/components/elm/src/biogeophys/WaterBudgetMod.F90 b/components/elm/src/biogeophys/WaterBudgetMod.F90 index 79ccce565fe5..cf42f1e63085 100644 --- a/components/elm/src/biogeophys/WaterBudgetMod.F90 +++ b/components/elm/src/biogeophys/WaterBudgetMod.F90 @@ -563,7 +563,7 @@ 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', & @@ -571,7 +571,7 @@ subroutine WaterBudget_Restart_Define(bounds, 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 diff --git a/components/elm/src/data_types/GridcellDataType.F90 b/components/elm/src/data_types/GridcellDataType.F90 index 5c312cdd035d..092cbd4e1378 100644 --- a/components/elm/src/data_types/GridcellDataType.F90 +++ b/components/elm/src/data_types/GridcellDataType.F90 @@ -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 @@ -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) @@ -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 From 6767fe73afc9829be133784cd39d48e3352182c9 Mon Sep 17 00:00:00 2001 From: Gautam Bisht Date: Tue, 27 Feb 2024 13:14:39 -0800 Subject: [PATCH 5/5] Corrects subroutine names --- components/elm/src/biogeochem/CNPBudgetMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/biogeochem/CNPBudgetMod.F90 b/components/elm/src/biogeochem/CNPBudgetMod.F90 index 7279c01cc90d..0a8117ecc45a 100644 --- a/components/elm/src/biogeochem/CNPBudgetMod.F90 +++ b/components/elm/src/biogeochem/CNPBudgetMod.F90 @@ -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) @@ -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')