Skip to content

Commit

Permalink
Merge pull request #1198 from rgknox/remove_nclmax
Browse files Browse the repository at this point in the history
Dynamic Patch Arrays - larger nclmax and nlevleaf
  • Loading branch information
rgknox authored Aug 14, 2024
2 parents a683a00 + ae32bd4 commit b469786
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 205 deletions.
256 changes: 137 additions & 119 deletions biogeochem/EDCanopyStructureMod.F90

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module EDPatchDynamicsMod
use EDTypesMod , only : site_fluxdiags_type
use EDTypesMod , only : min_patch_area
use EDTypesMod , only : min_patch_area_forced
use EDParamsMod , only : nclmax
use EDParamsMod , only : regeneration_model
use FatesInterfaceTypesMod, only : numpft
use FatesConstantsMod , only : dtype_ifall
Expand Down
5 changes: 2 additions & 3 deletions biogeochem/FatesAllometryMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module FatesAllometryMod
use FatesGlobals , only : endrun => fates_endrun
use FatesGlobals , only : FatesWarn,N2S,A2S,I2S
use EDParamsMod , only : nlevleaf,dinc_vai,dlower_vai
use EDParamsMod , only : nclmax
use DamageMainMod , only : GetCrownReduction

implicit none
Expand Down Expand Up @@ -676,7 +675,7 @@ real(r8) function tree_lai( leaf_c, pft, c_area, nplant, cl, canopy_lai, vcmax25
real(r8), intent(in) :: c_area ! areal extent of canopy (m2)
real(r8), intent(in) :: nplant ! number of individuals in cohort per ha
integer, intent(in) :: cl ! canopy layer index
real(r8), intent(in) :: canopy_lai(nclmax) ! total leaf area index of
real(r8), intent(in) :: canopy_lai(:) ! total leaf area index of
! each canopy layer
real(r8), intent(in) :: vcmax25top ! maximum carboxylation rate at canopy
! top, ref 25C
Expand Down Expand Up @@ -809,7 +808,7 @@ real(r8) function tree_sai(pft, dbh, crowndamage, canopy_trim, elongf_stem, c_ar
real(r8), intent(in) :: c_area ! crown area (m2)
real(r8), intent(in) :: nplant ! number of plants
integer, intent(in) :: cl ! canopy layer index
real(r8), intent(in) :: canopy_lai(nclmax) ! total leaf area index of
real(r8), intent(in) :: canopy_lai(:) ! total leaf area index of
! each canopy layer
real(r8), intent(in) :: treelai ! tree LAI for checking purposes only
real(r8), intent(in) :: vcmax25top ! maximum carboxylation rate at top of crown
Expand Down
3 changes: 1 addition & 2 deletions biogeochem/FatesCohortMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module FatesCohortMod
use FatesConstantsMod, only : nearzero
use FatesConstantsMod, only : ican_upper, ican_ustory
use EDParamsMod, only : nlevleaf
use EDParamsMod, only : nclmax
use FatesGlobals, only : endrun => fates_endrun
use FatesGlobals, only : fates_log
use PRTGenericMod, only : max_nleafage
Expand Down Expand Up @@ -560,7 +559,7 @@ subroutine Create(this, prt, pft, nn, height, coage, dbh, status, &
real(r8), intent(in) :: ctrim ! fraction of the maximum leaf biomass
real(r8), intent(in) :: spread ! how spread crowns are in horizontal space
real(r8), intent(in) :: carea ! area of cohort, for SP mode [m2]
real(r8), intent(in) :: can_tlai(nclmax) ! patch-level total LAI of each leaf layer
real(r8), intent(in) :: can_tlai(:) ! patch-level total LAI of each canopy layer
real(r8), intent(in) :: elongf_leaf ! leaf elongation factor [fraction]
real(r8), intent(in) :: elongf_fnrt ! fine-root "elongation factor" [fraction]
real(r8), intent(in) :: elongf_stem ! stem "elongation factor" [fraction]
Expand Down
289 changes: 231 additions & 58 deletions biogeochem/FatesPatchMod.F90

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions biogeophys/FatesPlantRespPhotosynthMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,16 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)

! leaf maintenance (dark) respiration [umol CO2/m**2/s]
real(r8) :: lmr_z(nlevleaf,maxpft,nclmax)

! stomatal resistance [s/m]
real(r8) :: rs_z(nlevleaf,maxpft,nclmax)

! net leaf photosynthesis averaged over sun and shade leaves. [umol CO2/m**2/s]
real(r8) :: anet_av_z(nlevleaf,maxpft,nclmax)

! Photosynthesis [umol /m2 /s]
real(r8) :: psn_z(nlevleaf,maxpft,nclmax)

! Mask used to determine which leaf-layer biophysical rates have been
! used already
logical :: rate_mask_z(nlevleaf,maxpft,nclmax)
Expand Down Expand Up @@ -353,6 +356,8 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)
bc_out(s)%rssun_pa(ifp) = 0._r8
bc_out(s)%rssha_pa(ifp) = 0._r8

psn_z(:,:,:) = 0._r8

g_sb_leaves = 0._r8
patch_la = 0._r8

Expand All @@ -369,7 +374,7 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)
! Part III. Calculate the number of sublayers for each pft and layer.
! And then identify which layer/pft combinations have things in them.
! Output:
! currentPatch%ncan(:,:)
! currentPatch%nleaf(:,:)
! currentPatch%canopy_mask(:,:)
call UpdateCanopyNCanNRadPresent(currentPatch)

Expand Down Expand Up @@ -723,7 +728,7 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)
lmr_z(iv,ft,cl), & ! in
leaf_psi, & ! in
bc_in(s)%rb_pa(ifp), & ! in
currentPatch%psn_z(cl,ft,iv), & ! out
psn_z(iv,ft,cl), & ! out
rs_z(iv,ft,cl), & ! out
anet_av_z(iv,ft,cl), & ! out
c13disc_z(cl,ft,iv)) ! out
Expand Down Expand Up @@ -755,7 +760,7 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)
if(radiation_model.eq.norman_solver) then

call ScaleLeafLayerFluxToCohort(nv, & !in
currentPatch%psn_z(cl,ft,1:nv), & !in
psn_z(1:nv,ft,cl), & !in
lmr_z(1:nv,ft,cl), & !in
rs_z(1:nv,ft,cl), & !in
currentPatch%elai_profile(cl,ft,1:nv), & !in
Expand All @@ -773,7 +778,7 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)
else

call ScaleLeafLayerFluxToCohort(nv, & !in
currentPatch%psn_z(cl,ft,1:nv), & !in
psn_z(1:nv,ft,cl), & !in
lmr_z(1:nv,ft,cl), & !in
rs_z(1:nv,ft,cl), & !in
cohort_layer_elai(1:nv), & !in
Expand Down Expand Up @@ -1975,16 +1980,16 @@ subroutine UpdateCanopyNCanNRadPresent(currentPatch)

! ---------------------------------------------------------------------------------
! This subroutine calculates two patch level quanities:
! currentPatch%ncan and
! currentPatch%nleaf and
! currentPatch%canopy_mask
!
! currentPatch%ncan(:,:) is a two dimensional array that indicates
! currentPatch%nleaf(:,:) is a two dimensional array that indicates
! the total number of leaf layers (including those that are not exposed to light)
! in each canopy layer and for each functional type.
!
! currentPatch%nrad(:,:) is a two dimensional array that indicates
! the total number of EXPOSED leaf layers, but for all intents and purposes
! in the photosynthesis routine, this appears to be the same as %ncan...
! in the photosynthesis routine, this appears to be the same as %nleaf...
!
! currentPatch%canopy_mask(:,:) has the same dimensions, is binary, and
! indicates whether or not leaf layers are present (by evaluating the canopy area
Expand All @@ -2005,25 +2010,25 @@ subroutine UpdateCanopyNCanNRadPresent(currentPatch)
! of the layer/pft index it is in
! ---------------------------------------------------------------------------------

currentPatch%ncan(:,:) = 0
currentPatch%nleaf(:,:) = 0
! redo the canopy structure algorithm to get round a
! bug that is happening for site 125, FT13.
currentCohort => currentPatch%tallest
do while(associated(currentCohort))

currentPatch%ncan(currentCohort%canopy_layer,currentCohort%pft) = &
max(currentPatch%ncan(currentCohort%canopy_layer,currentCohort%pft), &
currentPatch%nleaf(currentCohort%canopy_layer,currentCohort%pft) = &
max(currentPatch%nleaf(currentCohort%canopy_layer,currentCohort%pft), &
currentCohort%NV)

currentCohort => currentCohort%shorter

enddo !cohort

! NRAD = NCAN ...
currentPatch%nrad = currentPatch%ncan
currentPatch%nrad = currentPatch%nleaf

! Now loop through and identify which layer and pft combo has scattering elements
do cl = 1,nclmax
do cl = 1,currentPatch%ncl_p
do ft = 1,numpft
currentPatch%canopy_mask(cl,ft) = 0
do iv = 1, currentPatch%nrad(cl,ft);
Expand Down
5 changes: 4 additions & 1 deletion main/EDParamsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ module EDParamsMod

real(r8), parameter, public :: soil_tfrz_thresh = -2.0_r8 ! Soil temperature threshold below which hydraulic failure mortality is off (non-hydro only) in degrees C

integer, parameter, public :: nclmax = 2 ! Maximum number of canopy layers
integer, parameter, public :: nclmax = 2 ! Maximum number of canopy layers (used only for scratch arrays)
! We would make this even higher, but making this
! a little lower keeps the size down on some output arrays
! For large arrays at patch level we use dynamic allocation

! parameters that govern the VAI (LAI+SAI) bins used in radiative transfer code
integer, parameter, public :: nlevleaf = 30 ! number of leaf+stem layers in each canopy layer
Expand Down
2 changes: 1 addition & 1 deletion main/FatesHistoryInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5395,7 +5395,7 @@ subroutine update_history_hifrq2(this,nc,nsites,sites,bc_in,bc_out,dt_tstep)

do_pft1: do ipft=1,numpft
do_canlev1: do ican=1,cpatch%ncl_p
do_leaflev1: do ileaf=1,cpatch%ncan(ican,ipft)
do_leaflev1: do ileaf=1,cpatch%nleaf(ican,ipft)

! calculate where we are on multiplexed dimensions
clllpf_indx = ileaf + (ican-1) * nlevleaf + (ipft-1) * nlevleaf * nclmax
Expand Down
2 changes: 1 addition & 1 deletion main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ subroutine SeedlingParPatch(cpatch, &
cl_par = 0._r8
cl_area = 0._r8
do ipft = 1,numpft
iv = cpatch%ncan(cl,ipft)
iv = cpatch%nleaf(cl,ipft)
! Avoid calculating when there are no leaf layers for the given pft in the current canopy layer
if (iv .ne. 0) then
cl_par = cl_par + cpatch%canopy_area_profile(cl,ipft,1)* &
Expand Down
2 changes: 1 addition & 1 deletion main/FatesRestartInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3769,7 +3769,7 @@ subroutine update_3dpatch_radiation(this, nsites, sites, bc_out)
currentpatch => sites(s)%oldest_patch
do while (associated(currentpatch))
ifp = ifp+1

currentPatch%f_sun (:,:,:) = 0._r8
currentPatch%fabd_sun_z (:,:,:) = 0._r8
currentPatch%fabd_sha_z (:,:,:) = 0._r8
Expand Down
2 changes: 1 addition & 1 deletion radiation/FatesNormanRadMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ subroutine PatchNormanRadiation (currentPatch, &
tau_layer(:,:,:,:)=0.0_r8
f_abs(:,:,:,:)=0.0_r8
f_abs_leaf(:,:,:,:)=0._r8
do L = 1,nclmax
do L = 1,currentPatch%ncl_p
do ft = 1,numpft
currentPatch%canopy_mask(L,ft) = 0
do iv = 1, currentPatch%nrad(L,ft)
Expand Down
2 changes: 1 addition & 1 deletion radiation/FatesRadiationDriveMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ subroutine FatesSunShadeFracs(nsites, sites,bc_in,bc_out)
end do do_icol

do ft = 1,numpft
do_iv: do iv = 1, nlevleaf
do_iv: do iv = 1,cpatch%nleaf(cl,ft)
if(area_vlpfcl(iv,ft,cl)<nearzero) exit do_iv
cpatch%parprof_pft_dir_z(cl,ft,iv) = &
cpatch%parprof_pft_dir_z(cl,ft,iv) / area_vlpfcl(iv,ft,cl)
Expand Down
3 changes: 0 additions & 3 deletions radiation/FatesTwoStreamUtilsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ subroutine FatesConstructRadElements(site,fcansno_pa,coszen_pa)
!real(r8), parameter :: init_max_vai_diff_per_elem = 0.2_r8
!type(fates_cohort_type), pointer :: elem_co_ptrs(ncl*max_el_per_layer,100)




max_elements = -1
ifp=0
patch => site%oldest_patch
Expand Down

0 comments on commit b469786

Please sign in to comment.