Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bc6d321
mix of fixes for catchCN CLM 5.1
biljanaorescanin Sep 8, 2025
7d8e5f3
Merge branch 'feature/jkolassa_cnclm51' into feature/borescan_cnclm51
gmao-rreichle Sep 10, 2025
4b321a2
for reference, added commented version of Biljana's init of CNCOL, CN…
gmao-rreichle Sep 10, 2025
4d0ef80
turned Biljana's "safe" function into identity operator (CNProductsMo…
gmao-rreichle Sep 10, 2025
d803329
reverted unwanted changes from Biljana's commit (CNVegCarbonStateType…
gmao-rreichle Sep 10, 2025
8c01247
reverted more of Biljana's changes (CNVegCarbonStateType.F90)
gmao-rreichle Sep 10, 2025
3feb4cf
removed obsolete "use iulog" statements (CNVegNitrogenStateType.F90, …
gmao-rreichle Sep 10, 2025
0d58692
fix comment about PFTs in CatchCN51 (GEOS_CatchCNCLM51GridComp.F90)
gmao-rreichle Sep 11, 2025
69f46b5
use FVEG_MIN parameter instead of hard-coded 1.e-4
gmao-rreichle Sep 11, 2025
7454dda
fixed indent, improved vertical alignment, clarified/edited comments …
gmao-rreichle Sep 11, 2025
7f59504
fixed indentation, improved vertical alignment (CNCLM_init_mod.F90)
gmao-rreichle Sep 11, 2025
58e6770
bug fix: corrected assignment of restart variables cncol(:,:,[8,22]) …
gmao-rreichle Sep 11, 2025
8887576
fixed "if" condition involving "optional" argument (CanopyStateType.F90)
gmao-rreichle Sep 11, 2025
766560f
reverted init of "alphapsn" back to "spval", added comments (Photosyn…
gmao-rreichle Sep 11, 2025
cef80d9
added comment (CNCLM_DriverMod.F90)
gmao-rreichle Sep 11, 2025
c3bb4a3
enforce non-negative values without also setting upper bound (SoilBio…
gmao-rreichle Sep 11, 2025
67cb839
use FVEG_MIN from clm_varpar_shared module (CatchmentCNRst.F90)
gmao-rreichle Sep 11, 2025
aef24b8
added missing use statement for FVEG_MIN (PhotosynthesisMod.F90)
gmao-rreichle Sep 12, 2025
6d2be47
fixed T2MMIN5D exponential moving average (GEOS_CatchCNCLM51GridComp.…
gmao-rreichle Sep 12, 2025
e9ae56f
refine calculation for previous commit (GEOS_CatchCNCLM51GridComp.F90)
gmao-rreichle Sep 12, 2025
c41c399
fixed syntax error in previous commit (GEOS_CatchCNCLM51GridComp.F90)
gmao-rreichle Sep 12, 2025
7e32903
fixed _ASSERT error in previous commit (GEOS_CatchCNCLM51GridComp.F90)
gmao-rreichle Sep 12, 2025
cd634db
convert function LT2lon() into subroutine to make MAPL _ASSERT() work…
gmao-rreichle Sep 12, 2025
6e2ce45
avoid duplicate definition of index translation for C & N pools betwe…
gmao-rreichle Sep 12, 2025
9994298
added comment about different decomp pool orders in CatchCN and CTSM …
gmao-rreichle Sep 12, 2025
4442cd4
fixed bug in 5-day moving average of snow depth (GEOS_CatchCNCLM51Gri…
gmao-rreichle Sep 12, 2025
b9d6ad4
change comment so it does not trip up GNU (GEOS_CatchCNCLM51GridComp.…
gmao-rreichle Sep 12, 2025
acfe37b
use WHERE instead of indexing with logical array to make GNU happy (G…
gmao-rreichle Sep 13, 2025
a7a0f1b
removed re-setting of carbon restart variables to zero (CatchmentCNRs…
gmao-rreichle Sep 15, 2025
3717bd2
fixed indexing example (README_CN51.md)
gmao-rreichle Sep 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, &
end if

if (abs(col_errnb(c)) > this%nwarning) then
! write(iulog,*) 'nbalance warning at c =', c, col_errnb(c), col_endnb(c)
! write(iulog,*)'inputs,ffix,nfix,ndep = ',ffix_to_sminn(c)*dt,nfix_to_sminn(c)*dt,ndep_to_sminn(c)*dt
! write(iulog,*)'outputs,lch,roff,dnit = ',smin_no3_leached(c)*dt, smin_no3_runoff(c)*dt,f_n2o_nit(c)*dt
write(iulog,*) 'nbalance warning at c =', c, col_errnb(c), col_endnb(c)
write(iulog,*)'inputs,ffix,nfix,ndep = ',ffix_to_sminn(c)*dt,nfix_to_sminn(c)*dt,ndep_to_sminn(c)*dt
write(iulog,*)'outputs,lch,roff,dnit = ',smin_no3_leached(c)*dt, smin_no3_runoff(c)*dt,f_n2o_nit(c)*dt
end if

end do ! end of columns loop
Expand All @@ -540,8 +540,26 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, &
write(iulog,*)'input mass = ',col_ninputs(c)*dt
write(iulog,*)'output mass = ',col_noutputs(c)*dt
write(iulog,*)'net flux = ',(col_ninputs(c)-col_noutputs(c))*dt
write(iulog,*)'inputs,ffix,nfix,ndep = ',ffix_to_sminn(c)*dt,nfix_to_sminn(c)*dt,ndep_to_sminn(c)*dt
write(iulog,*)'outputs,ffix,nfix,ndep = ',smin_no3_leached(c)*dt, smin_no3_runoff(c)*dt,f_n2o_nit(c)*dt
write(iulog,*)'column nbalance error = ', col_errnb(c), c
write(iulog,*)'Latdeg,Londeg = ', grc%latdeg(col%gridcell(c)), grc%londeg(col%gridcell(c))
write(iulog,*)'begnb = ', col_begnb(c)
write(iulog,*)'endnb = ', col_endnb(c)
write(iulog,*)'delta store = ', col_endnb(c)-col_begnb(c)
write(iulog,*)'input mass (dt) = ', col_ninputs(c)*dt
write(iulog,*)'output mass (dt) = ', col_noutputs(c)*dt
write(iulog,*)'net flux (dt) = ', (col_ninputs(c)-col_noutputs(c))*dt

! Full IN terms (rates)
write(iulog,*) ' IN rates: ndep=', ndep_to_sminn(c), ' nfix=', nfix_to_sminn(c), &
' ffix=', ffix_to_sminn(c), ' supplement=', supplement_to_sminn(c), &
' fert=', fert_to_sminn(c), ' soyfix=', soyfixn_to_sminn(c)

! Full OUT terms (rates) exactly as used in col_noutputs(c)
write(iulog,*) 'OUT rates: denit=', denit(c), ' fireN=', col_fire_nloss(c), &
' wood=', wood_harvestn(c), ' grain=', grainn_to_cropprodn(c), &
' f_n2o=', f_n2o_nit(c), ' NO3_leach=', smin_no3_leached(c), &
' NO3_runoff=', smin_no3_runoff(c), ' somN_leach(NEG)=', som_n_leached(c)




Expand Down Expand Up @@ -597,10 +615,9 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, &
end if

if (abs(grc_errnb(g)) > this%nwarning) then
!write(iulog,*) 'nbalance warning at g =', g, grc_errnb(g), grc_endnb(g)
write(iulog,*) 'nbalance warning at g =', g, grc_errnb(g), grc_endnb(g)
end if
end do

if (err_found) then
g = err_index
write(iulog,*) 'gridcell nbalance error =', grc_errnb(g), g
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module CNCLM_DriverMod

use nanMod , only : nan
use CNVegetationFacade
use clm_varpar , only : nlevsno, nlevmaxurbgrnd, num_veg, num_zon, CN_zone_weight,&
var_col, var_pft, nlevgrnd, numpft, ndecomp_pools
use clm_varpar , only : nlevsno, nlevmaxurbgrnd, num_veg, num_zon, CN_zone_weight
use clm_varpar , only : var_col, var_pft, nlevgrnd, numpft, ndecomp_pools, FVEG_MIN
use clm_varpar , only : decomp_cpool_cncol_index, decomp_npool_cncol_index
use clm_varcon , only : grav, denh2o
use clm_time_manager , only : is_first_step, get_nstep
use decompMod
Expand Down Expand Up @@ -62,8 +63,9 @@ module CNCLM_DriverMod
public :: get_CN_LAI

contains

!---------------------------------

!---------------------------------

subroutine CN_Driver(istep,nch,ityp,fveg,ndep,tp1,tairm,psis,bee,dayl,btran_fire,car1m,&
rzm,sfm,rhm,windm,rainfm,snowfm,prec10d,prec60d,et365d,gdp,&
abm,peatf,hdm,lnfm,poros,rh30,totwat,bflow,runsrf,sndzn,&
Expand Down Expand Up @@ -306,19 +308,19 @@ subroutine CN_Driver(istep,nch,ityp,fveg,ndep,tp1,tairm,psis,bee,dayl,btran_fire
temperature_inst%t_ref2m_patch(p) = tairm(nc)
temperature_inst%soila10_patch(p) = tg10d(nc)
temperature_inst%t_a5min_patch(p) = t2m5d(nc)
cn2clm_inst%btran2_patch_cn2clm(p) = btran_fire(nc,nz)


cn2clm_inst%btran2_patch_cn2clm(p) = btran_fire(nc,nz) ! add root zone soil wetness ("btran_fire") into CN2CLM structure; fire modules read it from there
! cnfire_li2016_inst%cnfire_base_type%btran2_patch(p) = btran_fire(nc,nz)
! cnfire_li2021_inst%cnfire_base_type%btran2_patch(p) = btran_fire(nc,nz)

water_inst%wateratm2lndbulk_inst%prec60_patch(p) = prec60d(nc)
water_inst%wateratm2lndbulk_inst%prec10_patch(p) = prec10d(nc)
water_inst%wateratm2lndbulk_inst%rh30_patch(p) = rh30(nc)
frictionvel_inst%forc_hgt_u_patch(p) = 30. ! following CNCLM45 implementation, but this should be available from the GridComp
frictionvel_inst%forc_hgt_u_patch(p) = 30. ! following CNCLM45 implementation, but this should be available from the GridComp

do nv = 1,num_veg ! defined veg loop

if(ityp(nc,nv,nz)==np .and. fveg(nc,nv,nz)>1.e-4) then
if(ityp(nc,nv,nz)==np .and. fveg(nc,nv,nz)>FVEG_MIN) then

photosyns_inst%psnsun_patch(p) = psnsunm(nc,nv,nz)
photosyns_inst%psnsha_patch(p) = psnsham(nc,nv,nz)
Expand Down Expand Up @@ -506,7 +508,7 @@ subroutine CN_Driver(istep,nch,ityp,fveg,ndep,tp1,tairm,psis,bee,dayl,btran_fire

do nv = 1,num_veg ! defined veg loop

if(ityp(nc,nv,nz)==np .and. fveg(nc,nv,nz)>1.e-4) then
if(ityp(nc,nv,nz)==np .and. fveg(nc,nv,nz)>FVEG_MIN) then


zlai(nc,nv,nz) = canopystate_inst%elai_patch(p)
Expand Down Expand Up @@ -563,7 +565,7 @@ subroutine CN_exit(nch,ityp,fveg,cncol,cnpft)

! OUTPUT
real, dimension(nch,num_zon,var_col), intent(out) :: cncol ! column-level restart variables
real, dimension(nch,num_zon,num_veg,var_pft), intent(out) :: cnpft ! PFT-level restart variables
real, dimension(nch,num_zon,num_veg,var_pft), intent(out) :: cnpft ! PFT-level restart variables ! NOTE: order of dims DIFFERS from that of ityp & fveg !!!

! LOCAL

Expand All @@ -585,13 +587,12 @@ subroutine CN_exit(nch,ityp,fveg,cncol,cnpft)

integer :: n, p, nv, nc, nz, np, nd

! map between order of C & N pools in CNCOL and CTSM

integer, dimension(8) :: decomp_cpool_cncol_index = (/ 3, 4, 5, 2, 10, 11, 12, 13 /)
integer, dimension(8) :: decomp_npool_cncol_index = (/ 18, 19, 20, 17, 25, 26, 27, 28 /)

!----------------

!rrXbo10Sep2025 ! Clean slate: zero arrays so any unassigned slots are safe in the restart
!rrXbo10Sep2025 cncol(:,:,:) = 0.0
!rrXbo10Sep2025 cnpft(:,:,:,:) = 0.0

n = 0
np = 0

Expand All @@ -603,6 +604,8 @@ subroutine CN_exit(nch,ityp,fveg,cncol,cnpft)

cncol(nc,nz, 1) = soilbiogeochem_carbonstate_inst%ctrunc_vr_col(n,1)

! C and N decomposition pools are stored in cncol entries 2:5, 10:13, 17:20, and 25:28

do nd = 1,ndecomp_pools
! jkolassa: accounting for fact that pool order in CNCOL is different from CTSM
cncol(nc,nz,decomp_cpool_cncol_index(nd)) = soilbiogeochem_carbonstate_inst%decomp_cpools_vr_col( n,1,nd)
Expand All @@ -614,19 +617,19 @@ subroutine CN_exit(nch,ityp,fveg,cncol,cnpft)
! jkolassa: variables below transitioned from being column-level to being gridcell-level in CLM;
! assuming here that quantities are spread over zones according to zone weight
cncol(nc,nz, 7) = bgc_vegetation_inst%c_products_inst%prod100_grc( nc) * CN_zone_weight(nz)
cncol(nc,nz, 8) = bgc_vegetation_inst%c_products_inst%prod100_grc( nc) * CN_zone_weight(nz)
cncol(nc,nz, 8) = bgc_vegetation_inst%c_products_inst%prod10_grc( nc) * CN_zone_weight(nz)
cncol(nc,nz, 9) = bgc_vegetation_inst%cnveg_carbonstate_inst%seedc_grc( nc) * CN_zone_weight(nz)

cncol(nc,nz,14) = bgc_vegetation_inst%cnveg_carbonstate_inst%totc_col( n )
cncol(nc,nz,15) = soilbiogeochem_carbonstate_inst%totlitc_col( n )
cncol(nc,nz,16) = soilbiogeochem_nitrogenstate_inst%ntrunc_vr_col( n,1)


cncol(nc,nz,21) = bgc_vegetation_inst%n_products_inst%prod100_grc( nc) * CN_zone_weight(nz)
cncol(nc,nz,22) = bgc_vegetation_inst%n_products_inst%prod100_grc( nc) * CN_zone_weight(nz)
cncol(nc,nz,22) = bgc_vegetation_inst%n_products_inst%prod10_grc( nc) * CN_zone_weight(nz)
cncol(nc,nz,23) = bgc_vegetation_inst%cnveg_nitrogenstate_inst%seedn_grc( nc) * CN_zone_weight(nz)

cncol(nc,nz,24) = soilbiogeochem_nitrogenstate_inst%sminn_vr_col( n,1)

cncol(nc,nz,29) = bgc_vegetation_inst%cnveg_nitrogenstate_inst%totn_col( n )
cncol(nc,nz,30) = soilbiogeochem_state_inst%fpg_col( n )
cncol(nc,nz,31) = bgc_vegetation_inst%cnveg_state_inst%annsum_counter_col( n )
Expand All @@ -644,7 +647,7 @@ subroutine CN_exit(nch,ityp,fveg,cncol,cnpft)

do nv = 1,num_veg ! defined veg loop

if(ityp(nc,nv,nz)==p .and. fveg(nc,nv,nz)>1.e-4) then
if(ityp(nc,nv,nz)==p .and. fveg(nc,nv,nz)>FVEG_MIN) then

cnpft(nc,nz,nv, 1) = bgc_vegetation_inst%cnveg_carbonstate_inst%cpool_patch (np )
cnpft(nc,nz,nv, 2) = bgc_vegetation_inst%cnveg_carbonstate_inst%deadcrootc_patch (np )
Expand Down Expand Up @@ -786,7 +789,7 @@ subroutine get_CN_LAI(nch,ityp,fveg,elai,esai,tlai,tsai)

! extract LAI & SAI from CN clmtype
! ---------------------------------
if(ityp(nc,nv,nz)==p .and. ityp(nc,nv,nz)>0 .and. fveg(nc,nv,nz)>1.e-4) then
if(ityp(nc,nv,nz)==p .and. ityp(nc,nv,nz)>0 .and. fveg(nc,nv,nz)>FVEG_MIN) then
elai(nc,nv,nz) = elai_clm(np)
if(present(esai)) esai(nc,nv,nz) = esai_clm(np)
if(present(tlai)) tlai(nc,nv,nz) = tlai_clm(np)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module CNCLM_Photosynthesis

use MAPL_ConstantsMod
use clm_varpar, only : numpft, numrad, num_veg, num_zon, &
use clm_varpar, only : numpft, numrad, num_veg, num_zon, FVEG_MIN, &
nlevcan
use decompMod
use PatchType
Expand All @@ -23,7 +23,7 @@ module CNCLM_Photosynthesis
use WaterStateType
use WaterType
use CNVegetationFacade

implicit none

private
Expand Down Expand Up @@ -459,7 +459,7 @@ subroutine catchcn_calc_rc(nch,fveg,tc,qa,pbot,co2v,dayl_factor, &
do p = 0,numpft ! PFT index loop
np = np + 1
do nv = 1,num_veg ! defined veg loop
if(ityp(nc,nv,nz)==p .and. fveg(nc,nv,nz)>1.e-4) then
if(ityp(nc,nv,nz)==p .and. fveg(nc,nv,nz)>FVEG_MIN) then

! stomatal resistances
rs = laisun(np)/max(rssun(np), 1.e-06_r8 ) + laisha(np)/max(rssha(np), 1.e-06_r8 )
Expand Down
Loading
Loading