From d32245d3ee811c65c88ea5b5f54d4b387af6923e Mon Sep 17 00:00:00 2001 From: mvdebolskiy Date: Sun, 15 Jun 2025 19:02:25 +0200 Subject: [PATCH 1/4] update test --- .../clm/FatesColdClm60Cam7LndTuningMode/user_nl_clm | 1 + .../clm/FatesColdClm60Cam7LndTuningMode/user_nl_cpl | 1 + 2 files changed, 2 insertions(+) create mode 100644 cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_clm create mode 100644 cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_cpl diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_clm new file mode 100644 index 0000000000..03acbe5eb4 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_clm @@ -0,0 +1 @@ +force_send_to_atm = .true. \ No newline at end of file diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_cpl b/cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_cpl new file mode 100644 index 0000000000..d51fce2d1c --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdClm60Cam7LndTuningMode/user_nl_cpl @@ -0,0 +1 @@ +flds_co2b = .true. \ No newline at end of file From e23a6987daec506c9b913c631c3eb3cf7a3b4404 Mon Sep 17 00:00:00 2001 From: mvdebolskiy Date: Sun, 15 Jun 2025 19:02:46 +0200 Subject: [PATCH 2/4] update co2 flux from fates --- src/main/clm_driver.F90 | 16 +++++++++- src/utils/clmfates_interfaceMod.F90 | 48 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/main/clm_driver.F90 b/src/main/clm_driver.F90 index 9528e1f02f..a391fe1010 100644 --- a/src/main/clm_driver.F90 +++ b/src/main/clm_driver.F90 @@ -1343,7 +1343,21 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro ! 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) + if (.not. use_fates) then + net_carbon_exchange_grc = bgc_vegetation_inst%get_net_carbon_exchange_grc(bounds_proc) + else + net_carbon_exchange_grc(bounds_proc%begg:bounds_proc%endg) = 0.0_r8 + if (use_fates_bgc) then + !$OMP PARALLEL DO PRIVATE (nc, bounds_clump) + do nc = 1,nclumps + call get_clump_bounds(nc, bounds_clump) + call clm_fates%wrap_co2_to_atm(bounds_clump, & + filter_inactive_and_active(nc)%num_bgc_soilc, filter_inactive_and_active(nc)%bgc_soilc, & + soilbiogeochem_carbonflux_inst, net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg)) + end do + !$OMP END PARALLEL DO + endif + endif call lnd2atm(bounds_proc, & atm2lnd_inst, surfalb_inst, temperature_inst, frictionvel_inst, & diff --git a/src/utils/clmfates_interfaceMod.F90 b/src/utils/clmfates_interfaceMod.F90 index 22db3d76b5..b217f26389 100644 --- a/src/utils/clmfates_interfaceMod.F90 +++ b/src/utils/clmfates_interfaceMod.F90 @@ -272,6 +272,7 @@ module CLMFatesInterfaceMod procedure, public :: wrap_hydraulics_drive procedure, public :: WrapUpdateFatesRmean procedure, public :: wrap_WoodProducts + procedure, public :: wrap_co2_to_atm procedure, public :: WrapGlobalSeedDispersal procedure, public :: WrapUpdateFatesSeedInOut procedure, public :: UpdateCLitterFluxes @@ -2904,6 +2905,53 @@ subroutine wrap_WoodProducts(this, bounds_clump, num_soilc, filter_soilc, & return end subroutine wrap_WoodProducts + + ! ============================================================================== + + subroutine wrap_co2_to_atm(this, bounds_clump, num_soilc, filter_soilc, & + soilbiogeochem_carbonflux_inst, net_carbon_exchange_grc) + + ! USES + use subgridAveMod, only : c2g + use FatesConstantsMod, only: g_per_kg + ! !ARGUMENTS: + class(hlm_fates_interface_type) , intent(inout) :: this + type(bounds_type) , intent(in) :: bounds_clump + integer , intent(in) :: num_soilc ! size of column filter + integer , intent(in) :: filter_soilc(:) ! column filter + type(soilbiogeochem_carbonflux_type), intent(in) :: soilbiogeochem_carbonflux_inst + real(r8) , intent(inout) :: net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg) + + ! Locals + integer :: s,c,g,fc + integer :: ci ! Clump index + real(r8) :: net_carbon_exchange_col(bounds_clump%begc:bounds_clump%endc) + + net_carbon_exchange_col(bounds_clump%begc:bounds_clump%endc) = 0.0_r8 + net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg) = 0.0_r8 + ci = bounds_clump%clump_index + + ! Loop over columns + do fc = 1, num_soilc + + c = filter_soilc(fc) + s = this%f2hmap(ci)%hsites(c) + ! nbp = npp -fire - graz - soil respiratation + ! hr_col is updated above this call in CNDriver summaries + net_carbon_exchange_col(c) = this%fates(ci)%bc_out(s)%npp_site - & + (this%fates(ci)%bc_out(s)%grazing_closs_to_atm_si + & + this%fates(ci)%bc_out(s)%fire_closs_to_atm_si) * g_per_kg - & + soilbiogeochem_carbonflux_inst%hr_col(c) + end do + call c2g( bounds = bounds_clump, & + carr = net_carbon_exchange_col(bounds_clump%begc:bounds_clump%endc), & + garr = net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg), & + c2l_scale_type = 'unity', & + l2g_scale_type = 'unity') + ! change sign, same way it is done in get_net_carbon_exchange + net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg) = - net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg) + + end subroutine wrap_co2_to_atm ! ====================================================================================== From ee619df808fb6bb5f9260f79fe5f5e6966d52e32 Mon Sep 17 00:00:00 2001 From: rosiealice Date: Wed, 18 Jun 2025 11:27:22 +0200 Subject: [PATCH 3/4] adding product fluxes to FATES NBP --- src/biogeochem/CNDriverMod.F90 | 9 ++++++--- .../SoilBiogeochemCarbonFluxType.F90 | 16 +++++++++++++--- src/utils/clmfates_interfaceMod.F90 | 9 +++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/biogeochem/CNDriverMod.F90 b/src/biogeochem/CNDriverMod.F90 index b407e07ad5..68c438ed0e 100644 --- a/src/biogeochem/CNDriverMod.F90 +++ b/src/biogeochem/CNDriverMod.F90 @@ -902,13 +902,16 @@ subroutine CNDriverNoLeaching(bounds, if (use_c13) call c13_products_inst%ComputeProductSummaryVars(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) - + + if(use_fates_bgc)then + soilbiogeochem_carbonflux_inst%fates_product_loss_grc(bounds%begg:bounds%endg)=c_products_inst%product_loss_grc(bounds%begg:bounds%endg) + endif + call t_stopf('CNWoodProducts') !-------------------------------------------- diff --git a/src/soilbiogeochem/SoilBiogeochemCarbonFluxType.F90 b/src/soilbiogeochem/SoilBiogeochemCarbonFluxType.F90 index 23f24e44d5..c333a4939c 100644 --- a/src/soilbiogeochem/SoilBiogeochemCarbonFluxType.F90 +++ b/src/soilbiogeochem/SoilBiogeochemCarbonFluxType.F90 @@ -6,7 +6,7 @@ module SoilBiogeochemCarbonFluxType use clm_varpar , only : ndecomp_cascade_transitions, ndecomp_pools, ndecomp_cascade_outtransitions use clm_varpar , only : nlevdecomp_full, nlevgrnd, nlevdecomp, nlevsoi, ndecomp_pools_vr, i_cwdl2 use clm_varcon , only : spval, ispval, dzsoi_decomp - use clm_varctl , only : use_fates,use_cn + use clm_varctl , only : use_fates,use_fates_bgc,use_cn use pftconMod , only : pftcon use landunit_varcon , only : istsoil, istcrop, istdlak use ch4varcon , only : allowlakeprod @@ -61,7 +61,9 @@ module SoilBiogeochemCarbonFluxType real(r8), pointer :: soilc_change_col (:) ! (gC/m2/s) FUN used soil C real(r8), pointer :: fates_litter_flux (:) ! (gC/m2/s) A summary of the total litter ! flux passed in from FATES. - ! This is a diagnostic for balance checks only + ! This is a diagnostic for balance checks only + real(r8), pointer :: fates_product_loss_grc (:) ! (gC/m2/s) product loss flux at gridcell scale to be used with FATES is on + ! track tradiagonal matrix real(r8), pointer :: matrix_decomp_fire_k_col (:,:) ! decomposition rate due to fire (gC*m3)/(gC*m3*step)) real(r8), pointer :: tri_ma_vr (:,:) ! vertical C transfer rate in sparse matrix format (gC*m3)/(gC*m3*step)) @@ -121,11 +123,13 @@ subroutine InitAllocate(this, bounds) ! !LOCAL VARIABLES: integer :: begp,endp ! Begin and end patch integer :: begc,endc ! Begin and end column + integer :: begg, endg ! Begin and end gridcell integer :: Ntrans,Ntrans_diag ! N trans size for matrix solution !------------------------------------------------------------------------ begp = bounds%begp; endp = bounds%endp begc = bounds%begc; endc = bounds%endc + begg = bounds%begg; endg = bounds%endg allocate(this%t_scalar_col (begc:endc,1:nlevdecomp_full)); this%t_scalar_col (:,:) =spval allocate(this%w_scalar_col (begc:endc,1:nlevdecomp_full)); this%w_scalar_col (:,:) =spval @@ -136,7 +140,7 @@ subroutine InitAllocate(this, bounds) allocate(this%somc_fire_col (begc:endc)) ; this%somc_fire_col (:) =nan allocate(this%hr_vr_col (begc:endc,1:nlevdecomp_full)); this%hr_vr_col (:,:) =nan - allocate(this%decomp_cpools_sourcesink_col(begc:endc,1:nlevdecomp_full,1:ndecomp_pools)) + allocate(this%decomp_cpools_sourcesink_col(begc:endc,1:nlevdecomp_full,1:ndecomp_pools)) this%decomp_cpools_sourcesink_col(:,:,:)= nan allocate(this%c_overflow_vr(begc:endc,1:nlevdecomp_full,1:ndecomp_cascade_transitions)) @@ -180,6 +184,7 @@ subroutine InitAllocate(this, bounds) allocate(this%soilc_change_col (begc:endc)) ; this%soilc_change_col (:) = nan if(use_fates)then + allocate(this%fates_product_loss_grc(begg:endg)) ; this%fates_product_loss_grc(:) = nan allocate(this%fates_litter_flux(begc:endc)); this%fates_litter_flux(:) = nan else allocate(this%fates_litter_flux(0:0)); this%fates_litter_flux(:) = nan @@ -682,6 +687,10 @@ subroutine InitCold(this, bounds) call this%SetValues (num_column=num_special_col, filter_column=special_col, & value_column=0._r8) + if(use_fates_bgc)then + this%fates_product_loss_grc(bounds%begg:bounds%endg) = 0._r8 + endif + end subroutine InitCold !----------------------------------------------------------------------- @@ -796,6 +805,7 @@ subroutine SetValues ( this, num_column, filter_column, value_column) this%michr_col(i) = value_column this%soilc_change_col(i) = value_column end do + end subroutine SetValues diff --git a/src/utils/clmfates_interfaceMod.F90 b/src/utils/clmfates_interfaceMod.F90 index b217f26389..3ca223f4ee 100644 --- a/src/utils/clmfates_interfaceMod.F90 +++ b/src/utils/clmfates_interfaceMod.F90 @@ -2909,7 +2909,7 @@ end subroutine wrap_WoodProducts ! ============================================================================== subroutine wrap_co2_to_atm(this, bounds_clump, num_soilc, filter_soilc, & - soilbiogeochem_carbonflux_inst, net_carbon_exchange_grc) + soilbiogeochem_carbonflux_inst, net_carbon_exchange_grc ) ! USES use subgridAveMod, only : c2g @@ -2948,7 +2948,12 @@ subroutine wrap_co2_to_atm(this, bounds_clump, num_soilc, filter_soilc, & garr = net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg), & c2l_scale_type = 'unity', & l2g_scale_type = 'unity') - ! change sign, same way it is done in get_net_carbon_exchange + ! change sign, same way it is done in get_net_carbon_exchange + + do g = bounds_clump%begg,bounds_clump%endg + net_carbon_exchange_grc(g) = net_carbon_exchange_grc(g) - soilbiogeochem_carbonflux_inst%fates_product_loss_grc(g) + enddo + net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg) = - net_carbon_exchange_grc(bounds_clump%begg:bounds_clump%endg) end subroutine wrap_co2_to_atm From 6468961ed0a2fcf2f43c133c651efe7985acab1d Mon Sep 17 00:00:00 2001 From: rosiealice Date: Wed, 18 Jun 2025 12:03:16 +0200 Subject: [PATCH 4/4] change fates tag for ctsm --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index da867c2e8e..7febcbb3d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,7 +28,7 @@ [submodule "fates"] path = src/fates url = https://github.com/NorESMhub/fates -fxtag = sci.1.85.1_api.40.0.0_noresm_v0 +fxtag = sci.1.85.1_api.40.0.0_noresm_v1 fxrequired = AlwaysRequired # Standard Fork to compare to with "git fleximod test" to ensure personal forks aren't committed fxDONOTUSEurl = https://github.com/NorESMhub/fates