From 257acec0ea79d2bf2426a7dac34f600c1db60480 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 20 May 2025 14:53:17 -0700 Subject: [PATCH 001/124] initial addition of HLM-side BC transfer subroutine --- .../elm/src/main/elmfates_interfaceMod.F90 | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 9911879bbcfa..21ccea26d2cc 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3967,4 +3967,35 @@ subroutine GetLandusePFTData(bounds, landuse_pft_file, landuse_pft_map, landuse_ end subroutine GetLandusePFTData +! ====================================================================================== + + subroutine UpdateBCIn(this, nc) + + ! !DESCRIPTION: + ! --------------------------------------------------------------------------------- + ! This call updates the HLM inputs to FATES + ! Currently this handles a subset of bc_in variables in an effort to stage the + ! refactor over time + ! --------------------------------------------------------------------------------- + + ! !USES: + ! + ! !ARGUMENTS: + class(hlm_fates_interface_type), intent(inout) :: this + integer, intent(in) :: nc + + ! !LOCAL VARIABLES + integer :: s, p, c, l, i + + do s=1,this%fates(nc)%nsites + + c = GetColIndex(s) + call TransferBC(col_cf%w_scalar(c)) + + end do + + end subroutine UpdateBCIn + +! ====================================================================================== + end module ELMFatesInterfaceMod From ea362e209b8a0af6d6e99ae0961c89e70e1fcf81 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 21 May 2025 11:00:49 -0700 Subject: [PATCH 002/124] adding sketch code of how to make the transfer call iterable --- .../elm/src/main/elmfates_interfaceMod.F90 | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 21ccea26d2cc..4dcc0ff9ab61 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3990,7 +3990,36 @@ subroutine UpdateBCIn(this, nc) do s=1,this%fates(nc)%nsites c = GetColIndex(s) - call TransferBC(col_cf%w_scalar(c)) + + ! TODO - create a new type that holds tag names and pointers to hlm arrays + ! Note that the hlm_var is going to be clump bound, so this new type would + ! need to be clump bound as well. I.e. `newtype` would need to be specific + ! to site. The idea here is to "directly" input the BC values into fates + ! patch data structures. This associates a particular hlm variable with + ! a generic tag name that acts as the common denominator between hlm and fates + ! similar to `set_fates_ctrlparams`. + ! + ! Call this below somewhere during initialization: + ! subroutine SetAPIAssociation(this,num_hlmvar) + ! ivar = 1 + ! this%api_tag(ivar) = 'decomp_frac_moisture' + ! this%hlm_var(ivar) => col_cf%w_scalar + ! + ! ivar = ivar + 1 + ! this%api_tag(ivar) = 'decomp_frac_temperature' + ! this%hlm_var(ivar) => col_cf%t_scalar + ! + ! num_hlmvar = ivar + ! end subroutine SetAPIAssociation + ! + !... + ! + ! num_hlmvar = 1 + ! do ivar = 1,num_hlmvar + ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) + ! end do + + call TransferBCIn('decomp_frac_moisture',col_cf%w_scalar(c)) end do From e86ccee844d9ea1c4489f065494cfee7d86a7704 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 21 May 2025 20:25:50 -0700 Subject: [PATCH 003/124] add patch-level transfer bc in call --- components/elm/src/main/elmfates_interfaceMod.F90 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 4dcc0ff9ab61..3179377338da 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3989,8 +3989,6 @@ subroutine UpdateBCIn(this, nc) do s=1,this%fates(nc)%nsites - c = GetColIndex(s) - ! TODO - create a new type that holds tag names and pointers to hlm arrays ! Note that the hlm_var is going to be clump bound, so this new type would ! need to be clump bound as well. I.e. `newtype` would need to be specific @@ -4013,13 +4011,14 @@ subroutine UpdateBCIn(this, nc) ! end subroutine SetAPIAssociation ! !... - ! + ! num_hlmvar = 1 ! do ivar = 1,num_hlmvar ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) ! end do - call TransferBCIn('decomp_frac_moisture',col_cf%w_scalar(c)) + call TransferBCIn('decomp_frac_moisture',col_cf%w_scalar) + call TransferBCIn('leaf_area_index',canopystate_inst%tlai_patch) end do From eba5f2de7b9ecf991000e9bd3b9df909dc9e67dd Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 2 Jul 2025 09:50:16 -0700 Subject: [PATCH 004/124] remove unused bc_out from init_site_vars --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 3179377338da..0f2812aa4849 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2118,7 +2118,7 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in call get_clump_bounds(nc, bounds_clump) do s = 1,this%fates(nc)%nsites - call init_site_vars(this%fates(nc)%sites(s),this%fates(nc)%bc_in(s),this%fates(nc)%bc_out(s) ) + call init_site_vars(this%fates(nc)%sites(s),this%fates(nc)%bc_in(s) ) call zero_site(this%fates(nc)%sites(s)) end do From a24457c0cd22cf2346622b7e1a18fffc89a2e55e Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 2 Jul 2025 09:55:40 -0700 Subject: [PATCH 005/124] remove unused bc_in argument from canopy_summarization --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 0f2812aa4849..7412d0479c8e 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1573,8 +1573,7 @@ subroutine wrap_update_hlmfates_dyn(this, nc, bounds_clump, & ! Canopy diagnostics for FATES call canopy_summarization(this%fates(nc)%nsites, & - this%fates(nc)%sites, & - this%fates(nc)%bc_in) + this%fates(nc)%sites) ! Canopy diagnostic outputs for HLM, including LUC call update_hlm_dynamics(this%fates(nc)%nsites, & From 9dd02700190beb228bb26542efbca62c31e715a5 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 2 Jul 2025 09:58:22 -0700 Subject: [PATCH 006/124] remove unneeded bc_out argument passing to Accumulatefluxes_ED --- components/elm/src/main/elmfates_interfaceMod.F90 | 1 - 1 file changed, 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 7412d0479c8e..c03e8e2a6a97 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2724,7 +2724,6 @@ subroutine wrap_accumulatefluxes(this, bounds_clump, fn, filterp) call AccumulateFluxes_ED(this%fates(nc)%nsites, & this%fates(nc)%sites, & this%fates(nc)%bc_in, & - this%fates(nc)%bc_out, & dtime) return end subroutine wrap_accumulatefluxes From 4547b068d8b15ab943b14e9b8344b4e0054d7823 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 16 Jul 2025 15:31:46 -0700 Subject: [PATCH 007/124] add allocation of site-level mapping arrays --- components/elm/src/main/elmfates_interfaceMod.F90 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index c03e8e2a6a97..6b4f6e1afb6a 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -965,7 +965,12 @@ subroutine init(this, bounds_proc, flandusepftdat) this%fates(nc)%nsites = s ! Allocate the FATES sites - allocate (this%fates(nc)%sites(this%fates(nc)%nsites)) + allocate(this%fates(nc)%sites(this%fates(nc)%nsites)) + + ! Allocate HLM-FATES mapping arrays + ! TODO: update this to be agnostic to fates column run mode + allocate(this%fates(nc)%sites(:)%column_map(1)) + allocate(this%fates(nc)%sites(:)%patch_map(natpft_size)) ! Allocate the FATES boundary arrays (in) allocate(this%fates(nc)%bc_in(this%fates(nc)%nsites)) From 2202a11dbfa808936e886a533a7c3f47dfd006ab Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 16 Jul 2025 15:44:16 -0700 Subject: [PATCH 008/124] add local variable definition for canopystate type --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 6b4f6e1afb6a..43a7becd12d8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3988,8 +3988,10 @@ subroutine UpdateBCIn(this, nc) integer, intent(in) :: nc ! !LOCAL VARIABLES + type(canopystate_type) :: canopystate_inst integer :: s, p, c, l, i + do s=1,this%fates(nc)%nsites ! TODO - create a new type that holds tag names and pointers to hlm arrays From 98cb29029955dba02f45de75373454dbe5082916 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 16 Jul 2025 15:52:06 -0700 Subject: [PATCH 009/124] move mapping allocations inside site loop --- components/elm/src/main/elmfates_interfaceMod.F90 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 43a7becd12d8..68cf81640b15 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -967,11 +967,6 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Allocate the FATES sites allocate(this%fates(nc)%sites(this%fates(nc)%nsites)) - ! Allocate HLM-FATES mapping arrays - ! TODO: update this to be agnostic to fates column run mode - allocate(this%fates(nc)%sites(:)%column_map(1)) - allocate(this%fates(nc)%sites(:)%patch_map(natpft_size)) - ! Allocate the FATES boundary arrays (in) allocate(this%fates(nc)%bc_in(this%fates(nc)%nsites)) @@ -991,6 +986,13 @@ subroutine init(this, bounds_proc, flandusepftdat) do s = 1, this%fates(nc)%nsites + ! Allocate HLM-FATES mapping arrays + ! TODO: update this to be agnostic to fates column run mode + allocate(this%fates(nc)%sites(s)%column_map(1)) + allocate(this%fates(nc)%sites(s)%patch_map(natpft_size)) + + ! TODO: Assign column_map and patch_map values + c = this%f2hmap(nc)%fcolumn(s) this%fates(nc)%sites(s)%h_gid = c From 462bba0b155be40a00931542178e373fc028c370 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 16 Jul 2025 15:59:22 -0700 Subject: [PATCH 010/124] add use of transferbcin from fatesinterfacemod --- components/elm/src/main/elmfates_interfaceMod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 68cf81640b15..017e5c17bdb7 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3984,6 +3984,7 @@ subroutine UpdateBCIn(this, nc) ! --------------------------------------------------------------------------------- ! !USES: + use FatesInterfaceMod, only : TransferBCIn ! ! !ARGUMENTS: class(hlm_fates_interface_type), intent(inout) :: this From cc232c935e640c0c033b5534f66b150c6424dbf1 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 16 Jul 2025 17:13:01 -0700 Subject: [PATCH 011/124] utilize type-bound bc transfer procedure --- components/elm/src/main/elmfates_interfaceMod.F90 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 017e5c17bdb7..f387bfd448f4 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3984,17 +3984,15 @@ subroutine UpdateBCIn(this, nc) ! --------------------------------------------------------------------------------- ! !USES: - use FatesInterfaceMod, only : TransferBCIn ! ! !ARGUMENTS: - class(hlm_fates_interface_type), intent(inout) :: this + type(hlm_fates_interface_type), intent(inout) :: this integer, intent(in) :: nc ! !LOCAL VARIABLES type(canopystate_type) :: canopystate_inst integer :: s, p, c, l, i - do s=1,this%fates(nc)%nsites ! TODO - create a new type that holds tag names and pointers to hlm arrays @@ -4025,8 +4023,8 @@ subroutine UpdateBCIn(this, nc) ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) ! end do - call TransferBCIn('decomp_frac_moisture',col_cf%w_scalar) - call TransferBCIn('leaf_area_index',canopystate_inst%tlai_patch) + call this%fates(nc)%sites(s)%TransferBCIn_1d('leaf_area_index',canopystate_inst%tlai_patch) + call this%fates(nc)%sites(s)%TransferBCIn_2d('decomp_frac_moisture',col_cf%w_scalar) end do From 9802732db06027536b747fc1b31b457aaafac3b0 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 17 Jul 2025 15:43:32 -0700 Subject: [PATCH 012/124] call generic transfer bc in subroutine --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index f387bfd448f4..da5b5c097e95 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4023,8 +4023,8 @@ subroutine UpdateBCIn(this, nc) ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) ! end do - call this%fates(nc)%sites(s)%TransferBCIn_1d('leaf_area_index',canopystate_inst%tlai_patch) - call this%fates(nc)%sites(s)%TransferBCIn_2d('decomp_frac_moisture',col_cf%w_scalar) + call this%fates(nc)%sites(s)%TransferBCIn('leaf_area_index',canopystate_inst%tlai_patch) + call this%fates(nc)%sites(s)%TransferBCIn('decomp_frac_moisture',col_cf%w_scalar) end do From 079ce7bb48a1903e03d5c16fa06bbebf0c896805 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 17 Jul 2025 15:51:55 -0700 Subject: [PATCH 013/124] remove unused fates patch type --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index da5b5c097e95..151756d1ce87 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -156,7 +156,6 @@ module ELMFatesInterfaceMod use FatesInterfaceTypesMod, only : hlm_num_luh2_states use FatesIOVariableKindMod, only : group_dyna_simple, group_dyna_complx use PRTGenericMod , only : num_elements - use FatesPatchMod , only : fates_patch_type use FatesDispersalMod , only : lneighbors, dispersal_type, IsItDispersalTime use FatesInterfaceTypesMod, only : hlm_stepsize, hlm_current_day use EDMainMod , only : ed_ecosystem_dynamics @@ -2300,9 +2299,6 @@ subroutine wrap_sunfrac(this,bounds_clump,top_af_inst,canopystate_inst) ! on the site integer :: nc ! clump index - type(fates_patch_type), pointer :: cpatch ! c"urrent" patch INTERF-TODO: SHOULD - ! BE HIDDEN AS A FATES PRIVATE - associate( forc_solad => top_af_inst%solad, & forc_solai => top_af_inst%solai, & fsun => canopystate_inst%fsun_patch, & From ae8a1c4e8fb5b71a25bfe37af297c56ae32f8e8b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 22 Jul 2025 09:08:01 -0700 Subject: [PATCH 014/124] temporarily update lobata configuration --- cime_config/machines/config_machines.xml | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/cime_config/machines/config_machines.xml b/cime_config/machines/config_machines.xml index 8a9d032bb6aa..d7e95e094de7 100644 --- a/cime_config/machines/config_machines.xml +++ b/cime_config/machines/config_machines.xml @@ -4921,23 +4921,13 @@ --map-by ppr:{{ tasks_per_node }}:socket:PE=$ENV{OMP_NUM_THREADS} --bind-to hwthread - - /usr/share/modules/init/python.py - /usr/share/modules/init/perl.pm - /usr/share/modules/init/sh - /usr/share/modules/init/csh - /usr/bin/modulecmd python - /usr/bin/modulecmd perl - module - module - - - hdf5 - netcdf-c - netcdf-fortran - esmf - + + + /home/glemieux/Repos/spack/opt/spack/linux-pop22-skylake_avx512/gcc-11.4.0/netcdf-c-4.9.2-ko2blxkpb6mpnwx4bg6tberacqwfyzjq + /home/glemieux/Repos/spack/opt/spack/linux-pop22-skylake_avx512/gcc-11.4.0/netcdf-fortran-4.6.1-5og4oaakxzqvpc3avqzmr6jvupxsurj3 + + From fe5592c402c883e6cee82112d9bbac385f8a6da7 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 28 Jul 2025 16:34:14 -0700 Subject: [PATCH 015/124] remove unused w and t scalars assignment as this is handled by the new transfer function --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 151756d1ce87..cff1115fa110 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1238,10 +1238,6 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & nlevsoil = this%fates(nc)%bc_in(s)%nlevsoil - ! Decomposition fluxes - this%fates(nc)%bc_in(s)%w_scalar_sisl(1:nlevsoil) = col_cf%w_scalar(c,1:nlevsoil) - this%fates(nc)%bc_in(s)%t_scalar_sisl(1:nlevsoil) = col_cf%t_scalar(c,1:nlevsoil) - ! Soil water this%fates(nc)%bc_in(s)%h2o_liqvol_sl(1:nlevsoil) = & col_ws%h2osoi_vol(c,1:nlevsoil) From 5db079e3b98ec74bfec7db0cf178ef2994881469 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 28 Jul 2025 16:57:05 -0700 Subject: [PATCH 016/124] change updatebcin to use the fates_interface_type for legibility and simplicity --- .../elm/src/main/elmfates_interfaceMod.F90 | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index cff1115fa110..653bf0487356 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3978,47 +3978,43 @@ subroutine UpdateBCIn(this, nc) ! !USES: ! ! !ARGUMENTS: - type(hlm_fates_interface_type), intent(inout) :: this - integer, intent(in) :: nc + type(fates_interface_type), intent(inout) :: this + integer, intent(in) :: s ! !LOCAL VARIABLES - type(canopystate_type) :: canopystate_inst - integer :: s, p, c, l, i - - do s=1,this%fates(nc)%nsites - - ! TODO - create a new type that holds tag names and pointers to hlm arrays - ! Note that the hlm_var is going to be clump bound, so this new type would - ! need to be clump bound as well. I.e. `newtype` would need to be specific - ! to site. The idea here is to "directly" input the BC values into fates - ! patch data structures. This associates a particular hlm variable with - ! a generic tag name that acts as the common denominator between hlm and fates - ! similar to `set_fates_ctrlparams`. - ! - ! Call this below somewhere during initialization: - ! subroutine SetAPIAssociation(this,num_hlmvar) - ! ivar = 1 - ! this%api_tag(ivar) = 'decomp_frac_moisture' - ! this%hlm_var(ivar) => col_cf%w_scalar - ! - ! ivar = ivar + 1 - ! this%api_tag(ivar) = 'decomp_frac_temperature' - ! this%hlm_var(ivar) => col_cf%t_scalar - ! - ! num_hlmvar = ivar - ! end subroutine SetAPIAssociation - ! - !... - - ! num_hlmvar = 1 - ! do ivar = 1,num_hlmvar - ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) - ! end do + !type(canopystate_type) :: canopystate_inst + + ! TODO - create a new type that holds tag names and pointers to hlm arrays + ! Note that the hlm_var is going to be clump bound, so this new type would + ! need to be clump bound as well. I.e. `newtype` would need to be specific + ! to site. The idea here is to "directly" input the BC values into fates + ! patch data structures. This associates a particular hlm variable with + ! a generic tag name that acts as the common denominator between hlm and fates + ! similar to `set_fates_ctrlparams`. + ! + ! Call this below somewhere during initialization: + ! subroutine SetAPIAssociation(this,num_hlmvar) + ! ivar = 1 + ! this%api_tag(ivar) = 'decomp_frac_moisture' + ! this%hlm_var(ivar) => col_cf%w_scalar + ! + ! ivar = ivar + 1 + ! this%api_tag(ivar) = 'decomp_frac_temperature' + ! this%hlm_var(ivar) => col_cf%t_scalar + ! + ! num_hlmvar = ivar + ! end subroutine SetAPIAssociation + ! + !... - call this%fates(nc)%sites(s)%TransferBCIn('leaf_area_index',canopystate_inst%tlai_patch) - call this%fates(nc)%sites(s)%TransferBCIn('decomp_frac_moisture',col_cf%w_scalar) + ! num_hlmvar = 1 + ! do ivar = 1,num_hlmvar + ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) + ! end do - end do + !call this%fates(nc)%sites(s)%TransferBCIn('leaf_area_index',canopystate_inst%tlai_patch) + call this%sites(s)%TransferBCIn('decomp_frac_moisture',col_cf%w_scalar) + call this%sites(s)%TransferBCIn('decomp_frac_temperature',col_cf%t_scalar) end subroutine UpdateBCIn From 85576b8e5d5701deeda8ad0ec1cb96a488fcca2e Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 28 Jul 2025 16:57:19 -0700 Subject: [PATCH 017/124] call updatebcin --- components/elm/src/main/elmfates_interfaceMod.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 653bf0487356..3f563b2142c4 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1237,6 +1237,9 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & end if nlevsoil = this%fates(nc)%bc_in(s)%nlevsoil + + ! Decomposition fluxes + call this%fates(nc)%UpdateBCIn(s) ! Soil water this%fates(nc)%bc_in(s)%h2o_liqvol_sl(1:nlevsoil) = & @@ -3966,7 +3969,7 @@ end subroutine GetLandusePFTData ! ====================================================================================== - subroutine UpdateBCIn(this, nc) + subroutine UpdateBCIn(this, s) ! !DESCRIPTION: ! --------------------------------------------------------------------------------- From 36391f65f33dd271bdf91a42ab73388fc3190d58 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 29 Jul 2025 15:41:19 -0700 Subject: [PATCH 018/124] add HLM-FATES API variable mapping data structure and implement in transfer subroutine --- .../elm/src/main/elmfates_interfaceMod.F90 | 122 +++++++++++------- 1 file changed, 78 insertions(+), 44 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 3f563b2142c4..2f6426b5c9ac 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -254,6 +254,17 @@ module ELMFatesInterfaceMod ! Type structure that holds allocatable arrays for mpi-based seed dispersal type(dispersal_type) :: fates_seed + ! This is the array that contains the common API vocabulary + ! between FATES and the host land model. + character(len=*), allocatable :: api_str(:) + + ! This is the array that contains the host land model variable + ! associated with the common API vocabulary string + real(r8), allocatable :: hlm_var(:) + + ! This is the number of HLM variables that are being passed to FATES + integer :: num_hlmvar + contains procedure, public :: init @@ -276,6 +287,7 @@ module ELMFatesInterfaceMod procedure, public :: Init2 ! Initialization after determining subgrid weights procedure, public :: InitAccBuffer ! Initialize any accumulation buffers procedure, public :: InitAccVars ! Initialize any accumulation variables + procedure, public :: InitAndSetAPIAssociation procedure, public :: UpdateAccVars ! Update any accumulation variables procedure, public :: UpdateLitterFluxes procedure, private :: init_history_io @@ -286,6 +298,7 @@ module ELMFatesInterfaceMod procedure, public :: WrapUpdateFatesRmean procedure, public :: WrapGlobalSeedDispersal procedure, public :: WrapUpdateFatesSeedInOut + procedure, public :: WrapTransferBC end type hlm_fates_interface_type @@ -890,6 +903,7 @@ subroutine init(this, bounds_proc, flandusepftdat) call DetermineGridCellNeighbors(lneighbors,this%fates_seed,numg) end if + ! Allocate fates interface and fates to HLM interfac vectors nclumps = get_proc_clumps() allocate(this%fates(nclumps)) allocate(this%f2hmap(nclumps)) @@ -897,6 +911,9 @@ subroutine init(this, bounds_proc, flandusepftdat) if(debug)then write(iulog,*) 'alm_fates%init(): allocating for ',nclumps,' threads' end if + + ! Initialize the fates to host land model API variable mapping + call this%InitAndSetAPIAssociation() ! Retrieve the landuse x pft static data if the optional switch has been set if (use_fates_fixed_biogeog .and. use_fates_luh) then @@ -1212,6 +1229,9 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & endif gdp_lf_col = this%fates_fire_data_method%GetGDP() end if + + ! Transfer boundary conditions to the FATES patch data structure + call this%WrapTransferBC(nc) do s=1,this%fates(nc)%nsites @@ -3513,6 +3533,50 @@ subroutine init_soil_depths(this, nc) return end subroutine init_soil_depths +! ====================================================================================== + + subroutine InitAndSetAPIAssociation(this) + + ! !DESCRIPTION: + ! --------------------------------------------------------------------------------- + ! This subroutine sets the association between the hlm variables and the common API + ! vocabulary strings. + ! --------------------------------------------------------------------------------- + + ! !USES: + + ! !ARGUMENTS: + class(hlm_fates_interface_type), intent(inout) :: this + + ! !LOCAL: + integer :: ivar = 0 ! array index + integer, parameter :: num_hlmvar ! number of HLM variables + + ! Allocate the arrays + allocate(this%api_str(num_hlmvar)) + allocate(this%hlm_var(num_hlmvar)) + + ! Increment through the arrays and assign HLM variables to common API vocab + ivar = ivar + 1 + this%api_str(ivar) = 'decomp_frac_moisture' + this%hlm_var(ivar) => col_cf%w_scalar + + ivar = ivar + 1 + this%api_str(ivar) = 'decomp_frac_temperature' + this%hlm_var(ivar) => col_cf%t_scalar + + ! Check that the number of variables set matches + ! specifically in the case in which the number set + ! is lower than the allocated amount + if (ivar /= num_hlmvar) then + write(iulog,*) 'FATES API: Number of variables does not match the expected array size' + call endrun(msg=errMsg(sourcefile, __LINE__)) + else + this%num_hlmvar = num_hlmvar + end if + + end subroutine InitAndSetAPIAssociation + ! ====================================================================================== subroutine ComputeRootSoilFlux(this, bounds_clump, num_filterc, filterc, & @@ -3969,58 +4033,28 @@ end subroutine GetLandusePFTData ! ====================================================================================== - subroutine UpdateBCIn(this, s) + subroutine WrapTransferBC(this, nc) ! !DESCRIPTION: ! --------------------------------------------------------------------------------- - ! This call updates the HLM inputs to FATES - ! Currently this handles a subset of bc_in variables in an effort to stage the - ! refactor over time + ! This call updates the HLM inputs to FATES using the ! --------------------------------------------------------------------------------- ! !USES: ! ! !ARGUMENTS: - type(fates_interface_type), intent(inout) :: this - integer, intent(in) :: s - - ! !LOCAL VARIABLES - !type(canopystate_type) :: canopystate_inst - - ! TODO - create a new type that holds tag names and pointers to hlm arrays - ! Note that the hlm_var is going to be clump bound, so this new type would - ! need to be clump bound as well. I.e. `newtype` would need to be specific - ! to site. The idea here is to "directly" input the BC values into fates - ! patch data structures. This associates a particular hlm variable with - ! a generic tag name that acts as the common denominator between hlm and fates - ! similar to `set_fates_ctrlparams`. - ! - ! Call this below somewhere during initialization: - ! subroutine SetAPIAssociation(this,num_hlmvar) - ! ivar = 1 - ! this%api_tag(ivar) = 'decomp_frac_moisture' - ! this%hlm_var(ivar) => col_cf%w_scalar - ! - ! ivar = ivar + 1 - ! this%api_tag(ivar) = 'decomp_frac_temperature' - ! this%hlm_var(ivar) => col_cf%t_scalar - ! - ! num_hlmvar = ivar - ! end subroutine SetAPIAssociation - ! - !... - - ! num_hlmvar = 1 - ! do ivar = 1,num_hlmvar - ! call TransferBC(this%api_tag(ivar), this%hlm_var(ivar)) - ! end do - - !call this%fates(nc)%sites(s)%TransferBCIn('leaf_area_index',canopystate_inst%tlai_patch) - call this%sites(s)%TransferBCIn('decomp_frac_moisture',col_cf%w_scalar) - call this%sites(s)%TransferBCIn('decomp_frac_temperature',col_cf%t_scalar) - - end subroutine UpdateBCIn + class(hlm_fates_interface_type), intent(inout) :: this + integer, intent(in) :: nc + + ! !LOCAL: + integer :: s, ivar ! indices and loop counters + + do s = 1, this%fates(nc)%nsites + do ivar = 1,this%num_hlmvar + call this%fates(nc)%sites(s)%TransferBC(this%api_str(ivar), this%hlm_var(ivar)) + end do + end do -! ====================================================================================== + end subroutine WrapTransferBC end module ELMFatesInterfaceMod From aec6d1f0055dd3681bef51c68bad6be88205d098 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 30 Jul 2025 11:16:05 -0700 Subject: [PATCH 019/124] remove old bc transfer wrapper call that was accidentally left behind --- components/elm/src/main/elmfates_interfaceMod.F90 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 2f6426b5c9ac..e5d82e9e0db5 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1230,7 +1230,7 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & gdp_lf_col = this%fates_fire_data_method%GetGDP() end if - ! Transfer boundary conditions to the FATES patch data structure + ! Transfer decomposition fluxes to the FATES patch data structure call this%WrapTransferBC(nc) do s=1,this%fates(nc)%nsites @@ -1258,9 +1258,6 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & nlevsoil = this%fates(nc)%bc_in(s)%nlevsoil - ! Decomposition fluxes - call this%fates(nc)%UpdateBCIn(s) - ! Soil water this%fates(nc)%bc_in(s)%h2o_liqvol_sl(1:nlevsoil) = & col_ws%h2osoi_vol(c,1:nlevsoil) From 21397ca93b4db4940c6aa0dba2989d1ae08bbe28 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 30 Jul 2025 11:19:35 -0700 Subject: [PATCH 020/124] fixed deferred length character array --- components/elm/src/main/elmfates_interfaceMod.F90 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index e5d82e9e0db5..79f35f2573e1 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -256,7 +256,7 @@ module ELMFatesInterfaceMod ! This is the array that contains the common API vocabulary ! between FATES and the host land model. - character(len=*), allocatable :: api_str(:) + character(len=:), allocatable :: api_str(:) ! This is the array that contains the host land model variable ! associated with the common API vocabulary string @@ -3546,11 +3546,12 @@ subroutine InitAndSetAPIAssociation(this) class(hlm_fates_interface_type), intent(inout) :: this ! !LOCAL: - integer :: ivar = 0 ! array index - integer, parameter :: num_hlmvar ! number of HLM variables + integer :: ivar = 0 ! array index + integer, parameter :: max_string_length = 24 ! maximum length of common vocab string + integer, parameter :: num_hlmvar = 2 ! number of HLM variables ! Allocate the arrays - allocate(this%api_str(num_hlmvar)) + allocate(character(len=max_string_length) :: this%api_str(num_hlmvar)) allocate(this%hlm_var(num_hlmvar)) ! Increment through the arrays and assign HLM variables to common API vocab From 65b4f0ebea6f281ed6cc48b02ef0335c780624cf Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 30 Jul 2025 11:22:13 -0700 Subject: [PATCH 021/124] add new type to create an array of pointers to hlm arrays --- .../elm/src/main/elmfates_interfaceMod.F90 | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 79f35f2573e1..059ad33f70be 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -227,6 +227,14 @@ module ELMFatesInterfaceMod integer, allocatable :: hsites (:) end type f2hmap_type + + type, public :: hlm_fates_api_var_type + + ! This is the pointer to the host land model variable + ! data associated with the common API vocabulary string + real(r8), pointer :: hlm_var(:,:) + + end type hlm_fates_api_var_type type, public :: hlm_fates_interface_type @@ -258,9 +266,8 @@ module ELMFatesInterfaceMod ! between FATES and the host land model. character(len=:), allocatable :: api_str(:) - ! This is the array that contains the host land model variable - ! associated with the common API vocabulary string - real(r8), allocatable :: hlm_var(:) + ! This is the array of pointers to the host land model data + type(hlm_fates_api_var_type), allocatable :: hlm_var_2darray(:) ! This is the number of HLM variables that are being passed to FATES integer :: num_hlmvar @@ -3552,22 +3559,26 @@ subroutine InitAndSetAPIAssociation(this) ! Allocate the arrays allocate(character(len=max_string_length) :: this%api_str(num_hlmvar)) - allocate(this%hlm_var(num_hlmvar)) + allocate(this%hlm_var_2darray(num_hlmvar)) ! Increment through the arrays and assign HLM variables to common API vocab + ! 1D arrays + ! 2D arrays ivar = ivar + 1 this%api_str(ivar) = 'decomp_frac_moisture' - this%hlm_var(ivar) => col_cf%w_scalar + this%hlm_var_2darray(ivar)%hlm_var => col_cf%w_scalar ivar = ivar + 1 this%api_str(ivar) = 'decomp_frac_temperature' - this%hlm_var(ivar) => col_cf%t_scalar + this%hlm_var_2darray(ivar)%hlm_var => col_cf%t_scalar + + ! 3D arrays ! Check that the number of variables set matches ! specifically in the case in which the number set ! is lower than the allocated amount if (ivar /= num_hlmvar) then - write(iulog,*) 'FATES API: Number of variables does not match the expected array size' + write(iulog,*) 'FATES API: Number of API variables does not match the expected array size' call endrun(msg=errMsg(sourcefile, __LINE__)) else this%num_hlmvar = num_hlmvar From 29332289e612c3da9dcafa408d8d4b332e1f16ae Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 30 Jul 2025 11:22:50 -0700 Subject: [PATCH 022/124] update and move the WrapTransferBC call with new type --- .../elm/src/main/elmfates_interfaceMod.F90 | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 059ad33f70be..b72271b4c498 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3767,6 +3767,33 @@ subroutine wrap_hydraulics_drive(this, bounds_clump, & return end subroutine wrap_hydraulics_drive +! ====================================================================================== + + subroutine WrapTransferBC(this, nc) + + ! !DESCRIPTION: + ! --------------------------------------------------------------------------------- + ! This call passes the HLM inputs to FATES patch-level boundary conditions + ! --------------------------------------------------------------------------------- + + ! !USES: + ! + ! !ARGUMENTS: + class(hlm_fates_interface_type), intent(inout) :: this + integer, intent(in) :: nc + + ! !LOCAL: + integer :: s, ivar ! indices and loop counters + + do s = 1, this%fates(nc)%nsites + do ivar = 1,this%num_hlmvar + call this%fates(nc)%sites(s)%TransferBCIn(this%api_str(ivar), & + this%hlm_var_2darray(ivar)%hlm_var) + end do + end do + + end subroutine WrapTransferBC + ! ====================================================================================== subroutine hlm_bounds_to_fates_bounds(hlm, fates) @@ -4040,30 +4067,4 @@ subroutine GetLandusePFTData(bounds, landuse_pft_file, landuse_pft_map, landuse_ end subroutine GetLandusePFTData -! ====================================================================================== - - subroutine WrapTransferBC(this, nc) - - ! !DESCRIPTION: - ! --------------------------------------------------------------------------------- - ! This call updates the HLM inputs to FATES using the - ! --------------------------------------------------------------------------------- - - ! !USES: - ! - ! !ARGUMENTS: - class(hlm_fates_interface_type), intent(inout) :: this - integer, intent(in) :: nc - - ! !LOCAL: - integer :: s, ivar ! indices and loop counters - - do s = 1, this%fates(nc)%nsites - do ivar = 1,this%num_hlmvar - call this%fates(nc)%sites(s)%TransferBC(this%api_str(ivar), this%hlm_var(ivar)) - end do - end do - - end subroutine WrapTransferBC - end module ELMFatesInterfaceMod From 73ac954a4ee33fd1fd21ca96e1fb8c3aed3207ca Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 16 May 2025 17:02:40 -0700 Subject: [PATCH 023/124] replace column and site map with patch index --- .../elm/src/main/elmfates_interfaceMod.F90 | 114 ++++++++++++------ 1 file changed, 74 insertions(+), 40 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b72271b4c498..82a2c666b28b 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -217,14 +217,17 @@ module ELMFatesInterfaceMod implicit none - type, public :: f2hmap_type + type :: f2hmap_type - ! This is the associated column index of each FATES site - integer, allocatable :: fcolumn (:) + ! HLM patch index to FATES patchno index mapping, by site + integer, allocatable :: hlm_patch_index(:,:) - ! This is the associated site index of any HLM columns - ! This vector may be sparse, and non-sites have index 0 - integer, allocatable :: hsites (:) + contains + + procedure, public :: SetPatchIndex + procedure, public :: GetPatchIndex + procedure, public :: GetColumnIndex + procedure, public :: GetLandunitIndex end type f2hmap_type @@ -933,56 +936,40 @@ subroutine init(this, bounds_proc, flandusepftdat) do nc = 1,nclumps call get_clump_bounds(nc, bounds_clump) - nmaxcol = bounds_clump%endc - bounds_clump%begc + 1 + ! nmaxcol = bounds_clump%endc - bounds_clump%begc + 1 - allocate(collist(1:nmaxcol)) + ! allocate(collist(1:nmaxcol)) ! Allocate the mapping that points columns to FATES sites, 0 is NA - allocate(this%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc)) + ! allocate(this%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc)) ! Initialize all columns with a zero index, which indicates no FATES site - this%f2hmap(nc)%hsites(:) = 0 - - s = 0 - do c = bounds_clump%begc,bounds_clump%endc - l = col_pp%landunit(c) - - ! These are the key constraints that determine if this column - ! will have a FATES site associated with it - - ! INTERF-TODO: WE HAVE NOT FILTERED OUT FATES SITES ON INACTIVE COLUMNS.. YET - ! NEED A RUN-TIME ROUTINE THAT CLEARS AND REWRITES THE SITE LIST - - if ( (col_pp%is_soil(c)) .and. (col_pp%active(c)) ) then - s = s + 1 - collist(s) = c - this%f2hmap(nc)%hsites(c) = s - col_pp%is_fates(c) = .true. - + ! this%f2hmap(nc)%hsites(:) = 0 + + ! Determine the number of FATES site based of the clumping + ! This assumes one site per landunit currently. + num_landunits_veg = 0 + do l = bounds_clump%begl,bounds_clump%endl + if (lun_pp%itype(l) == istsoil) then + num_landunits_veg = num_landunits_veg + 1 if(debug)then - write(iulog,*) 'alm_fates%init(): thread',nc,': found column',c,'with lu',l + ! write(iulog,*) 'alm_fates%init(): thread',nc,': found column',c,'with lu',l write(iulog,*) 'LU type:', lun_pp%itype(l) end if endif - enddo + ! TODO Add adjustment to fates calculation here based on multi-column FATES options + s = num_landunits_veg + if(debug)then write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' end if - ! Allocate vectors that match FATES sites with HLM columns - ! RGK: Sites and fcolumns are forced as args during clm_driv() as of 6/4/2016 - ! We may have to give these a dummy allocation of 1, which should - ! not be a problem since we always iterate on nsites. + ! Allocate map from FATES patchno index to HLM patch index by site + allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) - allocate(this%f2hmap(nc)%fcolumn(s)) - - ! Assign the h2hmap indexing - this%f2hmap(nc)%fcolumn(1:s) = collist(1:s) - - ! Deallocate the temporary arrays - deallocate(collist) + call this%f2hmap(nc)%SetPatchIndex() ! Set the number of FATES sites this%fates(nc)%nsites = s @@ -4067,4 +4054,51 @@ subroutine GetLandusePFTData(bounds, landuse_pft_file, landuse_pft_map, landuse_ end subroutine GetLandusePFTData +! ====================================================================================== + + integer function GetColumnIndex(this,ifp,s) result(ifc) + + !------------------------------------------------------------------------ + ! This subroutine gets the mapping between the FATES patches and HLM columns + ! ------------------------------------------------------------------------ + + type(f2hmap_type), intent(inout) :: this + + integer :: ifp ! FATES bc_in/out patch dimension index + integer :: s ! FATES site index + + ifc = veg_pp%column(this%hlm_patch_index(ifp,s)) + + end function GetColumnIndex + +! ====================================================================================== + + subroutine SetPatchIndex(this,bounds_clump) + + !------------------------------------------------------------------------ + ! This subroutine sets the mapping between the FATES and HLM patches + ! ------------------------------------------------------------------------ + + type(f2hmap_type), intent(inout) :: this + type(bounds_type), intent(in) :: bounds_clump + + integer :: s ! FATES side index + integer :: l ! HLM landunit index + integer :: ifp ! FATES patch index (patchno) + + s = 0 + do l = bounds_clump%begl,bounds_clump%endl + if (lun_pp%itype(l) == istsoil) then + s = s + 1 + do ifp = 1,fates_maxPatchesperSite + ! This assumes that the first patch on the land unit is a vegetated + ! patch and that the patch indices are monotonically increasing. + ! See decompmod and initGridCellsMod for corroboration + this%hlm_patch_index(ifp,s) = lun_pp%pfti(l) + ifp + end do + end if + end do + + end function SetColumnIndex + end module ELMFatesInterfaceMod From 1f81e7fc36e55837551d253b9c41c8e1b5399519 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 11 Aug 2025 15:51:54 -0700 Subject: [PATCH 024/124] minor typo fix --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 82a2c666b28b..b7c4ee9a89e8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4082,7 +4082,7 @@ subroutine SetPatchIndex(this,bounds_clump) type(f2hmap_type), intent(inout) :: this type(bounds_type), intent(in) :: bounds_clump - integer :: s ! FATES side index + integer :: s ! FATES site index integer :: l ! HLM landunit index integer :: ifp ! FATES patch index (patchno) From 96f1e2c3e0dd34d85cae190659bce3c8881ee0cc Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 11 Aug 2025 15:56:13 -0700 Subject: [PATCH 025/124] correct end procedure name --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b7c4ee9a89e8..79da2c80fe22 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4099,6 +4099,6 @@ subroutine SetPatchIndex(this,bounds_clump) end if end do - end function SetColumnIndex + end subroutine SetPatchIndex end module ELMFatesInterfaceMod From b6dd28e3d93a152475f68a7e4b64b82f3a1d82c7 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 11 Aug 2025 16:05:33 -0700 Subject: [PATCH 026/124] add missing bounds clump argument to set patch index call --- components/elm/src/main/elmfates_interfaceMod.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 79da2c80fe22..ff53b0211eae 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -969,7 +969,8 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Allocate map from FATES patchno index to HLM patch index by site allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) - call this%f2hmap(nc)%SetPatchIndex() + ! Populate the fates to hlm patch map + call this%f2hmap(nc)%SetPatchIndex(bounds_clump) ! Set the number of FATES sites this%fates(nc)%nsites = s @@ -4086,6 +4087,8 @@ subroutine SetPatchIndex(this,bounds_clump) integer :: l ! HLM landunit index integer :: ifp ! FATES patch index (patchno) + ! Note while each HLM clump can have multiple sites, the site indices are not global, + ! i.e. the first site on each clump will have an index of 1 s = 0 do l = bounds_clump%begl,bounds_clump%endl if (lun_pp%itype(l) == istsoil) then From 748d4ec06ffbee037979bc2abcc99e83d1f480e0 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 11 Aug 2025 16:32:29 -0700 Subject: [PATCH 027/124] Update wrap bc transfer subroutine to be bc_in specific --- components/elm/src/main/elmfates_interfaceMod.F90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index ff53b0211eae..841222617590 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -308,7 +308,7 @@ module ELMFatesInterfaceMod procedure, public :: WrapUpdateFatesRmean procedure, public :: WrapGlobalSeedDispersal procedure, public :: WrapUpdateFatesSeedInOut - procedure, public :: WrapTransferBC + procedure, public :: WrapTransferBCIn end type hlm_fates_interface_type @@ -1226,7 +1226,7 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & end if ! Transfer decomposition fluxes to the FATES patch data structure - call this%WrapTransferBC(nc) + call this%WrapTransferBCIn(nc) do s=1,this%fates(nc)%nsites @@ -3757,7 +3757,7 @@ end subroutine wrap_hydraulics_drive ! ====================================================================================== - subroutine WrapTransferBC(this, nc) + subroutine WrapTransferBCIn(this, nc) ! !DESCRIPTION: ! --------------------------------------------------------------------------------- @@ -3780,7 +3780,7 @@ subroutine WrapTransferBC(this, nc) end do end do - end subroutine WrapTransferBC + end subroutine WrapTransferBCIn ! ====================================================================================== From 78fae2c562adf21ca40d51cb52b5ff3854a8b8ec Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 11 Aug 2025 16:35:39 -0700 Subject: [PATCH 028/124] add bc_out specific transfer wrap call --- .../elm/src/main/elmfates_interfaceMod.F90 | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 841222617590..4bb6f1a76cdd 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -309,6 +309,7 @@ module ELMFatesInterfaceMod procedure, public :: WrapGlobalSeedDispersal procedure, public :: WrapUpdateFatesSeedInOut procedure, public :: WrapTransferBCIn + procedure, public :: WrapTransferBCOut end type hlm_fates_interface_type @@ -3782,6 +3783,33 @@ subroutine WrapTransferBCIn(this, nc) end subroutine WrapTransferBCIn +! ====================================================================================== + + subroutine WrapTransferBCOut(this, nc) + + ! !DESCRIPTION: + ! --------------------------------------------------------------------------------- + ! This call passes the HLM inputs to FATES patch-level boundary conditions + ! --------------------------------------------------------------------------------- + + ! !USES: + ! + ! !ARGUMENTS: + class(hlm_fates_interface_type), intent(inout) :: this + integer, intent(in) :: nc + + ! !LOCAL: + integer :: s, ivar ! indices and loop counters + + do s = 1, this%fates(nc)%nsites + do ivar = 1,this%num_hlmvar + call this%fates(nc)%sites(s)%TransferBCOut(this%api_str(ivar), & + this%hlm_var_2darray(ivar)%hlm_var) + end do + end do + + end subroutine WrapTransferBCOut + ! ====================================================================================== subroutine hlm_bounds_to_fates_bounds(hlm, fates) From f4d1c4e4fb467faa87c4aef422a5eb4cbae21f45 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 11:10:13 -0700 Subject: [PATCH 029/124] restructure the hlm api type to separate the data being passed in versus out --- .../elm/src/main/elmfates_interfaceMod.F90 | 78 ++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 4bb6f1a76cdd..e063e02642c9 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -237,6 +237,13 @@ module ELMFatesInterfaceMod ! data associated with the common API vocabulary string real(r8), pointer :: hlm_var(:,:) + ! This is the array that contains the common API vocabulary + ! between FATES and the host land model. + character(len=:) :: api_str + + ! This is the number of HLM variables that are being passed to FATES + integer :: num_hlmvar + end type hlm_fates_api_var_type @@ -265,15 +272,10 @@ module ELMFatesInterfaceMod ! Type structure that holds allocatable arrays for mpi-based seed dispersal type(dispersal_type) :: fates_seed - ! This is the array that contains the common API vocabulary - ! between FATES and the host land model. - character(len=:), allocatable :: api_str(:) - - ! This is the array of pointers to the host land model data - type(hlm_fates_api_var_type), allocatable :: hlm_var_2darray(:) - - ! This is the number of HLM variables that are being passed to FATES - integer :: num_hlmvar + ! This is the array of pointer to the host land model data and its associated + ! common variable name + type(hlm_fates_api_var_type), allocatable :: bc_in(:) + type(hlm_fates_api_var_type), allocatable :: bc_out(:) contains @@ -3542,35 +3544,57 @@ subroutine InitAndSetAPIAssociation(this) class(hlm_fates_interface_type), intent(inout) :: this ! !LOCAL: - integer :: ivar = 0 ! array index + integer :: ivar ! array index integer, parameter :: max_string_length = 24 ! maximum length of common vocab string - integer, parameter :: num_hlmvar = 2 ! number of HLM variables + integer, parameter :: num_bc_in = 2 ! number of HLM variables + integer, parameter :: num_bc_out = 3 ! number of HLM variables ! Allocate the arrays - allocate(character(len=max_string_length) :: this%api_str(num_hlmvar)) - allocate(this%hlm_var_2darray(num_hlmvar)) + allocate(this%bc_in(num_bc_in)) + allocate(this%bc_out(num_bc_out)) ! Increment through the arrays and assign HLM variables to common API vocab - ! 1D arrays + ivar = 0 + + ! ! HLM -> FATES (bc_in) ! 2D arrays ivar = ivar + 1 - this%api_str(ivar) = 'decomp_frac_moisture' - this%hlm_var_2darray(ivar)%hlm_var => col_cf%w_scalar + this%bc_in(ivar)%api_str = 'decomp_frac_moisture' + this%bc_in(ivar)%hlm_var => col_cf%w_scalar(:,:) + + ivar = ivar + 1 + this%bc_in(ivar)%api_str = 'decomp_frac_temperature' + this%bc_in(ivar)%hlm_var => col_cf%t_scalar(:,:) + + this%bc_in%num_hlmvar = ivar + + ! ! FATES -> HLM (bc_out) + ivar = 0 + ! 2D arrays ivar = ivar + 1 - this%api_str(ivar) = 'decomp_frac_temperature' - this%hlm_var_2darray(ivar)%hlm_var => col_cf%t_scalar + this%bc_out(ivar)%api_str = 'decomp_cpools_met' + this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_met_lit) + + ivar = ivar + 1 + this%bc_out(ivar)%api_str = 'decomp_cpools_cel' + this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_cel_lit) + + ivar = ivar + 1 + this%bc_out(ivar)%api_str = 'decomp_cpools_lig' + this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_lig_lit) + + this%bc_out%num_hlmvar = ivar ! 3D arrays + ! TODO: is this really helpful since we'd hit out of bounds issues prior to this? ! Check that the number of variables set matches ! specifically in the case in which the number set ! is lower than the allocated amount - if (ivar /= num_hlmvar) then + if (this%bc_out%num_hlmvar /= num_bc_out .or. this%bc_in%num_hlmvar /= num_bc_in) then write(iulog,*) 'FATES API: Number of API variables does not match the expected array size' call endrun(msg=errMsg(sourcefile, __LINE__)) - else - this%num_hlmvar = num_hlmvar end if end subroutine InitAndSetAPIAssociation @@ -3775,9 +3799,9 @@ subroutine WrapTransferBCIn(this, nc) integer :: s, ivar ! indices and loop counters do s = 1, this%fates(nc)%nsites - do ivar = 1,this%num_hlmvar - call this%fates(nc)%sites(s)%TransferBCIn(this%api_str(ivar), & - this%hlm_var_2darray(ivar)%hlm_var) + do ivar = 1,this%bc_in%num_hlmvar + call this%fates(nc)%sites(s)%TransferBCIn(this%bc_in(ivar)%api_str, & + this%bc_in(ivar)%hlm_var) end do end do @@ -3802,9 +3826,9 @@ subroutine WrapTransferBCOut(this, nc) integer :: s, ivar ! indices and loop counters do s = 1, this%fates(nc)%nsites - do ivar = 1,this%num_hlmvar - call this%fates(nc)%sites(s)%TransferBCOut(this%api_str(ivar), & - this%hlm_var_2darray(ivar)%hlm_var) + do ivar = 1,this%bc_out%num_hlmvar + call this%fates(nc)%sites(s)%TransferBCIn(this%bc_out(ivar)%api_str, & + this%bc_out(ivar)%hlm_var) end do end do From 41e4105fe85053fe8ae91acb4d306553e4e71141 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 11:20:50 -0700 Subject: [PATCH 030/124] remove now unsed bc_out from fluxintolitterpools --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index e063e02642c9..aa9a26f5a87b 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1995,6 +1995,12 @@ subroutine restart( this, bounds_proc, ncid, flag, & this%fates(nc)%bc_out(s), & is_restarting = .true.) + ! This call sends internal fates variables into the + ! output boundary condition structures. Note: this is called + ! internally in fates dynamics as well. + + call FluxIntoLitterPools(this%fates(nc)%sites(s), & + this%fates(nc)%bc_in(s)) end do if(use_fates_sp)then From 451814c0d7223af3655d0ae28d25e3542c9cb7d5 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 11:21:35 -0700 Subject: [PATCH 031/124] again remove now unused bc_out from fluxintolitterpools --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index aa9a26f5a87b..cdbb9403f435 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2248,6 +2248,12 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in this%fates(nc)%bc_out(s), & is_restarting = .false.) + ! This call sends internal fates variables into the + ! output boundary condition structures. Note: this is called + ! internally in fates dynamics as well. + + call FluxIntoLitterPools(this%fates(nc)%sites(s), & + this%fates(nc)%bc_in(s)) end do ! ------------------------------------------------------------------------ From dda4064284a0ccb62fa9238bdde1a52e7b208767 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 11:22:43 -0700 Subject: [PATCH 032/124] fix logic check --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index cdbb9403f435..fbda02fa5eea 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3604,7 +3604,7 @@ subroutine InitAndSetAPIAssociation(this) ! Check that the number of variables set matches ! specifically in the case in which the number set ! is lower than the allocated amount - if (this%bc_out%num_hlmvar /= num_bc_out .or. this%bc_in%num_hlmvar /= num_bc_in) then + if ((this%bc_out%num_hlmvar /= num_bc_out) .or. (this%bc_in%num_hlmvar /= num_bc_in)) then write(iulog,*) 'FATES API: Number of API variables does not match the expected array size' call endrun(msg=errMsg(sourcefile, __LINE__)) end if From 9fdea167b3d6c138024e6616be28129945995e6a Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 11:27:22 -0700 Subject: [PATCH 033/124] define string length and comment out unused procedure definition --- components/elm/src/main/elmfates_interfaceMod.F90 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index fbda02fa5eea..35d0eeec66a2 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -225,9 +225,9 @@ module ELMFatesInterfaceMod contains procedure, public :: SetPatchIndex - procedure, public :: GetPatchIndex + ! procedure, public :: GetPatchIndex procedure, public :: GetColumnIndex - procedure, public :: GetLandunitIndex + ! procedure, public :: GetLandunitIndex end type f2hmap_type @@ -239,7 +239,7 @@ module ELMFatesInterfaceMod ! This is the array that contains the common API vocabulary ! between FATES and the host land model. - character(len=:) :: api_str + character(len=24) :: api_str ! This is the number of HLM variables that are being passed to FATES integer :: num_hlmvar @@ -3557,7 +3557,6 @@ subroutine InitAndSetAPIAssociation(this) ! !LOCAL: integer :: ivar ! array index - integer, parameter :: max_string_length = 24 ! maximum length of common vocab string integer, parameter :: num_bc_in = 2 ! number of HLM variables integer, parameter :: num_bc_out = 3 ! number of HLM variables From 029127cf6e1a541dbe96d920f48f9143b579d732 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 11:39:48 -0700 Subject: [PATCH 034/124] restore hsites and fcolumns to f2hmap type --- .../elm/src/main/elmfates_interfaceMod.F90 | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 35d0eeec66a2..fd012b66eb0f 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -221,6 +221,13 @@ module ELMFatesInterfaceMod ! HLM patch index to FATES patchno index mapping, by site integer, allocatable :: hlm_patch_index(:,:) + + ! This is the associated column index of each FATES site - to be deprecated + integer, allocatable :: fcolumn (:) + + ! This is the associated site index of any HLM columns - to be deprecated + ! This vector may be sparse, and non-sites have index 0 + integer, allocatable :: hsites (:) contains @@ -939,22 +946,31 @@ subroutine init(this, bounds_proc, flandusepftdat) do nc = 1,nclumps call get_clump_bounds(nc, bounds_clump) - ! nmaxcol = bounds_clump%endc - bounds_clump%begc + 1 + nmaxcol = bounds_clump%endc - bounds_clump%begc + 1 - ! allocate(collist(1:nmaxcol)) + allocate(collist(1:nmaxcol)) ! Allocate the mapping that points columns to FATES sites, 0 is NA - ! allocate(this%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc)) + allocate(this%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc)) ! Initialize all columns with a zero index, which indicates no FATES site - ! this%f2hmap(nc)%hsites(:) = 0 + this%f2hmap(nc)%hsites(:) = 0 ! Determine the number of FATES site based of the clumping ! This assumes one site per landunit currently. + s = 0 num_landunits_veg = 0 do l = bounds_clump%begl,bounds_clump%endl if (lun_pp%itype(l) == istsoil) then + num_landunits_veg = num_landunits_veg + 1 + + ! To be deprecated/refactored + s = s + 1 + collist(s) = c + this%f2hmap(nc)%hsites(c) = s + col_pp%is_fates(c) = .true. + if(debug)then ! write(iulog,*) 'alm_fates%init(): thread',nc,': found column',c,'with lu',l write(iulog,*) 'LU type:', lun_pp%itype(l) @@ -963,7 +979,20 @@ subroutine init(this, bounds_proc, flandusepftdat) enddo ! TODO Add adjustment to fates calculation here based on multi-column FATES options - s = num_landunits_veg + ! s = num_landunits_veg + + ! Allocate vectors that match FATES sites with HLM columns + ! RGK: Sites and fcolumns are forced as args during clm_driv() as of 6/4/2016 + ! We may have to give these a dummy allocation of 1, which should + ! not be a problem since we always iterate on nsites. + + allocate(this%f2hmap(nc)%fcolumn(s)) + + ! Assign the h2hmap indexing + this%f2hmap(nc)%fcolumn(1:s) = collist(1:s) + + ! Deallocate the temporary arrays + deallocate(collist) if(debug)then write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' From 15f48ccc1fd43b3a04f95b32793f52ff6b52a1fa Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 12:03:24 -0700 Subject: [PATCH 035/124] fix num landunits definiton --- components/elm/src/main/elmfates_interfaceMod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index fd012b66eb0f..1a3a2412b1e6 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -902,6 +902,7 @@ subroutine init(this, bounds_proc, flandusepftdat) integer :: nmaxcol integer :: ndecomp integer :: numg + integer :: num_landunits_veg real(r8), allocatable :: landuse_pft_map(:,:,:) real(r8), allocatable :: landuse_bareground(:) From b029dc51f98dbb27b5e36153344819ab2d5b2efb Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 12:04:02 -0700 Subject: [PATCH 036/124] move num_hlmvars --- .../elm/src/main/elmfates_interfaceMod.F90 | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 1a3a2412b1e6..fc5e81935eef 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -248,9 +248,6 @@ module ELMFatesInterfaceMod ! between FATES and the host land model. character(len=24) :: api_str - ! This is the number of HLM variables that are being passed to FATES - integer :: num_hlmvar - end type hlm_fates_api_var_type @@ -283,6 +280,10 @@ module ELMFatesInterfaceMod ! common variable name type(hlm_fates_api_var_type), allocatable :: bc_in(:) type(hlm_fates_api_var_type), allocatable :: bc_out(:) + + ! This is the number of HLM variables that are being passed in and out of FATES + integer, public :: num_hlmvar_in, num_hlmvar_out + contains @@ -3607,7 +3608,7 @@ subroutine InitAndSetAPIAssociation(this) this%bc_in(ivar)%api_str = 'decomp_frac_temperature' this%bc_in(ivar)%hlm_var => col_cf%t_scalar(:,:) - this%bc_in%num_hlmvar = ivar + this%num_hlmvar_in = ivar ! ! FATES -> HLM (bc_out) ivar = 0 @@ -3625,7 +3626,7 @@ subroutine InitAndSetAPIAssociation(this) this%bc_out(ivar)%api_str = 'decomp_cpools_lig' this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_lig_lit) - this%bc_out%num_hlmvar = ivar + this%num_hlmvar_out = ivar ! 3D arrays @@ -3633,7 +3634,7 @@ subroutine InitAndSetAPIAssociation(this) ! Check that the number of variables set matches ! specifically in the case in which the number set ! is lower than the allocated amount - if ((this%bc_out%num_hlmvar /= num_bc_out) .or. (this%bc_in%num_hlmvar /= num_bc_in)) then + if ((this%num_hlmvar_out /= num_bc_out) .or. (this%num_hlmvar_in /= num_bc_in)) then write(iulog,*) 'FATES API: Number of API variables does not match the expected array size' call endrun(msg=errMsg(sourcefile, __LINE__)) end if @@ -3840,7 +3841,7 @@ subroutine WrapTransferBCIn(this, nc) integer :: s, ivar ! indices and loop counters do s = 1, this%fates(nc)%nsites - do ivar = 1,this%bc_in%num_hlmvar + do ivar = 1,this%num_hlmvar_in call this%fates(nc)%sites(s)%TransferBCIn(this%bc_in(ivar)%api_str, & this%bc_in(ivar)%hlm_var) end do @@ -3867,7 +3868,7 @@ subroutine WrapTransferBCOut(this, nc) integer :: s, ivar ! indices and loop counters do s = 1, this%fates(nc)%nsites - do ivar = 1,this%bc_out%num_hlmvar + do ivar = 1,this%num_hlmvar_out call this%fates(nc)%sites(s)%TransferBCIn(this%bc_out(ivar)%api_str, & this%bc_out(ivar)%hlm_var) end do @@ -4156,7 +4157,7 @@ integer function GetColumnIndex(this,ifp,s) result(ifc) ! This subroutine gets the mapping between the FATES patches and HLM columns ! ------------------------------------------------------------------------ - type(f2hmap_type), intent(inout) :: this + class(f2hmap_type), intent(inout) :: this integer :: ifp ! FATES bc_in/out patch dimension index integer :: s ! FATES site index @@ -4173,7 +4174,7 @@ subroutine SetPatchIndex(this,bounds_clump) ! This subroutine sets the mapping between the FATES and HLM patches ! ------------------------------------------------------------------------ - type(f2hmap_type), intent(inout) :: this + class(f2hmap_type), intent(inout) :: this type(bounds_type), intent(in) :: bounds_clump integer :: s ! FATES site index From f332c66253fe9860c9e0ba67d80fe2637dc5362d Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 12 Aug 2025 15:40:26 -0700 Subject: [PATCH 037/124] add argument to pass time step size to fates for time conversions --- components/elm/src/main/elmfates_interfaceMod.F90 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index fc5e81935eef..06f696bd584d 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3851,7 +3851,7 @@ end subroutine WrapTransferBCIn ! ====================================================================================== - subroutine WrapTransferBCOut(this, nc) + subroutine WrapTransferBCOut(this, nc, dtime) ! !DESCRIPTION: ! --------------------------------------------------------------------------------- @@ -3866,11 +3866,15 @@ subroutine WrapTransferBCOut(this, nc) ! !LOCAL: integer :: s, ivar ! indices and loop counters - + real(r8) :: dtime ! step size to pass to FATES to handle timestep conversions + + ! Get the step size in seconds + dtime = real(get_step_size(),r8) + do s = 1, this%fates(nc)%nsites do ivar = 1,this%num_hlmvar_out call this%fates(nc)%sites(s)%TransferBCIn(this%bc_out(ivar)%api_str, & - this%bc_out(ivar)%hlm_var) + this%bc_out(ivar)%hlm_var, dtime) end do end do From 3749b4a4712a7c2e12c4dc75659702ad035e0074 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 21 Aug 2025 16:47:01 -0700 Subject: [PATCH 038/124] remove dtime argument for the wraptransfer as it is available in the subroutine --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 06f696bd584d..432d83b00126 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3851,7 +3851,7 @@ end subroutine WrapTransferBCIn ! ====================================================================================== - subroutine WrapTransferBCOut(this, nc, dtime) + subroutine WrapTransferBCOut(this, nc) ! !DESCRIPTION: ! --------------------------------------------------------------------------------- From e1190a12aa16bb04f2bde18c69f5731aaa76f222 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 21 Aug 2025 17:05:38 -0700 Subject: [PATCH 039/124] Setup call to bcout transfer --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 432d83b00126..0318550e366a 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2032,8 +2032,11 @@ subroutine restart( this, bounds_proc, ncid, flag, & call FluxIntoLitterPools(this%fates(nc)%sites(s), & this%fates(nc)%bc_in(s)) + end do + ! call this%WrapTransferBCOut(nc, dtime) + if(use_fates_sp)then do s = 1,this%fates(nc)%nsites c = this%f2hmap(nc)%fcolumn(s) From cf27f7ed119d0d14f7c884f8e982a327dbd138b4 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 22 Aug 2025 10:44:58 -0700 Subject: [PATCH 040/124] correct transfer call in wraptransfer bcout --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 0318550e366a..fa28c227d763 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3876,7 +3876,7 @@ subroutine WrapTransferBCOut(this, nc) do s = 1, this%fates(nc)%nsites do ivar = 1,this%num_hlmvar_out - call this%fates(nc)%sites(s)%TransferBCIn(this%bc_out(ivar)%api_str, & + call this%fates(nc)%sites(s)%TransferBCOut(this%bc_out(ivar)%api_str, & this%bc_out(ivar)%hlm_var, dtime) end do end do From fdef6cc01d249c7f6d92a2fe9faf45a526a3dff4 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sat, 23 Aug 2025 14:32:49 -0700 Subject: [PATCH 041/124] add the decomposition level to the values to be passed to FATES --- components/elm/src/main/elmfates_interfaceMod.F90 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index fa28c227d763..e6f5cf604c21 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3591,7 +3591,7 @@ subroutine InitAndSetAPIAssociation(this) ! !LOCAL: integer :: ivar ! array index - integer, parameter :: num_bc_in = 2 ! number of HLM variables + integer, parameter :: num_bc_in = 3 ! number of HLM variables integer, parameter :: num_bc_out = 3 ! number of HLM variables ! Allocate the arrays @@ -3602,6 +3602,11 @@ subroutine InitAndSetAPIAssociation(this) ivar = 0 ! ! HLM -> FATES (bc_in) + ! Scalar data + ivar = ivar + 1 + this%bc_in(ivar)%api_str = 'nlevdecomp' + this%bc_in(ivar)%hlm_var => nlevdecomp + ! 2D arrays ivar = ivar + 1 this%bc_in(ivar)%api_str = 'decomp_frac_moisture' From 0689e19cfdf04208f36a2ea26117216bcea9fbeb Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 27 Aug 2025 16:56:02 -0700 Subject: [PATCH 042/124] update fates and add call to interface registry initialization and pass data to be registered --- .../elm/src/main/elmfates_interfaceMod.F90 | 114 ++++-------------- 1 file changed, 24 insertions(+), 90 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index e6f5cf604c21..03568bec816c 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -238,19 +238,6 @@ module ELMFatesInterfaceMod end type f2hmap_type - type, public :: hlm_fates_api_var_type - - ! This is the pointer to the host land model variable - ! data associated with the common API vocabulary string - real(r8), pointer :: hlm_var(:,:) - - ! This is the array that contains the common API vocabulary - ! between FATES and the host land model. - character(len=24) :: api_str - - end type hlm_fates_api_var_type - - type, public :: hlm_fates_interface_type ! See above for descriptions of the sub-types populated @@ -307,7 +294,7 @@ module ELMFatesInterfaceMod procedure, public :: Init2 ! Initialization after determining subgrid weights procedure, public :: InitAccBuffer ! Initialize any accumulation buffers procedure, public :: InitAccVars ! Initialize any accumulation variables - procedure, public :: InitAndSetAPIAssociation + procedure, public :: RegisterHLMInterfaceVariables procedure, public :: UpdateAccVars ! Update any accumulation variables procedure, public :: UpdateLitterFluxes procedure, private :: init_history_io @@ -947,6 +934,9 @@ subroutine init(this, bounds_proc, flandusepftdat) !$OMP PARALLEL DO PRIVATE (nc,bounds_clump,nmaxcol,s,c,l,g,collist,pi,pf,ft) do nc = 1,nclumps + ! Register HLM variables to the interface registry + call this%RegisterHLMInterfaceVariables(nc) + call get_clump_bounds(nc, bounds_clump) nmaxcol = bounds_clump%endc - bounds_clump%begc + 1 @@ -1046,7 +1036,7 @@ subroutine init(this, bounds_proc, flandusepftdat) else ndecomp = 1 end if - + call allocate_bcin(this%fates(nc)%bc_in(s), col_pp%nlevbed(c), ndecomp, & num_harvest_vars, num_landuse_state_vars, num_landuse_transition_vars, & surfpft_lb, surfpft_ub) @@ -3574,81 +3564,6 @@ subroutine init_soil_depths(this, nc) return end subroutine init_soil_depths -! ====================================================================================== - - subroutine InitAndSetAPIAssociation(this) - - ! !DESCRIPTION: - ! --------------------------------------------------------------------------------- - ! This subroutine sets the association between the hlm variables and the common API - ! vocabulary strings. - ! --------------------------------------------------------------------------------- - - ! !USES: - - ! !ARGUMENTS: - class(hlm_fates_interface_type), intent(inout) :: this - - ! !LOCAL: - integer :: ivar ! array index - integer, parameter :: num_bc_in = 3 ! number of HLM variables - integer, parameter :: num_bc_out = 3 ! number of HLM variables - - ! Allocate the arrays - allocate(this%bc_in(num_bc_in)) - allocate(this%bc_out(num_bc_out)) - - ! Increment through the arrays and assign HLM variables to common API vocab - ivar = 0 - - ! ! HLM -> FATES (bc_in) - ! Scalar data - ivar = ivar + 1 - this%bc_in(ivar)%api_str = 'nlevdecomp' - this%bc_in(ivar)%hlm_var => nlevdecomp - - ! 2D arrays - ivar = ivar + 1 - this%bc_in(ivar)%api_str = 'decomp_frac_moisture' - this%bc_in(ivar)%hlm_var => col_cf%w_scalar(:,:) - - ivar = ivar + 1 - this%bc_in(ivar)%api_str = 'decomp_frac_temperature' - this%bc_in(ivar)%hlm_var => col_cf%t_scalar(:,:) - - this%num_hlmvar_in = ivar - - ! ! FATES -> HLM (bc_out) - ivar = 0 - - ! 2D arrays - ivar = ivar + 1 - this%bc_out(ivar)%api_str = 'decomp_cpools_met' - this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_met_lit) - - ivar = ivar + 1 - this%bc_out(ivar)%api_str = 'decomp_cpools_cel' - this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_cel_lit) - - ivar = ivar + 1 - this%bc_out(ivar)%api_str = 'decomp_cpools_lig' - this%bc_out(ivar)%hlm_var => col_cf%decomp_cpools_sourcesink(:,:,i_lig_lit) - - this%num_hlmvar_out = ivar - - ! 3D arrays - - ! TODO: is this really helpful since we'd hit out of bounds issues prior to this? - ! Check that the number of variables set matches - ! specifically in the case in which the number set - ! is lower than the allocated amount - if ((this%num_hlmvar_out /= num_bc_out) .or. (this%num_hlmvar_in /= num_bc_in)) then - write(iulog,*) 'FATES API: Number of API variables does not match the expected array size' - call endrun(msg=errMsg(sourcefile, __LINE__)) - end if - - end subroutine InitAndSetAPIAssociation - ! ====================================================================================== subroutine ComputeRootSoilFlux(this, bounds_clump, num_filterc, filterc, & @@ -4210,4 +4125,23 @@ subroutine SetPatchIndex(this,bounds_clump) end subroutine SetPatchIndex +! ====================================================================================== + + subroutine RegisterHLMInterfaceVariables(this, nc) + + class(hlm_fates_interface_type) :: this + + integer, intent(in) :: nc ! clump number + + ! Initialize the HLM-FATES interface variable registry + call this%fates(nc)%InitializeInterfaceRegistry() + + ! Register the HLM data + call this%fates(nc)%Register(vname='decomp_frac_moisture', data=col_cf%w_scalar) + call this%fates(nc)%Register(vname='decomp_frac_temperature', data=col_cf%t_scalar) + + end subroutine RegisterHLMInterfaceVariables + +! ====================================================================================== + end module ELMFatesInterfaceMod From 19346ca37bcaebd826d660d239aaa882520bd315 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 29 Aug 2025 15:27:31 -0700 Subject: [PATCH 043/124] correct argument call in HLM registry procedure --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 03568bec816c..c7998b3aedc8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4137,8 +4137,8 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%InitializeInterfaceRegistry() ! Register the HLM data - call this%fates(nc)%Register(vname='decomp_frac_moisture', data=col_cf%w_scalar) - call this%fates(nc)%Register(vname='decomp_frac_temperature', data=col_cf%t_scalar) + call this%fates(nc)%Register(key='decomp_frac_moisture', data=col_cf%w_scalar) + call this%fates(nc)%Register(key='decomp_frac_temperature', data=col_cf%t_scalar) end subroutine RegisterHLMInterfaceVariables From 71b6077e6675fd4d52d8c2f4b02e5bec00085f83 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 29 Aug 2025 16:43:10 -0700 Subject: [PATCH 044/124] temporarily comment out old hlm registry and transfer procedures --- .../elm/src/main/elmfates_interfaceMod.F90 | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index c7998b3aedc8..71fecd39746e 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -265,8 +265,8 @@ module ELMFatesInterfaceMod ! This is the array of pointer to the host land model data and its associated ! common variable name - type(hlm_fates_api_var_type), allocatable :: bc_in(:) - type(hlm_fates_api_var_type), allocatable :: bc_out(:) + ! type(hlm_fates_api_var_type), allocatable :: bc_in(:) + ! type(hlm_fates_api_var_type), allocatable :: bc_out(:) ! This is the number of HLM variables that are being passed in and out of FATES integer, public :: num_hlmvar_in, num_hlmvar_out @@ -305,8 +305,8 @@ module ELMFatesInterfaceMod procedure, public :: WrapUpdateFatesRmean procedure, public :: WrapGlobalSeedDispersal procedure, public :: WrapUpdateFatesSeedInOut - procedure, public :: WrapTransferBCIn - procedure, public :: WrapTransferBCOut + ! procedure, public :: WrapTransferBCIn + ! procedure, public :: WrapTransferBCOut end type hlm_fates_interface_type @@ -922,7 +922,7 @@ subroutine init(this, bounds_proc, flandusepftdat) end if ! Initialize the fates to host land model API variable mapping - call this%InitAndSetAPIAssociation() + ! call this%InitAndSetAPIAssociation() ! Retrieve the landuse x pft static data if the optional switch has been set if (use_fates_fixed_biogeog .and. use_fates_luh) then @@ -1250,7 +1250,7 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & end if ! Transfer decomposition fluxes to the FATES patch data structure - call this%WrapTransferBCIn(nc) + ! call this%WrapTransferBCIn(nc) do s=1,this%fates(nc)%nsites @@ -3747,61 +3747,61 @@ end subroutine wrap_hydraulics_drive ! ====================================================================================== - subroutine WrapTransferBCIn(this, nc) +! subroutine WrapTransferBCIn(this, nc) - ! !DESCRIPTION: - ! --------------------------------------------------------------------------------- - ! This call passes the HLM inputs to FATES patch-level boundary conditions - ! --------------------------------------------------------------------------------- +! ! !DESCRIPTION: +! ! --------------------------------------------------------------------------------- +! ! This call passes the HLM inputs to FATES patch-level boundary conditions +! ! --------------------------------------------------------------------------------- - ! !USES: - ! - ! !ARGUMENTS: - class(hlm_fates_interface_type), intent(inout) :: this - integer, intent(in) :: nc +! ! !USES: +! ! +! ! !ARGUMENTS: +! class(hlm_fates_interface_type), intent(inout) :: this +! integer, intent(in) :: nc - ! !LOCAL: - integer :: s, ivar ! indices and loop counters +! ! !LOCAL: +! integer :: s, ivar ! indices and loop counters - do s = 1, this%fates(nc)%nsites - do ivar = 1,this%num_hlmvar_in - call this%fates(nc)%sites(s)%TransferBCIn(this%bc_in(ivar)%api_str, & - this%bc_in(ivar)%hlm_var) - end do - end do +! do s = 1, this%fates(nc)%nsites +! do ivar = 1,this%num_hlmvar_in +! call this%fates(nc)%sites(s)%TransferBCIn(this%bc_in(ivar)%api_str, & +! this%bc_in(ivar)%hlm_var) +! end do +! end do - end subroutine WrapTransferBCIn +! end subroutine WrapTransferBCIn -! ====================================================================================== +! ! ====================================================================================== - subroutine WrapTransferBCOut(this, nc) +! subroutine WrapTransferBCOut(this, nc) - ! !DESCRIPTION: - ! --------------------------------------------------------------------------------- - ! This call passes the HLM inputs to FATES patch-level boundary conditions - ! --------------------------------------------------------------------------------- +! ! !DESCRIPTION: +! ! --------------------------------------------------------------------------------- +! ! This call passes the HLM inputs to FATES patch-level boundary conditions +! ! --------------------------------------------------------------------------------- - ! !USES: - ! - ! !ARGUMENTS: - class(hlm_fates_interface_type), intent(inout) :: this - integer, intent(in) :: nc +! ! !USES: +! ! +! ! !ARGUMENTS: +! class(hlm_fates_interface_type), intent(inout) :: this +! integer, intent(in) :: nc - ! !LOCAL: - integer :: s, ivar ! indices and loop counters - real(r8) :: dtime ! step size to pass to FATES to handle timestep conversions +! ! !LOCAL: +! integer :: s, ivar ! indices and loop counters +! real(r8) :: dtime ! step size to pass to FATES to handle timestep conversions - ! Get the step size in seconds - dtime = real(get_step_size(),r8) +! ! Get the step size in seconds +! dtime = real(get_step_size(),r8) - do s = 1, this%fates(nc)%nsites - do ivar = 1,this%num_hlmvar_out - call this%fates(nc)%sites(s)%TransferBCOut(this%bc_out(ivar)%api_str, & - this%bc_out(ivar)%hlm_var, dtime) - end do - end do +! do s = 1, this%fates(nc)%nsites +! do ivar = 1,this%num_hlmvar_out +! call this%fates(nc)%sites(s)%TransferBCOut(this%bc_out(ivar)%api_str, & +! this%bc_out(ivar)%hlm_var, dtime) +! end do +! end do - end subroutine WrapTransferBCOut +! end subroutine WrapTransferBCOut ! ====================================================================================== From a7bbbaa4f3981ba8568ba1315f55fdb3c9f228dc Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 2 Sep 2025 12:36:32 -0700 Subject: [PATCH 045/124] reinstate public to f2hmap type --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 71fecd39746e..4c4d57509d86 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -217,7 +217,7 @@ module ELMFatesInterfaceMod implicit none - type :: f2hmap_type + type, public :: f2hmap_type ! HLM patch index to FATES patchno index mapping, by site integer, allocatable :: hlm_patch_index(:,:) From 2b1c8102064feabaa656c944c0f6097114fbc522 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 2 Sep 2025 14:22:18 -0700 Subject: [PATCH 046/124] temporarily revert back to previous fates initialization method --- components/elm/src/main/elmfates_interfaceMod.F90 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 4c4d57509d86..7ff160444319 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -952,12 +952,15 @@ subroutine init(this, bounds_proc, flandusepftdat) ! This assumes one site per landunit currently. s = 0 num_landunits_veg = 0 - do l = bounds_clump%begl,bounds_clump%endl - if (lun_pp%itype(l) == istsoil) then + do c = bounds_clump%begc,bounds_clump%endc + l = col_pp%landunit(c) + ! do l = bounds_clump%begl,bounds_clump%endl + ! if (lun_pp%itype(l) == istsoil) then - num_landunits_veg = num_landunits_veg + 1 + ! num_landunits_veg = num_landunits_veg + 1 ! To be deprecated/refactored + if ( (lun_pp%itype(l) == istsoil) .and. (col_pp%active(c)) ) then s = s + 1 collist(s) = c this%f2hmap(nc)%hsites(c) = s @@ -4137,8 +4140,8 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%InitializeInterfaceRegistry() ! Register the HLM data - call this%fates(nc)%Register(key='decomp_frac_moisture', data=col_cf%w_scalar) - call this%fates(nc)%Register(key='decomp_frac_temperature', data=col_cf%t_scalar) + call this%fates(nc)%Register('decomp_frac_moisture', col_cf%w_scalar) + call this%fates(nc)%Register('decomp_frac_temperature', col_cf%t_scalar) end subroutine RegisterHLMInterfaceVariables From b42ac0954c8d82f2c12c724773fac9f4cdc693ca Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 2 Sep 2025 14:47:08 -0700 Subject: [PATCH 047/124] temporarily reinstate bcout to fluxintolitterpools --- components/elm/src/main/elmfates_interfaceMod.F90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 7ff160444319..7f5716820b1c 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2024,7 +2024,7 @@ subroutine restart( this, bounds_proc, ncid, flag, & ! internally in fates dynamics as well. call FluxIntoLitterPools(this%fates(nc)%sites(s), & - this%fates(nc)%bc_in(s)) + this%fates(nc)%bc_in(s), this%fates(nc)%bc_out(s)) end do @@ -2280,7 +2280,8 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in ! internally in fates dynamics as well. call FluxIntoLitterPools(this%fates(nc)%sites(s), & - this%fates(nc)%bc_in(s)) + this%fates(nc)%bc_in(s), & + this%fates(nc)%bc_out(s)) end do ! ------------------------------------------------------------------------ From 1cf57c06e189d72a10f6a18456c127f254908141 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 3 Sep 2025 16:20:38 -0700 Subject: [PATCH 048/124] update the call to the api registration procedure --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 7f5716820b1c..6ca0161a00c3 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4138,11 +4138,11 @@ subroutine RegisterHLMInterfaceVariables(this, nc) integer, intent(in) :: nc ! clump number ! Initialize the HLM-FATES interface variable registry - call this%fates(nc)%InitializeInterfaceRegistry() + call this%fates(nc)%api%InitializeInterfaceRegistry() ! Register the HLM data - call this%fates(nc)%Register('decomp_frac_moisture', col_cf%w_scalar) - call this%fates(nc)%Register('decomp_frac_temperature', col_cf%t_scalar) + call this%fates(nc)%api%Register('decomp_frac_moisture', col_cf%w_scalar) + call this%fates(nc)%api%Register('decomp_frac_temperature', col_cf%t_scalar) end subroutine RegisterHLMInterfaceVariables From 9b3d673d82899d7ba67f4b2b7a59cc93c3784e5d Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 9 Sep 2025 15:41:04 -0700 Subject: [PATCH 049/124] add call to update the fates interface variables at the start of the dynamics driver --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 6ca0161a00c3..a6b47dfd27ef 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1234,6 +1234,9 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & ! Set the FATES global time and date variables call GetAndSetTime + ! Update boundary conditions that change on a daily basis + call this%fates(nc)%UpdateInterfaceVariables() + if (fates_spitfire_mode > scalar_lightning) then allocate(lnfm24(bounds_clump%begg:bounds_clump%endg), stat=ier) if (ier /= 0) then From 305ae097fb68beb2849cfdfbd31a68fb6c583dc2 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 10 Sep 2025 17:23:23 -0700 Subject: [PATCH 050/124] update the registration call to pass in the appropriate subgrid index value --- components/elm/src/main/elmfates_interfaceMod.F90 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index a6b47dfd27ef..b82b7f571e1f 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4140,12 +4140,19 @@ subroutine RegisterHLMInterfaceVariables(this, nc) integer, intent(in) :: nc ! clump number + ! Subgrid levels for HLM-FATES interface variables + integer, parameter, private :: subgrid_gridcell = 5 + integer, parameter, private :: subgrid_topounit = 4 + integer, parameter, private :: subgrid_landunit = 3 + integer, parameter, private :: subgrid_column = 2 + integer, parameter, private :: subgrid_patch = 1 + ! Initialize the HLM-FATES interface variable registry call this%fates(nc)%api%InitializeInterfaceRegistry() ! Register the HLM data - call this%fates(nc)%api%Register('decomp_frac_moisture', col_cf%w_scalar) - call this%fates(nc)%api%Register('decomp_frac_temperature', col_cf%t_scalar) + call this%fates(nc)%api%Register('decomp_frac_moisture', col_cf%w_scalar, subgrid_column) + call this%fates(nc)%api%Register('decomp_frac_temperature', col_cf%t_scalar, subgrid_column) end subroutine RegisterHLMInterfaceVariables From 87fb25d79101d228dd5be1c85008677321be21d2 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 11 Sep 2025 22:52:36 -0700 Subject: [PATCH 051/124] move subgrid heirarchy values into fates interface types mod --- components/elm/src/main/elmfates_interfaceMod.F90 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b82b7f571e1f..601bab64aba7 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4136,17 +4136,12 @@ end subroutine SetPatchIndex subroutine RegisterHLMInterfaceVariables(this, nc) + use FatesInterfaceTypesMod, only : subgrid_column + class(hlm_fates_interface_type) :: this integer, intent(in) :: nc ! clump number - ! Subgrid levels for HLM-FATES interface variables - integer, parameter, private :: subgrid_gridcell = 5 - integer, parameter, private :: subgrid_topounit = 4 - integer, parameter, private :: subgrid_landunit = 3 - integer, parameter, private :: subgrid_column = 2 - integer, parameter, private :: subgrid_patch = 1 - ! Initialize the HLM-FATES interface variable registry call this%fates(nc)%api%InitializeInterfaceRegistry() From 2d558275a0c8a6bc1dfcfdb8f7771b5d370b4c02 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 12 Sep 2025 10:21:39 -0700 Subject: [PATCH 052/124] add intent for register interface variables --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 601bab64aba7..68b3d936c930 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4138,7 +4138,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc) use FatesInterfaceTypesMod, only : subgrid_column - class(hlm_fates_interface_type) :: this + class(hlm_fates_interface_type), intent(inout) :: this integer, intent(in) :: nc ! clump number From a135dcd010faaecc6923e2a8f72bef3d794dbd08 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 12 Sep 2025 14:38:14 -0700 Subject: [PATCH 053/124] update procedure to use parameter interface key variables --- components/elm/src/main/elmfates_interfaceMod.F90 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 68b3d936c930..644ef7418750 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4136,7 +4136,10 @@ end subroutine SetPatchIndex subroutine RegisterHLMInterfaceVariables(this, nc) - use FatesInterfaceTypesMod, only : subgrid_column + use FatesInterfaceTypesMod, only : hlm_fates_soil_level + use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture + use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_temperature + class(hlm_fates_interface_type), intent(inout) :: this @@ -4146,9 +4149,10 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%api%InitializeInterfaceRegistry() ! Register the HLM data - call this%fates(nc)%api%Register('decomp_frac_moisture', col_cf%w_scalar, subgrid_column) - call this%fates(nc)%api%Register('decomp_frac_temperature', col_cf%t_scalar, subgrid_column) - + call this%fates(nc)%api%Register(hlm_fates_soil_level, col_pp%nlevbed, subgrid_column_index) + call this%fates(nc)%api%Register(hlm_fates_decomp_frac_moisture, col_cf%w_scalar, subgrid_column_index) + call this%fates(nc)%api%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar, subgrid_column_index) + end subroutine RegisterHLMInterfaceVariables ! ====================================================================================== From aebc618a645145b89502a36c95074c3aa45ae9a9 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 12 Sep 2025 14:39:20 -0700 Subject: [PATCH 054/124] change subgrid type name to reflect fates-side update --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 644ef7418750..5cc0e707cfe3 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4136,6 +4136,8 @@ end subroutine SetPatchIndex subroutine RegisterHLMInterfaceVariables(this, nc) + use FatesInterfaceTypesMod, only : subgrid_column_index + use FatesInterfaceTypesMod, only : hlm_fates_soil_level use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_temperature From 0dc3a3fe9f1c337336fb15d94247ec87921af981 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 12 Sep 2025 16:29:09 -0700 Subject: [PATCH 055/124] update column map assignment This will need to be fleshed out to be agnostic to number of columns per landunit --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 5cc0e707cfe3..549eabb4bb7d 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1027,9 +1027,10 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Allocate HLM-FATES mapping arrays ! TODO: update this to be agnostic to fates column run mode allocate(this%fates(nc)%sites(s)%column_map(1)) - allocate(this%fates(nc)%sites(s)%patch_map(natpft_size)) + ! allocate(this%fates(nc)%sites(s)%patch_map(natpft_size)) ! TODO: Assign column_map and patch_map values + this%fates(nc)%sites(s)%column_map(1) = this%f2hmap(nc)%GetColumnIndex(1,s) c = this%f2hmap(nc)%fcolumn(s) this%fates(nc)%sites(s)%h_gid = c From 0cb0d9062422010a9a6e297d214855fb65618bb5 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 19 Sep 2025 13:07:39 -0700 Subject: [PATCH 056/124] move interface API registration after site setup --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 549eabb4bb7d..608604a5ee0f 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -934,9 +934,6 @@ subroutine init(this, bounds_proc, flandusepftdat) !$OMP PARALLEL DO PRIVATE (nc,bounds_clump,nmaxcol,s,c,l,g,collist,pi,pf,ft) do nc = 1,nclumps - ! Register HLM variables to the interface registry - call this%RegisterHLMInterfaceVariables(nc) - call get_clump_bounds(nc, bounds_clump) nmaxcol = bounds_clump%endc - bounds_clump%begc + 1 @@ -1022,6 +1019,9 @@ subroutine init(this, bounds_proc, flandusepftdat) ! This also needs call set_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp) + ! Register HLM variables to the interface registry + call this%RegisterHLMInterfaceVariables(nc) + do s = 1, this%fates(nc)%nsites ! Allocate HLM-FATES mapping arrays From 798944f41f7d161e95187df2b8bec556383d6c20 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 28 Sep 2025 10:33:06 -0700 Subject: [PATCH 057/124] call interface initialization --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 608604a5ee0f..d1e209de65c1 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -996,6 +996,10 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Populate the fates to hlm patch map call this%f2hmap(nc)%SetPatchIndex(bounds_clump) + ! Initialize interface registry + nmaxpatches = bounds_clump%endp - bounds_clump%begp + call this%fates(nc)%InitializeInterfaceRegistry(nmaxpatches) + ! Set the number of FATES sites this%fates(nc)%nsites = s From a7d001fea501a4041998509d545209be1605a090 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 29 Sep 2025 10:47:56 -0700 Subject: [PATCH 058/124] move registration calls and add BC initialization location Also updates the HLMregististration --- .../elm/src/main/elmfates_interfaceMod.F90 | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index d1e209de65c1..dce40333b6af 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -996,10 +996,13 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Populate the fates to hlm patch map call this%f2hmap(nc)%SetPatchIndex(bounds_clump) - ! Initialize interface registry + ! Initialize interface registries for each patch on the clump nmaxpatches = bounds_clump%endp - bounds_clump%begp call this%fates(nc)%InitializeInterfaceRegistry(nmaxpatches) + ! Register the HLM interface variables + call this%RegisterHLMInterfaceVariables(nc, nmaxpatches) + ! Set the number of FATES sites this%fates(nc)%nsites = s @@ -1016,6 +1019,9 @@ subroutine init(this, bounds_proc, flandusepftdat) ! These are staticaly allocated at maximums, so ! No information about the patch or cohort structure is needed at this step + ! Initialize fates boundary conditions arrays + call this%fates(nc)%InitializeBoundaryConditions(natpft_size) + ! Parameter Constants defined by FATES, but used in ELM ! Note that FATES has its parameters defined, so we can also set the values call allocate_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp) @@ -1028,13 +1034,9 @@ subroutine init(this, bounds_proc, flandusepftdat) do s = 1, this%fates(nc)%nsites - ! Allocate HLM-FATES mapping arrays - ! TODO: update this to be agnostic to fates column run mode - allocate(this%fates(nc)%sites(s)%column_map(1)) - ! allocate(this%fates(nc)%sites(s)%patch_map(natpft_size)) - ! TODO: Assign column_map and patch_map values - this%fates(nc)%sites(s)%column_map(1) = this%f2hmap(nc)%GetColumnIndex(1,s) + ! this%fates(nc)%sites(s)%column_map(:) = this%f2hmap(nc)%GetColumnIndex(1,s) + ! this%fates(nc)%sites(s)%patch_map(:) = this%f2hmap(nc)%hlm_patch_index(:,s) c = this%f2hmap(nc)%fcolumn(s) this%fates(nc)%sites(s)%h_gid = c @@ -1050,7 +1052,7 @@ subroutine init(this, bounds_proc, flandusepftdat) surfpft_lb, surfpft_ub) call allocate_bcout(this%fates(nc)%bc_out(s),col_pp%nlevbed(c),ndecomp) call zero_bcs(this%fates(nc),s) - + ! Pass any grid-cell derived attributes to the site ! --------------------------------------------------------------------------- @@ -2271,6 +2273,9 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in call init_patches(this%fates(nc)%nsites, this%fates(nc)%sites, & this%fates(nc)%bc_in) + + ! ! Initialize FATES patch api registries + ! call this%RegisterFatesInterfaceVariables(nc) do s = 1,this%fates(nc)%nsites @@ -4126,7 +4131,7 @@ subroutine SetPatchIndex(this,bounds_clump) do l = bounds_clump%begl,bounds_clump%endl if (lun_pp%itype(l) == istsoil) then s = s + 1 - do ifp = 1,fates_maxPatchesperSite + do ifp = 1, natpft_size ! This assumes that the first patch on the land unit is a vegetated ! patch and that the patch indices are monotonically increasing. ! See decompmod and initGridCellsMod for corroboration @@ -4139,29 +4144,40 @@ end subroutine SetPatchIndex ! ====================================================================================== - subroutine RegisterHLMInterfaceVariables(this, nc) + subroutine RegisterHLMInterfaceVariables(this, nc, nmaxpatches) use FatesInterfaceTypesMod, only : subgrid_column_index - use FatesInterfaceTypesMod, only : hlm_fates_soil_level use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_temperature - + ! Arguments class(hlm_fates_interface_type), intent(inout) :: this - - integer, intent(in) :: nc ! clump number - - ! Initialize the HLM-FATES interface variable registry - call this%fates(nc)%api%InitializeInterfaceRegistry() - - ! Register the HLM data - call this%fates(nc)%api%Register(hlm_fates_soil_level, col_pp%nlevbed, subgrid_column_index) - call this%fates(nc)%api%Register(hlm_fates_decomp_frac_moisture, col_cf%w_scalar, subgrid_column_index) - call this%fates(nc)%api%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar, subgrid_column_index) + integer, intent(in) :: nc ! clump number + integer, intent(in) :: nmaxpatches ! maximum patches for this clump + + ! Locals + integer :: p ! register index + integer :: c ! column index + + do i = 1, nmaxpatches + + ! Get the subgrid indices and assign them to the register metadata + call this%fates(nc)%register(p)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & + topounit = veg_pp%topounit(p), & + landunit = veg_pp%landunit(p), & + column = veg_pp%column(p), & + hlmpatch = p) + + ! Register and initialize the boundary condition variables necessary + c = this%fates(nc)%register(p)%GetColumnIndex() + call this%fates(nc)%register(p)%Register(hlm_fates_soil_level, col_pp%nlevbed(c), subgrid_column_index) + call this%fates(nc)%register(p)%Register(hlm_fates_decomp_frac_moisture, col_cf%w_scalar(c), subgrid_column_index) + call this%fates(nc)%register(p)%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar(c), subgrid_column_index) + + end do + end subroutine RegisterHLMInterfaceVariables -! ====================================================================================== - end module ELMFatesInterfaceMod From d9105e739059f1a78bc4ec3993ad900f551e8f97 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 29 Sep 2025 16:47:12 -0700 Subject: [PATCH 059/124] update registry initialization method This should eventually be unified with the site allocation code --- .../elm/src/main/elmfates_interfaceMod.F90 | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index dce40333b6af..b8d74f697c3e 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -884,13 +884,17 @@ subroutine init(this, bounds_proc, flandusepftdat) integer :: g ! HLM grid index integer :: m ! HLM PFT index integer :: ft ! FATES PFT index + integer :: i ! iterator integer :: pi,pf + integer :: p ! patch index integer, allocatable :: collist (:) + integer, allocatable :: patchlist(:) type(bounds_type) :: bounds_clump integer :: nmaxcol integer :: ndecomp integer :: numg integer :: num_landunits_veg + integer :: num_veg_patches real(r8), allocatable :: landuse_pft_map(:,:,:) real(r8), allocatable :: landuse_bareground(:) @@ -969,7 +973,7 @@ subroutine init(this, bounds_proc, flandusepftdat) end if endif enddo - + ! TODO Add adjustment to fates calculation here based on multi-column FATES options ! s = num_landunits_veg @@ -990,19 +994,40 @@ subroutine init(this, bounds_proc, flandusepftdat) write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' end if - ! Allocate map from FATES patchno index to HLM patch index by site - allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) + ! Iterate over all patches in this clump and determine the maximum number of non-crop + ! vegetated patches. These correspond to the fates patches. + num_veg_patches = 0 + i = 0 + nmaxpatches = bounds_clump%endp - bounds_clump%begp + 1 + allocate(patchlist(nmaxpatches)) + do p = bounds_clump%begp, bounds_clump%endp + c = veg_pp%column(p) + + ! If the column is a soil type, then the patch associated with it a vegetated patch, per initGridCells() + ! Record the patch index to the temporary patchlist + if (col_pp%itype(c) == istsoil) then + num_veg_patches = num_veg_patches + 1 + i = i + 1 + patchlist(i) = p + end if - ! Populate the fates to hlm patch map - call this%f2hmap(nc)%SetPatchIndex(bounds_clump) + end do - ! Initialize interface registries for each patch on the clump - nmaxpatches = bounds_clump%endp - bounds_clump%begp - call this%fates(nc)%InitializeInterfaceRegistry(nmaxpatches) + ! ! Allocate map from FATES patchno index to HLM patch index by site + ! allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) - ! Register the HLM interface variables - call this%RegisterHLMInterfaceVariables(nc, nmaxpatches) + ! ! Populate the fates to hlm patch map + ! call this%f2hmap(nc)%SetPatchIndex(bounds_clump) + ! Initialize interface registries for each patch on the clump + call this%fates(nc)%InitializeInterfaceRegistry(num_veg_patches) + + ! Register the HLM interface variables + call this%RegisterHLMInterfaceVariables(nc, num_veg_patches, patchlist) + + ! deallocate temporary patch list + deallocate(patchlist) + ! Set the number of FATES sites this%fates(nc)%nsites = s @@ -4144,7 +4169,7 @@ end subroutine SetPatchIndex ! ====================================================================================== - subroutine RegisterHLMInterfaceVariables(this, nc, nmaxpatches) + subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) use FatesInterfaceTypesMod, only : subgrid_column_index use FatesInterfaceTypesMod, only : hlm_fates_soil_level @@ -4153,15 +4178,18 @@ subroutine RegisterHLMInterfaceVariables(this, nc, nmaxpatches) ! Arguments class(hlm_fates_interface_type), intent(inout) :: this - integer, intent(in) :: nc ! clump number - integer, intent(in) :: nmaxpatches ! maximum patches for this clump + integer, intent(in) :: nc ! clump number + integer, intent(in) :: num_veg_patches ! maximum patches for this clump + integer, intent(in) :: patchlist(:) ! maximum patches for this clump ! Locals - integer :: p ! register index + integer :: r ! register index + integer :: p ! hlm patch index integer :: c ! column index - do i = 1, nmaxpatches - + do r = 1, num_veg_patches + p = patchlist(r) + ! Get the subgrid indices and assign them to the register metadata call this%fates(nc)%register(p)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & topounit = veg_pp%topounit(p), & @@ -4176,8 +4204,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc, nmaxpatches) call this%fates(nc)%register(p)%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar(c), subgrid_column_index) end do - - + end subroutine RegisterHLMInterfaceVariables end module ELMFatesInterfaceMod From 5dea15624486b65c5644d1e378dd6452f8683b25 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 30 Sep 2025 10:02:48 -0700 Subject: [PATCH 060/124] correct indexing for interface regsitry --- components/elm/src/main/elmfates_interfaceMod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b8d74f697c3e..1e141e37acc0 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4191,17 +4191,17 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) p = patchlist(r) ! Get the subgrid indices and assign them to the register metadata - call this%fates(nc)%register(p)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & + call this%fates(nc)%register(r)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & topounit = veg_pp%topounit(p), & landunit = veg_pp%landunit(p), & column = veg_pp%column(p), & hlmpatch = p) ! Register and initialize the boundary condition variables necessary - c = this%fates(nc)%register(p)%GetColumnIndex() - call this%fates(nc)%register(p)%Register(hlm_fates_soil_level, col_pp%nlevbed(c), subgrid_column_index) - call this%fates(nc)%register(p)%Register(hlm_fates_decomp_frac_moisture, col_cf%w_scalar(c), subgrid_column_index) - call this%fates(nc)%register(p)%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar(c), subgrid_column_index) + c = this%fates(nc)%register(r)%GetColumnIndex() + call this%fates(nc)%register(r)%Register(hlm_fates_soil_level, col_pp%nlevbed(c), subgrid_column_index) + call this%fates(nc)%register(r)%Register(hlm_fates_decomp_frac_moisture, col_cf%w_scalar(c,:), subgrid_column_index) + call this%fates(nc)%register(r)%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar(c,:), subgrid_column_index) end do From 77dce1ace689ac935ff37bc1ea6884bf8338e9f7 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 30 Sep 2025 10:05:23 -0700 Subject: [PATCH 061/124] remove old hlm registration call --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 1e141e37acc0..bd9fbf3a1bde 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1054,9 +1054,6 @@ subroutine init(this, bounds_proc, flandusepftdat) ! This also needs call set_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp) - ! Register HLM variables to the interface registry - call this%RegisterHLMInterfaceVariables(nc) - do s = 1, this%fates(nc)%nsites ! TODO: Assign column_map and patch_map values From a69283114171e297e28ca68494e789487ae08bec Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 30 Sep 2025 10:52:43 -0700 Subject: [PATCH 062/124] update registration call with flag --- components/elm/src/main/elmfates_interfaceMod.F90 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index bd9fbf3a1bde..6d2633e9402f 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4194,11 +4194,14 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) column = veg_pp%column(p), & hlmpatch = p) - ! Register and initialize the boundary condition variables necessary + ! Register and initialize the boundary condition variables c = this%fates(nc)%register(r)%GetColumnIndex() - call this%fates(nc)%register(r)%Register(hlm_fates_soil_level, col_pp%nlevbed(c), subgrid_column_index) - call this%fates(nc)%register(r)%Register(hlm_fates_decomp_frac_moisture, col_cf%w_scalar(c,:), subgrid_column_index) - call this%fates(nc)%register(r)%Register(hlm_fates_decomp_frac_temperature, col_cf%t_scalar(c,:), subgrid_column_index) + call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & + data=col_pp%nlevbed(c), hlm_flag=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_moisture, & + data=col_cf%w_scalar(c,:), hlm_flag=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_temperature, & + data=col_cf%t_scalar(c,:), hlm_flag=.true.) end do From 045795249058ebcb235c9d9f1d45737c93517c9f Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 30 Sep 2025 11:32:36 -0700 Subject: [PATCH 063/124] update number of patches for the interface level variable --- components/elm/src/main/elmfates_interfaceMod.F90 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 6d2633e9402f..603277b8d0b0 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1022,7 +1022,7 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Initialize interface registries for each patch on the clump call this%fates(nc)%InitializeInterfaceRegistry(num_veg_patches) - ! Register the HLM interface variables + ! Register the HLM interface variables that we be used to populate the FATES boundary conditions call this%RegisterHLMInterfaceVariables(nc, num_veg_patches, patchlist) ! deallocate temporary patch list @@ -4183,8 +4183,11 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) integer :: r ! register index integer :: p ! hlm patch index integer :: c ! column index + + ! Set the number of vegetated patches to the interface type level + this%npatches = num_veg_patches - do r = 1, num_veg_patches + do r = 1, this%npatches p = patchlist(r) ! Get the subgrid indices and assign them to the register metadata @@ -4195,6 +4198,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) hlmpatch = p) ! Register and initialize the boundary condition variables + ! Column level variables c = this%fates(nc)%register(r)%GetColumnIndex() call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & data=col_pp%nlevbed(c), hlm_flag=.true.) From f3059e082a3502de018797b2d7c329e7980f085b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 30 Sep 2025 16:41:39 -0700 Subject: [PATCH 064/124] remove defunct subgrid column index use --- components/elm/src/main/elmfates_interfaceMod.F90 | 1 - 1 file changed, 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 603277b8d0b0..62d9e27b49e5 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4168,7 +4168,6 @@ end subroutine SetPatchIndex subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) - use FatesInterfaceTypesMod, only : subgrid_column_index use FatesInterfaceTypesMod, only : hlm_fates_soil_level use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_temperature From 0cd67c44c03da8e4732c1b63632427d97e8373a6 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 1 Oct 2025 10:24:07 -0700 Subject: [PATCH 065/124] simplify patchlist index iteration --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 62d9e27b49e5..e4c1ba462ae4 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -997,7 +997,6 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Iterate over all patches in this clump and determine the maximum number of non-crop ! vegetated patches. These correspond to the fates patches. num_veg_patches = 0 - i = 0 nmaxpatches = bounds_clump%endp - bounds_clump%begp + 1 allocate(patchlist(nmaxpatches)) do p = bounds_clump%begp, bounds_clump%endp @@ -1007,8 +1006,7 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Record the patch index to the temporary patchlist if (col_pp%itype(c) == istsoil) then num_veg_patches = num_veg_patches + 1 - i = i + 1 - patchlist(i) = p + patchlist(num_veg_patches) = p end if end do From 0b277a4369ade05f4e8daf94a85fcb5f03065b9f Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 1 Oct 2025 10:26:44 -0700 Subject: [PATCH 066/124] move patchlist loop up prior to collist deallocation for eventual comparison --- components/elm/src/main/elmfates_interfaceMod.F90 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index e4c1ba462ae4..b97e20a186b1 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -987,13 +987,6 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Assign the h2hmap indexing this%f2hmap(nc)%fcolumn(1:s) = collist(1:s) - ! Deallocate the temporary arrays - deallocate(collist) - - if(debug)then - write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' - end if - ! Iterate over all patches in this clump and determine the maximum number of non-crop ! vegetated patches. These correspond to the fates patches. num_veg_patches = 0 @@ -1011,6 +1004,13 @@ subroutine init(this, bounds_proc, flandusepftdat) end do + ! Deallocate the temporary arrays + deallocate(collist) + + if(debug)then + write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' + end if + ! ! Allocate map from FATES patchno index to HLM patch index by site ! allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) From a918e20017cd7be5f0d9f8d401ec8b670794b8fc Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 1 Oct 2025 15:02:50 -0700 Subject: [PATCH 067/124] add sitelist for registry indexing --- .../elm/src/main/elmfates_interfaceMod.F90 | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b97e20a186b1..615c184473e8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -866,6 +866,7 @@ subroutine init(this, bounds_proc, flandusepftdat) use elm_varsur, only : wt_nat_patch use topounit_varcon, only : max_topounits, has_topounit use FATESFireFactoryMod, only : create_fates_fire_data_method + use FatesConstantsMod, only : fates_unset_int implicit none @@ -889,12 +890,15 @@ subroutine init(this, bounds_proc, flandusepftdat) integer :: p ! patch index integer, allocatable :: collist (:) integer, allocatable :: patchlist(:) + integer, allocatable :: sitelist(:) type(bounds_type) :: bounds_clump integer :: nmaxcol integer :: ndecomp integer :: numg integer :: num_landunits_veg integer :: num_veg_patches + integer :: nsites + integer :: gridcell_index real(r8), allocatable :: landuse_pft_map(:,:,:) real(r8), allocatable :: landuse_bareground(:) @@ -989,17 +993,33 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Iterate over all patches in this clump and determine the maximum number of non-crop ! vegetated patches. These correspond to the fates patches. + nsites = 0 num_veg_patches = 0 + gridcell_index = fates_unset_int nmaxpatches = bounds_clump%endp - bounds_clump%begp + 1 allocate(patchlist(nmaxpatches)) + allocate(sitelist(nmaxpatches)) + patchlist(:) = fates_unset_int + sitelist(:) = fates_unset_int + do p = bounds_clump%begp, bounds_clump%endp c = veg_pp%column(p) + g = veg_pp%gridcell(p) ! If the column is a soil type, then the patch associated with it a vegetated patch, per initGridCells() + ! We don't use lun_pp%itype == istsoil here as crops can live on landunits with this type ! Record the patch index to the temporary patchlist if (col_pp%itype(c) == istsoil) then + num_veg_patches = num_veg_patches + 1 patchlist(num_veg_patches) = p + + if (veg_pp%gridcell /= gridcell_index) then + gridcell_index = veg_pp%gridcell(p) + nsites = nsites + 1 + end if + sitelist(num_veg_patches) = nsites + end if end do From 5d42ee7561a6c9ede05185667a6a4e05aac4cf71 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 1 Oct 2025 15:21:20 -0700 Subject: [PATCH 068/124] Revert "move patchlist loop up prior to collist deallocation for eventual comparison" This reverts commit f066a898179557890b46742e052930ba6dc48165. --- components/elm/src/main/elmfates_interfaceMod.F90 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 615c184473e8..c7c1ac5653b0 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -991,6 +991,13 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Assign the h2hmap indexing this%f2hmap(nc)%fcolumn(1:s) = collist(1:s) + ! Deallocate the temporary arrays + deallocate(collist) + + if(debug)then + write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' + end if + ! Iterate over all patches in this clump and determine the maximum number of non-crop ! vegetated patches. These correspond to the fates patches. nsites = 0 @@ -1024,13 +1031,6 @@ subroutine init(this, bounds_proc, flandusepftdat) end do - ! Deallocate the temporary arrays - deallocate(collist) - - if(debug)then - write(iulog,*) 'alm_fates%init(): thread',nc,': allocated ',s,' sites' - end if - ! ! Allocate map from FATES patchno index to HLM patch index by site ! allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) From 8f557294e87a2cda97a0e1a153c4871af4173bbb Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 1 Oct 2025 15:35:42 -0700 Subject: [PATCH 069/124] temporary code to check sitelist --- components/elm/src/main/elmfates_interfaceMod.F90 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index c7c1ac5653b0..d6e0962a7ebf 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -899,6 +899,7 @@ subroutine init(this, bounds_proc, flandusepftdat) integer :: num_veg_patches integer :: nsites integer :: gridcell_index + integer :: c1, c2 real(r8), allocatable :: landuse_pft_map(:,:,:) real(r8), allocatable :: landuse_bareground(:) @@ -1030,7 +1031,7 @@ subroutine init(this, bounds_proc, flandusepftdat) end if end do - + ! ! Allocate map from FATES patchno index to HLM patch index by site ! allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) @@ -1072,6 +1073,17 @@ subroutine init(this, bounds_proc, flandusepftdat) ! This also needs call set_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp) + do p = 1, num_veg_patches + s = sitelist(p) + c1 = this%fates(nc)%fcolumn(s) + c2 = this%fates(bc)%register(p)%GetColumnIndex() + if (c1 /= c2 ) then + write(iulog,*) ' columns do not match: s, c1, c2: ', s, c1, c2 + call endrun(msg=errMsg(sourcefile, __LINE__)) + end if + + end do + do s = 1, this%fates(nc)%nsites ! TODO: Assign column_map and patch_map values From c86886634bafa2f02ef81a07ee8c7f6bd4a1ce8e Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 15:15:46 -0700 Subject: [PATCH 070/124] add missing nmaxpatches --- components/elm/src/main/elmfates_interfaceMod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index d6e0962a7ebf..de8602433f2d 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -900,6 +900,7 @@ subroutine init(this, bounds_proc, flandusepftdat) integer :: nsites integer :: gridcell_index integer :: c1, c2 + integer :: nmaxpatches real(r8), allocatable :: landuse_pft_map(:,:,:) real(r8), allocatable :: landuse_bareground(:) From af44611871041a54ee666efaad18fcb688558544 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 15:16:07 -0700 Subject: [PATCH 071/124] add missing fatesinterface type --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index de8602433f2d..386ead06df6a 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4215,9 +4215,9 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) integer :: c ! column index ! Set the number of vegetated patches to the interface type level - this%npatches = num_veg_patches + this%fates(nc)%npatches = num_veg_patches - do r = 1, this%npatches + do r = 1, this%fates(nc)%npatches p = patchlist(r) ! Get the subgrid indices and assign them to the register metadata @@ -4237,7 +4237,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_temperature, & data=col_cf%t_scalar(c,:), hlm_flag=.true.) - end do + end do end subroutine RegisterHLMInterfaceVariables From 70375e841dda2fa8b9419c207813b9ad311a3f42 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 15:16:46 -0700 Subject: [PATCH 072/124] add missing iterator index --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 386ead06df6a..201f7f1cd3a4 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1023,7 +1023,7 @@ subroutine init(this, bounds_proc, flandusepftdat) num_veg_patches = num_veg_patches + 1 patchlist(num_veg_patches) = p - if (veg_pp%gridcell /= gridcell_index) then + if (veg_pp%gridcell(p) /= gridcell_index) then gridcell_index = veg_pp%gridcell(p) nsites = nsites + 1 end if From 40b313265a3d260b4b21f4ebf84133376c8285df Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 15:17:08 -0700 Subject: [PATCH 073/124] correct typos --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 201f7f1cd3a4..5d9e68976ed0 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1076,8 +1076,8 @@ subroutine init(this, bounds_proc, flandusepftdat) do p = 1, num_veg_patches s = sitelist(p) - c1 = this%fates(nc)%fcolumn(s) - c2 = this%fates(bc)%register(p)%GetColumnIndex() + c1 = this%f2hmap(nc)%fcolumn(s) + c2 = this%fates(nc)%register(p)%GetColumnIndex() if (c1 /= c2 ) then write(iulog,*) ' columns do not match: s, c1, c2: ', s, c1, c2 call endrun(msg=errMsg(sourcefile, __LINE__)) From 5a40ad4c226e51b2c77d86c17f674b3c57757ca6 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 16:53:10 -0700 Subject: [PATCH 074/124] update interface registry to avoid having to pass number of vegetated passes twice --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 5d9e68976ed0..c5ed93081b90 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1040,10 +1040,10 @@ subroutine init(this, bounds_proc, flandusepftdat) ! call this%f2hmap(nc)%SetPatchIndex(bounds_clump) ! Initialize interface registries for each patch on the clump - call this%fates(nc)%InitializeInterfaceRegistry(num_veg_patches) + call this%fates(nc)%InitializeInterfaceRegistry(num_veg_patches, patchlist) ! Register the HLM interface variables that we be used to populate the FATES boundary conditions - call this%RegisterHLMInterfaceVariables(nc, num_veg_patches, patchlist) + call this%RegisterHLMInterfaceVariables(nc) ! deallocate temporary patch list deallocate(patchlist) From e80295334a9692887a618ac631dd939f3d6560e1 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 16:54:07 -0700 Subject: [PATCH 075/124] update register hlm interface to reduce arguments This also takes advantage of the new registry get functions --- .../elm/src/main/elmfates_interfaceMod.F90 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index c5ed93081b90..505bb6ed8290 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4197,7 +4197,7 @@ end subroutine SetPatchIndex ! ====================================================================================== - subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) + subroutine RegisterHLMInterfaceVariables(this, nc) use FatesInterfaceTypesMod, only : hlm_fates_soil_level use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture @@ -4206,26 +4206,27 @@ subroutine RegisterHLMInterfaceVariables(this, nc, num_veg_patches, patchlist) ! Arguments class(hlm_fates_interface_type), intent(inout) :: this integer, intent(in) :: nc ! clump number - integer, intent(in) :: num_veg_patches ! maximum patches for this clump - integer, intent(in) :: patchlist(:) ! maximum patches for this clump ! Locals integer :: r ! register index integer :: p ! hlm patch index integer :: c ! column index + integer :: s ! fates site index + integer :: ifp ! fates patch index - ! Set the number of vegetated patches to the interface type level - this%fates(nc)%npatches = num_veg_patches - + ! initialize the fates patch index counter + ifp = 0 + + ! Iterate over the number of vegetated patches do r = 1, this%fates(nc)%npatches - p = patchlist(r) + p = this%fates(nc)%GetHLMPatchIndex() ! Get the subgrid indices and assign them to the register metadata call this%fates(nc)%register(r)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & topounit = veg_pp%topounit(p), & landunit = veg_pp%landunit(p), & - column = veg_pp%column(p), & - hlmpatch = p) + column = veg_pp%column(p)) + ! Register and initialize the boundary condition variables ! Column level variables From 6bf92b24990903c7f08194b6fe7f80d0cee5bc88 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 16:57:55 -0700 Subject: [PATCH 076/124] add call to initialize fates sites This will eventuall supersede the site allocations --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 505bb6ed8290..ed852ed32d1d 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1045,6 +1045,9 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Register the HLM interface variables that we be used to populate the FATES boundary conditions call this%RegisterHLMInterfaceVariables(nc) + ! Initialize the FATES sites + call this%fates(nc)%InitializeFatesSites() + ! deallocate temporary patch list deallocate(patchlist) From e52149686daf689711a6eee8262eaf66ef65c331 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 6 Oct 2025 17:02:24 -0700 Subject: [PATCH 077/124] move patchlist deallocation --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index ed852ed32d1d..527cb38adb84 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1042,15 +1042,15 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Initialize interface registries for each patch on the clump call this%fates(nc)%InitializeInterfaceRegistry(num_veg_patches, patchlist) + ! deallocate temporary patch list + deallocate(patchlist) + ! Register the HLM interface variables that we be used to populate the FATES boundary conditions call this%RegisterHLMInterfaceVariables(nc) ! Initialize the FATES sites call this%fates(nc)%InitializeFatesSites() - ! deallocate temporary patch list - deallocate(patchlist) - ! Set the number of FATES sites this%fates(nc)%nsites = s From 2b140f817a8153d3573e0c3b30bf26ca73a3554f Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 7 Oct 2025 09:52:02 -0700 Subject: [PATCH 078/124] correct call to get patch index --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 527cb38adb84..50a53d373574 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4222,7 +4222,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc) ! Iterate over the number of vegetated patches do r = 1, this%fates(nc)%npatches - p = this%fates(nc)%GetHLMPatchIndex() + p = this%fates(nc)%register(r)%GetHLMPatchIndex() ! Get the subgrid indices and assign them to the register metadata call this%fates(nc)%register(r)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & From c82ed88a62ff359c501e1ab7946a0d2a2ef94cb2 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 7 Oct 2025 15:04:19 -0700 Subject: [PATCH 079/124] match the current initialization logic to check for the activate columns --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 50a53d373574..d6bd10089742 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1018,7 +1018,7 @@ subroutine init(this, bounds_proc, flandusepftdat) ! If the column is a soil type, then the patch associated with it a vegetated patch, per initGridCells() ! We don't use lun_pp%itype == istsoil here as crops can live on landunits with this type ! Record the patch index to the temporary patchlist - if (col_pp%itype(c) == istsoil) then + if ( (col_pp%itype(c) == istsoil) .and. (col_pp%active(c)) ) then num_veg_patches = num_veg_patches + 1 patchlist(num_veg_patches) = p From 3c28ec80458b8f76090ab1c3aa684d49156eda4b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 7 Oct 2025 15:59:57 -0700 Subject: [PATCH 080/124] update registration to include nlevdecomp_full --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index d6bd10089742..11c5c60ef1c7 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4202,6 +4202,7 @@ end subroutine SetPatchIndex subroutine RegisterHLMInterfaceVariables(this, nc) + use FatesInterfaceTypesMod, only : hlm_fates_decomp_max use FatesInterfaceTypesMod, only : hlm_fates_soil_level use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_temperature @@ -4232,6 +4233,9 @@ subroutine RegisterHLMInterfaceVariables(this, nc) ! Register and initialize the boundary condition variables + ! Global variables + call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_max, & + data=nlevdecomp_full, hlm_flag=.true.) ! Column level variables c = this%fates(nc)%register(r)%GetColumnIndex() call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & From 072d7120b12faf046aaa05a82ea8c840a0614023 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 7 Oct 2025 16:23:52 -0700 Subject: [PATCH 081/124] remove defunct mapping functions for f2hmap --- .../elm/src/main/elmfates_interfaceMod.F90 | 65 ------------------- 1 file changed, 65 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 11c5c60ef1c7..834ba31837f9 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -219,9 +219,6 @@ module ELMFatesInterfaceMod type, public :: f2hmap_type - ! HLM patch index to FATES patchno index mapping, by site - integer, allocatable :: hlm_patch_index(:,:) - ! This is the associated column index of each FATES site - to be deprecated integer, allocatable :: fcolumn (:) @@ -229,13 +226,6 @@ module ELMFatesInterfaceMod ! This vector may be sparse, and non-sites have index 0 integer, allocatable :: hsites (:) - contains - - procedure, public :: SetPatchIndex - ! procedure, public :: GetPatchIndex - procedure, public :: GetColumnIndex - ! procedure, public :: GetLandunitIndex - end type f2hmap_type type, public :: hlm_fates_interface_type @@ -1033,12 +1023,6 @@ subroutine init(this, bounds_proc, flandusepftdat) end do - ! ! Allocate map from FATES patchno index to HLM patch index by site - ! allocate(this%f2hmap(nc)%hlm_patch_index(fates_maxPatchesperSite,s)) - - ! ! Populate the fates to hlm patch map - ! call this%f2hmap(nc)%SetPatchIndex(bounds_clump) - ! Initialize interface registries for each patch on the clump call this%fates(nc)%InitializeInterfaceRegistry(num_veg_patches, patchlist) @@ -4149,55 +4133,6 @@ subroutine GetLandusePFTData(bounds, landuse_pft_file, landuse_pft_map, landuse_ end subroutine GetLandusePFTData -! ====================================================================================== - - integer function GetColumnIndex(this,ifp,s) result(ifc) - - !------------------------------------------------------------------------ - ! This subroutine gets the mapping between the FATES patches and HLM columns - ! ------------------------------------------------------------------------ - - class(f2hmap_type), intent(inout) :: this - - integer :: ifp ! FATES bc_in/out patch dimension index - integer :: s ! FATES site index - - ifc = veg_pp%column(this%hlm_patch_index(ifp,s)) - - end function GetColumnIndex - -! ====================================================================================== - - subroutine SetPatchIndex(this,bounds_clump) - - !------------------------------------------------------------------------ - ! This subroutine sets the mapping between the FATES and HLM patches - ! ------------------------------------------------------------------------ - - class(f2hmap_type), intent(inout) :: this - type(bounds_type), intent(in) :: bounds_clump - - integer :: s ! FATES site index - integer :: l ! HLM landunit index - integer :: ifp ! FATES patch index (patchno) - - ! Note while each HLM clump can have multiple sites, the site indices are not global, - ! i.e. the first site on each clump will have an index of 1 - s = 0 - do l = bounds_clump%begl,bounds_clump%endl - if (lun_pp%itype(l) == istsoil) then - s = s + 1 - do ifp = 1, natpft_size - ! This assumes that the first patch on the land unit is a vegetated - ! patch and that the patch indices are monotonically increasing. - ! See decompmod and initGridCellsMod for corroboration - this%hlm_patch_index(ifp,s) = lun_pp%pfti(l) + ifp - end do - end if - end do - - end subroutine SetPatchIndex - ! ====================================================================================== subroutine RegisterHLMInterfaceVariables(this, nc) From f9aaeb6ef5fc6d2a08126ed977ca17605f2eb0ce Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 7 Oct 2025 16:36:39 -0700 Subject: [PATCH 082/124] remove the use of the sitelist --- components/elm/src/main/elmfates_interfaceMod.F90 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 834ba31837f9..5b89fffcaf47 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -992,14 +992,10 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Iterate over all patches in this clump and determine the maximum number of non-crop ! vegetated patches. These correspond to the fates patches. - nsites = 0 num_veg_patches = 0 - gridcell_index = fates_unset_int nmaxpatches = bounds_clump%endp - bounds_clump%begp + 1 allocate(patchlist(nmaxpatches)) - allocate(sitelist(nmaxpatches)) patchlist(:) = fates_unset_int - sitelist(:) = fates_unset_int do p = bounds_clump%begp, bounds_clump%endp c = veg_pp%column(p) @@ -1013,12 +1009,6 @@ subroutine init(this, bounds_proc, flandusepftdat) num_veg_patches = num_veg_patches + 1 patchlist(num_veg_patches) = p - if (veg_pp%gridcell(p) /= gridcell_index) then - gridcell_index = veg_pp%gridcell(p) - nsites = nsites + 1 - end if - sitelist(num_veg_patches) = nsites - end if end do From f10cab4fb872e8f870eae90a286fa77a0bfe712b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 7 Oct 2025 16:37:20 -0700 Subject: [PATCH 083/124] comment out the allocation of the fates sites This will be handled by the fates site initialization routine --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 5b89fffcaf47..4076a46c2b0e 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1026,10 +1026,10 @@ subroutine init(this, bounds_proc, flandusepftdat) call this%fates(nc)%InitializeFatesSites() ! Set the number of FATES sites - this%fates(nc)%nsites = s + ! this%fates(nc)%nsites = s ! Allocate the FATES sites - allocate(this%fates(nc)%sites(this%fates(nc)%nsites)) + ! allocate(this%fates(nc)%sites(this%fates(nc)%nsites)) ! Allocate the FATES boundary arrays (in) allocate(this%fates(nc)%bc_in(this%fates(nc)%nsites)) From 69305bba8939cdf2c336f3bd2a72858b63185a8e Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 8 Oct 2025 09:28:37 -0700 Subject: [PATCH 084/124] move temporary column check up and index into site from registry metadata --- .../elm/src/main/elmfates_interfaceMod.F90 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 4076a46c2b0e..1b7f95760cd8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1025,6 +1025,17 @@ subroutine init(this, bounds_proc, flandusepftdat) ! Initialize the FATES sites call this%fates(nc)%InitializeFatesSites() + do p = 1, num_veg_patches + s = this%fates(nc)%register(p)%GetSiteIndex() + c1 = this%f2hmap(nc)%fcolumn(s) + c2 = this%fates(nc)%register(p)%GetColumnIndex() + if (c1 /= c2 ) then + write(iulog,*) ' columns do not match: p, s, c1, c2: ', p, s, c1, c2 + write(iulog,*) ' max sites: ', maxval(sitelist) + call endrun(msg=errMsg(sourcefile, __LINE__)) + end if + end do + ! Set the number of FATES sites ! this%fates(nc)%nsites = s @@ -1051,17 +1062,6 @@ subroutine init(this, bounds_proc, flandusepftdat) ! This also needs call set_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp) - do p = 1, num_veg_patches - s = sitelist(p) - c1 = this%f2hmap(nc)%fcolumn(s) - c2 = this%fates(nc)%register(p)%GetColumnIndex() - if (c1 /= c2 ) then - write(iulog,*) ' columns do not match: s, c1, c2: ', s, c1, c2 - call endrun(msg=errMsg(sourcefile, __LINE__)) - end if - - end do - do s = 1, this%fates(nc)%nsites ! TODO: Assign column_map and patch_map values From e012ae0f654d52e6778f7fe0153b3a599bdffe8e Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 8 Oct 2025 15:03:33 -0700 Subject: [PATCH 085/124] update hlm register procedure to use the interface parameters module --- components/elm/src/main/elmfates_interfaceMod.F90 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 1b7f95760cd8..93c9177bf252 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4127,10 +4127,7 @@ end subroutine GetLandusePFTData subroutine RegisterHLMInterfaceVariables(this, nc) - use FatesInterfaceTypesMod, only : hlm_fates_decomp_max - use FatesInterfaceTypesMod, only : hlm_fates_soil_level - use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_moisture - use FatesInterfaceTypesMod, only : hlm_fates_decomp_frac_temperature + use FatesInterfaceParametersMod ! Arguments class(hlm_fates_interface_type), intent(inout) :: this From 9c2566228023499d15444d4ee793a1e77e92b25b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 8 Oct 2025 15:08:28 -0700 Subject: [PATCH 086/124] add the carbon litter decomp pools to the registration procedure --- components/elm/src/main/elmfates_interfaceMod.F90 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 93c9177bf252..b87685842d8a 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4167,6 +4167,18 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_temperature, & data=col_cf%t_scalar(c,:), hlm_flag=.true.) + ! Variables that need to accumulate + call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_cellulose, & + data=col_cf%decomp_cpools_sourcesink(c,:,i_cel_lit), & + hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_lignin, & + data=col_cf%decomp_cpools_sourcesink(c,:,i_lig_lit), & + hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_labile, & + data=col_cf%decomp_cpools_sourcesink(c,:,i_lab_lit), & + hlm_flag=.true., accumulate=.true.) + + end do end subroutine RegisterHLMInterfaceVariables From e87f7248584eec2afe1ce15506871c1647ec8926 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 15 Oct 2025 09:58:46 -0700 Subject: [PATCH 087/124] add the new interface type bound update litter fluxes call. --- .../elm/src/main/elmfates_interfaceMod.F90 | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b87685842d8a..054860b18817 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1519,28 +1519,26 @@ subroutine UpdateLitterFluxes(this,bounds_clump) dtime = real(get_step_size(),r8) nc = bounds_clump%clump_index + + call this%fates(nc)%UpdateLitterFluxes(dtime) do s = 1, this%fates(nc)%nsites c = this%f2hmap(nc)%fcolumn(s) - call FluxIntoLitterPools(this%fates(nc)%sites(s), & - this%fates(nc)%bc_in(s), & - this%fates(nc)%bc_out(s)) - - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) = & - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_lab_c_si(1:nlevdecomp) * dtime - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_cel_c_si(1:nlevdecomp)* dtime - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_lig_c_si(1:nlevdecomp) * dtime - - col_cf%litfall(c) = & - sum(this%fates(nc)%bc_out(s)%litt_flux_lab_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - sum(this%fates(nc)%bc_out(s)%litt_flux_cel_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - sum(this%fates(nc)%bc_out(s)%litt_flux_lig_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) = & + ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) + & + ! this%fates(nc)%bc_out(s)%litt_flux_lab_c_si(1:nlevdecomp) * dtime + ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & + ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) + & + ! this%fates(nc)%bc_out(s)%litt_flux_cel_c_si(1:nlevdecomp)* dtime + ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & + ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) + & + ! this%fates(nc)%bc_out(s)%litt_flux_lig_c_si(1:nlevdecomp) * dtime + + ! col_cf%litfall(c) = & + ! sum(this%fates(nc)%bc_out(s)%litt_flux_lab_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & + ! sum(this%fates(nc)%bc_out(s)%litt_flux_cel_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & + ! sum(this%fates(nc)%bc_out(s)%litt_flux_lig_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) ! Since N and P are always allocated in ELM, AND, since on the FATES From d661d3668759d789382d3968046034c7c0383c10 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 15 Oct 2025 15:46:59 -0700 Subject: [PATCH 088/124] register additional data for litter flux update --- components/elm/src/main/elmfates_interfaceMod.F90 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 054860b18817..501f99f04733 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4154,8 +4154,15 @@ subroutine RegisterHLMInterfaceVariables(this, nc) ! Register and initialize the boundary condition variables ! Global variables + call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp, & + data=nlevdecomp, hlm_flag=.true.) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_max, & data=nlevdecomp_full, hlm_flag=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_thickness, & + data=dzsoi_decomp, hlm_flag=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_id, & + data=decomp_id, hlm_flag=.true.) + ! Column level variables c = this%fates(nc)%register(r)%GetColumnIndex() call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & @@ -4164,6 +4171,8 @@ subroutine RegisterHLMInterfaceVariables(this, nc) data=col_cf%w_scalar(c,:), hlm_flag=.true.) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_temperature, & data=col_cf%t_scalar(c,:), hlm_flag=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_total, & + data=col_cf%litfall(c), hlm_flag=.true.) ! Variables that need to accumulate call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_cellulose, & From 30b0212c3bd6dcc32278abe8c98c5ddd74519cd1 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 15 Oct 2025 15:55:13 -0700 Subject: [PATCH 089/124] update fluxintolitterpools call --- components/elm/src/main/elmfates_interfaceMod.F90 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 501f99f04733..1441c271c0d5 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2061,8 +2061,7 @@ subroutine restart( this, bounds_proc, ncid, flag, & ! output boundary condition structures. Note: this is called ! internally in fates dynamics as well. - call FluxIntoLitterPools(this%fates(nc)%sites(s), & - this%fates(nc)%bc_in(s), this%fates(nc)%bc_out(s)) + call FluxIntoLitterPools(this%fates(nc)%sites(s)) end do @@ -2320,9 +2319,8 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in ! output boundary condition structures. Note: this is called ! internally in fates dynamics as well. - call FluxIntoLitterPools(this%fates(nc)%sites(s), & - this%fates(nc)%bc_in(s), & - this%fates(nc)%bc_out(s)) + call FluxIntoLitterPools(this%fates(nc)%sites(s)) + end do ! ------------------------------------------------------------------------ From 39d31ccae59ff52e2ef234b4e627aaa11b2cd03b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 15 Oct 2025 16:00:12 -0700 Subject: [PATCH 090/124] update the calculation of the decomp_id array --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 1441c271c0d5..a19d57136db2 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -318,6 +318,8 @@ module ELMFatesInterfaceMod integer, parameter :: num_landuse_pft_vars = 4 + real(r8), allocatable :: decomp_id(:) ! array to hold the idea of the decomp layer + public :: ELMFatesGlobals1 public :: ELMFatesGlobals2 public :: ELMFatesTimesteps @@ -3580,10 +3582,13 @@ subroutine init_soil_depths(this, nc) this%fates(nc)%bc_in(s)%z_sisl(1:nlevsoil) = col_pp%z(c,1:nlevsoil) this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp) = & dzsoi_decomp(1:nlevdecomp) + + allocate(decomp_id(nlevsoil)) if (use_vertsoilc) then do j=1,nlevsoil this%fates(nc)%bc_in(s)%decomp_id(j) = j + decomp_id(j) = j ! Check to make sure that dz = dz_decomp_sisl when vertical soil dynamics ! are active if(abs(this%fates(nc)%bc_in(s)%dz_decomp_sisl(j)-this%fates(nc)%bc_in(s)%dz_sisl(j))>1.e-10_r8)then @@ -3598,6 +3603,7 @@ subroutine init_soil_depths(this, nc) else do j=1,nlevsoil this%fates(nc)%bc_in(s)%decomp_id(j) = 1 + decomp_id(j) = 1 end do end if From ac1d4a227021a33535a7988a5a8648185b338f99 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 15 Oct 2025 16:53:19 -0700 Subject: [PATCH 091/124] register rooting depth with the hlm variable While the associated boundary condition is currently set with a min check against this and nlevsoil, this check should be moved inside fates --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index a19d57136db2..58592e221794 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4166,11 +4166,13 @@ subroutine RegisterHLMInterfaceVariables(this, nc) data=dzsoi_decomp, hlm_flag=.true.) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_id, & data=decomp_id, hlm_flag=.true.) - + ! Column level variables c = this%fates(nc)%register(r)%GetColumnIndex() call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & data=col_pp%nlevbed(c), hlm_flag=.true.) + call this%fates(nc)%register(r)%Register(key=hlm_fates_rooting_max_depth, & + data=canopystate_inst%altmax_lastyear_indx_col(c), hlm_flag=.true.) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_moisture, & data=col_cf%w_scalar(c,:), hlm_flag=.true.) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_temperature, & From c722115486b3033ed1b777c46e948a23dfdee53b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 15 Oct 2025 22:24:49 -0700 Subject: [PATCH 092/124] register max thaw depth with new parameter key name Since the max rooting depth is calculated using multiple bc_in variables, handle the logic on the fates side --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 58592e221794..2776c41819e8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4171,7 +4171,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc) c = this%fates(nc)%register(r)%GetColumnIndex() call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & data=col_pp%nlevbed(c), hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_rooting_max_depth, & + call this%fates(nc)%register(r)%Register(key=hlm_fates_thaw_max_depth_index, & data=canopystate_inst%altmax_lastyear_indx_col(c), hlm_flag=.true.) call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_moisture, & data=col_cf%w_scalar(c,:), hlm_flag=.true.) From 0c5be787f844042ac2036f676fc7459bcd511de3 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 08:40:37 -0700 Subject: [PATCH 093/124] rename interface registry instance for clarity --- .../elm/src/main/elmfates_interfaceMod.F90 | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 2776c41819e8..a0b6a7bf5522 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4147,10 +4147,10 @@ subroutine RegisterHLMInterfaceVariables(this, nc) ! Iterate over the number of vegetated patches do r = 1, this%fates(nc)%npatches - p = this%fates(nc)%register(r)%GetHLMPatchIndex() + p = this%fates(nc)%registry(r)%GetHLMPatchIndex() ! Get the subgrid indices and assign them to the register metadata - call this%fates(nc)%register(r)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & + call this%fates(nc)%registry(r)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & topounit = veg_pp%topounit(p), & landunit = veg_pp%landunit(p), & column = veg_pp%column(p)) @@ -4158,36 +4158,36 @@ subroutine RegisterHLMInterfaceVariables(this, nc) ! Register and initialize the boundary condition variables ! Global variables - call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp, & data=nlevdecomp, hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_max, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_max, & data=nlevdecomp_full, hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_thickness, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_thickness, & data=dzsoi_decomp, hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_id, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_id, & data=decomp_id, hlm_flag=.true.) ! Column level variables - c = this%fates(nc)%register(r)%GetColumnIndex() - call this%fates(nc)%register(r)%Register(key=hlm_fates_soil_level, & + c = this%fates(nc)%registry(r)%GetColumnIndex() + call this%fates(nc)%registry(r)%Register(key=hlm_fates_soil_level, & data=col_pp%nlevbed(c), hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_thaw_max_depth_index, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_thaw_max_depth_index, & data=canopystate_inst%altmax_lastyear_indx_col(c), hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_moisture, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_moisture, & data=col_cf%w_scalar(c,:), hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_decomp_frac_temperature, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_temperature, & data=col_cf%t_scalar(c,:), hlm_flag=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_total, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_total, & data=col_cf%litfall(c), hlm_flag=.true.) ! Variables that need to accumulate - call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_cellulose, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_cellulose, & data=col_cf%decomp_cpools_sourcesink(c,:,i_cel_lit), & hlm_flag=.true., accumulate=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_lignin, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_lignin, & data=col_cf%decomp_cpools_sourcesink(c,:,i_lig_lit), & hlm_flag=.true., accumulate=.true.) - call this%fates(nc)%register(r)%Register(key=hlm_fates_litter_carbon_labile, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_labile, & data=col_cf%decomp_cpools_sourcesink(c,:,i_lab_lit), & hlm_flag=.true., accumulate=.true.) From 972ede01eb7fffac4ca1ff754eae602e70579016 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 08:45:56 -0700 Subject: [PATCH 094/124] remove fates site and patch index iterators This will be handle on the fates-side --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index a0b6a7bf5522..819a127d2b6b 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4139,11 +4139,6 @@ subroutine RegisterHLMInterfaceVariables(this, nc) integer :: r ! register index integer :: p ! hlm patch index integer :: c ! column index - integer :: s ! fates site index - integer :: ifp ! fates patch index - - ! initialize the fates patch index counter - ifp = 0 ! Iterate over the number of vegetated patches do r = 1, this%fates(nc)%npatches @@ -4191,7 +4186,6 @@ subroutine RegisterHLMInterfaceVariables(this, nc) data=col_cf%decomp_cpools_sourcesink(c,:,i_lab_lit), & hlm_flag=.true., accumulate=.true.) - end do end subroutine RegisterHLMInterfaceVariables From c08e19060313a58f0923ca33fdda6da2686d76ba Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 09:49:02 -0700 Subject: [PATCH 095/124] update the fates site initialization call to pass the natpft_size --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 819a127d2b6b..458cc1495e12 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1025,7 +1025,7 @@ subroutine init(this, bounds_proc, flandusepftdat) call this%RegisterHLMInterfaceVariables(nc) ! Initialize the FATES sites - call this%fates(nc)%InitializeFatesSites() + call this%fates(nc)%InitializeFatesSites(natpft_size) do p = 1, num_veg_patches s = this%fates(nc)%register(p)%GetSiteIndex() From cba1e2ae63327ca8295fb4be976bbc622726f962 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 10:10:09 -0700 Subject: [PATCH 096/124] manually remove superseded transfer bc calls --- .../elm/src/main/elmfates_interfaceMod.F90 | 81 ++++++------------- 1 file changed, 23 insertions(+), 58 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 458cc1495e12..b32c93b75d33 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3794,64 +3794,6 @@ subroutine wrap_hydraulics_drive(this, bounds_clump, & return end subroutine wrap_hydraulics_drive -! ====================================================================================== - -! subroutine WrapTransferBCIn(this, nc) - -! ! !DESCRIPTION: -! ! --------------------------------------------------------------------------------- -! ! This call passes the HLM inputs to FATES patch-level boundary conditions -! ! --------------------------------------------------------------------------------- - -! ! !USES: -! ! -! ! !ARGUMENTS: -! class(hlm_fates_interface_type), intent(inout) :: this -! integer, intent(in) :: nc - -! ! !LOCAL: -! integer :: s, ivar ! indices and loop counters - -! do s = 1, this%fates(nc)%nsites -! do ivar = 1,this%num_hlmvar_in -! call this%fates(nc)%sites(s)%TransferBCIn(this%bc_in(ivar)%api_str, & -! this%bc_in(ivar)%hlm_var) -! end do -! end do - -! end subroutine WrapTransferBCIn - -! ! ====================================================================================== - -! subroutine WrapTransferBCOut(this, nc) - -! ! !DESCRIPTION: -! ! --------------------------------------------------------------------------------- -! ! This call passes the HLM inputs to FATES patch-level boundary conditions -! ! --------------------------------------------------------------------------------- - -! ! !USES: -! ! -! ! !ARGUMENTS: -! class(hlm_fates_interface_type), intent(inout) :: this -! integer, intent(in) :: nc - -! ! !LOCAL: -! integer :: s, ivar ! indices and loop counters -! real(r8) :: dtime ! step size to pass to FATES to handle timestep conversions - -! ! Get the step size in seconds -! dtime = real(get_step_size(),r8) - -! do s = 1, this%fates(nc)%nsites -! do ivar = 1,this%num_hlmvar_out -! call this%fates(nc)%sites(s)%TransferBCOut(this%bc_out(ivar)%api_str, & -! this%bc_out(ivar)%hlm_var, dtime) -! end do -! end do - -! end subroutine WrapTransferBCOut - ! ====================================================================================== subroutine hlm_bounds_to_fates_bounds(hlm, fates) @@ -4186,6 +4128,29 @@ subroutine RegisterHLMInterfaceVariables(this, nc) data=col_cf%decomp_cpools_sourcesink(c,:,i_lab_lit), & hlm_flag=.true., accumulate=.true.) + select case(fates_parteh_mode) + case (prt_cnp_flex_allom_hyp) + ! Phosphorus + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_cellulose, & + data=col_cf%decomp_ppools_sourcesink(c,:,i_cel_lit), & + hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_lignin, & + data=col_cf%decomp_ppools_sourcesink(c,:,i_lig_lit), & + hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_labile, & + data=col_cf%decomp_ppools_sourcesink(c,:,i_lab_lit), & + hlm_flag=.true., accumulate=.true.) + ! Nitrogen + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_cellulose, & + data=col_cf%decomp_npools_sourcesink(c,:,i_cel_lit), & + hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_lignin, & + data=col_cf%decomp_npools_sourcesink(c,:,i_lig_lit), & + hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_labile, & + data=col_cf%decomp_npools_sourcesink(c,:,i_lab_lit), & + hlm_flag=.true., accumulate=.true.) + end select end do end subroutine RegisterHLMInterfaceVariables From 22c47b008a96f53cf91aa12c71c9df38fe200f52 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 10:12:57 -0700 Subject: [PATCH 097/124] manually remove wraptransfer calls --- components/elm/src/main/elmfates_interfaceMod.F90 | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b32c93b75d33..6f1b189ceea6 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -295,8 +295,6 @@ module ELMFatesInterfaceMod procedure, public :: WrapUpdateFatesRmean procedure, public :: WrapGlobalSeedDispersal procedure, public :: WrapUpdateFatesSeedInOut - ! procedure, public :: WrapTransferBCIn - ! procedure, public :: WrapTransferBCOut end type hlm_fates_interface_type @@ -1066,10 +1064,6 @@ subroutine init(this, bounds_proc, flandusepftdat) do s = 1, this%fates(nc)%nsites - ! TODO: Assign column_map and patch_map values - ! this%fates(nc)%sites(s)%column_map(:) = this%f2hmap(nc)%GetColumnIndex(1,s) - ! this%fates(nc)%sites(s)%patch_map(:) = this%f2hmap(nc)%hlm_patch_index(:,s) - c = this%f2hmap(nc)%fcolumn(s) this%fates(nc)%sites(s)%h_gid = c @@ -1294,9 +1288,6 @@ subroutine dynamics_driv(this, bounds_clump, top_as_inst, & gdp_lf_col = this%fates_fire_data_method%GetGDP() end if - ! Transfer decomposition fluxes to the FATES patch data structure - ! call this%WrapTransferBCIn(nc) - do s=1,this%fates(nc)%nsites c = this%f2hmap(nc)%fcolumn(s) @@ -2067,8 +2058,6 @@ subroutine restart( this, bounds_proc, ncid, flag, & end do - ! call this%WrapTransferBCOut(nc, dtime) - if(use_fates_sp)then do s = 1,this%fates(nc)%nsites c = this%f2hmap(nc)%fcolumn(s) From 2168852b33fee14af3f1677f1aef1dff1aeac2c5 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 10:22:42 -0700 Subject: [PATCH 098/124] remove superseded code from the elm fates interface --- .../elm/src/main/elmfates_interfaceMod.F90 | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 6f1b189ceea6..907a1a3366ac 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -253,15 +253,6 @@ module ELMFatesInterfaceMod ! Type structure that holds allocatable arrays for mpi-based seed dispersal type(dispersal_type) :: fates_seed - ! This is the array of pointer to the host land model data and its associated - ! common variable name - ! type(hlm_fates_api_var_type), allocatable :: bc_in(:) - ! type(hlm_fates_api_var_type), allocatable :: bc_out(:) - - ! This is the number of HLM variables that are being passed in and out of FATES - integer, public :: num_hlmvar_in, num_hlmvar_out - - contains procedure, public :: init @@ -880,7 +871,6 @@ subroutine init(this, bounds_proc, flandusepftdat) integer :: p ! patch index integer, allocatable :: collist (:) integer, allocatable :: patchlist(:) - integer, allocatable :: sitelist(:) type(bounds_type) :: bounds_clump integer :: nmaxcol integer :: ndecomp @@ -951,10 +941,6 @@ subroutine init(this, bounds_proc, flandusepftdat) num_landunits_veg = 0 do c = bounds_clump%begc,bounds_clump%endc l = col_pp%landunit(c) - ! do l = bounds_clump%begl,bounds_clump%endl - ! if (lun_pp%itype(l) == istsoil) then - - ! num_landunits_veg = num_landunits_veg + 1 ! To be deprecated/refactored if ( (lun_pp%itype(l) == istsoil) .and. (col_pp%active(c)) ) then @@ -964,7 +950,7 @@ subroutine init(this, bounds_proc, flandusepftdat) col_pp%is_fates(c) = .true. if(debug)then - ! write(iulog,*) 'alm_fates%init(): thread',nc,': found column',c,'with lu',l + write(iulog,*) 'alm_fates%init(): thread',nc,': found column',c,'with lu',l write(iulog,*) 'LU type:', lun_pp%itype(l) end if endif @@ -1031,17 +1017,10 @@ subroutine init(this, bounds_proc, flandusepftdat) c2 = this%fates(nc)%register(p)%GetColumnIndex() if (c1 /= c2 ) then write(iulog,*) ' columns do not match: p, s, c1, c2: ', p, s, c1, c2 - write(iulog,*) ' max sites: ', maxval(sitelist) call endrun(msg=errMsg(sourcefile, __LINE__)) end if end do - ! Set the number of FATES sites - ! this%fates(nc)%nsites = s - - ! Allocate the FATES sites - ! allocate(this%fates(nc)%sites(this%fates(nc)%nsites)) - ! Allocate the FATES boundary arrays (in) allocate(this%fates(nc)%bc_in(this%fates(nc)%nsites)) From 80ad87a37a347461eb244121cf2c5beceb247b28 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 13:56:02 -0700 Subject: [PATCH 099/124] add P and N litter fluxes to the fates interface registry --- components/elm/src/main/elmfates_interfaceMod.F90 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 907a1a3366ac..d3e2e34f21a5 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4108,6 +4108,10 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_labile, & data=col_cf%decomp_ppools_sourcesink(c,:,i_lab_lit), & hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_all, & + data=col_pf%plant_to_litter_pflux(c), & + hlm_flag=.true., accumulate=.true.) + ! Nitrogen call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_cellulose, & data=col_cf%decomp_npools_sourcesink(c,:,i_cel_lit), & @@ -4118,6 +4122,9 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_labile, & data=col_cf%decomp_npools_sourcesink(c,:,i_lab_lit), & hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_all, & + data=col_pf%plant_to_litter_nflux(c), & + hlm_flag=.true., accumulate=.true.) end select end do From cfa9d621337b6f190eee4763b88970e9688d3a3b Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 16 Oct 2025 15:48:57 -0700 Subject: [PATCH 100/124] remove all litter flux bc calculations These have moved into fates --- .../elm/src/main/elmfates_interfaceMod.F90 | 76 ++----------------- 1 file changed, 6 insertions(+), 70 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index d3e2e34f21a5..f6cd0e61e0e7 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1494,73 +1494,6 @@ subroutine UpdateLitterFluxes(this,bounds_clump) call this%fates(nc)%UpdateLitterFluxes(dtime) - do s = 1, this%fates(nc)%nsites - c = this%f2hmap(nc)%fcolumn(s) - - ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) = & - ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) + & - ! this%fates(nc)%bc_out(s)%litt_flux_lab_c_si(1:nlevdecomp) * dtime - ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & - ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) + & - ! this%fates(nc)%bc_out(s)%litt_flux_cel_c_si(1:nlevdecomp)* dtime - ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & - ! col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) + & - ! this%fates(nc)%bc_out(s)%litt_flux_lig_c_si(1:nlevdecomp) * dtime - - ! col_cf%litfall(c) = & - ! sum(this%fates(nc)%bc_out(s)%litt_flux_lab_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - ! sum(this%fates(nc)%bc_out(s)%litt_flux_cel_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - ! sum(this%fates(nc)%bc_out(s)%litt_flux_lig_c_si(1:nlevdecomp) * this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) - - - ! Since N and P are always allocated in ELM, AND, since on the FATES - ! side we have prepped these arrays, which may be zero fluxes in the case of - ! prescribed FATES nutrient mode, we can send the fluxes into the source pools - - select case(fates_parteh_mode) - case (prt_cnp_flex_allom_hyp ) - - col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_met_lit) = & - col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_met_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_lab_p_si(1:nlevdecomp) * dtime - - col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & - col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_cel_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_cel_p_si(1:nlevdecomp)* dtime - - col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & - col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_lig_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_lig_p_si(1:nlevdecomp) * dtime - - ! Diagnostic for mass balancing (gP/m2/s) - col_pf%plant_to_litter_pflux(c) = & - sum(this%fates(nc)%bc_out(s)%litt_flux_lab_p_si(1:nlevdecomp)*this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - sum(this%fates(nc)%bc_out(s)%litt_flux_cel_p_si(1:nlevdecomp)*this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - sum(this%fates(nc)%bc_out(s)%litt_flux_lig_p_si(1:nlevdecomp)*this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) - - ! Transfer Nitrogen - col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_met_lit) = & - col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_met_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_lab_n_si(1:nlevdecomp) * dtime - - col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & - col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_cel_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_cel_n_si(1:nlevdecomp)* dtime - - col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & - col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_lig_lit) + & - this%fates(nc)%bc_out(s)%litt_flux_lig_n_si(1:nlevdecomp) * dtime - - ! Diagnostic for mass balancing (gN/m2/s) - col_nf%plant_to_litter_nflux(c) = & - sum(this%fates(nc)%bc_out(s)%litt_flux_lab_n_si(1:nlevdecomp)*this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - sum(this%fates(nc)%bc_out(s)%litt_flux_cel_n_si(1:nlevdecomp)*this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) + & - sum(this%fates(nc)%bc_out(s)%litt_flux_lig_n_si(1:nlevdecomp)*this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp)) - - end select - - end do - end subroutine UpdateLitterFluxes !-------------------------------------------------------------------------------------- @@ -4095,9 +4028,12 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_labile, & data=col_cf%decomp_cpools_sourcesink(c,:,i_lab_lit), & hlm_flag=.true., accumulate=.true.) + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_all, & + data=col_cf%litfall(c), & + hlm_flag=.true., accumulate=.true.) - select case(fates_parteh_mode) - case (prt_cnp_flex_allom_hyp) + ! Register nitrogen and phosphorus litter fluxes if necessary + if (fates_parteh_mode == prt_cnp_flex_allom_hyp) then ! Phosphorus call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_cellulose, & data=col_cf%decomp_ppools_sourcesink(c,:,i_cel_lit), & @@ -4125,7 +4061,7 @@ subroutine RegisterHLMInterfaceVariables(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_all, & data=col_pf%plant_to_litter_nflux(c), & hlm_flag=.true., accumulate=.true.) - end select + end if end do end subroutine RegisterHLMInterfaceVariables From 2f95acb358184a2708c45fa8a1bb1bac6967b131 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 14:44:14 -0700 Subject: [PATCH 101/124] correct decomp pool registration calls --- .../elm/src/main/elmfates_interfaceMod.F90 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index f6cd0e61e0e7..64e2f45e8286 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4026,9 +4026,9 @@ subroutine RegisterHLMInterfaceVariables(this, nc) data=col_cf%decomp_cpools_sourcesink(c,:,i_lig_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_labile, & - data=col_cf%decomp_cpools_sourcesink(c,:,i_lab_lit), & + data=col_cf%decomp_cpools_sourcesink(c,:,i_met_lit), & hlm_flag=.true., accumulate=.true.) - call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_all, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_total, & data=col_cf%litfall(c), & hlm_flag=.true., accumulate=.true.) @@ -4036,30 +4036,30 @@ subroutine RegisterHLMInterfaceVariables(this, nc) if (fates_parteh_mode == prt_cnp_flex_allom_hyp) then ! Phosphorus call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_cellulose, & - data=col_cf%decomp_ppools_sourcesink(c,:,i_cel_lit), & + data=col_pf%decomp_ppools_sourcesink(c,:,i_cel_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_lignin, & - data=col_cf%decomp_ppools_sourcesink(c,:,i_lig_lit), & + data=col_pf%decomp_ppools_sourcesink(c,:,i_lig_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_labile, & - data=col_cf%decomp_ppools_sourcesink(c,:,i_lab_lit), & + data=col_pf%decomp_ppools_sourcesink(c,:,i_met_lit), & hlm_flag=.true., accumulate=.true.) - call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_all, & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_total, & data=col_pf%plant_to_litter_pflux(c), & hlm_flag=.true., accumulate=.true.) ! Nitrogen call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_cellulose, & - data=col_cf%decomp_npools_sourcesink(c,:,i_cel_lit), & + data=col_nf%decomp_npools_sourcesink(c,:,i_cel_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_lignin, & - data=col_cf%decomp_npools_sourcesink(c,:,i_lig_lit), & + data=col_nf%decomp_npools_sourcesink(c,:,i_lig_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_labile, & - data=col_cf%decomp_npools_sourcesink(c,:,i_lab_lit), & + data=col_nf%decomp_npools_sourcesink(c,:,i_met_lit), & hlm_flag=.true., accumulate=.true.) - call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_all, & - data=col_pf%plant_to_litter_nflux(c), & + call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_total, & + data=col_nf%plant_to_litter_nflux(c), & hlm_flag=.true., accumulate=.true.) end if end do From 4e0e5ef8c1a4992cf0f2d9f968d56fd837b625f0 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 14:45:13 -0700 Subject: [PATCH 102/124] add decomp litter poo type variable usage --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 64e2f45e8286..257bf8c340fa 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3974,6 +3974,10 @@ subroutine RegisterHLMInterfaceVariables(this, nc) use FatesInterfaceParametersMod + use elm_varpar, only : i_met_lit + use elm_varpar, only : i_cel_lit + use elm_varpar, only : i_lig_lit + ! Arguments class(hlm_fates_interface_type), intent(inout) :: this integer, intent(in) :: nc ! clump number From 4e9a54881156e51a529c916bdee613fd30b2df39 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 14:46:34 -0700 Subject: [PATCH 103/124] split up the registration subroutines to accomodate registration that can/should take place during init_coldstart instead of init This will mostly be the non-global data type variables --- .../elm/src/main/elmfates_interfaceMod.F90 | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 257bf8c340fa..93400f1f3d4e 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -275,7 +275,8 @@ module ELMFatesInterfaceMod procedure, public :: Init2 ! Initialization after determining subgrid weights procedure, public :: InitAccBuffer ! Initialize any accumulation buffers procedure, public :: InitAccVars ! Initialize any accumulation variables - procedure, public :: RegisterHLMInterfaceVariables + procedure, public :: RegisterInterfaceVariablesInit + procedure, public :: RegisterInterfaceVariablesColdStart procedure, public :: UpdateAccVars ! Update any accumulation variables procedure, public :: UpdateLitterFluxes procedure, private :: init_history_io @@ -1006,7 +1007,7 @@ subroutine init(this, bounds_proc, flandusepftdat) deallocate(patchlist) ! Register the HLM interface variables that we be used to populate the FATES boundary conditions - call this%RegisterHLMInterfaceVariables(nc) + call this%RegisterInterfaceVariablesInitialization(nc) ! Initialize the FATES sites call this%fates(nc)%InitializeFatesSites(natpft_size) @@ -2107,6 +2108,9 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in if ( this%fates(nc)%nsites>0 ) then + ! Register interface variables + call this%RegisterInterfaceVariablesColdStart(nc, canopystate_inst) + call get_clump_bounds(nc, bounds_clump) do s = 1,this%fates(nc)%nsites @@ -3970,7 +3974,7 @@ end subroutine GetLandusePFTData ! ====================================================================================== - subroutine RegisterHLMInterfaceVariables(this, nc) + subroutine RegisterInterfaceVariablesInit(this, nc) use FatesInterfaceParametersMod @@ -4013,8 +4017,6 @@ subroutine RegisterHLMInterfaceVariables(this, nc) c = this%fates(nc)%registry(r)%GetColumnIndex() call this%fates(nc)%registry(r)%Register(key=hlm_fates_soil_level, & data=col_pp%nlevbed(c), hlm_flag=.true.) - call this%fates(nc)%registry(r)%Register(key=hlm_fates_thaw_max_depth_index, & - data=canopystate_inst%altmax_lastyear_indx_col(c), hlm_flag=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_moisture, & data=col_cf%w_scalar(c,:), hlm_flag=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_temperature, & @@ -4067,7 +4069,33 @@ subroutine RegisterHLMInterfaceVariables(this, nc) hlm_flag=.true., accumulate=.true.) end if end do - - end subroutine RegisterHLMInterfaceVariables - + +end subroutine RegisterInterfaceVariablesInit + +! ====================================================================================== + +subroutine RegisterInterfaceVariablesColdStart(this, nc, canopystate_inst) + + use FatesInterfaceParametersMod, only : hlm_fates_thaw_max_depth_index + + class(hlm_fates_interface_type), intent(inout) :: this + integer, intent(in) :: nc + type(canopystate_type), intent(inout) :: canopystate_inst + + ! Locals + integer :: r ! register index + integer :: c ! column index + + ! Iterate over the number of vegetated patches + do r = 1, this%fates(nc)%npatches + + ! Column variables + c = this%fates(nc)%registry(r)%GetColumnIndex() + + call this%fates(nc)%registry(r)%Register(key=hlm_fates_thaw_max_depth_index, & + data=canopystate_inst%altmax_lastyear_indx_col(c), hlm_flag=.true.) + end do + +end subroutine RegisterInterfaceVariablesColdStart + end module ELMFatesInterfaceMod From 80ad5253ba61d611826c16903353073c77de59bd Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 14:47:00 -0700 Subject: [PATCH 104/124] correct the site check call to the new fates registry name --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 93400f1f3d4e..a7cc7dad10d9 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1013,9 +1013,9 @@ subroutine init(this, bounds_proc, flandusepftdat) call this%fates(nc)%InitializeFatesSites(natpft_size) do p = 1, num_veg_patches - s = this%fates(nc)%register(p)%GetSiteIndex() + s = this%fates(nc)%registry(p)%GetSiteIndex() c1 = this%f2hmap(nc)%fcolumn(s) - c2 = this%fates(nc)%register(p)%GetColumnIndex() + c2 = this%fates(nc)%registry(p)%GetColumnIndex() if (c1 /= c2 ) then write(iulog,*) ' columns do not match: p, s, c1, c2: ', p, s, c1, c2 call endrun(msg=errMsg(sourcefile, __LINE__)) From 155429149d29ecf9120e8c916cb57b5bd2d905d6 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 21:18:50 -0700 Subject: [PATCH 105/124] remove decomp_id Since we pass vert_soilc namelist tag, we can replace this init_soil_depths logic on the fates side --- components/elm/src/main/elmfates_interfaceMod.F90 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index a7cc7dad10d9..2612a31a7c85 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -308,8 +308,6 @@ module ELMFatesInterfaceMod integer, parameter :: num_landuse_pft_vars = 4 - real(r8), allocatable :: decomp_id(:) ! array to hold the idea of the decomp layer - public :: ELMFatesGlobals1 public :: ELMFatesGlobals2 public :: ELMFatesTimesteps @@ -3488,12 +3486,9 @@ subroutine init_soil_depths(this, nc) this%fates(nc)%bc_in(s)%dz_decomp_sisl(1:nlevdecomp) = & dzsoi_decomp(1:nlevdecomp) - allocate(decomp_id(nlevsoil)) - if (use_vertsoilc) then do j=1,nlevsoil this%fates(nc)%bc_in(s)%decomp_id(j) = j - decomp_id(j) = j ! Check to make sure that dz = dz_decomp_sisl when vertical soil dynamics ! are active if(abs(this%fates(nc)%bc_in(s)%dz_decomp_sisl(j)-this%fates(nc)%bc_in(s)%dz_sisl(j))>1.e-10_r8)then @@ -3508,7 +3503,6 @@ subroutine init_soil_depths(this, nc) else do j=1,nlevsoil this%fates(nc)%bc_in(s)%decomp_id(j) = 1 - decomp_id(j) = 1 end do end if @@ -4010,8 +4004,6 @@ subroutine RegisterInterfaceVariablesInit(this, nc) data=nlevdecomp_full, hlm_flag=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_thickness, & data=dzsoi_decomp, hlm_flag=.true.) - call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_id, & - data=decomp_id, hlm_flag=.true.) ! Column level variables c = this%fates(nc)%registry(r)%GetColumnIndex() From 11f5c4cc92348daec71ffbc17c405617561d4f43 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 21:41:35 -0700 Subject: [PATCH 106/124] correct registerinterfacevariablesinit call --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 2612a31a7c85..16d9104b0fb3 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1005,7 +1005,7 @@ subroutine init(this, bounds_proc, flandusepftdat) deallocate(patchlist) ! Register the HLM interface variables that we be used to populate the FATES boundary conditions - call this%RegisterInterfaceVariablesInitialization(nc) + call this%RegisterInterfaceVariablesInit(nc) ! Initialize the FATES sites call this%fates(nc)%InitializeFatesSites(natpft_size) From 5426d600046605419c420ed7613582ed579733e3 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Oct 2025 22:52:46 -0700 Subject: [PATCH 107/124] remove duplicate interface variable registration --- components/elm/src/main/elmfates_interfaceMod.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 16d9104b0fb3..91a7ca3a3757 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4013,8 +4013,6 @@ subroutine RegisterInterfaceVariablesInit(this, nc) data=col_cf%w_scalar(c,:), hlm_flag=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_temperature, & data=col_cf%t_scalar(c,:), hlm_flag=.true.) - call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_total, & - data=col_cf%litfall(c), hlm_flag=.true.) ! Variables that need to accumulate call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_cellulose, & From 497d567e4019bf906d2f0574f5af9866dfc88db7 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 21 Oct 2025 23:08:24 -0700 Subject: [PATCH 108/124] add interface variable initialization update during cold start --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 91a7ca3a3757..55077eaa82a6 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -2109,6 +2109,9 @@ subroutine init_coldstart(this, canopystate_inst, soilstate_inst, frictionvel_in ! Register interface variables call this%RegisterInterfaceVariablesColdStart(nc, canopystate_inst) + ! Update the interface variables + call this%fates(nc)%UpdateInterfaceVariables(initialize=.true.) + call get_clump_bounds(nc, bounds_clump) do s = 1,this%fates(nc)%nsites From 7e4eb5bf4caacb8d98b0ddff03e1a19c1d820f88 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 29 Oct 2025 22:20:21 -0700 Subject: [PATCH 109/124] temporary diagnostics --- .../elm/src/main/elmfates_interfaceMod.F90 | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 55077eaa82a6..f7c31ffe40b7 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1477,12 +1477,17 @@ end subroutine dynamics_driv subroutine UpdateLitterFluxes(this,bounds_clump) + use elm_varpar, only : i_met_lit + use elm_varpar, only : i_cel_lit + use elm_varpar, only : i_lig_lit + implicit none class(hlm_fates_interface_type), intent(inout) :: this type(bounds_type) , intent(in) :: bounds_clump ! !LOCAL VARIABLES: integer :: s ! site index + integer :: r ! site index integer :: c ! column index (HLM) integer :: nc ! clump index integer :: nld_si @@ -1490,8 +1495,27 @@ subroutine UpdateLitterFluxes(this,bounds_clump) dtime = real(get_step_size(),r8) nc = bounds_clump%clump_index + + do s = 1, this%fates(nc)%nsites + write(iulog,*) 'Updating litter fluxes for site: ', s + call FluxIntoLitterPools(this%fates(nc)%sites(s)) + end do call this%fates(nc)%UpdateLitterFluxes(dtime) + write(iulog,*) 'After UpdateLitterFluxes call' + + do r=1,this%fates(nc)%npatches + c = this%fates(nc)%registry(r)%GetColumnIndex() + + write(iulog,*) 'r,c,litfall: ',r,c,col_cf%litfall(c) + write(iulog,*) 'r,c,sumcel: ',r,c,sum(col_cf%decomp_cpools_sourcesink(c,:,i_cel_lit)) + write(iulog,*) 'r,c,sumlab: ',r,c,sum(col_cf%decomp_cpools_sourcesink(c,:,i_met_lit)) + write(iulog,*) 'r,c,sumlig: ',r,c,sum(col_cf%decomp_cpools_sourcesink(c,:,i_lig_lit)) + + end do + + write(iulog,*) 'Completed elmfates UpdateLitterFluxes subroutine' + end subroutine UpdateLitterFluxes From dece200f0d140deec67f26c8a2b549c09be8ed73 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Thu, 30 Oct 2025 09:20:21 -0700 Subject: [PATCH 110/124] add registration calls for restart --- components/elm/src/main/elmfates_interfaceMod.F90 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index f7c31ffe40b7..8aa001dac3b8 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1963,6 +1963,11 @@ subroutine restart( this, bounds_proc, ncid, flag, & call this%fates_restart%get_restart_vectors(nc, this%fates(nc)%nsites, & this%fates(nc)%sites ) + ! Register interface variables handled normally during cold start + call this%RegisterInterfaceVariablesColdStart(nc, canopystate_inst) + + ! Update the interface variables + call this%fates(nc)%UpdateInterfaceVariables(initialize=.true.) ! I think ed_update_site and update_hlmfates_dyn are doing some similar From 7b1e44e42922ce685345e6663a0e63ff768b55ce Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Fri, 31 Oct 2025 16:36:39 -0700 Subject: [PATCH 111/124] update fates hash --- components/elm/src/external_models/fates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/external_models/fates b/components/elm/src/external_models/fates index 55ec6c776806..5869e048634d 160000 --- a/components/elm/src/external_models/fates +++ b/components/elm/src/external_models/fates @@ -1 +1 @@ -Subproject commit 55ec6c7768061148fc107a0810d3690763d85320 +Subproject commit 5869e048634d9a4d71a71c6cb54bc1625fa8e487 From c37eda0664fca82b8101d256eb369346de9ffbb3 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 4 Nov 2025 22:32:50 -0800 Subject: [PATCH 112/124] add update interface call with new restart argument --- components/elm/src/main/elmfates_interfaceMod.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 8aa001dac3b8..dce1c715c456 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1963,11 +1963,12 @@ subroutine restart( this, bounds_proc, ncid, flag, & call this%fates_restart%get_restart_vectors(nc, this%fates(nc)%nsites, & this%fates(nc)%sites ) + ! Register interface variables handled normally during cold start call this%RegisterInterfaceVariablesColdStart(nc, canopystate_inst) ! Update the interface variables - call this%fates(nc)%UpdateInterfaceVariables(initialize=.true.) + call this%fates(nc)%UpdateInterfaceVariables(restarting=.true.) ! I think ed_update_site and update_hlmfates_dyn are doing some similar From ca05713d8239e395804589191d565a5afe9adec1 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 12 Nov 2025 08:59:13 -0800 Subject: [PATCH 113/124] Revert "temporary diagnostics" This reverts commit a781bbfc9f8f60705e88fc0183555687fcd3cb00. --- .../elm/src/main/elmfates_interfaceMod.F90 | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index dce1c715c456..1c062b90b6f6 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1477,17 +1477,12 @@ end subroutine dynamics_driv subroutine UpdateLitterFluxes(this,bounds_clump) - use elm_varpar, only : i_met_lit - use elm_varpar, only : i_cel_lit - use elm_varpar, only : i_lig_lit - implicit none class(hlm_fates_interface_type), intent(inout) :: this type(bounds_type) , intent(in) :: bounds_clump ! !LOCAL VARIABLES: integer :: s ! site index - integer :: r ! site index integer :: c ! column index (HLM) integer :: nc ! clump index integer :: nld_si @@ -1495,27 +1490,8 @@ subroutine UpdateLitterFluxes(this,bounds_clump) dtime = real(get_step_size(),r8) nc = bounds_clump%clump_index - - do s = 1, this%fates(nc)%nsites - write(iulog,*) 'Updating litter fluxes for site: ', s - call FluxIntoLitterPools(this%fates(nc)%sites(s)) - end do call this%fates(nc)%UpdateLitterFluxes(dtime) - write(iulog,*) 'After UpdateLitterFluxes call' - - do r=1,this%fates(nc)%npatches - c = this%fates(nc)%registry(r)%GetColumnIndex() - - write(iulog,*) 'r,c,litfall: ',r,c,col_cf%litfall(c) - write(iulog,*) 'r,c,sumcel: ',r,c,sum(col_cf%decomp_cpools_sourcesink(c,:,i_cel_lit)) - write(iulog,*) 'r,c,sumlab: ',r,c,sum(col_cf%decomp_cpools_sourcesink(c,:,i_met_lit)) - write(iulog,*) 'r,c,sumlig: ',r,c,sum(col_cf%decomp_cpools_sourcesink(c,:,i_lig_lit)) - - end do - - write(iulog,*) 'Completed elmfates UpdateLitterFluxes subroutine' - end subroutine UpdateLitterFluxes From 70df6fff0295b74bb4f3b355112c3287c4624690 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 17 Nov 2025 10:10:53 -0800 Subject: [PATCH 114/124] reinstate fluxintolitterpools --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 1c062b90b6f6..e96d6ec0e8cb 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1490,6 +1490,10 @@ subroutine UpdateLitterFluxes(this,bounds_clump) dtime = real(get_step_size(),r8) nc = bounds_clump%clump_index + + do s = 1, this%fates(nc)%nsites + call FluxIntoLitterPools(this%fates(nc)%sites(s)) + end do call this%fates(nc)%UpdateLitterFluxes(dtime) From 73baba86c6a8903d8c5ed62479bdacb93b9621ab Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 24 Nov 2025 15:07:23 -0800 Subject: [PATCH 115/124] update register call to only use the nlevdecomp bounds --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index e96d6ec0e8cb..55de68832253 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4029,13 +4029,13 @@ subroutine RegisterInterfaceVariablesInit(this, nc) ! Variables that need to accumulate call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_cellulose, & - data=col_cf%decomp_cpools_sourcesink(c,:,i_cel_lit), & + data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_lignin, & - data=col_cf%decomp_cpools_sourcesink(c,:,i_lig_lit), & + data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_labile, & - data=col_cf%decomp_cpools_sourcesink(c,:,i_met_lit), & + data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit), & hlm_flag=.true., accumulate=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_total, & data=col_cf%litfall(c), & From 95afd187ead7ca5d683c962b4fe44c25d37b5ad7 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Mon, 24 Nov 2025 15:06:38 -0800 Subject: [PATCH 116/124] add code to set ew bareground patch registry data --- components/elm/src/main/elmfates_interfaceMod.F90 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 55de68832253..2e2eb7febeec 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -3997,16 +3997,24 @@ subroutine RegisterInterfaceVariablesInit(this, nc) integer :: r ! register index integer :: p ! hlm patch index integer :: c ! column index + logical :: is_bareground ! Iterate over the number of vegetated patches do r = 1, this%fates(nc)%npatches p = this%fates(nc)%registry(r)%GetHLMPatchIndex() + ! Determine if the HLM patch is the initial (i.e. bareground patch) on the column + is_bareground = .false. + if (col_pp%pfti(veg_pp%column(p)) == p) then + is_bareground = .true. + end if + ! Get the subgrid indices and assign them to the register metadata call this%fates(nc)%registry(r)%SetSubgridIndices(gridcell = veg_pp%gridcell(p), & topounit = veg_pp%topounit(p), & landunit = veg_pp%landunit(p), & - column = veg_pp%column(p)) + column = veg_pp%column(p), & + bareground = is_bareground) ! Register and initialize the boundary condition variables From 9e26d60fd3ec38615c3a3f3bcb4efa5d969cb5f6 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 7 Jan 2026 15:03:52 -0800 Subject: [PATCH 117/124] add timestep conversion --- .../elm/src/main/elmfates_interfaceMod.F90 | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 2e2eb7febeec..945c346a58e4 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1497,6 +1497,38 @@ subroutine UpdateLitterFluxes(this,bounds_clump) call this%fates(nc)%UpdateLitterFluxes(dtime) + ! Scale the decomposition pools post accumulation at the column level + do c = bounds_clump%begc,bounds_clump%endc + + if (col_pp%is_fates(c)) then + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) = & + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) * dtime + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) * dtime + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) * dtime + + select case(fates_parteh_mode) + case (prt_cnp_flex_allom_hyp ) + + col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_met_lit) = & + col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_met_lit) * dtime + col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & + col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_cel_lit) * dtime + col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & + col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_lig_lit) * dtime + + col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_met_lit) = & + col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_met_lit) * dtime + col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & + col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_cel_lit) * dtime + col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & + col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_lig_lit) * dtime + + end select + + end if + end do end subroutine UpdateLitterFluxes !-------------------------------------------------------------------------------------- From 707dcf370400e6e8c85d05ae69293be8b371536c Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Wed, 7 Jan 2026 15:04:58 -0800 Subject: [PATCH 118/124] add zeroing of plan P and N fluxes before fates update --- components/elm/src/main/elmfates_interfaceMod.F90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 945c346a58e4..8ef9e3cf990c 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1495,6 +1495,12 @@ subroutine UpdateLitterFluxes(this,bounds_clump) call FluxIntoLitterPools(this%fates(nc)%sites(s)) end do + do c = bounds_clump%begc,bounds_clump%endc + if (col_pp%is_fates(c)) then + col_pf%plant_to_litter_pflux(c) = 0._r8 + col_nf%plant_to_litter_nflux(c) = 0._r8 + end if + end do call this%fates(nc)%UpdateLitterFluxes(dtime) ! Scale the decomposition pools post accumulation at the column level From e20d96171c41f2cce7e0cf21a28466bcf8943ace Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 13 Jan 2026 15:26:35 -0800 Subject: [PATCH 119/124] update registration calls to pass in is_first option as necessary --- .../elm/src/main/elmfates_interfaceMod.F90 | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 8ef9e3cf990c..9820b71e8b92 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4032,10 +4032,8 @@ subroutine RegisterInterfaceVariablesInit(this, nc) integer, intent(in) :: nc ! clump number ! Locals - integer :: r ! register index - integer :: p ! hlm patch index - integer :: c ! column index - logical :: is_bareground + logical :: is_first ! Is this register associated with the first patch on the column, landunit, etc + ! This is necessary to ensure that accumulation variables are zero'd properly ! Iterate over the number of vegetated patches do r = 1, this%fates(nc)%npatches @@ -4053,7 +4051,6 @@ subroutine RegisterInterfaceVariablesInit(this, nc) landunit = veg_pp%landunit(p), & column = veg_pp%column(p), & bareground = is_bareground) - ! Register and initialize the boundary condition variables ! Global variables @@ -4064,8 +4061,17 @@ subroutine RegisterInterfaceVariablesInit(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_thickness, & data=dzsoi_decomp, hlm_flag=.true.) - ! Column level variables + !! Column level variables + ! Get the column index c = this%fates(nc)%registry(r)%GetColumnIndex() + + ! Determine if this is the first register on the column + is_first = .false. + if (is_bareground) then + is_first = .true. + end if + + ! Variables that do not need to accumulate call this%fates(nc)%registry(r)%Register(key=hlm_fates_soil_level, & data=col_pp%nlevbed(c), hlm_flag=.true.) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_moisture, & @@ -4083,9 +4089,11 @@ subroutine RegisterInterfaceVariablesInit(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_labile, & data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit), & hlm_flag=.true., accumulate=.true.) + + ! Pass is_first option to assure HLM updates are zero'd call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_total, & data=col_cf%litfall(c), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., is_first=is_first) ! Register nitrogen and phosphorus litter fluxes if necessary if (fates_parteh_mode == prt_cnp_flex_allom_hyp) then @@ -4099,9 +4107,11 @@ subroutine RegisterInterfaceVariablesInit(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_labile, & data=col_pf%decomp_ppools_sourcesink(c,:,i_met_lit), & hlm_flag=.true., accumulate=.true.) + + ! Pass is_first option to assure HLM updates are zero'd call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_total, & data=col_pf%plant_to_litter_pflux(c), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., is_first=is_first) ! Nitrogen call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_cellulose, & @@ -4113,9 +4123,11 @@ subroutine RegisterInterfaceVariablesInit(this, nc) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_labile, & data=col_nf%decomp_npools_sourcesink(c,:,i_met_lit), & hlm_flag=.true., accumulate=.true.) + + ! Pass is_first option to assure HLM updates are zero'd call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_total, & data=col_nf%plant_to_litter_nflux(c), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., is_first=is_first) end if end do From 337a84fc0e4f5a2771adf783afa2c4b896f398b7 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 13 Jan 2026 15:55:52 -0800 Subject: [PATCH 120/124] remove unnecessary zero setting in updatelitterfluxes and add comment --- components/elm/src/main/elmfates_interfaceMod.F90 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 9820b71e8b92..086920aa8396 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1495,12 +1495,7 @@ subroutine UpdateLitterFluxes(this,bounds_clump) call FluxIntoLitterPools(this%fates(nc)%sites(s)) end do - do c = bounds_clump%begc,bounds_clump%endc - if (col_pp%is_fates(c)) then - col_pf%plant_to_litter_pflux(c) = 0._r8 - col_nf%plant_to_litter_nflux(c) = 0._r8 - end if - end do + ! Accumulate the litter fluxes at the column level call this%fates(nc)%UpdateLitterFluxes(dtime) ! Scale the decomposition pools post accumulation at the column level From be74e87f489b6c4b6bbcd2545779324b73901d9c Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 13 Jan 2026 15:56:39 -0800 Subject: [PATCH 121/124] minor text formatting --- components/elm/src/main/elmfates_interfaceMod.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index 086920aa8396..b66c3cd3ed82 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4027,6 +4027,10 @@ subroutine RegisterInterfaceVariablesInit(this, nc) integer, intent(in) :: nc ! clump number ! Locals + integer :: r ! Register index + integer :: p ! HLM patch index + integer :: c ! Column index + logical :: is_bareground ! Is this register associated with a bareground patch logical :: is_first ! Is this register associated with the first patch on the column, landunit, etc ! This is necessary to ensure that accumulation variables are zero'd properly From 5788937d89f01c74f0c47b11b590ff962961e7a0 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 27 Jan 2026 16:10:33 -0800 Subject: [PATCH 122/124] update registration call with subgrid_type argument --- .../elm/src/main/elmfates_interfaceMod.F90 | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index b66c3cd3ed82..ef62de11d9e0 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -4063,7 +4063,7 @@ subroutine RegisterInterfaceVariablesInit(this, nc) !! Column level variables ! Get the column index c = this%fates(nc)%registry(r)%GetColumnIndex() - + ! Determine if this is the first register on the column is_first = .false. if (is_bareground) then @@ -4072,61 +4072,76 @@ subroutine RegisterInterfaceVariablesInit(this, nc) ! Variables that do not need to accumulate call this%fates(nc)%registry(r)%Register(key=hlm_fates_soil_level, & - data=col_pp%nlevbed(c), hlm_flag=.true.) + data=col_pp%nlevbed(c), hlm_flag=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_moisture, & - data=col_cf%w_scalar(c,:), hlm_flag=.true.) + data=col_cf%w_scalar(c,:), hlm_flag=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_decomp_frac_temperature, & - data=col_cf%t_scalar(c,:), hlm_flag=.true.) + data=col_cf%t_scalar(c,:), hlm_flag=.true., & + subgrid_type=registry_var_intid_column) ! Variables that need to accumulate call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_cellulose, & data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_lignin, & data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_labile, & data=col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) ! Pass is_first option to assure HLM updates are zero'd call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_carbon_total, & data=col_cf%litfall(c), & - hlm_flag=.true., accumulate=.true., is_first=is_first) + hlm_flag=.true., accumulate=.true., is_first=is_first, & + subgrid_type=registry_var_intid_column) ! Register nitrogen and phosphorus litter fluxes if necessary if (fates_parteh_mode == prt_cnp_flex_allom_hyp) then ! Phosphorus call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_cellulose, & data=col_pf%decomp_ppools_sourcesink(c,:,i_cel_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_lignin, & data=col_pf%decomp_ppools_sourcesink(c,:,i_lig_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_labile, & data=col_pf%decomp_ppools_sourcesink(c,:,i_met_lit), & - hlm_flag=.true., accumulate=.true.) - + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) + ! Pass is_first option to assure HLM updates are zero'd call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_phosphorus_total, & data=col_pf%plant_to_litter_pflux(c), & - hlm_flag=.true., accumulate=.true., is_first=is_first) + hlm_flag=.true., accumulate=.true., is_first=is_first, & + subgrid_type=registry_var_intid_column) ! Nitrogen call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_cellulose, & data=col_nf%decomp_npools_sourcesink(c,:,i_cel_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_lignin, & data=col_nf%decomp_npools_sourcesink(c,:,i_lig_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_labile, & data=col_nf%decomp_npools_sourcesink(c,:,i_met_lit), & - hlm_flag=.true., accumulate=.true.) + hlm_flag=.true., accumulate=.true., & + subgrid_type=registry_var_intid_column) ! Pass is_first option to assure HLM updates are zero'd call this%fates(nc)%registry(r)%Register(key=hlm_fates_litter_nitrogen_total, & data=col_nf%plant_to_litter_nflux(c), & - hlm_flag=.true., accumulate=.true., is_first=is_first) + hlm_flag=.true., accumulate=.true., is_first=is_first, & + subgrid_type=registry_var_intid_column) end if end do From 39324070b4c16840f27da10519bcb8eed5763866 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 27 Jan 2026 16:11:35 -0800 Subject: [PATCH 123/124] white space alignment update --- .../elm/src/main/elmfates_interfaceMod.F90 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/elm/src/main/elmfates_interfaceMod.F90 b/components/elm/src/main/elmfates_interfaceMod.F90 index ef62de11d9e0..b69ab053ea65 100644 --- a/components/elm/src/main/elmfates_interfaceMod.F90 +++ b/components/elm/src/main/elmfates_interfaceMod.F90 @@ -1502,14 +1502,15 @@ subroutine UpdateLitterFluxes(this,bounds_clump) do c = bounds_clump%begc,bounds_clump%endc if (col_pp%is_fates(c)) then - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) = & - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) * dtime - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) * dtime - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & - col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) * dtime + + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) = & + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_met_lit) * dtime + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) = & + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_cel_lit) * dtime + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & + col_cf%decomp_cpools_sourcesink(c,1:nlevdecomp,i_lig_lit) * dtime - select case(fates_parteh_mode) + select case(fates_parteh_mode) case (prt_cnp_flex_allom_hyp ) col_pf%decomp_ppools_sourcesink(c,1:nlevdecomp,i_met_lit) = & @@ -1525,8 +1526,7 @@ subroutine UpdateLitterFluxes(this,bounds_clump) col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_cel_lit) * dtime col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_lig_lit) = & col_nf%decomp_npools_sourcesink(c,1:nlevdecomp,i_lig_lit) * dtime - - end select + end select end if end do From 07af80cefd5f4b9e00f037b88c69ee9151d44771 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Sun, 19 Apr 2026 16:23:56 -0700 Subject: [PATCH 124/124] update fates commit --- components/elm/src/external_models/fates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/elm/src/external_models/fates b/components/elm/src/external_models/fates index 5869e048634d..336b87f29e3d 160000 --- a/components/elm/src/external_models/fates +++ b/components/elm/src/external_models/fates @@ -1 +1 @@ -Subproject commit 5869e048634d9a4d71a71c6cb54bc1625fa8e487 +Subproject commit 336b87f29e3d57d19cdd8625e57985502da1d913