Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long run restart fix #1098

Merged
merged 7 commits into from
Nov 10, 2023
Merged
43 changes: 22 additions & 21 deletions main/EDMainMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
subroutine ed_update_site( currentSite, bc_in, bc_out, is_restarting )
!
! !DESCRIPTION:
! Calls routines to consolidate the ED growth process.
Expand All @@ -781,17 +781,19 @@ 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_restarting ! is this called during restart read?
!
! !LOCAL VARIABLES:
type (fates_patch_type) , pointer :: currentPatch
!-----------------------------------------------------------------------
if(hlm_use_sp.eq.ifalse)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)then
if(hlm_use_sp.eq.ifalse .and. (.not.is_restarting) )then
call canopy_structure(currentSite, bc_in)
endif

Expand All @@ -805,22 +807,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_restarting)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)
Expand All @@ -832,10 +834,9 @@ subroutine ed_update_site( currentSite, bc_in, bc_out )

! 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_restarting)) then
if(hlm_use_sp.eq.ifalse)then
call trim_canopy(currentSite)
endif
endif

Expand Down
77 changes: 50 additions & 27 deletions main/FatesRestartInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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
Expand Down Expand Up @@ -141,7 +143,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
Expand Down Expand Up @@ -1014,6 +1017,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


Expand Down Expand Up @@ -1124,25 +1133,35 @@ subroutine define_restart_vars(this, initialize_variables)

! Only register satellite phenology related restart variables if it is turned on!
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor cleanup; since we use hlm_use_sp in a bunch of places still, I think moving this up to be included in a general comment would be ideal. Or we can strike it altogether since it's not relevant in this specific place in the code anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed with @glemieux will incorporate into future PR


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 )
end if

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 )

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!

Expand Down Expand Up @@ -2278,6 +2297,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
Expand Down Expand Up @@ -2355,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
Expand Down Expand Up @@ -2420,6 +2439,8 @@ subroutine set_restart_vectors(this,nc,nsites,sites)
,io_idx_co,cohortsperpatch
endif

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

Expand Down Expand Up @@ -3214,6 +3235,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)
Expand Down Expand Up @@ -3289,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
Expand Down Expand Up @@ -3323,6 +3344,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)%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)
call this%GetRMeanRestartVar(cpatch%tveg_lpa, ir_tveglpa_pa, io_idx_co_1st)
Expand Down