Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1ac342a
add wrap_carbonfluxes routine
rosiealice Apr 30, 2025
ee534a0
make CTSM structured version of wrap function
rosiealice Apr 30, 2025
c57a896
add call to fates_atmos wrapper in clm_driver
rosiealice May 13, 2025
fc62c19
add composite fluxes for FATES into soilbiogeochemistry as placeholder
rosiealice May 13, 2025
d5f3bc2
add wrap_atmosphericcarbonfluxes routine to clmfates_interface
rosiealice May 13, 2025
08d591b
move call to wrap_atmos to ecosystemdynamicspostdraiinage
rosiealice May 14, 2025
f2f3f94
send clm_fates structure to the ecosystemdynamics call
rosiealice May 14, 2025
4bf0be1
test modify the soilbgc variables to the cnflux variables
rosiealice May 14, 2025
5f6befa
shift back to the soilbgc fates_nep variable as the CNflux version ca…
rosiealice May 14, 2025
29102a5
transfer product pool into the soilbgc variable
rosiealice May 15, 2025
6a18fe3
adding product flux to SoilBiogeochemCarbonFluxType as the cnveg_carb…
rosiealice May 15, 2025
7e63c45
add bc_out site level npp to wrap_atmos routine
rosiealice May 20, 2025
000f6c6
adding total carbon stock variable to soilbiogeochem
rosiealice May 21, 2025
c341eeb
move fates_total_carbon_col to soilbiogeochemcarbonstatemod
rosiealice May 21, 2025
d3f9c34
add the npp_acc flux to the total fates carbon.
rosiealice May 21, 2025
50dbf64
move the call to wrap_atmosfluxes before the summary routines
rosiealice May 25, 2025
97fdd6f
create npp and fire_grazing fluxes and add summary routines in soilbi…
rosiealice May 25, 2025
9424ace
modify the clmfates_interface to accept NPP and fire/grazing fluxes
rosiealice May 25, 2025
4027c85
adding unreleased flux variable to soilbgc
rosiealice May 26, 2025
251b09a
move unreleased fluxes into soilbgc state as they are in gC/m2
rosiealice May 26, 2025
e0eaca2
remove some write statements
rosiealice May 26, 2025
f4e0bec
move commited fluxes back into fluxes
rosiealice May 26, 2025
267b0b5
changes to column balance check. and a lot of write statements
rosiealice May 29, 2025
c385576
updates to clmfates_nterface. Will need cleaning
rosiealice May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 56 additions & 20 deletions src/biogeochem/CNBalanceCheckMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ subroutine BeginCNColumnBalance(this, bounds, num_soilc, filter_soilc, &
c = filter_soilc(fc)

col_begcb(c) = totcolc(c)
if(use_fates_bgc)then
col_begcb(c)= soilbiogeochem_carbonstate_inst%totsomc_col(c)
endif
col_begnb(c) = totcoln(c)

end do
Expand Down Expand Up @@ -304,17 +307,18 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, &


if( col%is_fates(c) ) then

col_endcb(c) = soilbiogeochem_carbonstate_inst%totsomc_col(c)
s = clm_fates%f2hmap(ic)%hsites(c)

! this balance check determines the column level balance of the soil pool
! when FATES is on.
col_cinputs = fates_litter_flux(c)

! calculate total column-level outputs
! fates has already exported burn losses and fluxes to the atm
! So they are irrelevant here

! calculate total column-level outputs from soil pool
! (gC/m2/s) total heterotrophic respiration
! what about leaching?

col_coutputs = soilbiogeochem_carbonflux_inst%hr_col(c)

else

! calculate total column-level inputs
Expand Down Expand Up @@ -350,10 +354,11 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, &
err_index = c
end if
if (abs(col_errcb(c)) > this%cwarning) then
write(iulog,*) 'cbalance warning at c =', c, col_errcb(c), col_endcb(c)
write(iulog,*) 'cbalance warning at c =', c, col_errcb(c), col_endcb(c)
write(iulog,*) 'flux, dstock',(col_cinputs - col_coutputs)*dt, (col_endcb(c) - col_begcb(c))
end if

end do ! end of columns loop
! end do ! end of columns loop

if (err_found) then
c = err_index
Expand Down Expand Up @@ -381,26 +386,41 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, &
write(iulog,*)'hr = ',soilbiogeochem_carbonflux_inst%hr_col(c)*dt
end if
write(iulog,*)'-1*som_c_leached = ',som_c_leached(c)*dt
call endrun(subgrid_index=c, subgrid_level=subgrid_level_column, msg=errMsg(sourcefile, __LINE__))
if(.not. use_fates_bgc)then
call endrun(subgrid_index=c, subgrid_level=subgrid_level_column, msg=errMsg(sourcefile, __LINE__))
endif
end if
end do ! end of columns loop



! Repeat error check at the gridcell level
call c2g( bounds = bounds, &
carr = totcolc(bounds%begc:bounds%endc), &
garr = totgrcc(bounds%begg:bounds%endg), &
c2l_scale_type = 'unity', &
l2g_scale_type = 'unity')
! write(*,*) 'totc',totcolc(bounds%begc:bounds%endc)
write(*,*) 'totg',totgrcc(bounds%begg:bounds%endg)

call c2g( bounds = bounds, &
carr = som_c_leached(bounds%begc:bounds%endc), &
garr = som_c_leached_grc(bounds%begg:bounds%endg), &
c2l_scale_type = 'unity', &
l2g_scale_type = 'unity')

if(use_fates_bgc)then
call c2g( bounds = bounds, &
carr = soilbiogeochem_carbonflux_inst%fates_nbp_col(bounds%begc:bounds%endc), &
garr = soilbiogeochem_carbonflux_inst%fates_nbp_grc(bounds%begg:bounds%endg), &
c2l_scale_type = 'unity', &
l2g_scale_type = 'unity')
end if

err_found = .false.
do g = bounds%begg, bounds%endg
! calculate gridcell-level carbon storage for mass conservation check
! Notes:
! totgrcc = totcolc = totc_p2c_col(c) + soilbiogeochem_cwdc_col(c) + soilbiogeochem_totlitc_col(c) + soilbiogeochem_totmicc_col(c) + soilbiogeochem_totsomc_col(c) + soilbiogeochem_ctrunc_col(c)
! Notes: totgrcc = totcolc = totc_p2c_col(c) + soilbiogeochem_cwdc_col(c) + soilbiogeochem_totlitc_col(c) + soilbiogeochem_totmicc_col(c) + soilbiogeochem_totsomc_col(c) + soilbiogeochem_ctrunc_col(c)
! totc_p2c_col = totc_patch = totvegc_patch(p) + xsmrpool_patch(p) + ctrunc_patch(p) + cropseedc_deficit_patch(p)
! Not including seedc_grc in grc_begcb and grc_endcb because
! seedc_grc forms out of thin air, for now, and equals
Expand Down Expand Up @@ -439,26 +459,39 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, &

else

! Totally punt on this for now. We just don't track these gridscale variables yet (RGK)
grc_cinputs = 0._r8
grc_endcb(g) = grc_begcb(g)
grc_coutputs = 0._r8
grc_errcb(g) = 0._r8
! FATES gridcell level balance check.
! Inputs are calculated from the fates_nbp
! Outputs the same as for cn mode.
! Total land carbon is informed by FATES carbon.
grc_endcb(g) = totgrcc(g) + tot_woodprod_grc(g) + cropprod1_grc(g)


nbp_grc(g) = soilbiogeochem_carbonflux_inst%fates_nbp_grc(g)-soilbiogeochem_carbonflux_inst%hr_col(c)

grc_cinputs = nbp_grc(g)
grc_cinputs = soilbiogeochem_carbonflux_inst%fates_nbp_grc(g) !newr calc
! removing the hr_col here as it is 0 in the clmfates_interface, but not in the summary
grc_coutputs = - som_c_leached_grc(g)

grc_errcb(g) = (grc_cinputs - grc_coutputs) * dt - &
(grc_endcb(g) - grc_begcb(g))
! write(*,*) 'GCELL error:',g,grc_errcb(g)
write(*,*) 'GCELL ERR,b-e',grc_begcb(g), grc_endcb(g)
! write(*,*) 'GCELL error:' ,grc_endcb(g) - grc_begcb(g),(grc_cinputs - grc_coutputs) * dt
end if

! check for significant errors
if (abs(grc_errcb(g)) > this%cerror) then
err_found = .true.
err_index = g
write(*,*) 'error found',g, grc_errcb(g)
end if
if (abs(grc_errcb(g)) > this%cwarning) then
write(iulog,*) 'cbalance warning at g =', g, grc_errcb(g), grc_endcb(g)
write(iulog,*) 'cbal warning:', g, grc_errcb(g), grc_endcb(g)
end if
end do ! end of gridcell loop

if (err_found) then
g = err_index
!g = err_index
write(iulog,*)'gridcell cbalance error =', grc_errcb(g), g
write(iulog,*)'latdeg, londeg =', grc%latdeg(g), grc%londeg(g)
write(iulog,*)'begcb =', grc_begcb(g)
Expand All @@ -472,7 +505,10 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, &
write(iulog,*)'-1*som_c_leached_grc = ', som_c_leached_grc(g) * dt
call endrun(subgrid_index=g, subgrid_level=subgrid_level_gridcell, msg=errMsg(sourcefile, __LINE__))
end if


! moving the update until after the error report.
grc_endcb(g) = grc_begcb(g)
end do !
end associate

end subroutine CBalanceCheck
Expand Down
7 changes: 5 additions & 2 deletions src/biogeochem/CNDriverMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ subroutine CNDriverNoLeaching(bounds,
end if

if_bgc_vegp2: if(num_bgc_vegp>0)then

call c_products_inst%UpdateProducts(bounds, &
num_bgc_vegp, filter_bgc_vegp, &
dwt_wood_product_gain_patch = cnveg_carbonflux_inst%dwt_wood_productc_gain_patch(begp:endp), &
Expand Down Expand Up @@ -903,11 +904,13 @@ subroutine CNDriverNoLeaching(bounds,
if (use_c14) call c14_products_inst%ComputeProductSummaryVars(bounds)
call n_products_inst%ComputeProductSummaryVars(bounds)


call c_products_inst%ComputeSummaryVars(bounds)
if (use_c13) call c13_products_inst%ComputeSummaryVars(bounds)
if (use_c14) call c14_products_inst%ComputeSummaryVars(bounds)
call n_products_inst%ComputeSummaryVars(bounds)

! unsure where else to put this - it can't go in the summary as that is all column variables.
soilbiogeochem_carbonflux_inst%fates_product_loss_grc(bounds%begg:bounds%endg)=c_products_inst%product_loss_grc(bounds%begg:bounds%endg)

call t_stopf('CNWoodProducts')

Expand Down Expand Up @@ -1261,7 +1264,7 @@ subroutine CNDriverSummarizeFluxes(bounds, &
! ----------------------------------------------
! soilbiogeochem carbon/nitrogen flux summary
! ----------------------------------------------

call soilbiogeochem_carbonflux_inst%Summary(bounds, num_bgc_soilc, filter_bgc_soilc, &
num_bgc_vegp, filter_bgc_vegp, &
soilbiogeochem_carbonflux_inst%decomp_cascade_ctransfer_col(begc:endc,1:ndecomp_cascade_transitions), &
Expand Down
19 changes: 15 additions & 4 deletions src/biogeochem/CNVegetationFacade.F90
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ subroutine Init(this, bounds, NLFilename, nskip_steps, params_ncid)
call this%CNReadNML( NLFilename ) ! MUST be called first as passes down control information to others
end if


if(use_cn.or.use_fates_bgc)then
call this%cnveg_carbonstate_inst%Init(bounds, carbon_type='c12', ratio=1._r8, &
NLFilename=NLFilename, dribble_crophrv_xsmrpool_2atm=this%dribble_crophrv_xsmrpool_2atm, &
Expand Down Expand Up @@ -912,7 +913,7 @@ subroutine InitGridcellBalance(this, bounds, num_allc, filter_allc, &
garr = soilbiogeochem_carbonstate_inst%totc_grc(bounds%begg:bounds%endg), &
c2l_scale_type = 'unity', &
l2g_scale_type = 'unity')

! total gridcell nitrogen (TOTGRIDCELLN)
call c2g( bounds = bounds, &
carr = soilbiogeochem_nitrogenstate_inst%totn_col(bounds%begc:bounds%endc), &
Expand Down Expand Up @@ -1061,7 +1062,8 @@ subroutine EcosystemDynamicsPostDrainage(this, bounds, num_allc, filter_allc, &
soilbiogeochem_carbonflux_inst, soilbiogeochem_carbonstate_inst, &
c13_soilbiogeochem_carbonflux_inst, c13_soilbiogeochem_carbonstate_inst, &
c14_soilbiogeochem_carbonflux_inst, c14_soilbiogeochem_carbonstate_inst, &
soilbiogeochem_nitrogenflux_inst, soilbiogeochem_nitrogenstate_inst)
soilbiogeochem_nitrogenflux_inst, soilbiogeochem_nitrogenstate_inst,c_products_inst,&
clm_fates)
!
! !DESCRIPTION:
! Do the main science for CN vegetation that needs to be done after hydrology-drainage
Expand Down Expand Up @@ -1100,7 +1102,9 @@ subroutine EcosystemDynamicsPostDrainage(this, bounds, num_allc, filter_allc, &
type(soilbiogeochem_carbonstate_type) , intent(inout) :: c14_soilbiogeochem_carbonstate_inst
type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst
type(soilbiogeochem_nitrogenstate_type) , intent(inout) :: soilbiogeochem_nitrogenstate_inst
!
type(cn_products_type) , intent(inout) :: c_products_inst
type(hlm_fates_interface_type) , intent(inout) :: clm_fates
!
! !LOCAL VARIABLES:

character(len=*), parameter :: subname = 'EcosystemDynamicsPostDrainage'
Expand Down Expand Up @@ -1140,8 +1144,11 @@ subroutine EcosystemDynamicsPostDrainage(this, bounds, num_allc, filter_allc, &
c14_soilbiogeochem_carbonstate_inst,soilbiogeochem_nitrogenstate_inst)
call t_stopf('SoilBiogeochemPrecisionControl')

if(use_fates_bgc)then
call clm_fates%wrap_AtmosphericCarbonFluxes(bounds,soilbiogeochem_carbonflux_inst,soilbiogeochem_carbonstate_inst)
endif

! Call to all CN summary routines

call CNDriverSummarizeStates(bounds, &
num_allc, filter_allc, &
num_bgc_soilc, filter_bgc_soilc, &
Expand Down Expand Up @@ -1172,6 +1179,8 @@ subroutine EcosystemDynamicsPostDrainage(this, bounds, num_allc, filter_allc, &
soilbiogeochem_nitrogenstate_inst, &
soilbiogeochem_nitrogenflux_inst)



! On the radiation time step, use C state variables to calculate
! vegetation structure (LAI, SAI, height)
if(num_bgc_vegp>0)then
Expand All @@ -1181,6 +1190,7 @@ subroutine EcosystemDynamicsPostDrainage(this, bounds, num_allc, filter_allc, &
crop_inst, this%cnveg_carbonstate_inst, canopystate_inst)
end if
end if


end subroutine EcosystemDynamicsPostDrainage

Expand Down Expand Up @@ -1217,6 +1227,7 @@ subroutine BalanceCheck(this, bounds, num_bgc_soilc, filter_bgc_soilc, &
character(len=*), parameter :: subname = 'BalanceCheck'
!-----------------------------------------------------------------------


DA_nstep = get_nstep_since_startup_or_lastDA_restart_or_pause()
if (DA_nstep <= skip_steps )then
if (masterproc) then
Expand Down
21 changes: 16 additions & 5 deletions src/main/clm_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module clm_driver
use clm_instMod
use SoilMoistureStreamMod , only : PrescribedSoilMoistureInterp, PrescribedSoilMoistureAdvance
use SoilBiogeochemDecompCascadeConType , only : no_soil_decomp, decomp_method
use CNProductsMod , only : cn_products_type
!
! !PUBLIC TYPES:
implicit none
Expand Down Expand Up @@ -128,6 +129,9 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
logical, intent(in) :: nlend ! true => end of run on this step
character(len=*),intent(in) :: rdate ! restart file time stamp for name

!where are all the other instances defined? I can't figure this out!
type(cn_products_type) :: c_products_inst

! Whether we're running with a prognostic ROF component. This shouldn't change from
! timestep to timestep, but we pass it into the driver loop because it isn't available
! in initialization.
Expand Down Expand Up @@ -1041,6 +1045,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
call t_stopf('ecosysdyn')
end if


! Prescribed biogeography - prescribed canopy structure, some prognostic carbon fluxes

if (((.not. use_cn) .and. (.not. use_fates) .and. (doalb))) then
Expand Down Expand Up @@ -1104,7 +1109,6 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro

call t_stopf('hydro2_drainage')


if (use_cn .or. use_fates_bgc) then
call t_startf('EcosysDynPostDrainage')
call bgc_vegetation_inst%EcosystemDynamicsPostDrainage(bounds_clump, &
Expand All @@ -1120,7 +1124,8 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
soilbiogeochem_carbonflux_inst, soilbiogeochem_carbonstate_inst, &
c13_soilbiogeochem_carbonflux_inst, c13_soilbiogeochem_carbonstate_inst, &
c14_soilbiogeochem_carbonflux_inst, c14_soilbiogeochem_carbonstate_inst, &
soilbiogeochem_nitrogenflux_inst, soilbiogeochem_nitrogenstate_inst)
soilbiogeochem_nitrogenflux_inst, soilbiogeochem_nitrogenstate_inst, c_products_inst,&
clm_fates)
call t_stopf('EcosysDynPostDrainage')
end if

Expand Down Expand Up @@ -1148,7 +1153,9 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
water_inst%waterstatebulk_inst, water_inst%waterdiagnosticbulk_inst, &
water_inst%wateratm2lndbulk_inst, canopystate_inst, soilbiogeochem_carbonflux_inst, &
frictionvel_inst, soil_water_retention_curve)

if(use_fates)then
! call clm_fates%wrap_AtmosphericCarbonFluxes(nc,bounds_proc,soilbiogeochem_carbonflux_inst,c_products_inst)
endif
! TODO(wjs, 2016-04-01) I think this setFilters call should be replaced by a
! call to reweight_wrapup, if it's needed at all.
call setFilters( bounds_clump, glc_behavior )
Expand Down Expand Up @@ -1304,9 +1311,13 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
! based on similar pgi compiler bugs that we have run into before). Also note that I
! don't have explicit bounds on the left-hand-side of this assignment: excluding these
! explicit bounds seemed to be needed to get around other compiler bugs.
allocate(net_carbon_exchange_grc(bounds_proc%begg:bounds_proc%endg))
net_carbon_exchange_grc = bgc_vegetation_inst%get_net_carbon_exchange_grc(bounds_proc)

allocate(net_carbon_exchange_grc(bounds_proc%begg:bounds_proc%endg))
if(use_fates_bgc)then
net_carbon_exchange_grc = soilbiogeochem_carbonflux_inst%fates_nbp_grc(bounds_proc%begg:bounds_proc%endg)
else
net_carbon_exchange_grc = bgc_vegetation_inst%get_net_carbon_exchange_grc(bounds_proc)
endif
call lnd2atm(bounds_proc, &
atm2lnd_inst, surfalb_inst, temperature_inst, frictionvel_inst, &
water_inst, &
Expand Down
Loading