From af6a2717d3e45b0b75d1d33126e7b6f3ab34c6a5 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Fri, 13 Oct 2023 13:10:58 -0600 Subject: [PATCH 1/5] Removed canopy_structure() from the restart sequence, it shouldn't be there --- main/EDMainMod.F90 | 33 ++++++++++++++++--------------- main/FatesRestartInterfaceMod.F90 | 17 +++++++++++++++- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/main/EDMainMod.F90 b/main/EDMainMod.F90 index 7bbe46cb99..6a360352ab 100644 --- a/main/EDMainMod.F90 +++ b/main/EDMainMod.F90 @@ -763,7 +763,7 @@ subroutine ed_integrate_state_variables(currentSite, bc_in, bc_out ) end subroutine ed_integrate_state_variables !-------------------------------------------------------------------------------! - subroutine ed_update_site( currentSite, bc_in, bc_out ) + subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) ! ! !DESCRIPTION: ! Calls routines to consolidate the ED growth process. @@ -779,6 +779,7 @@ subroutine ed_update_site( currentSite, bc_in, bc_out ) type(ed_site_type) , intent(inout), target :: currentSite type(bc_in_type) , intent(in) :: bc_in type(bc_out_type) , intent(inout) :: bc_out + logical,intent(in) :: is_restart ! is this called during restart read? ! ! !LOCAL VARIABLES: type (fates_patch_type) , pointer :: currentPatch @@ -789,7 +790,7 @@ subroutine ed_update_site( currentSite, bc_in, bc_out ) call TotalBalanceCheck(currentSite,6) - if(hlm_use_sp.eq.ifalse)then + if(hlm_use_sp.eq.ifalse .and. (.not.is_restart) )then call canopy_structure(currentSite, bc_in) endif @@ -803,22 +804,22 @@ subroutine ed_update_site( currentSite, bc_in, bc_out ) currentPatch => currentSite%oldest_patch do while(associated(currentPatch)) - ! Is termination really needed here? - ! Canopy_structure just called it several times! (rgk) - call terminate_cohorts(currentSite, currentPatch, 1, 11, bc_in) - call terminate_cohorts(currentSite, currentPatch, 2, 11, bc_in) - - ! This cohort count is used in the photosynthesis loop - call count_cohorts(currentPatch) - - ! Update the total area of by patch age class array - currentSite%area_by_age(currentPatch%age_class) = & - currentSite%area_by_age(currentPatch%age_class) + currentPatch%area - - currentPatch => currentPatch%younger + if(.not.is_restart)then + call terminate_cohorts(currentSite, currentPatch, 1, 11, bc_in) + call terminate_cohorts(currentSite, currentPatch, 2, 11, bc_in) + end if + ! This cohort count is used in the photosynthesis loop + call count_cohorts(currentPatch) + + ! Update the total area of by patch age class array + currentSite%area_by_age(currentPatch%age_class) = & + currentSite%area_by_age(currentPatch%age_class) + currentPatch%area + + currentPatch => currentPatch%younger + enddo - + ! The HLMs need to know about nutrient demand, and/or ! root mass and affinities call PrepNutrientAquisitionBCs(currentSite,bc_in,bc_out) diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90 index 55016e9acb..05fa063601 100644 --- a/main/FatesRestartInterfaceMod.F90 +++ b/main/FatesRestartInterfaceMod.F90 @@ -140,7 +140,8 @@ module FatesRestartInterfaceMod integer :: ir_treesai_co integer :: ir_canopy_layer_tlai_pa - + integer :: ir_nclp_pa + integer :: ir_zstar_pa !Logging integer :: ir_lmort_direct_co @@ -1133,12 +1134,22 @@ subroutine define_restart_vars(this, initialize_variables) long_name='stem area index of fates cohort', & units='m2/m2', flushval = flushzero, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_treesai_co ) + call this%set_restart_var(vname='fates_canopy_layer_tlai_pa', vtype=cohort_r8, & long_name='total patch level leaf area index of each fates canopy layer', & units='m2/m2', flushval = flushzero, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_canopy_layer_tlai_pa ) end if + call this%set_restart_var(vname='fates_nclp_pa', vtype=cohort_r8, & + long_name='total number of canopy layers', & + units='-', flushval = flushzero, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_nclp_pa ) + + call this%set_restart_var(vname='fates_zstar_pa', vtype=cohort_r8, & + long_name='patch zstar', & + units='-', flushval = flushzero, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_zstar_pa ) ! Only register hydraulics restart variables if it is turned on! @@ -2402,6 +2413,8 @@ subroutine set_restart_vectors(this,nc,nsites,sites) ,io_idx_co,cohortsperpatch endif + this%rvars(ir_nclp_pa)%r81d(io_idx_co_1st) = cpatch%ncl_p + this%rvars(ir_zstar_pa)%r81d(io_idx_co_1st) = cpatch%zstar if(hlm_use_sp.eq.ifalse)then @@ -3301,6 +3314,8 @@ subroutine get_restart_vectors(this, nc, nsites, sites) cpatch%solar_zenith_flag = ( rio_solar_zenith_flag_pa(io_idx_co_1st) .eq. itrue ) cpatch%solar_zenith_angle = rio_solar_zenith_angle_pa(io_idx_co_1st) + cpatch%ncl_p = this%rvars(ir_nclp_pa)%r81d(io_idx_co_1st) + cpatch%zstar = this%rvars(ir_zstar_pa)%r81d(io_idx_co_1st) call this%GetRMeanRestartVar(cpatch%tveg24, ir_tveg24_pa, io_idx_co_1st) call this%GetRMeanRestartVar(cpatch%tveg_lpa, ir_tveglpa_pa, io_idx_co_1st) From 438a1e5c428242a5d628e8bec6deac3f1bc5c008 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Mon, 16 Oct 2023 10:25:41 -0400 Subject: [PATCH 2/5] Changed ncl_p restart variable to integer, since... its and integer --- main/FatesRestartInterfaceMod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90 index 05fa063601..96ef276779 100644 --- a/main/FatesRestartInterfaceMod.F90 +++ b/main/FatesRestartInterfaceMod.F90 @@ -1141,7 +1141,7 @@ subroutine define_restart_vars(this, initialize_variables) hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_canopy_layer_tlai_pa ) end if - call this%set_restart_var(vname='fates_nclp_pa', vtype=cohort_r8, & + call this%set_restart_var(vname='fates_nclp_pa', vtype=cohort_int, & long_name='total number of canopy layers', & units='-', flushval = flushzero, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_nclp_pa ) @@ -2413,7 +2413,7 @@ subroutine set_restart_vectors(this,nc,nsites,sites) ,io_idx_co,cohortsperpatch endif - this%rvars(ir_nclp_pa)%r81d(io_idx_co_1st) = cpatch%ncl_p + this%rvars(ir_nclp_pa)%int1d(io_idx_co_1st) = cpatch%ncl_p this%rvars(ir_zstar_pa)%r81d(io_idx_co_1st) = cpatch%zstar if(hlm_use_sp.eq.ifalse)then @@ -3314,7 +3314,7 @@ subroutine get_restart_vectors(this, nc, nsites, sites) cpatch%solar_zenith_flag = ( rio_solar_zenith_flag_pa(io_idx_co_1st) .eq. itrue ) cpatch%solar_zenith_angle = rio_solar_zenith_angle_pa(io_idx_co_1st) - cpatch%ncl_p = this%rvars(ir_nclp_pa)%r81d(io_idx_co_1st) + cpatch%ncl_p = this%rvars(ir_nclp_pa)%int1d(io_idx_co_1st) cpatch%zstar = this%rvars(ir_zstar_pa)%r81d(io_idx_co_1st) call this%GetRMeanRestartVar(cpatch%tveg24, ir_tveg24_pa, io_idx_co_1st) From 078003df72eef69db66cabcc5f492dd894f4be92 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Sun, 29 Oct 2023 10:28:15 -0600 Subject: [PATCH 3/5] Added yearly net uptake vector to restart, added a filter on trimming so it doesnt happen an extra time on the restart call (unlikely but possible) --- main/EDMainMod.F90 | 10 +++++----- main/FatesRestartInterfaceMod.F90 | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/main/EDMainMod.F90 b/main/EDMainMod.F90 index 6a360352ab..52176e199f 100644 --- a/main/EDMainMod.F90 +++ b/main/EDMainMod.F90 @@ -784,7 +784,8 @@ subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) ! !LOCAL VARIABLES: type (fates_patch_type) , pointer :: currentPatch !----------------------------------------------------------------------- - if(hlm_use_sp.eq.ifalse)then + + if(hlm_use_sp.eq.ifalse .and. (.not.is_restart))then call canopy_spread(currentSite) end if @@ -831,10 +832,9 @@ subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) ! FIX(RF,032414). This needs to be monthly, not annual ! If this is the second to last day of the year, then perform trimming - if( hlm_day_of_year == hlm_days_per_year-1) then - - if(hlm_use_sp.eq.ifalse)then - call trim_canopy(currentSite) + if( hlm_day_of_year == hlm_days_per_year-1 .and. (.not.is_restart)) then + if(hlm_use_sp.eq.ifalse)then + call trim_canopy(currentSite) endif endif diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90 index 05fa063601..8c08c88c93 100644 --- a/main/FatesRestartInterfaceMod.F90 +++ b/main/FatesRestartInterfaceMod.F90 @@ -104,6 +104,8 @@ module FatesRestartInterfaceMod integer :: ir_canopy_trim_co integer :: ir_l2fr_co + integer :: ir_year_net_up_co + integer :: ir_cx_int_co integer :: ir_emadcxdt_co integer :: ir_cx0_co @@ -1011,6 +1013,12 @@ subroutine define_restart_vars(this, initialize_variables) hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_litter_moisture_pa_nfsc) end if + + call this%RegisterCohortVector(symbol_base='fates_year_net_up', vtype=cohort_r8, & + long_name_base='yearly net uptake at leaf layers', & + units='kg/m2/year', veclength=nlevleaf, flushval = flushzero, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_year_net_up_co ) + ! Site Level Diagnostics over multiple nutrients @@ -2271,6 +2279,8 @@ subroutine set_restart_vectors(this,nc,nsites,sites) end do end do + call this%SetCohortRealVector(ccohort%year_net_uptake,nlevleaf,ir_year_net_up_co,io_idx_co) + rio_l2fr_co(io_idx_co) = ccohort%l2fr if(hlm_parteh_mode .eq. prt_cnp_flex_allom_hyp) then @@ -3205,6 +3215,8 @@ subroutine get_restart_vectors(this, nc, nsites, sites) ccohort%canopy_trim = rio_canopy_trim_co(io_idx_co) ccohort%l2fr = rio_l2fr_co(io_idx_co) + call this%GetCohortRealVector(ccohort%year_net_uptake,nlevleaf,ir_year_net_up_co,io_idx_co) + if(hlm_parteh_mode .eq. prt_cnp_flex_allom_hyp) then ccohort%cx_int = this%rvars(ir_cx_int_co)%r81d(io_idx_co) ccohort%ema_dcxdt = this%rvars(ir_emadcxdt_co)%r81d(io_idx_co) From 261811b5351433c17b1033ebdd8708217a7b2748 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Tue, 7 Nov 2023 20:07:57 -0700 Subject: [PATCH 4/5] Fixed keyword name to match --- main/EDMainMod.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main/EDMainMod.F90 b/main/EDMainMod.F90 index 2b2da8a2ee..59e3096409 100644 --- a/main/EDMainMod.F90 +++ b/main/EDMainMod.F90 @@ -765,7 +765,7 @@ subroutine ed_integrate_state_variables(currentSite, bc_in, bc_out ) end subroutine ed_integrate_state_variables !-------------------------------------------------------------------------------! - subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) + subroutine ed_update_site( currentSite, bc_in, bc_out, is_restarting ) ! ! !DESCRIPTION: ! Calls routines to consolidate the ED growth process. @@ -781,19 +781,19 @@ subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) type(ed_site_type) , intent(inout), target :: currentSite type(bc_in_type) , intent(in) :: bc_in type(bc_out_type) , intent(inout) :: bc_out - logical,intent(in) :: is_restart ! is this called during restart read? + logical,intent(in) :: is_restarting ! is this called during restart read? ! ! !LOCAL VARIABLES: type (fates_patch_type) , pointer :: currentPatch !----------------------------------------------------------------------- - if(hlm_use_sp.eq.ifalse .and. (.not.is_restart))then + if(hlm_use_sp.eq.ifalse .and. (.not.is_restarting))then call canopy_spread(currentSite) end if call TotalBalanceCheck(currentSite,6) - if(hlm_use_sp.eq.ifalse .and. (.not.is_restart) )then + if(hlm_use_sp.eq.ifalse .and. (.not.is_restarting) )then call canopy_structure(currentSite, bc_in) endif @@ -807,7 +807,7 @@ subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) currentPatch => currentSite%oldest_patch do while(associated(currentPatch)) - if(.not.is_restart)then + if(.not.is_restarting)then call terminate_cohorts(currentSite, currentPatch, 1, 11, bc_in) call terminate_cohorts(currentSite, currentPatch, 2, 11, bc_in) end if @@ -834,7 +834,7 @@ subroutine ed_update_site( currentSite, bc_in, bc_out, is_restart ) ! FIX(RF,032414). This needs to be monthly, not annual ! If this is the second to last day of the year, then perform trimming - if( hlm_day_of_year == hlm_days_per_year-1 .and. (.not.is_restart)) then + if( hlm_day_of_year == hlm_days_per_year-1 .and. (.not.is_restarting)) then if(hlm_use_sp.eq.ifalse)then call trim_canopy(currentSite) endif From 80c0fa9a9d1ee4d4cc1d5322860df0130588dd5c Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Wed, 8 Nov 2023 08:09:02 -0700 Subject: [PATCH 5/5] making crown area available in the restart, because its needed --- main/FatesRestartInterfaceMod.F90 | 50 ++++++++++++++----------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90 index baec2149e5..36a571516b 100644 --- a/main/FatesRestartInterfaceMod.F90 +++ b/main/FatesRestartInterfaceMod.F90 @@ -1133,21 +1133,21 @@ subroutine define_restart_vars(this, initialize_variables) ! Only register satellite phenology related restart variables if it is turned on! - if(hlm_use_sp .eq. itrue) then - call this%set_restart_var(vname='fates_cohort_area', vtype=cohort_r8, & - long_name='area of the fates cohort', & - units='m2', flushval = flushzero, & - hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_c_area_co ) - call this%set_restart_var(vname='fates_cohort_treelai', vtype=cohort_r8, & - long_name='leaf area index of fates cohort', & - units='m2/m2', flushval = flushzero, & - hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_treelai_co ) - call this%set_restart_var(vname='fates_cohort_treesai', vtype=cohort_r8, & - long_name='stem area index of fates cohort', & - units='m2/m2', flushval = flushzero, & - hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_treesai_co ) - - call this%set_restart_var(vname='fates_canopy_layer_tlai_pa', vtype=cohort_r8, & + call this%set_restart_var(vname='fates_cohort_area', vtype=cohort_r8, & + long_name='area of the fates cohort', & + units='m2', flushval = flushzero, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_c_area_co ) + call this%set_restart_var(vname='fates_cohort_treelai', vtype=cohort_r8, & + long_name='leaf area index of fates cohort', & + units='m2/m2', flushval = flushzero, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_treelai_co ) + call this%set_restart_var(vname='fates_cohort_treesai', vtype=cohort_r8, & + long_name='stem area index of fates cohort', & + units='m2/m2', flushval = flushzero, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_treesai_co ) + + if(hlm_use_sp .eq. itrue)then + call this%set_restart_var(vname='fates_canopy_layer_tlai_pa', vtype=cohort_r8, & long_name='total patch level leaf area index of each fates canopy layer', & units='m2/m2', flushval = flushzero, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_canopy_layer_tlai_pa ) @@ -2376,12 +2376,10 @@ subroutine set_restart_vectors(this,nc,nsites,sites) rio_isnew_co(io_idx_co) = old_cohort endif - if (hlm_use_sp .eq. itrue) then - this%rvars(ir_c_area_co)%r81d(io_idx_co) = ccohort%c_area - this%rvars(ir_treelai_co)%r81d(io_idx_co) = ccohort%treelai - this%rvars(ir_treesai_co)%r81d(io_idx_co) = ccohort%treesai - end if - + this%rvars(ir_c_area_co)%r81d(io_idx_co) = ccohort%c_area + this%rvars(ir_treelai_co)%r81d(io_idx_co) = ccohort%treelai + this%rvars(ir_treesai_co)%r81d(io_idx_co) = ccohort%treesai + if ( debug ) then write(fates_log(),*) 'CLTV offsetNumCohorts II ',io_idx_co, & cohortsperpatch @@ -3314,12 +3312,10 @@ subroutine get_restart_vectors(this, nc, nsites, sites) ! (Keeping as an example) !call this%GetRMeanRestartVar(ccohort%tveg_lpa, ir_tveglpa_co, io_idx_co) - if (hlm_use_sp .eq. itrue) then - ccohort%c_area = this%rvars(ir_c_area_co)%r81d(io_idx_co) - ccohort%treelai = this%rvars(ir_treelai_co)%r81d(io_idx_co) - ccohort%treesai = this%rvars(ir_treesai_co)%r81d(io_idx_co) - end if - + ccohort%c_area = this%rvars(ir_c_area_co)%r81d(io_idx_co) + ccohort%treelai = this%rvars(ir_treelai_co)%r81d(io_idx_co) + ccohort%treesai = this%rvars(ir_treesai_co)%r81d(io_idx_co) + io_idx_co = io_idx_co + 1 ccohort => ccohort%taller