Skip to content

Commit 20649ac

Browse files
authored
Merge pull request #1226 from rgknox/luh2_nocomp_merge-bcindex
cleaning up nocomp patch indexing
2 parents eb64928 + 368906c commit 20649ac

16 files changed

+169
-170
lines changed

biogeochem/EDCanopyStructureMod.F90

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module EDCanopyStructureMod
2020
use EDCohortDynamicsMod , only : InitPRTObject
2121
use FatesAllometryMod , only : tree_lai_sai
2222
use EDTypesMod , only : ed_site_type
23+
use EDTypesMod , only : set_patchno
2324
use FatesAllometryMod , only : VegAreaLayer
2425
use FatesAllometryMod , only : CrownDepth
2526
use FatesPatchMod, only : fates_patch_type
@@ -1313,7 +1314,6 @@ subroutine canopy_summarization( nsites, sites, bc_in )
13131314
! ---------------------------------------------------------------------------------
13141315

13151316
use FatesInterfaceTypesMod , only : hlm_use_cohort_age_tracking
1316-
use EDPatchDynamicsMod , only : set_patchno
13171317
use FatesSizeAgeTypeIndicesMod, only : sizetype_class_index
13181318
use FatesSizeAgeTypeIndicesMod, only : coagetype_class_index
13191319
use EDtypesMod , only : area
@@ -1350,7 +1350,7 @@ subroutine canopy_summarization( nsites, sites, bc_in )
13501350
! driving model. Loops through all patches and sets cpatch%patchno to the integer
13511351
! order of oldest to youngest where the oldest is 1.
13521352
! --------------------------------------------------------------------------------
1353-
call set_patchno( sites(s) )
1353+
call set_patchno( sites(s) , .false., 0)
13541354

13551355
currentPatch => sites(s)%oldest_patch
13561356

@@ -1896,7 +1896,6 @@ subroutine update_hlm_dynamics(nsites,sites,fcolumn,bc_out)
18961896

18971897
do s = 1,nsites
18981898

1899-
ifp = 0
19001899
total_patch_area = 0._r8
19011900
total_canopy_area = 0._r8
19021901
bc_out(s)%canopy_fraction_pa(:) = 0._r8
@@ -1908,9 +1907,8 @@ subroutine update_hlm_dynamics(nsites,sites,fcolumn,bc_out)
19081907
c = fcolumn(s)
19091908
do while(associated(currentPatch))
19101909

1911-
if(currentPatch%nocomp_pft_label.ne.nocomp_bareground)then ! ignore the bare-ground-PFT patch entirely for these BC outs
1912-
1913-
ifp = ifp+1
1910+
ifp = currentPatch%patchno
1911+
if_bare: if(currentPatch%nocomp_pft_label.ne.nocomp_bareground)then ! ignore the bare-ground-PFT patch entirely for these BC outs
19141912

19151913
if ( currentPatch%total_canopy_area-currentPatch%area > 0.000001_r8 ) then
19161914
if(debug)then
@@ -2028,7 +2026,7 @@ subroutine update_hlm_dynamics(nsites,sites,fcolumn,bc_out)
20282026

20292027
total_patch_area = total_patch_area + currentPatch%area/AREA
20302028

2031-
end if
2029+
end if if_bare
20322030
currentPatch => currentPatch%younger
20332031
end do
20342032

@@ -2048,13 +2046,11 @@ subroutine update_hlm_dynamics(nsites,sites,fcolumn,bc_out)
20482046
end if
20492047

20502048
currentPatch => sites(s)%oldest_patch
2051-
ifp = 0
20522049
do while(associated(currentPatch))
2050+
ifp = currentPatch%patchno
20532051
if(currentPatch%nocomp_pft_label.ne.nocomp_bareground)then ! for vegetated patches only
2054-
ifp = ifp+1
20552052
bc_out(s)%canopy_fraction_pa(ifp) = bc_out(s)%canopy_fraction_pa(ifp)/total_patch_area
20562053
endif ! veg patch
2057-
20582054
currentPatch => currentPatch%younger
20592055
end do
20602056

biogeochem/EDPatchDynamicsMod.F90

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module EDPatchDynamicsMod
2222
use FatesConstantsMod , only : patchfusion_dbhbin_loweredges
2323
use EDtypesMod , only : force_patchfuse_min_biomass
2424
use EDTypesMod , only : ed_site_type
25-
use FatesPatchMod, only : fates_patch_type
25+
use FatesPatchMod , only : fates_patch_type
26+
use EDTypesMod , only : set_patchno
2627
use FatesCohortMod , only : fates_cohort_type
2728
use EDTypesMod , only : site_massbal_type
2829
use EDTypesMod , only : site_fluxdiags_type
@@ -124,7 +125,6 @@ module EDPatchDynamicsMod
124125
public :: patch_pft_size_profile
125126
public :: disturbance_rates
126127
public :: check_patch_area
127-
public :: set_patchno
128128
private:: fuse_2_patches
129129

130130
character(len=*), parameter, private :: sourcefile = &
@@ -1323,7 +1323,7 @@ subroutine spawn_patches( currentSite, bc_in)
13231323

13241324

13251325
call check_patch_area(currentSite)
1326-
call set_patchno(currentSite)
1326+
call set_patchno(currentSite,.false.,0)
13271327

13281328
end do landusechange_receiverpatchlabel_loop
13291329
end do landuse_donortype_loop
@@ -1810,48 +1810,6 @@ subroutine check_patch_area( currentSite )
18101810
return
18111811
end subroutine check_patch_area
18121812

1813-
! ============================================================================
1814-
subroutine set_patchno( currentSite )
1815-
!
1816-
! !DESCRIPTION:
1817-
! Give patches an order number from the oldest to youngest.
1818-
!
1819-
! !USES:
1820-
!
1821-
! !ARGUMENTS:
1822-
type(ed_site_type),intent(in) :: currentSite
1823-
!
1824-
! !LOCAL VARIABLES:
1825-
type(fates_patch_type), pointer :: currentPatch
1826-
integer patchno
1827-
!---------------------------------------------------------------------
1828-
1829-
patchno = 1
1830-
currentPatch => currentSite%oldest_patch
1831-
do while(associated(currentPatch))
1832-
currentPatch%patchno = patchno
1833-
patchno = patchno + 1
1834-
currentPatch => currentPatch%younger
1835-
enddo
1836-
1837-
if(hlm_use_fixed_biogeog.eq.itrue .and. hlm_use_nocomp.eq.itrue)then
1838-
patchno = 1
1839-
currentPatch => currentSite%oldest_patch
1840-
do while(associated(currentPatch))
1841-
if(currentPatch%nocomp_pft_label.eq.nocomp_bareground)then
1842-
! for bareground patch, we make the patch number 0
1843-
! we also do not count this in the veg. patch numbering scheme.
1844-
currentPatch%patchno = 0
1845-
else
1846-
currentPatch%patchno = patchno
1847-
patchno = patchno + 1
1848-
endif
1849-
currentPatch => currentPatch%younger
1850-
enddo
1851-
endif
1852-
1853-
end subroutine set_patchno
1854-
18551813
! ============================================================================
18561814

18571815
subroutine TransLitterNewPatch(currentSite, &
@@ -3595,6 +3553,8 @@ subroutine terminate_patches(currentSite, bc_in)
35953553
!check area is not exceeded
35963554
call check_patch_area( currentSite )
35973555

3556+
call set_patchno( currentSite, .false., 0)
3557+
35983558
return
35993559
end subroutine terminate_patches
36003560

biogeochem/EDPhysiologyMod.F90

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,6 @@ subroutine trim_canopy( currentSite )
638638
real(r8) :: cumulative_lai_cohort ! cumulative LAI within the current cohort only
639639

640640
! Temporary diagnostic ouptut
641-
integer :: ipatch
642-
integer :: icohort
643641

644642
! LAPACK linear least squares fit variables
645643
! The standard equation for a linear fit, y = mx + b, is converted to a linear system, AX=B and has
@@ -673,19 +671,15 @@ subroutine trim_canopy( currentSite )
673671
real(r8) :: leaf_long ! temporary leaf lifespan before accounting for deciduousness
674672
!----------------------------------------------------------------------
675673

676-
ipatch = 1 ! Start counting patches
677-
678674
currentPatch => currentSite%youngest_patch
679675
do while(associated(currentPatch))
680676

681677
! Add debug diagnstic output to determine which patch
682678
if (debug) then
683-
write(fates_log(),*) 'Current patch:', ipatch
679+
write(fates_log(),*) 'Current patch:', currentPatch%patchno
684680
write(fates_log(),*) 'Current patch cohorts:', currentPatch%num_cohorts
685681
endif
686682

687-
icohort = 1
688-
689683
currentCohort => currentPatch%tallest
690684
do while (associated(currentCohort))
691685

@@ -695,7 +689,6 @@ subroutine trim_canopy( currentSite )
695689

696690
! Add debug diagnostic output to determine which cohort
697691
if (debug) then
698-
write(fates_log(),*) 'Current cohort:', icohort
699692
write(fates_log(),*) 'Starting canopy trim:', initial_trim
700693
endif
701694

@@ -907,10 +900,9 @@ subroutine trim_canopy( currentSite )
907900

908901
! currentCohort%canopy_trim = 1.0_r8 !FIX(RF,032414) this turns off ctrim for now.
909902
currentCohort => currentCohort%shorter
910-
icohort = icohort + 1
911903
enddo
912904
currentPatch => currentPatch%older
913-
ipatch = ipatch + 1
905+
914906
enddo
915907

916908
end subroutine trim_canopy

biogeochem/FatesSoilBGCFluxMod.F90

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ subroutine PrepCH4BCs(csite,bc_in,bc_out)
252252
type(fates_patch_type), pointer :: cpatch ! current patch pointer
253253
type(fates_cohort_type), pointer :: ccohort ! current cohort pointer
254254
integer :: pft ! plant functional type
255-
integer :: fp ! patch index of the site
255+
integer :: ifp ! patch index of the site
256256
real(r8) :: agnpp ! Above ground daily npp
257257
real(r8) :: bgnpp ! Below ground daily npp
258258
real(r8) :: plant_area ! crown area (m2) of all plants in patch
@@ -283,17 +283,17 @@ subroutine PrepCH4BCs(csite,bc_in,bc_out)
283283

284284
! Process CH4 variables first
285285
!if(.not.(hlm_use_ch4==itrue) .and. .not.(hlm_parteh_mode==prt_cnp_flex_allom_hyp) )
286-
287-
fp = 0
286+
288287
cpatch => csite%oldest_patch
289288
do while (associated(cpatch))
289+
290+
ifp = cpatch%patchno
291+
290292
if_notbare: if(cpatch%nocomp_pft_label .ne. nocomp_bareground)then
291293
! Patch ordering when passing boundary conditions
292294
! always goes from oldest to youngest, following
293295
! the convention of EDPatchDynamics::set_patchno()
294-
295-
fp = fp + 1
296-
296+
297297
agnpp = 0._r8
298298
bgnpp = 0._r8
299299
woody_area = 0._r8
@@ -334,13 +334,13 @@ subroutine PrepCH4BCs(csite,bc_in,bc_out)
334334
if(hlm_use_ch4==itrue)then
335335

336336
! Fine root fraction over depth
337-
bc_out%rootfr_pa(fp,1:bc_in%nlevsoil) = &
338-
bc_out%rootfr_pa(fp,1:bc_in%nlevsoil) + &
337+
bc_out%rootfr_pa(ifp,1:bc_in%nlevsoil) = &
338+
bc_out%rootfr_pa(ifp,1:bc_in%nlevsoil) + &
339339
csite%rootfrac_scr(1:bc_in%nlevsoil)
340340

341341
! Fine root carbon, convert [kg/plant] -> [g/m2]
342-
bc_out%frootc_pa(fp) = &
343-
bc_out%frootc_pa(fp) + &
342+
bc_out%frootc_pa(ifp) = &
343+
bc_out%frootc_pa(ifp) + &
344344
fnrt_c*ccohort%n/cpatch%area * g_per_kg
345345

346346
! (gC/m2/s) root respiration (fine root MR + total root GR)
@@ -366,10 +366,10 @@ subroutine PrepCH4BCs(csite,bc_in,bc_out)
366366
end do
367367

368368
if(hlm_use_ch4==itrue)then
369-
if( sum(bc_out%rootfr_pa(fp,1:bc_in%nlevsoil)) > nearzero) then
370-
bc_out%rootfr_pa(fp,1:bc_in%nlevsoil) = &
371-
bc_out%rootfr_pa(fp,1:bc_in%nlevsoil) / &
372-
sum(bc_out%rootfr_pa(fp,1:bc_in%nlevsoil))
369+
if( sum(bc_out%rootfr_pa(ifp,1:bc_in%nlevsoil)) > nearzero) then
370+
bc_out%rootfr_pa(ifp,1:bc_in%nlevsoil) = &
371+
bc_out%rootfr_pa(ifp,1:bc_in%nlevsoil) / &
372+
sum(bc_out%rootfr_pa(ifp,1:bc_in%nlevsoil))
373373
end if
374374

375375
! RGK: These averages should switch to the new patch averaging methods
@@ -378,17 +378,18 @@ subroutine PrepCH4BCs(csite,bc_in,bc_out)
378378
! would be arguably worse than just using the instantaneous value
379379

380380
! gC/m2/s
381-
bc_out%annavg_agnpp_pa(fp) = agnpp
382-
bc_out%annavg_bgnpp_pa(fp) = bgnpp
381+
bc_out%annavg_agnpp_pa(ifp) = agnpp
382+
bc_out%annavg_bgnpp_pa(ifp) = bgnpp
383383
! gc/m2/yr
384-
bc_out%annsum_npp_pa(fp) = (bgnpp+agnpp)*days_per_year*sec_per_day
384+
bc_out%annsum_npp_pa(ifp) = (bgnpp+agnpp)*days_per_year*sec_per_day
385385

386386
if(plant_area>nearzero) then
387-
bc_out%woody_frac_aere_pa(fp) = woody_area/plant_area
387+
bc_out%woody_frac_aere_pa(ifp) = woody_area/plant_area
388388
end if
389389

390390
end if
391391
end if if_notbare
392+
392393
cpatch => cpatch%younger
393394
end do
394395

biogeophys/EDAccumulateFluxesMod.F90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module EDAccumulateFluxesMod
1515
use FatesConstantsMod , only : r8 => fates_r8
1616
use FatesConstantsMod , only : nocomp_bareground
1717

18-
1918
implicit none
2019
private
2120
!
@@ -62,16 +61,16 @@ subroutine AccumulateFluxes_ED(nsites, sites, bc_in, bc_out, dt_time)
6261

6362
do s = 1, nsites
6463

65-
ifp = 0
66-
6764
! Note: Do not attempt to accumulate or log any
6865
! heterotrophic respiration fluxes from the HLM here
6966
! It is likely this has not been calculated yet (ELM/CLM)
7067

7168
cpatch => sites(s)%oldest_patch
72-
do while (associated(cpatch))
69+
do while (associated(cpatch))
70+
71+
ifp = cpatch%patchno
72+
7373
if(cpatch%nocomp_pft_label.ne.nocomp_bareground)then
74-
ifp = ifp+1
7574

7675
if( bc_in(s)%filter_photo_pa(ifp) == 3 ) then
7776
ccohort => cpatch%shortest
@@ -105,6 +104,7 @@ subroutine AccumulateFluxes_ED(nsites, sites, bc_in, bc_out, dt_time)
105104
enddo ! while(associated(ccohort))
106105
end if
107106
end if ! not bare ground
107+
108108
cpatch => cpatch%younger
109109
end do ! while(associated(cpatch))
110110
end do

biogeophys/EDBtranMod.F90

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ subroutine btran_ed( nsites, sites, bc_in, bc_out)
137137

138138
bc_out(s)%rootr_pasl(:,:) = 0._r8
139139

140-
ifp = 0
141140
cpatch => sites(s)%oldest_patch
142-
do while (associated(cpatch))
143-
if(cpatch%nocomp_pft_label.ne.nocomp_bareground)then ! only for veg patches
144-
ifp=ifp+1
141+
do while (associated(cpatch))
142+
143+
ifp = cpatch%patchno
144+
145+
if_bare: if(cpatch%nocomp_pft_label.ne.nocomp_bareground)then ! only for veg patches
145146

146147
! THIS SHOULD REALLY BE A COHORT LOOP ONCE WE HAVE rootfr_ft FOR COHORTS (RGK)
147148

@@ -246,7 +247,7 @@ subroutine btran_ed( nsites, sites, bc_in, bc_out)
246247
enddo
247248

248249
end if
249-
endif ! not bare ground
250+
endif if_bare
250251
cpatch => cpatch%younger
251252
end do
252253

biogeophys/FatesPlantHydraulicsMod.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,10 +2152,10 @@ subroutine BTranForHLMDiagnosticsFromCohortHydr(nsites,sites,bc_out)
21522152

21532153
do s = 1,nsites
21542154

2155-
ifp = 0
21562155
cpatch => sites(s)%oldest_patch
21572156
do while (associated(cpatch))
2158-
ifp=ifp+1
2157+
2158+
ifp = cpatch%patchno
21592159

21602160
balive_patch = 0._r8
21612161
ccohort=>cpatch%tallest
@@ -2496,12 +2496,12 @@ subroutine hydraulics_bc ( nsites, sites, bc_in, bc_out, dtime)
24962496
!err_soil = delta_soil_storage - root_flux
24972497
!err_plot = delta_plant_storage - (root_flux - transp_flux)
24982498

2499-
ifp = 0
25002499
cpatch => sites(s)%oldest_patch
25012500
do while (associated(cpatch))
25022501

2502+
ifp = cpatch%patchno
2503+
25032504
if(cpatch%nocomp_pft_label.ne.nocomp_bareground)then
2504-
ifp = ifp + 1
25052505

25062506
! ----------------------------------------------------------------------------
25072507
! Objective: Partition the transpiration flux

biogeophys/FatesPlantRespPhotosynthMod.F90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,13 @@ subroutine FatesPlantRespPhotosynthDrive (nsites, sites,bc_in,bc_out,dtime)
344344
end do
345345

346346

347-
ifp = 0
348347
currentpatch => sites(s)%oldest_patch
349348
do while (associated(currentpatch))
349+
350+
ifp = currentPatch%patchno
351+
350352
if_notbare: if(currentpatch%nocomp_pft_label.ne.nocomp_bareground)then
351-
ifp = ifp+1
353+
352354
NCL_p = currentPatch%NCL_p
353355

354356
! Part I. Zero output boundary conditions

0 commit comments

Comments
 (0)