From f5db16b10a0f850b588198e007e5cb5d38ff58d4 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Fri, 14 Aug 2020 12:44:03 -0400 Subject: [PATCH 1/5] Added the phen_model_day timer to work with all restart conditions --- biogeochem/EDPhysiologyMod.F90 | 11 +++++- main/EDInitMod.F90 | 66 ++++++++++++++++--------------- main/EDTypesMod.F90 | 5 +++ main/FatesRestartInterfaceMod.F90 | 48 ++++++++++++---------- 4 files changed, 76 insertions(+), 54 deletions(-) diff --git a/biogeochem/EDPhysiologyMod.F90 b/biogeochem/EDPhysiologyMod.F90 index 0c23795f9a..3d35319b42 100644 --- a/biogeochem/EDPhysiologyMod.F90 +++ b/biogeochem/EDPhysiologyMod.F90 @@ -744,8 +744,9 @@ subroutine phenology( currentSite, bc_in ) ! This is the integer model day. The first day of the simulation is 1, and it ! continues monotonically, indefinitely - model_day_int = nint(hlm_model_day) + + model_day_int = currentSite%phen_model_date ! Use the following layer index to calculate drought conditions ilayer_swater = minloc(abs(bc_in%z_sisl(:)-dphen_soil_depth),dim=1) @@ -1061,6 +1062,12 @@ subroutine phenology( currentSite, bc_in ) call phenology_leafonoff(currentSite) + ! Advance the model day (this should be a global, no reason + ! for site level, but we don't have global scalars in the + ! restart file) + + currentSite%phen_model_date = currentSite%phen_model_date + 1 + end subroutine phenology ! ============================================================================ @@ -1349,7 +1356,7 @@ subroutine SeedIn( currentSite, bc_in ) ! !USES: use EDTypesMod, only : area use EDTypesMod, only : homogenize_seed_pfts - !use FatesInterfaceTypesMod, only : hlm_use_fixed_biogeog ! For future reduced complexity? + ! ! !ARGUMENTS type(ed_site_type), intent(inout), target :: currentSite diff --git a/main/EDInitMod.F90 b/main/EDInitMod.F90 index 646084ef1b..a9f2ee4c69 100644 --- a/main/EDInitMod.F90 +++ b/main/EDInitMod.F90 @@ -25,32 +25,33 @@ module EDInitMod use EDTypesMod , only : AREA use EDTypesMod , only : init_spread_near_bare_ground use EDTypesMod , only : init_spread_inventory - use EDTypesMod , only : leaves_on - use EDTypesMod , only : leaves_off - use EDTypesMod , only : num_elements - use EDTypesMod , only : element_list - use EDTypesMod , only : phen_cstat_nevercold - use EDTypesMod , only : phen_cstat_iscold - use EDTypesMod , only : phen_dstat_timeoff - use EDTypesMod , only : phen_dstat_moistoff - use EDTypesMod , only : phen_cstat_notcold - use EDTypesMod , only : phen_dstat_moiston - use FatesInterfaceTypesMod , only : bc_in_type - use FatesInterfaceTypesMod , only : hlm_use_planthydro - use FatesInterfaceTypesMod , only : hlm_use_inventory_init - use FatesInterfaceTypesMod , only : hlm_use_fixed_biogeog - use FatesInterfaceTypesMod , only : numpft - use FatesInterfaceTypesMod , only : nleafage - use FatesInterfaceTypesMod , only : nlevsclass - use FatesInterfaceTypesMod , only : nlevcoage - use FatesAllometryMod , only : h2d_allom - use FatesAllometryMod , only : bagw_allom - use FatesAllometryMod , only : bbgw_allom - use FatesAllometryMod , only : bleaf - use FatesAllometryMod , only : bfineroot - use FatesAllometryMod , only : bsap_allom - use FatesAllometryMod , only : bdead_allom - use FatesAllometryMod , only : bstore_allom + use EDTypesMod , only : leaves_on + use EDTypesMod , only : leaves_off + use EDTypesMod , only : num_elements + use EDTypesMod , only : element_list + use EDTypesMod , only : phen_cstat_nevercold + use EDTypesMod , only : phen_cstat_iscold + use EDTypesMod , only : phen_dstat_timeoff + use EDTypesMod , only : phen_dstat_moistoff + use EDTypesMod , only : phen_cstat_notcold + use EDTypesMod , only : phen_dstat_moiston + use FatesInterfaceTypesMod , only : hlm_day_of_year + use FatesInterfaceTypesMod , only : bc_in_type + use FatesInterfaceTypesMod , only : hlm_use_planthydro + use FatesInterfaceTypesMod , only : hlm_use_inventory_init + use FatesInterfaceTypesMod , only : hlm_use_fixed_biogeog + use FatesInterfaceTypesMod , only : numpft + use FatesInterfaceTypesMod , only : nleafage + use FatesInterfaceTypesMod , only : nlevsclass + use FatesInterfaceTypesMod , only : nlevcoage + use FatesAllometryMod , only : h2d_allom + use FatesAllometryMod , only : bagw_allom + use FatesAllometryMod , only : bbgw_allom + use FatesAllometryMod , only : bleaf + use FatesAllometryMod , only : bfineroot + use FatesAllometryMod , only : bsap_allom + use FatesAllometryMod , only : bdead_allom + use FatesAllometryMod , only : bstore_allom use FatesInterfaceTypesMod, only : hlm_parteh_mode use PRTGenericMod, only : prt_carbon_allom_hyp @@ -167,16 +168,16 @@ subroutine zero_site( site_in ) site_in%cstatus = fates_unset_int ! are leaves in this pixel on or off? site_in%dstatus = fates_unset_int - site_in%grow_deg_days = nan ! growing degree days + site_in%grow_deg_days = nan ! growing degree days site_in%nchilldays = fates_unset_int site_in%ncolddays = fates_unset_int - site_in%cleafondate = fates_unset_int ! doy of leaf on - site_in%cleafoffdate = fates_unset_int ! doy of leaf off - site_in%dleafondate = fates_unset_int ! doy of leaf on drought - site_in%dleafoffdate = fates_unset_int ! doy of leaf on drought + site_in%cleafondate = fates_unset_int + site_in%cleafoffdate = fates_unset_int + site_in%dleafondate = fates_unset_int + site_in%dleafoffdate = fates_unset_int site_in%water_memory(:) = nan site_in%vegtemp_memory(:) = nan ! record of last 10 days temperature for senescence model. - + site_in%phen_model_date = fates_unset_int ! FIRE site_in%acc_ni = 0.0_r8 ! daily nesterov index accumulating over time. time unlimited theoretically. @@ -277,6 +278,7 @@ subroutine set_site_properties( nsites, sites,bc_in ) ! is memory-less, but needed ! for first value in history file + sites(s)%phen_model_date = hlm_day_of_year sites(s)%cleafondate = cleafon sites(s)%cleafoffdate = cleafoff sites(s)%dleafoffdate = dleafoff diff --git a/main/EDTypesMod.F90 b/main/EDTypesMod.F90 index 0e843df123..e3f0555722 100644 --- a/main/EDTypesMod.F90 +++ b/main/EDTypesMod.F90 @@ -690,7 +690,12 @@ module EDTypesMod integer :: cleafoffdate ! model date (day integer) of leaf off (cold):- integer :: dleafondate ! model date (day integer) of leaf on drought:- integer :: dleafoffdate ! model date (day integer) of leaf off drought:- + integer :: phen_model_date ! current model date (day integer) + ! this date stays continuous when + ! in runs that are restarted, regardless of + ! the conditions of restart + real(r8) :: water_memory(numWaterMem) ! last 10 days of soil moisture memory... diff --git a/main/FatesRestartInterfaceMod.F90 b/main/FatesRestartInterfaceMod.F90 index 6f32df2382..3b315183ec 100644 --- a/main/FatesRestartInterfaceMod.F90 +++ b/main/FatesRestartInterfaceMod.F90 @@ -80,10 +80,11 @@ module FatesRestartInterfaceMod integer :: ir_dd_status_si integer :: ir_nchill_days_si integer :: ir_ncold_days_si - integer :: ir_leafondate_si - integer :: ir_leafoffdate_si + integer :: ir_cleafondate_si + integer :: ir_cleafoffdate_si integer :: ir_dleafondate_si integer :: ir_dleafoffdate_si + integer :: ir_phenmodeldate_si integer :: ir_acc_ni_si integer :: ir_gdd_si integer :: ir_trunk_product_si @@ -577,22 +578,26 @@ subroutine define_restart_vars(this, initialize_variables) long_name='cold day counter', units='unitless', flushval = flushinvalid, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_ncold_days_si ) - call this%set_restart_var(vname='fates_leafondate', vtype=site_int, & - long_name='the day of year for leaf on', units='day of year', flushval = flushinvalid, & - hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_leafondate_si ) + call this%set_restart_var(vname='fates_cold_leafondate', vtype=site_int, & + long_name='the model day of last cold leaf on', units='absolute integer day', flushval = flushinvalid, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cleafondate_si ) - call this%set_restart_var(vname='fates_leafoffdate', vtype=site_int, & - long_name='the day of year for leaf off', units='day of year', flushval = flushinvalid, & - hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_leafoffdate_si ) + call this%set_restart_var(vname='fates_cold_leafoffdate', vtype=site_int, & + long_name='the model day last cold leaf off', units='absolute integer day', flushval = flushinvalid, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_cleafoffdate_si ) call this%set_restart_var(vname='fates_drought_leafondate', vtype=site_int, & - long_name='the day of year for drought based leaf-on', units='day of year', flushval = flushinvalid, & + long_name='the model day of last drought based leaf-on', units='absolute integer day', flushval = flushinvalid, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_dleafondate_si ) call this%set_restart_var(vname='fates_drought_leafoffdate', vtype=site_int, & - long_name='the day of year for drought based leaf-off', units='day of year', flushval = flushinvalid, & + long_name='the model day of last drought based leaf-off', units='absolute integer day', flushval = flushinvalid, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_dleafoffdate_si ) + call this%set_restart_var(vname='fates_phen_model_date', vtype=site_int, & + long_name='integer model day used for phen timing', units='absolute integer day', flushval = flushinvalid, & + hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_phenmodeldate_si ) + call this%set_restart_var(vname='fates_acc_nesterov_id', vtype=site_r8, & long_name='a nesterov index accumulator', units='unitless', flushval = flushzero, & hlms='CLM:ALM', initialize=initialize_variables, ivar=ivar, index = ir_acc_ni_si ) @@ -1491,10 +1496,11 @@ subroutine set_restart_vectors(this,nc,nsites,sites) rio_dd_status_si => this%rvars(ir_dd_status_si)%int1d, & rio_nchill_days_si => this%rvars(ir_nchill_days_si)%int1d, & rio_ncold_days_si => this%rvars(ir_ncold_days_si)%int1d, & - rio_leafondate_si => this%rvars(ir_leafondate_si)%int1d, & - rio_leafoffdate_si => this%rvars(ir_leafoffdate_si)%int1d, & + rio_cleafondate_si => this%rvars(ir_cleafondate_si)%int1d, & + rio_cleafoffdate_si => this%rvars(ir_cleafoffdate_si)%int1d, & rio_dleafondate_si => this%rvars(ir_dleafondate_si)%int1d, & rio_dleafoffdate_si => this%rvars(ir_dleafoffdate_si)%int1d, & + rio_phenmodeldate_si => this%rvars(ir_phenmodeldate_si)%int1d, & rio_acc_ni_si => this%rvars(ir_acc_ni_si)%r81d, & rio_gdd_si => this%rvars(ir_gdd_si)%r81d, & rio_trunk_product_si => this%rvars(ir_trunk_product_si)%r81d, & @@ -1902,9 +1908,9 @@ subroutine set_restart_vectors(this,nc,nsites,sites) rio_dd_status_si(io_idx_si) = sites(s)%dstatus rio_nchill_days_si(io_idx_si) = sites(s)%nchilldays rio_ncold_days_si(io_idx_si) = sites(s)%ncolddays - rio_leafondate_si(io_idx_si) = sites(s)%cleafondate - rio_leafoffdate_si(io_idx_si) = sites(s)%cleafoffdate - + rio_cleafondate_si(io_idx_si) = sites(s)%cleafondate + rio_cleafoffdate_si(io_idx_si) = sites(s)%cleafoffdate + rio_phenmodeldate_si(io_idx_si)= sites(s)%phen_model_date rio_dleafondate_si(io_idx_si) = sites(s)%dleafondate rio_dleafoffdate_si(io_idx_si) = sites(s)%dleafoffdate rio_acc_ni_si(io_idx_si) = sites(s)%acc_NI @@ -2238,10 +2244,11 @@ subroutine get_restart_vectors(this, nc, nsites, sites) rio_dd_status_si => this%rvars(ir_dd_status_si)%int1d, & rio_nchill_days_si => this%rvars(ir_nchill_days_si)%int1d, & rio_ncold_days_si => this%rvars(ir_ncold_days_si)%int1d, & - rio_leafondate_si => this%rvars(ir_leafondate_si)%int1d, & - rio_leafoffdate_si => this%rvars(ir_leafoffdate_si)%int1d, & + rio_cleafondate_si => this%rvars(ir_cleafondate_si)%int1d, & + rio_cleafoffdate_si => this%rvars(ir_cleafoffdate_si)%int1d, & rio_dleafondate_si => this%rvars(ir_dleafondate_si)%int1d, & rio_dleafoffdate_si => this%rvars(ir_dleafoffdate_si)%int1d, & + rio_phenmodeldate_si => this%rvars(ir_phenmodeldate_si)%int1d, & rio_acc_ni_si => this%rvars(ir_acc_ni_si)%r81d, & rio_gdd_si => this%rvars(ir_gdd_si)%r81d, & rio_trunk_product_si => this%rvars(ir_trunk_product_si)%r81d, & @@ -2678,13 +2685,14 @@ subroutine get_restart_vectors(this, nc, nsites, sites) sites(s)%dstatus = rio_dd_status_si(io_idx_si) sites(s)%nchilldays = rio_nchill_days_si(io_idx_si) sites(s)%ncolddays = rio_ncold_days_si(io_idx_si) - sites(s)%cleafondate = rio_leafondate_si(io_idx_si) - sites(s)%cleafoffdate = rio_leafoffdate_si(io_idx_si) + sites(s)%cleafondate = rio_cleafondate_si(io_idx_si) + sites(s)%cleafoffdate = rio_cleafoffdate_si(io_idx_si) sites(s)%dleafondate = rio_dleafondate_si(io_idx_si) sites(s)%dleafoffdate = rio_dleafoffdate_si(io_idx_si) sites(s)%acc_NI = rio_acc_ni_si(io_idx_si) sites(s)%grow_deg_days = rio_gdd_si(io_idx_si) - + sites(s)%phen_model_date= rio_phenmodeldate_si(io_idx_si) + sites(s)%resources_management%trunk_product_site = rio_trunk_product_si(io_idx_si) end do From 325245ae826d3af4290536eaa04430924e993ece Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Fri, 14 Aug 2020 19:42:03 -0400 Subject: [PATCH 2/5] fixed dleafon_date in history writes. Slightly shifted the phenology model day counter to start at 0, and +1 at start of phenology routine, which is simpler for restarts. --- biogeochem/EDPhysiologyMod.F90 | 6 +- main/EDInitMod.F90 | 189 +----------------------------- main/FatesHistoryInterfaceMod.F90 | 17 ++- 3 files changed, 17 insertions(+), 195 deletions(-) diff --git a/biogeochem/EDPhysiologyMod.F90 b/biogeochem/EDPhysiologyMod.F90 index 3d35319b42..d689411953 100644 --- a/biogeochem/EDPhysiologyMod.F90 +++ b/biogeochem/EDPhysiologyMod.F90 @@ -745,7 +745,7 @@ subroutine phenology( currentSite, bc_in ) ! This is the integer model day. The first day of the simulation is 1, and it ! continues monotonically, indefinitely - + currentSite%phen_model_date = currentSite%phen_model_date + 1 model_day_int = currentSite%phen_model_date ! Use the following layer index to calculate drought conditions @@ -850,7 +850,7 @@ subroutine phenology( currentSite, bc_in ) end if if (model_day_int < currentSite%cleafondate) then - dayssincecleafon = model_day_int - (currentSite%cleafondate-365) + dayssincecleafon = model_day_int - (currentSite%cleafondate - 365) else dayssincecleafon = model_day_int - currentSite%cleafondate end if @@ -1066,7 +1066,7 @@ subroutine phenology( currentSite, bc_in ) ! for site level, but we don't have global scalars in the ! restart file) - currentSite%phen_model_date = currentSite%phen_model_date + 1 + end subroutine phenology diff --git a/main/EDInitMod.F90 b/main/EDInitMod.F90 index a9f2ee4c69..074f645cb4 100644 --- a/main/EDInitMod.F90 +++ b/main/EDInitMod.F90 @@ -1,181 +1,4 @@ -module EDInitMod - ! ============================================================================ - ! Contains all modules to set up the ED structure. - ! ============================================================================ - - use FatesConstantsMod , only : r8 => fates_r8 - use FatesConstantsMod , only : ifalse - use FatesConstantsMod , only : itrue - use FatesConstantsMod , only : fates_unset_int - use FatesConstantsMod , only : primaryforest - use FatesGlobals , only : endrun => fates_endrun - use EDTypesMod , only : nclmax - use FatesGlobals , only : fates_log - use FatesInterfaceTypesMod , only : hlm_is_restart - use EDPftvarcon , only : EDPftvarcon_inst - use EDCohortDynamicsMod , only : create_cohort, fuse_cohorts, sort_cohorts - use EDCohortDynamicsMod , only : InitPRTObject - use EDPatchDynamicsMod , only : create_patch - use ChecksBalancesMod , only : SiteMassStock - use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type - use EDTypesMod , only : numWaterMem - use EDTypesMod , only : num_vegtemp_mem - use EDTypesMod , only : maxpft - use EDTypesMod , only : AREA - use EDTypesMod , only : init_spread_near_bare_ground - use EDTypesMod , only : init_spread_inventory - use EDTypesMod , only : leaves_on - use EDTypesMod , only : leaves_off - use EDTypesMod , only : num_elements - use EDTypesMod , only : element_list - use EDTypesMod , only : phen_cstat_nevercold - use EDTypesMod , only : phen_cstat_iscold - use EDTypesMod , only : phen_dstat_timeoff - use EDTypesMod , only : phen_dstat_moistoff - use EDTypesMod , only : phen_cstat_notcold - use EDTypesMod , only : phen_dstat_moiston - use FatesInterfaceTypesMod , only : hlm_day_of_year - use FatesInterfaceTypesMod , only : bc_in_type - use FatesInterfaceTypesMod , only : hlm_use_planthydro - use FatesInterfaceTypesMod , only : hlm_use_inventory_init - use FatesInterfaceTypesMod , only : hlm_use_fixed_biogeog - use FatesInterfaceTypesMod , only : numpft - use FatesInterfaceTypesMod , only : nleafage - use FatesInterfaceTypesMod , only : nlevsclass - use FatesInterfaceTypesMod , only : nlevcoage - use FatesAllometryMod , only : h2d_allom - use FatesAllometryMod , only : bagw_allom - use FatesAllometryMod , only : bbgw_allom - use FatesAllometryMod , only : bleaf - use FatesAllometryMod , only : bfineroot - use FatesAllometryMod , only : bsap_allom - use FatesAllometryMod , only : bdead_allom - use FatesAllometryMod , only : bstore_allom - - use FatesInterfaceTypesMod, only : hlm_parteh_mode - use PRTGenericMod, only : prt_carbon_allom_hyp - use PRTGenericMod, only : prt_cnp_flex_allom_hyp - use PRTGenericMod, only : prt_vartypes - use PRTGenericMod, only : leaf_organ - use PRTGenericMod, only : fnrt_organ - use PRTGenericMod, only : sapw_organ - use PRTGenericMod, only : store_organ - use PRTGenericMod, only : struct_organ - use PRTGenericMod, only : repro_organ - use PRTGenericMod, only : carbon12_element - use PRTGenericMod, only : nitrogen_element - use PRTGenericMod, only : phosphorus_element - use PRTGenericMod, only : SetState - - ! CIME GLOBALS - use shr_log_mod , only : errMsg => shr_log_errMsg - - implicit none - private - - logical :: debug = .false. - - character(len=*), parameter, private :: sourcefile = & - __FILE__ - - public :: zero_site - public :: init_site_vars - public :: init_patches - public :: set_site_properties - private :: init_cohorts - - - ! ============================================================================ - -contains - - ! ============================================================================ - - subroutine init_site_vars( site_in, bc_in ) - ! - ! !DESCRIPTION: - ! - ! - ! !ARGUMENTS - type(ed_site_type), intent(inout) :: site_in - type(bc_in_type),intent(in) :: bc_in - ! - ! !LOCAL VARIABLES: - !---------------------------------------------------------------------- - integer :: el - - ! - allocate(site_in%term_nindivs_canopy(1:nlevsclass,1:numpft)) - allocate(site_in%term_nindivs_ustory(1:nlevsclass,1:numpft)) - allocate(site_in%demotion_rate(1:nlevsclass)) - allocate(site_in%promotion_rate(1:nlevsclass)) - allocate(site_in%imort_rate(1:nlevsclass,1:numpft)) - allocate(site_in%fmort_rate_canopy(1:nlevsclass,1:numpft)) - allocate(site_in%fmort_rate_ustory(1:nlevsclass,1:numpft)) - allocate(site_in%fmort_rate_cambial(1:nlevsclass,1:numpft)) - allocate(site_in%fmort_rate_crown(1:nlevsclass,1:numpft)) - allocate(site_in%growthflux_fusion(1:nlevsclass,1:numpft)) - allocate(site_in%mass_balance(1:num_elements)) - allocate(site_in%flux_diags(1:num_elements)) - - site_in%nlevsoil = bc_in%nlevsoil - allocate(site_in%rootfrac_scr(site_in%nlevsoil)) - allocate(site_in%zi_soil(0:site_in%nlevsoil)) - allocate(site_in%dz_soil(site_in%nlevsoil)) - allocate(site_in%z_soil(site_in%nlevsoil)) - - allocate(site_in%area_pft(1:numpft)) - allocate(site_in%use_this_pft(1:numpft)) - - do el=1,num_elements - allocate(site_in%flux_diags(el)%leaf_litter_input(1:numpft)) - allocate(site_in%flux_diags(el)%root_litter_input(1:numpft)) - end do - - ! Initialize the static soil - ! arrays from the boundary (initial) condition - - - site_in%zi_soil(:) = bc_in%zi_sisl(:) - site_in%dz_soil(:) = bc_in%dz_sisl(:) - site_in%z_soil(:) = bc_in%z_sisl(:) - - - ! - end subroutine init_site_vars - - ! ============================================================================ - subroutine zero_site( site_in ) - ! - ! !DESCRIPTION: - ! - ! !USES: - use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=) - ! - ! !ARGUMENTS - type(ed_site_type), intent(inout) :: site_in - ! - ! !LOCAL VARIABLES: - integer :: el - !---------------------------------------------------------------------- - - site_in%oldest_patch => null() ! pointer to oldest patch at the site - site_in%youngest_patch => null() ! pointer to yngest patch at the site - - - ! PHENOLOGY - - site_in%cstatus = fates_unset_int ! are leaves in this pixel on or off? - site_in%dstatus = fates_unset_int - site_in%grow_deg_days = nan ! growing degree days - site_in%nchilldays = fates_unset_int - site_in%ncolddays = fates_unset_int - site_in%cleafondate = fates_unset_int - site_in%cleafoffdate = fates_unset_int - site_in%dleafondate = fates_unset_int - site_in%dleafoffdate = fates_unset_int - site_in%water_memory(:) = nan site_in%vegtemp_memory(:) = nan ! record of last 10 days temperature for senescence model. site_in%phen_model_date = fates_unset_int @@ -278,12 +101,12 @@ subroutine set_site_properties( nsites, sites,bc_in ) ! is memory-less, but needed ! for first value in history file - sites(s)%phen_model_date = hlm_day_of_year - sites(s)%cleafondate = cleafon - sites(s)%cleafoffdate = cleafoff - sites(s)%dleafoffdate = dleafoff - sites(s)%dleafondate = dleafon - sites(s)%grow_deg_days = GDD + sites(s)%phen_model_date = 0 + sites(s)%cleafondate = cleafon - hlm_day_of_year + sites(s)%cleafoffdate = cleafoff - hlm_day_of_year + sites(s)%dleafoffdate = dleafoff - hlm_day_of_year + sites(s)%dleafondate = dleafon - hlm_day_of_year + sites(s)%grow_deg_days = GDD sites(s)%water_memory(1:numWaterMem) = watermem sites(s)%vegtemp_memory(1:num_vegtemp_mem) = 0._r8 diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90 index a022e64624..6b408e713f 100644 --- a/main/FatesHistoryInterfaceMod.F90 +++ b/main/FatesHistoryInterfaceMod.F90 @@ -1695,7 +1695,6 @@ subroutine update_history_dyn(this,nc,nsites,sites) integer :: height_bin_max, height_bin_min ! which height bin a given cohort's canopy is in integer :: i_heightbin ! iterator for height bins integer :: el ! Loop index for elements - integer :: model_day_int ! integer model day from reference integer :: ageclass_since_anthrodist ! what is the equivalent age class for ! time-since-anthropogenic-disturbance of secondary forest @@ -1973,7 +1972,7 @@ subroutine update_history_dyn(this,nc,nsites,sites) hio_cleafoff_si => this%hvars(ih_cleafoff_si)%r81d, & hio_cleafon_si => this%hvars(ih_cleafon_si)%r81d, & hio_dleafoff_si => this%hvars(ih_dleafoff_si)%r81d, & - hio_dleafon_si => this%hvars(ih_dleafoff_si)%r81d, & + hio_dleafon_si => this%hvars(ih_dleafon_si)%r81d, & hio_meanliqvol_si => this%hvars(ih_meanliqvol_si)%r81d, & hio_cbal_err_fates_si => this%hvars(ih_cbal_err_fates_si)%r81d, & hio_err_fates_si => this%hvars(ih_err_fates_si)%r82d ) @@ -1989,7 +1988,7 @@ subroutine update_history_dyn(this,nc,nsites,sites) ! If we don't have dynamics turned on, we just abort these diagnostics if (hlm_use_ed_st3.eq.itrue) return - model_day_int = nint(hlm_model_day) + ! --------------------------------------------------------------------------------- ! Loop through the FATES scale hierarchy and fill the history IO arrays @@ -2034,12 +2033,12 @@ subroutine update_history_dyn(this,nc,nsites,sites) hio_gdd_si(io_si) = sites(s)%grow_deg_days - hio_cleafoff_si(io_si) = real(model_day_int - sites(s)%cleafoffdate,r8) - hio_cleafon_si(io_si) = real(model_day_int - sites(s)%cleafondate,r8) - hio_dleafoff_si(io_si) = real(model_day_int - sites(s)%dleafoffdate,r8) - hio_dleafon_si(io_si) = real(model_day_int - sites(s)%dleafondate,r8) - - if(model_day_int>numWaterMem)then + hio_cleafoff_si(io_si) = real(sites(s)%phen_model_date - sites(s)%cleafoffdate,r8) + hio_cleafon_si(io_si) = real(sites(s)%phen_model_date - sites(s)%cleafondate,r8) + hio_dleafoff_si(io_si) = real(sites(s)%phen_model_date - sites(s)%dleafoffdate,r8) + hio_dleafon_si(io_si) = real(sites(s)%phen_model_date - sites(s)%dleafondate,r8) + + if(sites(s)%phen_model_date>numWaterMem)then hio_meanliqvol_si(io_si) = & sum(sites(s)%water_memory(1:numWaterMem))/real(numWaterMem,r8) end if From 4f102243ea247633d9d5bb07fee27dc21d24b633 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Fri, 14 Aug 2020 19:57:48 -0400 Subject: [PATCH 3/5] Somehow some really strange changes got into last commit (bumped keyboard), this reverts and fixes EDInitMod.F90 --- main/EDInitMod.F90 | 178 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 177 insertions(+), 1 deletion(-) diff --git a/main/EDInitMod.F90 b/main/EDInitMod.F90 index 074f645cb4..02630b0092 100644 --- a/main/EDInitMod.F90 +++ b/main/EDInitMod.F90 @@ -1,4 +1,181 @@ +module EDInitMod + ! ============================================================================ + ! Contains all modules to set up the ED structure. + ! ============================================================================ + + use FatesConstantsMod , only : r8 => fates_r8 + use FatesConstantsMod , only : ifalse + use FatesConstantsMod , only : itrue + use FatesConstantsMod , only : fates_unset_int + use FatesConstantsMod , only : primaryforest + use FatesGlobals , only : endrun => fates_endrun + use EDTypesMod , only : nclmax + use FatesGlobals , only : fates_log + use FatesInterfaceTypesMod , only : hlm_is_restart + use EDPftvarcon , only : EDPftvarcon_inst + use EDCohortDynamicsMod , only : create_cohort, fuse_cohorts, sort_cohorts + use EDCohortDynamicsMod , only : InitPRTObject + use EDPatchDynamicsMod , only : create_patch + use ChecksBalancesMod , only : SiteMassStock + use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type + use EDTypesMod , only : numWaterMem + use EDTypesMod , only : num_vegtemp_mem + use EDTypesMod , only : maxpft + use EDTypesMod , only : AREA + use EDTypesMod , only : init_spread_near_bare_ground + use EDTypesMod , only : init_spread_inventory + use EDTypesMod , only : leaves_on + use EDTypesMod , only : leaves_off + use EDTypesMod , only : num_elements + use EDTypesMod , only : element_list + use EDTypesMod , only : phen_cstat_nevercold + use EDTypesMod , only : phen_cstat_iscold + use EDTypesMod , only : phen_dstat_timeoff + use EDTypesMod , only : phen_dstat_moistoff + use EDTypesMod , only : phen_cstat_notcold + use EDTypesMod , only : phen_dstat_moiston + use FatesInterfaceTypesMod , only : hlm_day_of_year + use FatesInterfaceTypesMod , only : bc_in_type + use FatesInterfaceTypesMod , only : hlm_use_planthydro + use FatesInterfaceTypesMod , only : hlm_use_inventory_init + use FatesInterfaceTypesMod , only : hlm_use_fixed_biogeog + use FatesInterfaceTypesMod , only : numpft + use FatesInterfaceTypesMod , only : nleafage + use FatesInterfaceTypesMod , only : nlevsclass + use FatesInterfaceTypesMod , only : nlevcoage + use FatesAllometryMod , only : h2d_allom + use FatesAllometryMod , only : bagw_allom + use FatesAllometryMod , only : bbgw_allom + use FatesAllometryMod , only : bleaf + use FatesAllometryMod , only : bfineroot + use FatesAllometryMod , only : bsap_allom + use FatesAllometryMod , only : bdead_allom + use FatesAllometryMod , only : bstore_allom + + use FatesInterfaceTypesMod, only : hlm_parteh_mode + use PRTGenericMod, only : prt_carbon_allom_hyp + use PRTGenericMod, only : prt_cnp_flex_allom_hyp + use PRTGenericMod, only : prt_vartypes + use PRTGenericMod, only : leaf_organ + use PRTGenericMod, only : fnrt_organ + use PRTGenericMod, only : sapw_organ + use PRTGenericMod, only : store_organ + use PRTGenericMod, only : struct_organ + use PRTGenericMod, only : repro_organ + use PRTGenericMod, only : carbon12_element + use PRTGenericMod, only : nitrogen_element + use PRTGenericMod, only : phosphorus_element + use PRTGenericMod, only : SetState + + ! CIME GLOBALS + use shr_log_mod , only : errMsg => shr_log_errMsg + + implicit none + private + + logical :: debug = .false. + + character(len=*), parameter, private :: sourcefile = & + __FILE__ + + public :: zero_site + public :: init_site_vars + public :: init_patches + public :: set_site_properties + private :: init_cohorts + + + ! ============================================================================ + +contains + + ! ============================================================================ + + subroutine init_site_vars( site_in, bc_in ) + ! + ! !DESCRIPTION: + ! + ! + ! !ARGUMENTS + type(ed_site_type), intent(inout) :: site_in + type(bc_in_type),intent(in) :: bc_in + ! + ! !LOCAL VARIABLES: + !---------------------------------------------------------------------- + integer :: el + + ! + allocate(site_in%term_nindivs_canopy(1:nlevsclass,1:numpft)) + allocate(site_in%term_nindivs_ustory(1:nlevsclass,1:numpft)) + allocate(site_in%demotion_rate(1:nlevsclass)) + allocate(site_in%promotion_rate(1:nlevsclass)) + allocate(site_in%imort_rate(1:nlevsclass,1:numpft)) + allocate(site_in%fmort_rate_canopy(1:nlevsclass,1:numpft)) + allocate(site_in%fmort_rate_ustory(1:nlevsclass,1:numpft)) + allocate(site_in%fmort_rate_cambial(1:nlevsclass,1:numpft)) + allocate(site_in%fmort_rate_crown(1:nlevsclass,1:numpft)) + allocate(site_in%growthflux_fusion(1:nlevsclass,1:numpft)) + allocate(site_in%mass_balance(1:num_elements)) + allocate(site_in%flux_diags(1:num_elements)) + + site_in%nlevsoil = bc_in%nlevsoil + allocate(site_in%rootfrac_scr(site_in%nlevsoil)) + allocate(site_in%zi_soil(0:site_in%nlevsoil)) + allocate(site_in%dz_soil(site_in%nlevsoil)) + allocate(site_in%z_soil(site_in%nlevsoil)) + + allocate(site_in%area_pft(1:numpft)) + allocate(site_in%use_this_pft(1:numpft)) + + do el=1,num_elements + allocate(site_in%flux_diags(el)%leaf_litter_input(1:numpft)) + allocate(site_in%flux_diags(el)%root_litter_input(1:numpft)) + end do + + ! Initialize the static soil + ! arrays from the boundary (initial) condition + + + site_in%zi_soil(:) = bc_in%zi_sisl(:) + site_in%dz_soil(:) = bc_in%dz_sisl(:) + site_in%z_soil(:) = bc_in%z_sisl(:) + + + ! + end subroutine init_site_vars + + ! ============================================================================ + subroutine zero_site( site_in ) + ! + ! !DESCRIPTION: + ! + ! !USES: + use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=) + ! + ! !ARGUMENTS + type(ed_site_type), intent(inout) :: site_in + ! + ! !LOCAL VARIABLES: + integer :: el + !---------------------------------------------------------------------- + + site_in%oldest_patch => null() ! pointer to oldest patch at the site + site_in%youngest_patch => null() ! pointer to yngest patch at the site + + + ! PHENOLOGY + + site_in%cstatus = fates_unset_int ! are leaves in this pixel on or off? + site_in%dstatus = fates_unset_int + site_in%grow_deg_days = nan ! growing degree days + site_in%nchilldays = fates_unset_int + site_in%ncolddays = fates_unset_int + site_in%cleafondate = fates_unset_int + site_in%cleafoffdate = fates_unset_int + site_in%dleafondate = fates_unset_int + site_in%dleafoffdate = fates_unset_int + site_in%water_memory(:) = nan site_in%vegtemp_memory(:) = nan ! record of last 10 days temperature for senescence model. site_in%phen_model_date = fates_unset_int @@ -100,7 +277,6 @@ subroutine set_site_properties( nsites, sites,bc_in ) ! immediately, so yes this ! is memory-less, but needed ! for first value in history file - sites(s)%phen_model_date = 0 sites(s)%cleafondate = cleafon - hlm_day_of_year sites(s)%cleafoffdate = cleafoff - hlm_day_of_year From f7d864b9c71982405aade80780bdcaf6ed39abc3 Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Fri, 23 Oct 2020 10:26:13 -0600 Subject: [PATCH 4/5] Moved comment on phen model day counter to correct position --- biogeochem/EDPhysiologyMod.F90 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/biogeochem/EDPhysiologyMod.F90 b/biogeochem/EDPhysiologyMod.F90 index 39bea9ea14..ad3497c56f 100644 --- a/biogeochem/EDPhysiologyMod.F90 +++ b/biogeochem/EDPhysiologyMod.F90 @@ -745,6 +745,9 @@ subroutine phenology( currentSite, bc_in ) ! This is the integer model day. The first day of the simulation is 1, and it ! continues monotonically, indefinitely + ! Advance it. (this should be a global, no reason + ! for site level, but we don't have global scalars in the + ! restart file) currentSite%phen_model_date = currentSite%phen_model_date + 1 model_day_int = currentSite%phen_model_date @@ -1063,12 +1066,7 @@ subroutine phenology( currentSite, bc_in ) call phenology_leafonoff(currentSite) - ! Advance the model day (this should be a global, no reason - ! for site level, but we don't have global scalars in the - ! restart file) - - - + return end subroutine phenology ! ============================================================================ From 1f4693bb01f2d54ff320a8b7ffa9d0c3f0118dbd Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Thu, 25 Aug 2022 12:21:09 -0600 Subject: [PATCH 5/5] Added model_day_int def --- main/FatesHistoryInterfaceMod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/main/FatesHistoryInterfaceMod.F90 b/main/FatesHistoryInterfaceMod.F90 index 417f38e2b9..b9d539be2c 100644 --- a/main/FatesHistoryInterfaceMod.F90 +++ b/main/FatesHistoryInterfaceMod.F90 @@ -1755,6 +1755,7 @@ subroutine update_history_dyn(this,nc,nsites,sites) integer :: height_bin_max, height_bin_min ! which height bin a given cohort's canopy is in integer :: i_heightbin ! iterator for height bins integer :: el ! Loop index for elements + integer :: model_day_int ! Integer model day since simulation start integer :: ageclass_since_anthrodist ! what is the equivalent age class for ! time-since-anthropogenic-disturbance of secondary forest