From 2ade2b15244e3d25a40018df9dd4cc8981a080ae Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 2 Apr 2024 14:33:24 -0700 Subject: [PATCH 1/2] move get_current_landuse_statevector into ed_site_type --- biogeochem/EDPatchDynamicsMod.F90 | 39 ++---------------------------- main/EDMainMod.F90 | 3 +-- main/EDTypesMod.F90 | 40 ++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/biogeochem/EDPatchDynamicsMod.F90 b/biogeochem/EDPatchDynamicsMod.F90 index e610e7c22a..b174ef8b9f 100644 --- a/biogeochem/EDPatchDynamicsMod.F90 +++ b/biogeochem/EDPatchDynamicsMod.F90 @@ -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__ @@ -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) + call site_in%get_current_landuse_statevector(current_fates_landuse_state_vector) ! 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 @@ -3555,7 +3554,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) + call currentSite%get_current_landuse_statevector(state_vector_internal) 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 get_luh_statedata(bc_in, state_vector_driver) @@ -3755,40 +3754,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: diff --git a/main/EDMainMod.F90 b/main/EDMainMod.F90 index af41670045..3368d1284f 100644 --- a/main/EDMainMod.F90 +++ b/main/EDMainMod.F90 @@ -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 @@ -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) + call currentSite%get_current_landuse_statevector(current_fates_landuse_state_vector) ! Clear site GPP and AR passing to HLM bc_out%gpp_site = 0._r8 diff --git a/main/EDTypesMod.F90 b/main/EDTypesMod.F90 index bb62dfba6e..deceac558b 100644 --- a/main/EDTypesMod.F90 +++ b/main/EDTypesMod.F90 @@ -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 @@ -508,7 +512,41 @@ subroutine dump_site(csite) write(fates_log(),*) '----------------------------------------' return -end subroutine dump_site + end subroutine dump_site + + ! ===================================================================================== + + subroutine get_current_landuse_statevector(this, 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), intent(out) :: 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 From 833e39719e5b3b51d24ce298269432f770adbcf5 Mon Sep 17 00:00:00 2001 From: Gregory Lemieux Date: Tue, 2 Apr 2024 14:44:46 -0700 Subject: [PATCH 2/2] covert get_current_landuse_statevector to a function --- biogeochem/EDPatchDynamicsMod.F90 | 4 ++-- main/EDMainMod.F90 | 2 +- main/EDTypesMod.F90 | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/biogeochem/EDPatchDynamicsMod.F90 b/biogeochem/EDPatchDynamicsMod.F90 index b174ef8b9f..4d37ecc6d3 100644 --- a/biogeochem/EDPatchDynamicsMod.F90 +++ b/biogeochem/EDPatchDynamicsMod.F90 @@ -222,7 +222,7 @@ subroutine disturbance_rates( site_in, bc_in) !---------------------------------------------------------------------------------------------- ! first calculate the fraction of the site that is primary land - call site_in%get_current_landuse_statevector(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 @@ -3554,7 +3554,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 currentSite%get_current_landuse_statevector(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 get_luh_statedata(bc_in, state_vector_driver) diff --git a/main/EDMainMod.F90 b/main/EDMainMod.F90 index 3368d1284f..cd98993a6b 100644 --- a/main/EDMainMod.F90 +++ b/main/EDMainMod.F90 @@ -414,7 +414,7 @@ subroutine ed_integrate_state_variables(currentSite, bc_in, bc_out ) !----------------------------------------------------------------------- - call currentSite%get_current_landuse_statevector(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 diff --git a/main/EDTypesMod.F90 b/main/EDTypesMod.F90 index deceac558b..18498230f6 100644 --- a/main/EDTypesMod.F90 +++ b/main/EDTypesMod.F90 @@ -516,7 +516,7 @@ end subroutine dump_site ! ===================================================================================== - subroutine get_current_landuse_statevector(this, current_state_vector) + function get_current_landuse_statevector(this) result(current_state_vector) ! ! !DESCRIPTION: @@ -527,8 +527,8 @@ subroutine get_current_landuse_statevector(this, current_state_vector) ! !USES: ! ! !ARGUMENTS: - class(ed_site_type) :: this - real(r8), intent(out) :: current_state_vector(n_landuse_cats) + class(ed_site_type) :: this + real(r8) :: current_state_vector(n_landuse_cats) ! !LOCAL VARIABLES: type(fates_patch_type), pointer :: currentPatch