Skip to content

Commit

Permalink
Fixed restart issues for sp and allvars with integrated flux
Browse files Browse the repository at this point in the history
  • Loading branch information
rgknox committed Oct 23, 2024
1 parent 3fbc57f commit 147d411
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
10 changes: 8 additions & 2 deletions main/EDInitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,12 @@ subroutine init_patches( nsites, sites, bc_in)
do el=1,num_elements
call SiteMassStock(sites(s),el,sites(s)%mass_balance(el)%old_stock, &
biomass_stock,litter_stock,seed_stock)
! Initialize the integrated flux balance diagnostics
! No need to initialize the instantaneous states, those are re-calculated
sites(s)%iflux_balance(el)%iflux_liveveg = &
(biomass_stock + seed_stock)*area_inv
sites(s)%iflux_balance(el)%iflux_litter = litter_stock * area_inv

end do
call set_patchno(sites(s))
enddo
Expand Down Expand Up @@ -972,7 +978,7 @@ subroutine init_patches( nsites, sites, bc_in)
do el=1,num_elements
call SiteMassStock(sites(s),el,sites(s)%mass_balance(el)%old_stock, &
biomass_stock,litter_stock,seed_stock)

! Initialize the integrated flux balance diagnostics
! No need to initialize the instantaneous states, those are re-calculated
sites(s)%iflux_balance(el)%iflux_liveveg = &
Expand All @@ -983,7 +989,7 @@ subroutine init_patches( nsites, sites, bc_in)

call set_patchno(sites(s))

enddo sites_loop !s
enddo sites_loop
end if

! zero all the patch fire variables for the first timestep
Expand Down
5 changes: 4 additions & 1 deletion main/EDMainMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,10 @@ subroutine ed_update_site( currentSite, bc_in, bc_out, is_restarting )
enddo

! Check to see if the time integrated fluxes match the state
call CheckIntegratedMassPools(currentSite)
! Dont call this if we are restarting, it will double count the flux
if(.not.is_restarting)then
call CheckIntegratedMassPools(currentSite)
end if

! The HLMs need to know about nutrient demand, and/or
! root mass and affinities
Expand Down
61 changes: 31 additions & 30 deletions main/FatesHistoryInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module FatesHistoryInterfaceMod
use FatesInterfaceTypesMod , only : numpft
use FatesInterfaceTypesMod , only : hlm_freq_day
use FatesInterfaceTypesMod , only : hlm_parteh_mode
use FatesInterfaceTypesMod , only : hlm_use_sp
use EDParamsMod , only : ED_val_comp_excln
use EDParamsMod , only : ED_val_phen_coldtemp
use EDParamsMod , only : nlevleaf
Expand Down Expand Up @@ -3101,9 +3102,7 @@ subroutine update_history_dyn2(this,nc,nsites,sites,bc_in)

real(r8), parameter :: reallytalltrees = 1000. ! some large number (m)

!
associate( hio_err_fates_elem => this%hvars(ih_err_fates_elem)%r82d, &
hio_biomass_si_pft => this%hvars(ih_biomass_si_pft)%r82d, &
associate( hio_biomass_si_pft => this%hvars(ih_biomass_si_pft)%r82d, &
hio_biomass_sec_si_pft => this%hvars(ih_biomass_sec_si_pft)%r82d, &
hio_leafbiomass_si_pft => this%hvars(ih_leafbiomass_si_pft)%r82d, &
hio_storebiomass_si_pft => this%hvars(ih_storebiomass_si_pft)%r82d, &
Expand Down Expand Up @@ -3315,11 +3314,8 @@ subroutine update_history_dyn2(this,nc,nsites,sites,bc_in)
hio_nplant_understory_si_scag => this%hvars(ih_nplant_understory_si_scag)%r82d, &
hio_disturbance_rate_si_lulu => this%hvars(ih_disturbance_rate_si_lulu)%r82d, &
hio_cstarvmortality_continuous_carbonflux_si_pft => this%hvars(ih_cstarvmortality_continuous_carbonflux_si_pft)%r82d, &
hio_interr_liveveg_elem => this%hvars(ih_interr_liveveg_elem)%r82d, &
hio_interr_litter_elem => this%hvars(ih_interr_litter_elem)%r82d, &
hio_transition_matrix_si_lulu => this%hvars(ih_transition_matrix_si_lulu)%r82d)


model_day_int = nint(hlm_model_day)

! ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -3363,13 +3359,17 @@ subroutine update_history_dyn2(this,nc,nsites,sites,bc_in)

do el = 1, num_elements

! Total model error [kg/day -> kg/s] (all elements)
hio_err_fates_elem(io_si,el) = sites(s)%mass_balance(el)%err_fates / sec_per_day
if((.not.hlm_use_ed_st3) .and. (.not.hlm_use_sp))then

hio_interr_liveveg_elem(io_si,el) = sites(s)%flux_diags%elem(el)%err_liveveg
! Total model error [kg/day -> kg/s] (all elements)
this%hvars(ih_err_fates_elem)%r82d(io_si,el) = sites(s)%mass_balance(el)%err_fates / sec_per_day

this%hvars(ih_interr_liveveg_elem)%r82d(io_si,el) = sites(s)%flux_diags%elem(el)%err_liveveg

hio_interr_litter_elem(io_si,el) = sites(s)%flux_diags%elem(el)%err_litter

this%hvars(ih_interr_litter_elem)%r82d(io_si,el) = sites(s)%flux_diags%elem(el)%err_litter

end if

! Total element lost to atmosphere from burning (kg/site/day -> kg/m2/s)
hio_burn_flux_elem(io_si,el) = &
sites(s)%mass_balance(el)%burn_flux_to_atm * ha_per_m2 * &
Expand Down Expand Up @@ -8462,25 +8462,26 @@ subroutine define_history_vars(this, initialize_variables)
hlms='CLM:ALM', upfreq=group_dyna_complx, ivar=ivar, &
initialize=initialize_variables, index = ih_burn_flux_elem)


call this%set_history_var(vname='FATES_ERROR_EL', units='kg s-1', &
long='total mass-balance error in kg per second by element', &
use_default='active', avgflag='A', vtype=site_elem_r8, &
hlms='CLM:ALM', upfreq=group_dyna_complx, ivar=ivar, initialize=initialize_variables, &
index = ih_err_fates_elem)

call this%set_history_var(vname='FATES_INTERR_LIVEVEG_EL',units='kg m-2', &
long='Bias error between integrated flux and (minus) state in live vegetation ', &
use_default='active', avgflag='A', vtype=site_elem_r8, hlms='CLM:ALM', &
upfreq=group_dyna_complx, ivar=ivar, initialize=initialize_variables, &
index = ih_interr_liveveg_elem)

call this%set_history_var(vname='FATES_INTERR_LITTER_EL',units='kg m-2', &
long='Bias error between integrated flux and (minus) state in litter ', &
use_default='active', avgflag='A', vtype=site_elem_r8, hlms='CLM:ALM', &
upfreq=group_dyna_complx, ivar=ivar, initialize=initialize_variables, &
index = ih_interr_litter_elem)

if((.not.hlm_use_ed_st3) .and. (.not.hlm_use_sp))then
call this%set_history_var(vname='FATES_ERROR_EL', units='kg s-1', &
long='total mass-balance error in kg per second by element', &
use_default='active', avgflag='A', vtype=site_elem_r8, &
hlms='CLM:ALM', upfreq=group_dyna_complx, ivar=ivar, initialize=initialize_variables, &
index = ih_err_fates_elem)

call this%set_history_var(vname='FATES_INTERR_LIVEVEG_EL',units='kg m-2', &
long='Bias error between integrated flux and (minus) state in live vegetation ', &
use_default='active', avgflag='A', vtype=site_elem_r8, hlms='CLM:ALM', &
upfreq=group_dyna_complx, ivar=ivar, initialize=initialize_variables, &
index = ih_interr_liveveg_elem)

call this%set_history_var(vname='FATES_INTERR_LITTER_EL',units='kg m-2', &
long='Bias error between integrated flux and (minus) state in litter ', &
use_default='active', avgflag='A', vtype=site_elem_r8, hlms='CLM:ALM', &
upfreq=group_dyna_complx, ivar=ivar, initialize=initialize_variables, &
index = ih_interr_litter_elem)
end if

call this%set_history_var(vname='FATES_LITTER_AG_FINE_EL', units='kg m-2', &
long='mass of aboveground litter in fines (leaves, nonviable seed) by element', &
use_default='active', avgflag='A', vtype=site_elem_r8, &
Expand Down

0 comments on commit 147d411

Please sign in to comment.