Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e505dc8
Add two 1x1 FatesColdPRT2 tests, one with, one without MIMICS
slevis-lmwg Jul 30, 2025
01671b9
Uncomment if ( .not. use_fates_sp ) section of clmfates_interfaceMod
slevis-lmwg Aug 11, 2025
59f9d09
Replace plant_ndemand(c) * nuptake_prof(c,j) with plant_ndemand_vr(c,j)
slevis-lmwg Aug 12, 2025
b155e58
New use_fates section for plant_ndemand_vr and plant_ndemand from fates
slevis-lmwg Aug 13, 2025
c79230c
New use_fates section to set the FATES N uptake fluxes
slevis-lmwg Aug 13, 2025
98b4b7d
Change clm_fate from "in" to "inout" argument
slevis-lmwg Aug 13, 2025
a46a76c
Replace if (use_fates) with (is_fates(c)) to add flexibility
slevis-lmwg Aug 14, 2025
f2202fb
Remove two unhelpful 1x1 FatesColdPRT2 tests that I added earlier
slevis-lmwg Aug 15, 2025
e96b87e
New is_fates section for plant_ndemand, now when use_nitrif_denitrif
slevis-lmwg Aug 26, 2025
b24738b
Add (really, uncomment) FATES npp to enable fixation
slevis-lmwg Aug 26, 2025
00a332e
Uncomment hrv_deadstem_to_prod* lines in clmfates_interfaceMod
slevis-lmwg Sep 19, 2025
2bbdd64
Add error check about fates_parteh_mode = 2 and suplnitro = suplnAll
slevis-lmwg Sep 20, 2025
d8bc6ce
Upd. namelist_defaults for suplnitro when parteh_mode == 1 or /= 1
slevis-lmwg Sep 22, 2025
116b310
prt_carbon_allom_hyp -> fates_c_only & prt_cnp_flex_allom_hyp ->fates_cn
slevis-lmwg Sep 22, 2025
ba955b6
Correction to syntax error caught by gnu and nvhpc, not intel
slevis-lmwg Sep 23, 2025
391a023
Update fates paramfile var prescribed_puptake to 1 for PRT2 test
slevis-lmwg Sep 23, 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
22 changes: 22 additions & 0 deletions cime_config/testdefs/testlist_clm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,28 @@
<option name="comment">ERP FATES test covering all standard FATES history variables.</option>
</options>
</test>
<test name="ERS_D_Ld30" grid="1x1_brazil" compset="I2000Clm60FatesCrujraRs" testmods="clm/FatesColdPRT2">
<machines>
<machine name="derecho" compiler="intel" category="fates"/>
<machine name="izumi" compiler="nag" category="fates"/>
<machine name="lawrencium-lr3" compiler="intel" category="fates"/>
</machines>
<options>
<option name="wallclock">00:40:00</option>
<option name="comment">1x1 exact restart debug test covering Fates CNP nutrients mode.</option>
</options>
</test>
<test name="ERS_D_Ld30" grid="1x1_brazil" compset="I2000Clm60FatesCrujraRs" testmods="clm/FatesColdPRT2--clm/mimicsFatesCold--clm-nofireemis">
<machines>
<machine name="derecho" compiler="intel" category="fates"/>
<machine name="izumi" compiler="nag" category="fates"/>
<machine name="lawrencium-lr3" compiler="intel" category="fates"/>
</machines>
<options>
<option name="wallclock">00:40:00</option>
<option name="comment">Same 1x1 exact restart test but with MIMICS.</option>
</options>
</test>
<test name="ERS_D_Ld30" grid="f45_f45_mg37" compset="I2000Clm50FatesCruRsGs" testmods="clm/FatesColdPRT2">
<machines>
<machine name="derecho" compiler="intel" category="fates"/>
Expand Down
2 changes: 1 addition & 1 deletion src/biogeochem/CNDriverMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ subroutine CNDriverNoLeaching(bounds,
cnveg_carbonflux_inst,cnveg_nitrogenstate_inst,cnveg_nitrogenflux_inst, &
soilbiogeochem_carbonflux_inst,&
soilbiogeochem_state_inst,soilbiogeochem_nitrogenstate_inst, &
soilbiogeochem_nitrogenflux_inst,canopystate_inst)
soilbiogeochem_nitrogenflux_inst,canopystate_inst, clm_fates)
call t_stopf('soilbiogeochemcompetition')

! distribute the available N between the competing patches on the basis of
Expand Down
141 changes: 113 additions & 28 deletions src/soilbiogeochem/SoilBiogeochemCompetitionMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module SoilBiogeochemCompetitionMod
use TemperatureType , only : temperature_type
use SoilStateType , only : soilstate_type
use CanopyStateType , only : CanopyState_type
use CLMFatesInterfaceMod, only : hlm_fates_interface_type
!
implicit none
private
Expand Down Expand Up @@ -172,10 +173,10 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
cnveg_carbonflux_inst,cnveg_nitrogenstate_inst,cnveg_nitrogenflux_inst, &
soilbiogeochem_carbonflux_inst, &
soilbiogeochem_state_inst, soilbiogeochem_nitrogenstate_inst, &
soilbiogeochem_nitrogenflux_inst,canopystate_inst)
soilbiogeochem_nitrogenflux_inst,canopystate_inst, clm_fates)
!
! !USES:
use clm_varctl , only: cnallocate_carbon_only, iulog
use clm_varctl , only: use_fates, cnallocate_carbon_only, iulog
use clm_varpar , only: nlevdecomp, ndecomp_cascade_transitions
use clm_varpar , only: i_cop_mic, i_oli_mic
use clm_varcon , only: nitrif_n2o_loss_frac
Expand Down Expand Up @@ -207,11 +208,16 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
type(soilbiogeochem_nitrogenstate_type) , intent(inout) :: soilbiogeochem_nitrogenstate_inst
type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst
type(canopystate_type) , intent(inout) :: canopystate_inst
type(hlm_fates_interface_type), intent(inout) :: clm_fates
!
!
! !LOCAL VARIABLES:
integer :: c,p,l,pi,j,k ! indices
integer :: fc ! filter column index
integer :: ft ! FATES functional type index
integer :: f ! loop index for FATES plant competitors
integer :: n_pcomp ! number of FATES plant competitors
integer :: ci, s ! used for FATES BC (clump index, site index)
logical :: local_use_fun ! local version of use_fun
real(r8) :: amnf_immob_vr ! actual mineral N flux from immobilization (gN/m3/s)
real(r8) :: n_deficit_vr ! microbial N deficit, vertically resolved (gN/m3/s)
Expand All @@ -221,13 +227,15 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
real(r8) :: compet_decomp_nh4 ! (unitless) relative competitiveness of immobilizers for NH4
real(r8) :: compet_denit ! (unitless) relative competitiveness of denitrifiers for NO3
real(r8) :: compet_nit ! (unitless) relative competitiveness of nitrifiers for NH4
real(r8) :: ndemand ! (gN/m2/s) nitrogen demand per FATES plant competitor f (see local variable f above)
real(r8) :: fpi_no3_vr(bounds%begc:bounds%endc,1:nlevdecomp) ! fraction of potential immobilization supplied by no3(no units)
real(r8) :: fpi_nh4_vr(bounds%begc:bounds%endc,1:nlevdecomp) ! fraction of potential immobilization supplied by nh4 (no units)
real(r8) :: sum_nh4_demand(bounds%begc:bounds%endc,1:nlevdecomp)
real(r8) :: sum_nh4_demand_scaled(bounds%begc:bounds%endc,1:nlevdecomp)
real(r8) :: sum_no3_demand(bounds%begc:bounds%endc,1:nlevdecomp)
real(r8) :: sum_no3_demand_scaled(bounds%begc:bounds%endc,1:nlevdecomp)
real(r8) :: sum_ndemand_vr(bounds%begc:bounds%endc, 1:nlevdecomp) !total column N demand (gN/m3/s) at a given level
real(r8) :: plant_ndemand_vr(bounds%begc:bounds%endc, 1:nlevdecomp) !plant column N demand (gN/m3/s) at a given level
real(r8) :: nuptake_prof(bounds%begc:bounds%endc, 1:nlevdecomp)
real(r8) :: sminn_tot(bounds%begc:bounds%endc)
integer :: nlimit(bounds%begc:bounds%endc,0:nlevdecomp) !flag for N limitation
Expand Down Expand Up @@ -319,12 +327,51 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
end do
end do

do j = 1, nlevdecomp
do fc=1,num_bgc_soilc
c = filter_bgc_soilc(fc)
sum_ndemand_vr(c,j) = plant_ndemand(c) * nuptake_prof(c,j) + potential_immob_vr(c,j)
bgc_soilc_loop: do fc = 1, num_bgc_soilc
c = filter_bgc_soilc(fc)

fates: if (use_fates) then
ci = bounds%clump_index
s = clm_fates%f2hmap(ci)%hsites(c)
n_pcomp = clm_fates%fates(ci)%bc_out(s)%num_plant_comps

! Overwrite the column level demands, since fates plants are all sharing
! the same space, in units per the same square meter, we just add demand
! to scale up to column
plant_ndemand(c) = 0._r8

! We fill the vertically resolved array to simplify some jointly used code
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the if fates_parteh_mode == 2 here and make the else set plant_ndemand(_vr) = 0 to hopefully resolve the N balance error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely still need to resolve N bal. error when parteh == 2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3rd test still fails with a N-bal error, and I'm running the 4th test to see what happens:

  • I still see indications of badly initialized variables...
  • Try uncommenting the harvest lines mentioned in an earlier post
  • Consider inconsistent if-statements

Copy link
Contributor Author

@slevis-lmwg slevis-lmwg Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rethinking my tests:

  1. The 1x1 tests have not helped (I have now removed them)
  2. The ERP...PRT2 test fails with
    FAILED to get /glade/derecho/scratch/slevis/ERP_Ld9.f45_f45_mg37.I2000Clm50FatesRs.derecho_intel.clm-FatesColdPRT2.20250814_175600_rzyi7o/case2/ERP_Ld9.f45_f45_mg37.I2000Clm50FatesRs.derecho_intel.clm-FatesColdPRT2.20250814_175600_rzyi7o/fates_params_prt2_prescribed_np.nc
    so I will go back and try the preexisting PRT2 test and the closest non-PRT2:
./create_test ERS_D_Ld30.f45_f45_mg37.I2000Clm50FatesCruRsGs.derecho_intel.clm-FatesColdPRT2 -c /glade/campaign/cgd/tss/ctsm_baselines/fates-sci.1.84.0_api.40.0.0-ctsm5.3.066
./create_test ERS_D_Ld30.f45_f45_mg37.I2000Clm50FatesCruRsGs.derecho_intel.clm-FatesColdLUH2 -c /glade/campaign/cgd/tss/ctsm_baselines/fates-sci.1.84.0_api.40.0.0-ctsm5.3.066
  • before this PR's changes: caseids 20250815_113417_sx4t8g and 20250815_113743_mr25bk
  • with 01671b9: caseids 20250815_114817_ilbscj and 20250815_114840_il903r
  • FAIL with the latest commit:
  • testid 20250815_120848_v9vgmh gives this Traceback <-- TROUBLESHOOTING THIS CASE
error (65): floating invalid
Image              PC                Routine            Line        Source
libpthread-2.31.s  0000149243D098C0  Unknown               Unknown  Unknown
cesm.exe           0000000002F2D454  soilbiogeochemcom         608  SoilBiogeochemCompetitionMod.F90
cesm.exe           0000000003FCD516  cndrivermod_mp_cn         474  CNDriverMod.F90
cesm.exe           0000000001A99BF1  cnvegetationfacad        1030  CNVegetationFacade.F90
cesm.exe           0000000000A8B2C7  clm_driver_mp_clm        1058  clm_driver.F90

UPDATE I had placed the new code in the if (.not. use_nitrif_denitrif) opposite to what I should have done. I have now updated the code (while still keeping the new code in the ".not." section). Testing PASSed 20250825_174700_7w8gx9

  • testid 20250815_120902_1msot7 gives the same Traceback, but also before the Traceback this error
Nan values for pftareafrac. dumping site info.
----------------------------------------
Site Coordinates
----------------------------------------
latitude                    =   -74.0000000000000
longitude                   =    255.000000000000

Same test PASSed with the above update 20250826_101645_52b4zd

  • Tests now work, though should they DIFF from the baseline?

do j = 1, nlevdecomp
plant_ndemand_vr(c,j) = 0._r8

do f = 1, n_pcomp
ft = clm_fates%fates(ci)%bc_out(s)%ft_index(f)

! [gN/m3/s] = [gC/m3] * [gN/gC/s]
plant_ndemand_vr(c,j) = plant_ndemand_vr(c,j) + &
clm_fates%fates(ci)%bc_out(s)%veg_rootc(f,j) * &
(clm_fates%fates(ci)%bc_pconst%vmax_nh4(ft) + &
clm_fates%fates(ci)%bc_pconst%vmax_no3(ft))
end do

! [gN/m2/s]
plant_ndemand(c) = plant_ndemand(c) + plant_ndemand_vr(c,j) * dzsoi_decomp(j)

end do

else ! not use_fates

do j = 1, nlevdecomp
plant_ndemand_vr(c,j) = plant_ndemand(c) * nuptake_prof(c,j)
end do

end if fates

do j = 1, nlevdecomp
sum_ndemand_vr(c,j) = plant_ndemand_vr(c,j) + potential_immob_vr(c,j)
end do
end do

end do bgc_soilc_loop

do j = 1, nlevdecomp
do fc=1,num_bgc_soilc
Expand All @@ -337,7 +384,7 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
nlimit(c,j) = 0
fpi_vr(c,j) = 1.0_r8
actual_immob_vr(c,j) = potential_immob_vr(c,j)
sminn_to_plant_vr(c,j) = plant_ndemand(c) * nuptake_prof(c,j)
sminn_to_plant_vr(c,j) = plant_ndemand_vr(c,j)
else if ( cnallocate_carbon_only()) then !.or. &
! this code block controls the addition of N to sminn pool
! to eliminate any N limitation, when Carbon_Only is set. This lets the
Expand All @@ -349,7 +396,7 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
nlimit(c,j) = 1
fpi_vr(c,j) = 1.0_r8
actual_immob_vr(c,j) = potential_immob_vr(c,j)
sminn_to_plant_vr(c,j) = plant_ndemand(c) * nuptake_prof(c,j)
sminn_to_plant_vr(c,j) = plant_ndemand_vr(c,j)
supplement_to_sminn_vr(c,j) = sum_ndemand_vr(c,j) - (sminn_vr(c,j)/dt)
else
! N availability can not satisfy the sum of immobilization and
Expand Down Expand Up @@ -552,8 +599,8 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
l = col%landunit(c)

! first compete for nh4
sum_nh4_demand(c,j) = plant_ndemand(c) * nuptake_prof(c,j) + potential_immob_vr(c,j) + pot_f_nit_vr(c,j)
sum_nh4_demand_scaled(c,j) = plant_ndemand(c)* nuptake_prof(c,j) * compet_plant_nh4 + &
sum_nh4_demand(c,j) = plant_ndemand_vr(c,j) + potential_immob_vr(c,j) + pot_f_nit_vr(c,j)
sum_nh4_demand_scaled(c,j) = plant_ndemand_vr(c,j) * compet_plant_nh4 + &
potential_immob_vr(c,j)*compet_decomp_nh4 + pot_f_nit_vr(c,j)*compet_nit

if (sum_nh4_demand(c,j)*dt < smin_nh4_vr(c,j)) then
Expand All @@ -568,7 +615,7 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
f_nit_vr(c,j) = pot_f_nit_vr(c,j)

if ( .not. local_use_fun ) then
smin_nh4_to_plant_vr(c,j) = plant_ndemand(c) * nuptake_prof(c,j)
smin_nh4_to_plant_vr(c,j) = plant_ndemand_vr(c,j)
else
smin_nh4_to_plant_vr(c,j) = smin_nh4_vr(c,j)/dt - actual_immob_nh4_vr(c,j) - f_nit_vr(c,j)
end if
Expand All @@ -588,8 +635,8 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
sum_nh4_demand_scaled(c,j)), pot_f_nit_vr(c,j))

if ( .not. local_use_fun ) then
smin_nh4_to_plant_vr(c,j) = min((smin_nh4_vr(c,j)/dt)*(plant_ndemand(c)* &
nuptake_prof(c,j)*compet_plant_nh4 / sum_nh4_demand_scaled(c,j)), plant_ndemand(c)*nuptake_prof(c,j))
smin_nh4_to_plant_vr(c,j) = min((smin_nh4_vr(c,j)/dt) * (plant_ndemand_vr(c,j) * &
compet_plant_nh4 / sum_nh4_demand_scaled(c,j)), plant_ndemand_vr(c,j))

else
! RF added new term. send rest of N to plant - which decides whether it should pay or not?
Expand Down Expand Up @@ -619,15 +666,15 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
end if

if(.not.local_use_fun)then
sum_no3_demand(c,j) = (plant_ndemand(c)*nuptake_prof(c,j)-smin_nh4_to_plant_vr(c,j)) + &
sum_no3_demand(c,j) = (plant_ndemand_vr(c,j) - smin_nh4_to_plant_vr(c,j)) + &
(potential_immob_vr(c,j)-actual_immob_nh4_vr(c,j)) + pot_f_denit_vr(c,j)
sum_no3_demand_scaled(c,j) = (plant_ndemand(c)*nuptake_prof(c,j) &
sum_no3_demand_scaled(c,j) = (plant_ndemand_vr(c,j) &
-smin_nh4_to_plant_vr(c,j))*compet_plant_no3 + &
(potential_immob_vr(c,j)-actual_immob_nh4_vr(c,j))*compet_decomp_no3 + pot_f_denit_vr(c,j)*compet_denit
else
sum_no3_demand(c,j) = plant_ndemand(c)*nuptake_prof(c,j) + &
sum_no3_demand(c,j) = plant_ndemand_vr(c,j) + &
(potential_immob_vr(c,j)-actual_immob_nh4_vr(c,j)) + pot_f_denit_vr(c,j)
sum_no3_demand_scaled(c,j) = (plant_ndemand(c)*nuptake_prof(c,j))*compet_plant_no3 + &
sum_no3_demand_scaled(c,j) = (plant_ndemand_vr(c,j)) * compet_plant_no3 + &
(potential_immob_vr(c,j)-actual_immob_nh4_vr(c,j))*compet_decomp_no3 + pot_f_denit_vr(c,j)*compet_denit
endif

Expand All @@ -642,12 +689,12 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
f_denit_vr(c,j) = pot_f_denit_vr(c,j)

if(.not.local_use_fun)then
smin_no3_to_plant_vr(c,j) = (plant_ndemand(c)*nuptake_prof(c,j)-smin_nh4_to_plant_vr(c,j))
smin_no3_to_plant_vr(c,j) = (plant_ndemand_vr(c,j) - smin_nh4_to_plant_vr(c,j))
else
! This restricts the N uptake of a single layer to the value determined from the total demands and the
! hypothetical uptake profile above. Which is a strange thing to do, since that is independent of FUN
! do we need this at all?
smin_no3_to_plant_vr(c,j) = plant_ndemand(c)*nuptake_prof(c,j)
smin_no3_to_plant_vr(c,j) = plant_ndemand_vr(c,j)
! RF added new term. send rest of N to plant - which decides whether it should pay or not?
if ( local_use_fun ) then
smin_no3_to_plant_vr(c,j) = smin_no3_vr(c,j)/dt - actual_immob_no3_vr(c,j) - f_denit_vr(c,j)
Expand All @@ -667,9 +714,9 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
actual_immob_nh4_vr(c,j))*compet_decomp_no3 / sum_no3_demand_scaled(c,j)), &
potential_immob_vr(c,j)-actual_immob_nh4_vr(c,j))

smin_no3_to_plant_vr(c,j) = min((smin_no3_vr(c,j)/dt)*((plant_ndemand(c)* &
nuptake_prof(c,j)-smin_nh4_to_plant_vr(c,j))*compet_plant_no3 / sum_no3_demand_scaled(c,j)), &
plant_ndemand(c)*nuptake_prof(c,j)-smin_nh4_to_plant_vr(c,j))
smin_no3_to_plant_vr(c,j) = min((smin_no3_vr(c,j)/dt) * ((plant_ndemand_vr(c,j) - &
smin_nh4_to_plant_vr(c,j)) * compet_plant_no3 / sum_no3_demand_scaled(c,j)), &
plant_ndemand_vr(c,j) - smin_nh4_to_plant_vr(c,j))

f_denit_vr(c,j) = min((smin_no3_vr(c,j)/dt)*(pot_f_denit_vr(c,j)*compet_denit / &
sum_no3_demand_scaled(c,j)), pot_f_denit_vr(c,j))
Expand All @@ -681,8 +728,8 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
f_denit_vr(c,j) = min((smin_no3_vr(c,j)/dt)*(pot_f_denit_vr(c,j)*compet_denit / &
sum_no3_demand_scaled(c,j)), pot_f_denit_vr(c,j))

smin_no3_to_plant_vr(c,j) = (smin_no3_vr(c,j)/dt)*((plant_ndemand(c)* &
nuptake_prof(c,j)-smin_nh4_to_plant_vr(c,j))*compet_plant_no3 / sum_no3_demand_scaled(c,j))
smin_no3_to_plant_vr(c,j) = (smin_no3_vr(c,j)/dt) * ((plant_ndemand_vr(c,j) - &
smin_nh4_to_plant_vr(c,j)) * compet_plant_no3 / sum_no3_demand_scaled(c,j))

! RF added new term. send rest of N to plant - which decides whether it should pay or not?
smin_no3_to_plant_vr(c,j) = (smin_no3_vr(c,j) / dt) - actual_immob_no3_vr(c,j) - f_denit_vr(c,j)
Expand Down Expand Up @@ -737,10 +784,10 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
! update to new values that satisfy demand
actual_immob_nh4_vr(c,j) = potential_immob_vr(c,j) - actual_immob_no3_vr(c,j)
end if
if ( smin_no3_to_plant_vr(c,j) + smin_nh4_to_plant_vr(c,j) < plant_ndemand(c)*nuptake_prof(c,j) ) then
if ( smin_no3_to_plant_vr(c,j) + smin_nh4_to_plant_vr(c,j) < plant_ndemand_vr(c,j) ) then
supplement_to_sminn_vr(c,j) = supplement_to_sminn_vr(c,j) + &
(plant_ndemand(c)*nuptake_prof(c,j) - smin_no3_to_plant_vr(c,j)) - smin_nh4_to_plant_vr(c,j) ! use old values
smin_nh4_to_plant_vr(c,j) = plant_ndemand(c)*nuptake_prof(c,j) - smin_no3_to_plant_vr(c,j)
(plant_ndemand_vr(c,j) - smin_no3_to_plant_vr(c,j)) - smin_nh4_to_plant_vr(c,j) ! use old values
smin_nh4_to_plant_vr(c,j) = plant_ndemand_vr(c,j) - smin_no3_to_plant_vr(c,j)
end if
sminn_to_plant_vr(c,j) = smin_no3_to_plant_vr(c,j) + smin_nh4_to_plant_vr(c,j)
end if
Expand Down Expand Up @@ -991,6 +1038,44 @@ subroutine SoilBiogeochemCompetition (bounds, num_bgc_soilc, filter_bgc_soilc,nu
end if
end do ! end of column loops

! Set the FATES N uptake fluxes

if (use_fates) then
do fc=1, num_bgc_soilc
c = filter_bgc_soilc(fc)
ci = bounds%clump_index
s = clm_fates%f2hmap(ci)%hsites(c)
n_pcomp = clm_fates%fates(ci)%bc_out(s)%num_plant_comps

if ( plant_ndemand(c) > tiny(plant_ndemand(c)) ) then
do f = 1, n_pcomp
ft = clm_fates%fates(ci)%bc_out(s)%ft_index(f)

! [gN/m2/s]
ndemand = 0._r8

do j = 1, nlevdecomp
ndemand = ndemand + clm_fates%fates(ci)%bc_out(s)%veg_rootc(f,j) * &
(clm_fates%fates(ci)%bc_pconst%vmax_nh4(ft) + &
clm_fates%fates(ci)%bc_pconst%vmax_no3(ft)) * dzsoi_decomp(j)
end do

do j = 1, nlevdecomp
clm_fates%fates(ci)%bc_in(s)%plant_nh4_uptake_flux(f,1) = &
clm_fates%fates(ci)%bc_in(s)%plant_nh4_uptake_flux(f,1) + &
smin_nh4_to_plant_vr(c,j) * dt * dzsoi_decomp(j) * &
(ndemand / plant_ndemand(c))

clm_fates%fates(ci)%bc_in(s)%plant_no3_uptake_flux(f,1) = &
clm_fates%fates(ci)%bc_in(s)%plant_no3_uptake_flux(f,1) + &
smin_no3_to_plant_vr(c,j) * dt * dzsoi_decomp(j) * &
(ndemand / plant_ndemand(c))
end do
end do
end if
end do
end if

end if if_nitrif !end of if_not_use_nitrif_denitrif

end associate
Expand Down
Loading