Skip to content

Commit

Permalink
Merge pull request NGEET#19 from glemieux/landusev2-sitefunc
Browse files Browse the repository at this point in the history
Landuse V2: convert `get_current_landuse_statevector` into a site-level method
  • Loading branch information
glemieux authored May 8, 2024
2 parents ff16157 + 833e397 commit 7fe31f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
39 changes: 2 additions & 37 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ module EDPatchDynamicsMod
public :: check_patch_area
public :: set_patchno
private:: fuse_2_patches
public :: get_current_landuse_statevector

character(len=*), parameter, private :: sourcefile = &
__FILE__
Expand Down Expand Up @@ -223,7 +222,7 @@ subroutine disturbance_rates( site_in, bc_in)
!----------------------------------------------------------------------------------------------

! first calculate the fraction of the site that is primary land
call get_current_landuse_statevector(site_in, current_fates_landuse_state_vector)
current_fates_landuse_state_vector = site_in%get_current_landuse_statevector()

! check status of transition_landuse_from_off_to_on flag, and do some error checking on it
if(site_in%transition_landuse_from_off_to_on) then
Expand Down Expand Up @@ -3526,7 +3525,7 @@ subroutine terminate_patches(currentSite, bc_in)
write(fates_log(),*) patchpointer%area, patchpointer%nocomp_pft_label, patchpointer%land_use_label
patchpointer => patchpointer%older
end do
call get_current_landuse_statevector(currentSite, state_vector_internal)
state_vector_internal = currentSite%get_current_landuse_statevector()
write(fates_log(),*) 'current landuse state vector: ', state_vector_internal
write(fates_log(),*) 'current landuse state vector (not including bare gruond): ', state_vector_internal/(1._r8-currentSite%area_bareground)
call GetLUHStatedata(bc_in, state_vector_driver)
Expand Down Expand Up @@ -3726,40 +3725,6 @@ end function countPatches

! =====================================================================================

subroutine get_current_landuse_statevector(site_in, current_state_vector)

!
! !DESCRIPTION:
! Calculate how much of a site is each land use category.
! this does not include bare ground when nocomp + fixed biogeography is on,
! so will not sum to one in that case. otherwise it will sum to one.
!
! !USES:
use EDTypesMod , only : ed_site_type
!
! !ARGUMENTS:
type(ed_site_type) , intent(in), target :: site_in
real(r8) , intent(out) :: current_state_vector(n_landuse_cats)

! !LOCAL VARIABLES:
type (fates_patch_type), pointer :: currentPatch

current_state_vector(:) = 0._r8

currentPatch => site_in%oldest_patch
do while (associated(currentPatch))
if (currentPatch%land_use_label .gt. nocomp_bareground_land) then
current_state_vector(currentPatch%land_use_label) = &
current_state_vector(currentPatch%land_use_label) + &
currentPatch%area/AREA
end if
currentPatch => currentPatch%younger
end do

end subroutine get_current_landuse_statevector

! =====================================================================================

subroutine InsertPatch(currentSite, newPatch)

! !DESCRIPTION:
Expand Down
3 changes: 1 addition & 2 deletions main/EDMainMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ module EDMainMod
use EDLoggingMortalityMod , only : IsItLoggingTime
use EDLoggingMortalityMod , only : get_harvestable_carbon
use DamageMainMod , only : IsItDamageTime
use EDPatchDynamicsMod , only : get_current_landuse_statevector
use FatesGlobals , only : endrun => fates_endrun
use ChecksBalancesMod , only : SiteMassStock
use EDMortalityFunctionsMod , only : Mortality_Derivative
Expand Down Expand Up @@ -415,7 +414,7 @@ subroutine ed_integrate_state_variables(currentSite, bc_in, bc_out )

!-----------------------------------------------------------------------

call get_current_landuse_statevector(currentSite, current_fates_landuse_state_vector)
current_fates_landuse_state_vector = currentSite%get_current_landuse_statevector()

! Clear site GPP and AR passing to HLM
bc_out%gpp_site = 0._r8
Expand Down
40 changes: 39 additions & 1 deletion main/EDTypesMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ module EDTypesMod
logical, allocatable :: landuse_vector_gt_min(:) ! is the land use state vector for each land use type greater than the minimum below which we ignore?
logical :: transition_landuse_from_off_to_on ! special flag to use only when reading restarts, which triggers procedure to initialize land use

contains

public :: get_current_landuse_statevector

end type ed_site_type

! Make public necessary subroutines and functions
Expand Down Expand Up @@ -508,7 +512,41 @@ subroutine dump_site(csite)
write(fates_log(),*) '----------------------------------------'
return

end subroutine dump_site
end subroutine dump_site

! =====================================================================================

function get_current_landuse_statevector(this) result(current_state_vector)

!
! !DESCRIPTION:
! Calculate how much of a site is each land use category.
! this does not include bare ground when nocomp + fixed biogeography is on,
! so will not sum to one in that case. otherwise it will sum to one.
!
! !USES:
!
! !ARGUMENTS:
class(ed_site_type) :: this
real(r8) :: current_state_vector(n_landuse_cats)

! !LOCAL VARIABLES:
type(fates_patch_type), pointer :: currentPatch

current_state_vector(:) = 0._r8

currentPatch => this%oldest_patch
do while (associated(currentPatch))
if (currentPatch%land_use_label .gt. nocomp_bareground_land) then
current_state_vector(currentPatch%land_use_label) = &
current_state_vector(currentPatch%land_use_label) + &
currentPatch%area/AREA
end if
currentPatch => currentPatch%younger
end do

end subroutine get_current_landuse_statevector



end module EDTypesMod

0 comments on commit 7fe31f9

Please sign in to comment.