Skip to content

Commit

Permalink
when CLM-CN coupled with PFLOTRAN-bgc, all vertically-resolved (soil)…
Browse files Browse the repository at this point in the history
… variables summarized into column-level are done for the whole soil layers (’nlevdcomp_full’). It’s because PFLOTRAN-bgc mode is operational for all domain. In this way, both aq. NH4 and NO3 N column-level mass-balance checking can be carried out correctly.
  • Loading branch information
fmyuan committed Apr 26, 2017
1 parent 72c3c8d commit 79c6a89
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 104 deletions.
36 changes: 17 additions & 19 deletions components/clm/src/biogeochem/CNBalanceCheckMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ subroutine NBalanceCheck(bounds, &
product_nloss => nitrogenflux_vars%product_nloss_col , & ! Input: [real(r8) (:)] (gN/m2/s) total wood product nitrogen loss
som_n_leached => nitrogenflux_vars%som_n_leached_col , & ! Input: [real(r8) (:)] total SOM N loss from vertical transport
! pflotran:
col_decompn_delta => nitrogenflux_vars%externaln_to_decomp_delta_col, & ! Input: [real(r8) (:) ] (gN/m2/s) summarized net change of whole column N i/o to decomposing pool bwtn time-step
col_no3_delta => nitrogenflux_vars%no3_net_transport_delta_col , & ! Input: [real(r8) (:) ] (gN/m2/s) summarized net change of whole column NO3 leaching bwtn time-step
col_decompn_delta => nitrogenflux_vars%externaln_to_decomp_delta_col , & ! Input: [real(r8) (:) ] (gN/m2/s) summarized net change of whole column N i/o to decomposing pool bwtn time-step

col_ninputs => nitrogenflux_vars%ninputs_col , & ! Output: [real(r8) (:)] column-level N inputs (gN/m2/s)
col_noutputs => nitrogenflux_vars%noutputs_col , & ! Output: [real(r8) (:)] column-level N outputs (gN/m2/s)
Expand Down Expand Up @@ -341,7 +340,15 @@ subroutine NBalanceCheck(bounds, &
else
col_noutputs(c) = col_noutputs(c) + f_n2o_nit(c)

col_noutputs(c) = col_noutputs(c) + smin_no3_leached(c) + smin_no3_runoff(c)
if(use_pflotran .and. pf_cmode) then
! inclusion of aq. NH4 transport by PFLOTRAN-bgc
col_noutputs(c) = col_noutputs(c) + sminn_leached(c)
else

col_noutputs(c) = col_noutputs(c) + smin_no3_leached(c) + smin_no3_runoff(c)

endif

end if
endif

Expand All @@ -357,10 +364,6 @@ subroutine NBalanceCheck(bounds, &
if (use_pflotran .and. pf_cmode) then
col_errnb(c) = col_errnb(c) - col_decompn_delta(c)*dt
! here is '-' adjustment. It says that the adding to PF decomp n pools was less.

! if not hydrology-coupled, NO3 leaching/runoff at previous time-step used as 'source' (out, -) to PFLOTRAN bgc
! if (.not.pf_hmode) col_errnb(c) = col_errnb(c) + col_no3_delta(c)*dt
! here is '+' adjustment. It says that the taking to PF no3 pools was more.
end if

if (abs(col_errnb(c)) > 1e-8_r8) then
Expand Down Expand Up @@ -395,17 +398,12 @@ subroutine NBalanceCheck(bounds, &
write(iulog,*)'prod = ',product_nloss(c)*dt

if (use_pflotran .and. pf_cmode) then

if (abs(col_errnb(c)) > 1e-7_r8) then
!! for unknown reason, loosen this error-checking criteria will remarkably speed up CLM-PFLOTRAN simulation
!! the 'col_errnb' is about 2.67e-8 at timestep=75653, i.e., 0005-04-27_02:30:00, which resulted in the crash of ALM but PF converged well.
!! if 1e-8_r8 < abs(col_errnb(c)) <= 1e-7_r8, continue model run, but print 'err_found'
call endrun(msg=errMsg(__FILE__, __LINE__))
end if
else
call endrun(msg=errMsg(__FILE__, __LINE__))
write(iulog,*)'pf_delta_decompn = ',col_decompn_delta(c)*dt
end if

call endrun(msg=errMsg(__FILE__, __LINE__))


end if

end associate
Expand Down Expand Up @@ -460,9 +458,9 @@ subroutine PBalanceCheck(bounds, &
!X.YANG testing P Balance, from VEGP
totpftp => phosphorusstate_vars%totpftp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
totsomp => phosphorusstate_vars%totsomp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
cwdp => phosphorusstate_vars%cwdp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
totlitp => phosphorusstate_vars%totlitp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
sminp => phosphorusstate_vars%sminp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
cwdp => phosphorusstate_vars%cwdp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
totlitp => phosphorusstate_vars%totlitp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
sminp => phosphorusstate_vars%sminp_col , & ! Input: [real(r8) (:)] (gP/m2) total column phosphorus, incl veg
leafp_to_litter => phosphorusflux_vars%leafp_to_litter_patch , & ! Input: [real(r8) (:)] soil mineral P pool loss to leaching (gP/m2/s)
frootp_to_litter => phosphorusflux_vars%frootp_to_litter_patch , & ! Input: [real(r8) (:)] soil mineral P pool loss to leaching (gP/m2/s)
sminp_to_plant => phosphorusflux_vars%sminp_to_plant_col ,&
Expand Down
51 changes: 28 additions & 23 deletions components/clm/src/biogeochem/CNCarbonFluxType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4309,6 +4309,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
use subgridAveMod , only : p2c
use tracer_varcon , only : is_active_betr_bgc
use MathfuncMod , only : dot_sum
use clm_varpar , only : nlevdecomp_full
!
! !ARGUMENTS:
class(carbonflux_type) :: this
Expand All @@ -4324,6 +4325,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
integer :: c,p,j,k,l ! indices
integer :: fp,fc ! lake filter indices
real(r8) :: maxdepth ! depth to integrate soil variables
integer :: nlev
!-----------------------------------------------------------------------

associate(&
Expand Down Expand Up @@ -4689,6 +4691,8 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
endif

! column variables
nlev = nlevdecomp
if (use_pflotran .and. pf_cmode) nlev = nlevdecomp_full

! some zeroing
do fc = 1,num_soilc
Expand All @@ -4703,7 +4707,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
! vertically integrate HR and decomposition cascade fluxes
do k = 1, ndecomp_cascade_transitions

do j = 1,nlevdecomp
do j = 1,nlev
do fc = 1,num_soilc
c = filter_soilc(fc)

Expand Down Expand Up @@ -4774,7 +4778,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil

! vertically integrate column-level carbon fire losses
do l = 1, ndecomp_pools
do j = 1,nlevdecomp
do j = 1,nlev
do fc = 1,num_soilc
c = filter_soilc(fc)
this%m_decomp_cpools_to_fire_col(c,l) = &
Expand Down Expand Up @@ -4906,7 +4910,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
c = filter_soilc(fc)
this%decomp_cpools_leached_col(c,l) = 0._r8
end do
do j = 1, nlevdecomp
do j = 1, nlev
do fc = 1,num_soilc
c = filter_soilc(fc)
this%decomp_cpools_leached_col(c,l) = &
Expand All @@ -4928,7 +4932,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
c = filter_soilc(fc)
this%plant_to_litter_cflux(c) = 0._r8
this%plant_to_cwd_cflux(c) = 0._r8
do j = 1, nlevdecomp
do j = 1, nlev
this%plant_to_litter_cflux(c) = &
this%plant_to_litter_cflux(c) + &
this%phenology_c_to_litr_met_c_col(c,j)* dzsoi_decomp(j) + &
Expand Down Expand Up @@ -4961,7 +4965,7 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
!
! !USES:
use shr_sys_mod, only: shr_sys_flush
use clm_varpar , only: nlevdecomp,ndecomp_pools,ndecomp_cascade_transitions
use clm_varpar , only: nlevdecomp_full,ndecomp_pools,ndecomp_cascade_transitions
use clm_varpar , only: i_met_lit, i_cel_lit, i_lig_lit, i_cwd
use clm_time_manager , only : get_step_size

Expand Down Expand Up @@ -4998,7 +5002,7 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)

do fc = 1,num_soilc
c = filter_soilc(fc)
do j = 1,nlevdecomp
do j = 1,nlevdecomp_full
this%hr_col(c) = this%hr_col(c) + this%hr_vr_col(c,j) * dzsoi_decomp(j)
end do
end do
Expand All @@ -5008,7 +5012,7 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
c = filter_soilc(fc)
this%f_co2_soil_col(c) = 0._r8
end do
do j = 1,nlevdecomp
do j = 1,nlevdecomp_full
do fc = 1,num_soilc
c = filter_soilc(fc)
this%f_co2_soil_col(c) = this%f_co2_soil_col(c) + &
Expand All @@ -5029,7 +5033,7 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
if ( is_cwd(l) ) then
do fc = 1,num_soilc
c = filter_soilc(fc)
do j = 1, nlevdecomp
do j = 1, nlevdecomp_full
this%cwdc_loss_col(c) = &
this%cwdc_loss_col(c) + &
this%decomp_cpools_sourcesink_col(c,j,l) / dtime
Expand All @@ -5040,7 +5044,7 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
if ( is_litter(l) ) then
do fc = 1,num_soilc
c = filter_soilc(fc)
do j = 1, nlevdecomp
do j = 1, nlevdecomp_full
this%litterc_loss_col(c) = &
this%litterc_loss_col(c) + &
this%decomp_cpools_sourcesink_col(c,j,l) / dtime
Expand All @@ -5049,7 +5053,6 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
end if

end do
end if !!if (use_pflotran.and.pf_cmode)

! add up all vertically-resolved addition/removal rates (gC/m3/s) of decomp_pools for PFLOTRAN-bgc
! (note: this can be for general purpose, although here added an 'if...endif' block for PF-bgc)
Expand All @@ -5065,20 +5068,20 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
this%externalc_to_decomp_cpools_col(c,j,l)*dzsoi_decomp(j)
end do
end do
end do
end do


! do the initialization for the following variable here.
! DON'T do so in the beginning of CLM-CN time-step (otherwise the above saved will not work)
this%externalc_to_decomp_cpools_col(:,:,:) = 0._r8
! do the initialization for the following variable here.
! DON'T do so in the beginning of CLM-CN time-step (otherwise the above saved will not work)
this%externalc_to_decomp_cpools_col(:,:,:) = 0._r8

!!wgs:2017: NGEE-pflotran includes the item 'decomp_cpools_transport_tendency_col';
!!In order to keep externalc_to_decomp_cpools_col(c,j,l) >=0, I suggest to exclude this item, as this variable could be >0 or <0.
!!if decomp_cpools_transport_tendency_col(c,j,l)<0, it may result in externalc_to_decomp_cpools_col(c,j,l) < 0

do fc = 1,num_soilc
do fc = 1,num_soilc
c = filter_soilc(fc)
do j = 1, nlevdecomp
do j = 1, nlevdecomp_full
do l = 1, ndecomp_pools
! for litter C pools
if (l==i_met_lit) then
Expand Down Expand Up @@ -5149,14 +5152,16 @@ subroutine CSummary_interface(this, bounds, num_soilc, filter_soilc)
end if

end do !!l = 1, ndecomp_pools
end do !!j = 1, nlevdecomp
end do !!fc = 1,num_soilc
end do !!j = 1, nlevdecomp_full
end do !!fc = 1,num_soilc

! change the sign so that it is the increments from the previous time-step (unit: from g/m2/s)
do fc = 1, num_soilc
c = filter_soilc(fc)
this%externalc_to_decomp_delta_col(c) = -this%externalc_to_decomp_delta_col(c)
end do
! change the sign so that it is the increments from the previous time-step (unit: from g/m2/s)
do fc = 1, num_soilc
c = filter_soilc(fc)
this%externalc_to_decomp_delta_col(c) = -this%externalc_to_decomp_delta_col(c)
end do

end if !!if (use_pflotran.and.pf_cmode)

end associate
end subroutine CSummary_interface
Expand Down
12 changes: 8 additions & 4 deletions components/clm/src/biogeochem/CNCarbonStateType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module CNCarbonStateType
use ColumnType , only : col
use PatchType , only : pft
use clm_varctl , only : nu_com
! bgc interface & pflotran
use clm_varctl , only : use_bgc_interface, use_pflotran, pf_cmode

!
! !PUBLIC TYPES:
Expand Down Expand Up @@ -2836,7 +2838,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
use clm_varctl , only: iulog
use clm_time_manager , only: get_step_size
use clm_varcon , only: secspday
use clm_varpar , only: nlevdecomp, ndecomp_pools
use clm_varpar , only: nlevdecomp, ndecomp_pools, nlevdecomp_full
!
! !ARGUMENTS:
class(carbonstate_type) :: this
Expand All @@ -2851,6 +2853,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
integer :: c,p,j,k,l ! indices
integer :: fp,fc ! lake filter indices
real(r8) :: maxdepth ! depth to integrate soil variables
integer :: nlev
!-----------------------------------------------------------------------

! calculate patch -level summary of carbon state
Expand Down Expand Up @@ -2927,7 +2930,8 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil

! column level summary


nlev = nlevdecomp
if (use_pflotran .and. pf_cmode) nlev = nlevdecomp_full

! vertically integrate each of the decomposing C pools
do l = 1, ndecomp_pools
Expand All @@ -2937,7 +2941,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
end do
end do
do l = 1, ndecomp_pools
do j = 1, nlevdecomp
do j = 1, nlev
do fc = 1,num_soilc
c = filter_soilc(fc)
this%decomp_cpools_col(c,l) = &
Expand Down Expand Up @@ -3064,7 +3068,7 @@ subroutine Summary(this, bounds, num_soilc, filter_soilc, num_soilp, filter_soil
c = filter_soilc(fc)
this%ctrunc_col(c) = 0._r8
end do
do j = 1, nlevdecomp
do j = 1, nlev
do fc = 1,num_soilc
c = filter_soilc(fc)
this%ctrunc_col(c) = &
Expand Down
Loading

0 comments on commit 79c6a89

Please sign in to comment.