From d0a710a14c0fce5b38efe95aab06eb1951eee68a Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Mon, 16 May 2016 18:31:02 -0700 Subject: [PATCH 1/2] Migrated calls to ecosystem dynamics into the clmfates interface, moved timing calls out of FATES code and into the interface. Evaluated udata%, which is not thread-safe, yet at the same time, all threads should be re-writing the same values. However, udata had been incrementing a cohort index number that had been used to test for identity during fusion (so a cohort doesnt fuse itself). The indices could had gotten jumbled if two threads simultaneously incremented the udata structure before assigning the index to the cohort variable. If this happened it would not had affected the fusion process, but would had been a problem if these variables were compared in output. Also, the cohort indices could start to get vary large. The variable was stored as an integer, and udata% was incrementing for every new cohort created per thread. So threads with many gridcells, and many patches, with many cohorts over a long time could generate very large number which could overfill the integer. So the index number was removed from the cohorts and from udata. Test to prevent self fusion now utilize the two argument associated() intrinsic, which tests to see if two pointers are on the same address (in a scalar). --- .../src/ED/biogeochem/EDCohortDynamicsMod.F90 | 27 +++--- .../clm/src/ED/biogeochem/EDPhysiologyMod.F90 | 12 +-- components/clm/src/ED/main/EDInitMod.F90 | 2 +- components/clm/src/ED/main/EDMainMod.F90 | 97 ++----------------- .../clm/src/ED/main/EDRestVectorMod.F90 | 4 - components/clm/src/ED/main/EDTypesMod.F90 | 7 +- .../clm/src/ED/main/FatesInterfaceMod.F90 | 2 +- .../clm/src/utils/clmfates_interfaceMod.F90 | 79 +++++++++++++-- 8 files changed, 107 insertions(+), 123 deletions(-) diff --git a/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 b/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 index 9d46aca904..3cf565dd4e 100755 --- a/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 +++ b/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 @@ -10,8 +10,8 @@ module EDCohortDynamicsMod use EDEcophysContype , only : EDecophyscon use EDGrowthFunctionsMod , only : c_area, tree_lai use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type - use EDTypesMod , only : fusetol, nclmax - use EDtypesMod , only : ncwd, numcohortsperpatch, udata + use EDTypesMod , only : fusetol, nclmax, udata + use EDtypesMod , only : ncwd, numcohortsperpatch use EDtypesMod , only : sclass_ed,nlevsclass_ed,AREA use EDtypesMod , only : min_npm2, min_nppatch, min_n_safemath ! @@ -68,7 +68,6 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, & !---------------------------------------------------------------------- allocate(new_cohort) - udata%cohort_number = udata%cohort_number + 1 !give each cohort a unique number for checking cohort fusing routine. call nan_cohort(new_cohort) ! Make everything in the cohort not-a-number call zero_cohort(new_cohort) ! Zero things that need to be zeroed. @@ -77,7 +76,7 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, & ! Define cohort state variable !**********************/ - new_cohort%indexnumber = udata%cohort_number +! new_cohort%indexnumber = udata%cohort_number new_cohort%siteptr => patchptr%siteptr new_cohort%patchptr => patchptr new_cohort%pft = pft @@ -613,7 +612,6 @@ subroutine fuse_cohorts(patchptr) iterate = 1 fusion_took_place = 0 currentPatch => patchptr - ! maxcohorts = currentPatch%NCL_p * numCohortsPerPatch maxcohorts = numCohortsPerPatch !---------------------------------------------------------------------! @@ -624,8 +622,13 @@ subroutine fuse_cohorts(patchptr) currentCohort => currentPatch%tallest - !CHANGED FROM C VERSION loop from tallest to smallest, fusing if they are similar - do while (currentCohort%indexnumber /= currentPatch%shortest%indexnumber) + ! The following logic continues the loop while the current cohort is not the shortest cohort + ! if they point to the same target (ie equivalence), then the loop ends. + ! This loop is different than the simple "continue while associated" loop in that + ! it omits the last cohort (because it has already been compared by that point) + + do while ( .not.associated(currentCohort,currentPatch%shortest) ) + nextc => currentPatch%tallest do while (associated(nextc)) @@ -636,7 +639,9 @@ subroutine fuse_cohorts(patchptr) if (diff < dynamic_fusion_tolerance) then - if (currentCohort%indexnumber /= nextc%indexnumber) then + ! Don't fuse a cohort with itself! + if (.not.associated(currentCohort,nextc) ) then +! if (currentCohort%indexnumber /= nextc%indexnumber) then if (currentCohort%pft == nextc%pft) then @@ -981,9 +986,9 @@ subroutine copy_cohort( currentCohort,copyc ) o => currentCohort n => copyc - udata%cohort_number = udata%cohort_number + 1 - n%indexnumber = udata%cohort_number - +! udata%cohort_number = udata%cohort_number + 1 + !n%indexnumber = udata%cohort_number + ! VEGETATION STRUCTURE n%pft = o%pft n%n = o%n diff --git a/components/clm/src/ED/biogeochem/EDPhysiologyMod.F90 b/components/clm/src/ED/biogeochem/EDPhysiologyMod.F90 index 2f63f7a94c..7dc3190a81 100755 --- a/components/clm/src/ED/biogeochem/EDPhysiologyMod.F90 +++ b/components/clm/src/ED/biogeochem/EDPhysiologyMod.F90 @@ -18,7 +18,7 @@ module EDPhysiologyMod use EDCohortDynamicsMod , only : create_cohort, fuse_cohorts, sort_cohorts use EDPhenologyType , only : ed_phenology_type use EDTypesMod , only : dg_sf, dinc_ed, external_recruitment - use EDTypesMod , only : ncwd, nlevcan_ed, n_sub, numpft_ed, senes + use EDTypesMod , only : ncwd, nlevcan_ed, numpft_ed, senes use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type implicit none @@ -250,7 +250,7 @@ subroutine phenology( currentSite, ed_phenology_inst, temperature_inst, watersta use EDTypesMod, only : udata ! ! !ARGUMENTS: - type(ed_site_type) , intent(inout), pointer:: currentSite + type(ed_site_type) , intent(inout), target :: currentSite type(ed_phenology_type) , intent(in) :: ed_phenology_inst type(temperature_type) , intent(in) :: temperature_inst type(waterstate_type) , intent(in) :: waterstate_inst @@ -504,7 +504,7 @@ subroutine phenology_leafonoff(currentSite) ! !USES: ! ! !ARGUMENTS: - type(ed_site_type), intent(inout), pointer:: currentSite + type(ed_site_type), intent(inout), target :: currentSite ! ! !LOCAL VARIABLES: type(ed_patch_type) , pointer :: currentPatch @@ -771,9 +771,9 @@ subroutine Growth_Derivatives( currentCohort) ! NPP if ( DEBUG ) write(iulog,*) 'EDphys 716 ',currentCohort%npp_acc - currentCohort%npp = currentCohort%npp_acc * N_SUB !Link to CLM. convert from kgC/indiv/day into kgC/indiv/year - currentCohort%gpp = currentCohort%gpp_acc * N_SUB !Link to CLM. convert from kgC/indiv/day into kgC/indiv/year - currentCohort%resp = currentCohort%resp_acc * N_SUB !Link to CLM. convert from kgC/indiv/day into kgC/indiv/year + currentCohort%npp = currentCohort%npp_acc * udata%n_sub !Link to CLM. convert from kgC/indiv/day into kgC/indiv/year + currentCohort%gpp = currentCohort%gpp_acc * udata%n_sub !Link to CLM. convert from kgC/indiv/day into kgC/indiv/year + currentCohort%resp = currentCohort%resp_acc * udata%n_sub !Link to CLM. convert from kgC/indiv/day into kgC/indiv/year currentSite%flux_in = currentSite%flux_in + currentCohort%npp_acc * currentCohort%n diff --git a/components/clm/src/ED/main/EDInitMod.F90 b/components/clm/src/ED/main/EDInitMod.F90 index 534d320b5c..a98808f9af 100755 --- a/components/clm/src/ED/main/EDInitMod.F90 +++ b/components/clm/src/ED/main/EDInitMod.F90 @@ -63,7 +63,7 @@ subroutine ed_init_sites( bounds, ed_allsites_inst ) ! INITIALISE THE SITE STRUCTURES ! ! Makes unique cohort identifiers. Needs zeroing at beginning of run. - udata%cohort_number = 0 +! udata%cohort_number = 0 do g = bounds%begg,bounds%endg ! zero the site diff --git a/components/clm/src/ED/main/EDMainMod.F90 b/components/clm/src/ED/main/EDMainMod.F90 index c52c6330dc..720f03c823 100755 --- a/components/clm/src/ED/main/EDMainMod.F90 +++ b/components/clm/src/ED/main/EDMainMod.F90 @@ -5,7 +5,7 @@ module EDMainMod ! ============================================================================ use shr_kind_mod , only : r8 => shr_kind_r8 - use spmdMod , only : masterproc + use decompMod , only : bounds_type use clm_varctl , only : iulog use atm2lndType , only : atm2lnd_type @@ -16,7 +16,7 @@ module EDMainMod use EDPatchDynamicsMod , only : disturbance_rates, fuse_patches, spawn_patches, terminate_patches use EDPhysiologyMod , only : canopy_derivs, non_canopy_derivs, phenology, recruitment, trim_canopy use SFMainMod , only : fire_model - use EDtypesMod , only : ncwd, n_sub, numpft_ed, udata + use EDtypesMod , only : ncwd, numpft_ed, udata use EDtypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type use EDPhenologyType , only : ed_phenology_type use EDCLMLinkMod , only : ed_clm_type @@ -26,11 +26,11 @@ module EDMainMod ! ! !PUBLIC MEMBER FUNCTIONS: - public :: ed_driver + public :: ed_ecosystem_dynamics public :: ed_update_site ! ! !PRIVATE MEMBER FUNCTIONS: - private :: ed_ecosystem_dynamics + private :: ed_integrate_state_variables private :: ed_total_balance_check @@ -41,83 +41,6 @@ module EDMainMod contains - !----------------------------------------------------------------------- - subroutine ed_driver( bounds, ed_allsites_inst, ed_clm_inst, ed_phenology_inst, & - atm2lnd_inst, soilstate_inst, temperature_inst, waterstate_inst, canopystate_inst) - ! - ! !DESCRIPTION: - ! Main ed model routine containing gridcell loop - ! - ! !USES: - use clm_time_manager , only : get_days_per_year, get_curr_date - use clm_time_manager , only : get_ref_date, timemgr_datediff - use CanopySTateType , only : canopystate_type - ! - ! !ARGUMENTS: - type(bounds_type) , intent(in) :: bounds - type(ed_site_type) , intent(inout), target :: ed_allsites_inst( bounds%begg: ) - type(ed_clm_type) , intent(inout) :: ed_clm_inst - type(ed_phenology_type) , intent(inout) :: ed_phenology_inst - type(atm2lnd_type) , intent(in) :: atm2lnd_inst - type(soilstate_type) , intent(in) :: soilstate_inst - type(temperature_type) , intent(in) :: temperature_inst - type(waterstate_type) , intent(inout) :: waterstate_inst - type(canopystate_type) , intent(inout) :: canopystate_inst - ! - ! !LOCAL VARIABLES: - type(ed_site_type), pointer :: currentSite - real(r8) :: dayDiff ! day of run - integer :: dayDiffInt ! integer of day of run - integer :: g ! gridcell - integer :: yr ! year (0, ...) - integer :: mon ! month (1, ..., 12) - integer :: day ! day of month (1, ..., 31) - integer :: sec ! seconds of the day - integer :: ncdate ! current date - integer :: nbdate ! base date (reference date) - !----------------------------------------------------------------------- - - call ed_clm_inst%SetValues( bounds, 0._r8 ) - - ! timing statements. - n_sub = get_days_per_year() - udata%deltat = 1.0_r8/n_sub !for working out age of patches in years - if(udata%time_period == 0)then - udata%time_period = n_sub - endif - - call get_curr_date(yr, mon, day, sec) - ncdate = yr*10000 + mon*100 + day - call get_ref_date(yr, mon, day, sec) - nbdate = yr*10000 + mon*100 + day - - call timemgr_datediff(nbdate, 0, ncdate, sec, dayDiff) - - dayDiffInt = floor(dayDiff) - udata%time_period = mod( dayDiffInt , n_sub ) - - ! where most things happen - do g = bounds%begg,bounds%endg - if (ed_allsites_inst(g)%istheresoil) then - currentSite => ed_allsites_inst(g) - call ed_ecosystem_dynamics(currentSite, & - ed_clm_inst, ed_phenology_inst, atm2lnd_inst, & - soilstate_inst, temperature_inst, waterstate_inst) - - call ed_update_site( ed_allsites_inst(g)) - endif - enddo - - ! link to CLM structures - call ed_clm_inst%ed_clm_link( bounds, ed_allsites_inst(bounds%begg:bounds%endg), & - ed_phenology_inst, waterstate_inst, canopystate_inst) - - if (masterproc) then - write(iulog, *) 'clm: leaving ED model', bounds%begg, bounds%endg, dayDiffInt - end if - - end subroutine ed_driver - !-------------------------------------------------------------------------------! subroutine ed_ecosystem_dynamics(currentSite, & ed_clm_inst, ed_phenology_inst, atm2lnd_inst, & @@ -127,7 +50,7 @@ subroutine ed_ecosystem_dynamics(currentSite, & ! Core of ed model, calling all subsequent vegetation dynamics routines ! ! !ARGUMENTS: - type(ed_site_type) , intent(inout), pointer :: currentSite + type(ed_site_type) , intent(inout), target :: currentSite type(ed_phenology_type) , intent(in) :: ed_phenology_inst type(ed_clm_type) , intent(in) :: ed_clm_inst type(atm2lnd_type) , intent(in) :: atm2lnd_inst @@ -221,10 +144,10 @@ subroutine ed_integrate_state_variables(currentSite, soilstate_inst, temperature ! !USES: ! ! !ARGUMENTS: - type(ed_site_type) , intent(in) :: currentSite - type(soilstate_type) , intent(in) :: soilstate_inst - type(temperature_type) , intent(in) :: temperature_inst - type(waterstate_type) , intent(in) :: waterstate_inst + type(ed_site_type) , intent(in) :: currentSite + type(soilstate_type) , intent(in) :: soilstate_inst + type(temperature_type) , intent(in) :: temperature_inst + type(waterstate_type) , intent(in) :: waterstate_inst ! ! !LOCAL VARIABLES: type(ed_patch_type) , pointer :: currentPatch @@ -418,7 +341,7 @@ subroutine ed_update_site( currentSite ) enddo ! FIX(RF,032414). This needs to be monthly, not annual - if((udata%time_period == N_SUB-1))then + if((udata%time_period == udata%n_sub-1))then write(iulog,*) 'calling trim canopy' call trim_canopy(currentSite) endif diff --git a/components/clm/src/ED/main/EDRestVectorMod.F90 b/components/clm/src/ED/main/EDRestVectorMod.F90 index 0ca33d588a..873523c5db 100755 --- a/components/clm/src/ED/main/EDRestVectorMod.F90 +++ b/components/clm/src/ED/main/EDRestVectorMod.F90 @@ -634,7 +634,6 @@ subroutine getVectors( this, bounds, ed_allsites_inst ) ! !USES: use clm_time_manager , only : get_nstep use EDCLMLinkMod , only : ed_clm_type - use EDInitMod , only : ed_init_sites use EDMainMod , only : ed_update_site ! ! !ARGUMENTS: @@ -662,9 +661,6 @@ subroutine getVectors( this, bounds, ed_allsites_inst ) end if end do -! call ed_clm_inst%ed_clm_link( bounds, ed_allsites_inst(bounds%begg:bounds%endg), & -! ed_phenology_inst, waterstate_inst, canopystate_inst) - if (this%DEBUG) then call this%printIoInfoLL ( bounds, ed_allsites_inst(bounds%begg:bounds%endg) ) call this%printDataInfoLL ( bounds, ed_allsites_inst(bounds%begg:bounds%endg) ) diff --git a/components/clm/src/ED/main/EDTypesMod.F90 b/components/clm/src/ED/main/EDTypesMod.F90 index 47934da698..8d1e341b3e 100755 --- a/components/clm/src/ED/main/EDTypesMod.F90 +++ b/components/clm/src/ED/main/EDTypesMod.F90 @@ -14,7 +14,7 @@ module EDTypesMod ! MODEL PARAMETERS real(r8) :: timestep_secs ! subdaily timestep in seconds (e.g. 1800 or 3600) - integer :: n_sub ! num of substeps in year + real(r8), parameter :: AREA = 10000.0_r8 ! Notional area of simulated forest m2 integer doy @@ -438,13 +438,14 @@ module EDTypesMod !************************************ type userdata - integer :: cohort_number ! Counts up the number of cohorts which have been made. + integer :: n_sub ! num of substeps in year real(r8) :: deltat ! fraction of year used for each timestep (1/N_SUB) integer :: time_period ! Within year timestep (1:N_SUB) day of year integer :: restart_year ! Which year of simulation are we starting in? end type userdata - type(userdata), public, target :: udata + + type(userdata), public, target :: udata ! THIS WAS NOT THREADSAFE !-------------------------------------------------------------------------------------! public :: ed_hist_scpfmaps diff --git a/components/clm/src/ED/main/FatesInterfaceMod.F90 b/components/clm/src/ED/main/FatesInterfaceMod.F90 index 26302b19f9..3f64470bb8 100644 --- a/components/clm/src/ED/main/FatesInterfaceMod.F90 +++ b/components/clm/src/ED/main/FatesInterfaceMod.F90 @@ -21,7 +21,7 @@ module FatesInterfaceMod ! ------------------------------------------------------------------------------------ use EDtypesMod , only : ed_patch_type, ed_site_type, numpft_ed - use EDtypesMod , only : map_clmpatch_to_edpatch + use EDtypesMod , only : map_clmpatch_to_edpatch, userdata use EDSurfaceRadiationMod , only : ED_SunShadeFracs use EDInitMod , only : ed_init_sites use EDMainMod , only : ed_update_site diff --git a/components/clm/src/utils/clmfates_interfaceMod.F90 b/components/clm/src/utils/clmfates_interfaceMod.F90 index d5b8315fce..d637dfb7c0 100644 --- a/components/clm/src/utils/clmfates_interfaceMod.F90 +++ b/components/clm/src/utils/clmfates_interfaceMod.F90 @@ -45,16 +45,17 @@ module CLMFatesInterfaceMod use SolarAbsorbedType , only : solarabs_type use clm_time_manager , only : is_restart use ncdio_pio , only : file_desc_t - + use clm_time_manager , only : get_days_per_year, get_curr_date + use clm_time_manager , only : get_ref_date, timemgr_datediff + use spmdMod , only : masterproc ! Used FATES Modules use FatesInterfaceMod , only : fates_interface_type use EDCLMLinkMod , only : ed_clm_type use EDPhenologyType , only : ed_phenology_type - - use EDMainMod , only : ed_driver - - + use EDTypesMod , only : udata + use EDMainMod , only : ed_ecosystem_dynamics + use EDMainMod , only : ed_update_site implicit none @@ -192,6 +193,20 @@ subroutine dynamics_driv(this, nc, bounds_clump, & integer , intent(in) :: nc type(waterstate_type) , intent(inout) :: waterstate_inst type(canopystate_type) , intent(inout) :: canopystate_inst + + ! !LOCAL VARIABLES: + integer :: n_sub ! local counterpart to udata%n_sub + real(r8) :: dayDiff ! day of run + integer :: dayDiffInt ! integer of day of run + integer :: g ! gridcell + integer :: yr ! year (0, ...) + integer :: mon ! month (1, ..., 12) + integer :: day ! day of month (1, ..., 31) + integer :: sec ! seconds of the day + integer :: ncdate ! current date + integer :: nbdate ! base date (reference date) + !----------------------------------------------------------------------- + ! --------------------------------------------------------------------------------- ! INTERF-TODO: REMOVE ED_DRIVER ARGUMENTS OF CLM STUCTURED TYPES AND @@ -204,13 +219,57 @@ subroutine dynamics_driv(this, nc, bounds_clump, & ! this%fates(nc)%fatesbc) ! --------------------------------------------------------------------------------- + + call this%fates2hlm_inst%SetValues( bounds_clump, 0._r8 ) + + ! timing statements. + n_sub = get_days_per_year() + udata%n_sub = n_sub + udata%deltat = 1.0_r8/dble(n_sub) !for working out age of patches in years + if(udata%time_period == 0)then + udata%time_period = n_sub + endif + + call get_curr_date(yr, mon, day, sec) + ncdate = yr*10000 + mon*100 + day + call get_ref_date(yr, mon, day, sec) + nbdate = yr*10000 + mon*100 + day + + call timemgr_datediff(nbdate, 0, ncdate, sec, dayDiff) + + dayDiffInt = floor(dayDiff) + udata%time_period = mod( dayDiffInt , n_sub ) - call ed_driver( bounds_clump, & + + ! TODO-INTEF: PROCEDURE FOR CONVERTING CLM/ALM FIELDS TO MODEL BOUNDARY + ! CONDITIONS. IE. + + + ! where most things happen + do g = bounds_clump%begg,bounds_clump%endg + if (this%fates(nc)%sites(g)%istheresoil) then + call ed_ecosystem_dynamics(this%fates(nc)%sites(g), & + this%fates2hlm_inst, & + this%phen_inst, atm2lnd_inst, & + soilstate_inst, temperature_inst, waterstate_inst) + + call ed_update_site(this%fates(nc)%sites(g)) + endif + enddo + + ! link to CLM/ALM structures + call this%fates2hlm_inst%ed_clm_link( bounds_clump, & this%fates(nc)%sites(bounds_clump%begg:bounds_clump%endg), & - this%fates2hlm_inst, & - this%phen_inst, & - atm2lnd_inst, soilstate_inst, temperature_inst, & - waterstate_inst, canopystate_inst) + this%phen_inst, & + waterstate_inst, & + canopystate_inst) + + + if (masterproc) then + write(iulog, *) 'clm: leaving ED model', bounds_clump%begg, & + bounds_clump%endg, dayDiffInt + end if + return end subroutine dynamics_driv From dc7a6fb24fe5bee4d59378e6820a79d63454cedd Mon Sep 17 00:00:00 2001 From: Ryan Knox Date: Wed, 18 May 2016 13:52:38 -0700 Subject: [PATCH 2/2] Reverted the pre-mature removal of udata%cohort_index and cohort%cohort_index. This variable will be evaluated in a seperate issue. --- .../clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 | 14 +++++++------- components/clm/src/ED/main/EDInitMod.F90 | 2 +- components/clm/src/ED/main/EDTypesMod.F90 | 1 + components/clm/src/ED/main/FatesInterfaceMod.F90 | 2 +- components/clm/src/utils/clmfates_interfaceMod.F90 | 12 +++++------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 b/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 index 3cf565dd4e..0443de25ab 100755 --- a/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 +++ b/components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90 @@ -10,8 +10,8 @@ module EDCohortDynamicsMod use EDEcophysContype , only : EDecophyscon use EDGrowthFunctionsMod , only : c_area, tree_lai use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type - use EDTypesMod , only : fusetol, nclmax, udata - use EDtypesMod , only : ncwd, numcohortsperpatch + use EDTypesMod , only : fusetol, nclmax + use EDtypesMod , only : ncwd, numcohortsperpatch, udata use EDtypesMod , only : sclass_ed,nlevsclass_ed,AREA use EDtypesMod , only : min_npm2, min_nppatch, min_n_safemath ! @@ -68,7 +68,8 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, & !---------------------------------------------------------------------- allocate(new_cohort) - + udata%cohort_number = udata%cohort_number + 1 !give each cohort a unique number for checking cohort fusing routine. + call nan_cohort(new_cohort) ! Make everything in the cohort not-a-number call zero_cohort(new_cohort) ! Zero things that need to be zeroed. @@ -76,7 +77,7 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, & ! Define cohort state variable !**********************/ -! new_cohort%indexnumber = udata%cohort_number + new_cohort%indexnumber = udata%cohort_number new_cohort%siteptr => patchptr%siteptr new_cohort%patchptr => patchptr new_cohort%pft = pft @@ -641,7 +642,6 @@ subroutine fuse_cohorts(patchptr) ! Don't fuse a cohort with itself! if (.not.associated(currentCohort,nextc) ) then -! if (currentCohort%indexnumber /= nextc%indexnumber) then if (currentCohort%pft == nextc%pft) then @@ -986,8 +986,8 @@ subroutine copy_cohort( currentCohort,copyc ) o => currentCohort n => copyc -! udata%cohort_number = udata%cohort_number + 1 - !n%indexnumber = udata%cohort_number + udata%cohort_number = udata%cohort_number + 1 + n%indexnumber = udata%cohort_number ! VEGETATION STRUCTURE n%pft = o%pft diff --git a/components/clm/src/ED/main/EDInitMod.F90 b/components/clm/src/ED/main/EDInitMod.F90 index a98808f9af..534d320b5c 100755 --- a/components/clm/src/ED/main/EDInitMod.F90 +++ b/components/clm/src/ED/main/EDInitMod.F90 @@ -63,7 +63,7 @@ subroutine ed_init_sites( bounds, ed_allsites_inst ) ! INITIALISE THE SITE STRUCTURES ! ! Makes unique cohort identifiers. Needs zeroing at beginning of run. -! udata%cohort_number = 0 + udata%cohort_number = 0 do g = bounds%begg,bounds%endg ! zero the site diff --git a/components/clm/src/ED/main/EDTypesMod.F90 b/components/clm/src/ED/main/EDTypesMod.F90 index 8d1e341b3e..50f5dc0939 100755 --- a/components/clm/src/ED/main/EDTypesMod.F90 +++ b/components/clm/src/ED/main/EDTypesMod.F90 @@ -438,6 +438,7 @@ module EDTypesMod !************************************ type userdata + integer :: cohort_number ! Counts up the number of cohorts which have been made. integer :: n_sub ! num of substeps in year real(r8) :: deltat ! fraction of year used for each timestep (1/N_SUB) integer :: time_period ! Within year timestep (1:N_SUB) day of year diff --git a/components/clm/src/ED/main/FatesInterfaceMod.F90 b/components/clm/src/ED/main/FatesInterfaceMod.F90 index 3f64470bb8..26302b19f9 100644 --- a/components/clm/src/ED/main/FatesInterfaceMod.F90 +++ b/components/clm/src/ED/main/FatesInterfaceMod.F90 @@ -21,7 +21,7 @@ module FatesInterfaceMod ! ------------------------------------------------------------------------------------ use EDtypesMod , only : ed_patch_type, ed_site_type, numpft_ed - use EDtypesMod , only : map_clmpatch_to_edpatch, userdata + use EDtypesMod , only : map_clmpatch_to_edpatch use EDSurfaceRadiationMod , only : ED_SunShadeFracs use EDInitMod , only : ed_init_sites use EDMainMod , only : ed_update_site diff --git a/components/clm/src/utils/clmfates_interfaceMod.F90 b/components/clm/src/utils/clmfates_interfaceMod.F90 index d637dfb7c0..16c41c5bb4 100644 --- a/components/clm/src/utils/clmfates_interfaceMod.F90 +++ b/components/clm/src/utils/clmfates_interfaceMod.F90 @@ -195,7 +195,6 @@ subroutine dynamics_driv(this, nc, bounds_clump, & type(canopystate_type) , intent(inout) :: canopystate_inst ! !LOCAL VARIABLES: - integer :: n_sub ! local counterpart to udata%n_sub real(r8) :: dayDiff ! day of run integer :: dayDiffInt ! integer of day of run integer :: g ! gridcell @@ -223,11 +222,10 @@ subroutine dynamics_driv(this, nc, bounds_clump, & call this%fates2hlm_inst%SetValues( bounds_clump, 0._r8 ) ! timing statements. - n_sub = get_days_per_year() - udata%n_sub = n_sub - udata%deltat = 1.0_r8/dble(n_sub) !for working out age of patches in years + udata%n_sub = get_days_per_year() + udata%deltat = 1.0_r8/dble(udata%n_sub) !for working out age of patches in years if(udata%time_period == 0)then - udata%time_period = n_sub + udata%time_period = udata%n_sub endif call get_curr_date(yr, mon, day, sec) @@ -238,7 +236,7 @@ subroutine dynamics_driv(this, nc, bounds_clump, & call timemgr_datediff(nbdate, 0, ncdate, sec, dayDiff) dayDiffInt = floor(dayDiff) - udata%time_period = mod( dayDiffInt , n_sub ) + udata%time_period = mod( dayDiffInt , udata%n_sub ) ! TODO-INTEF: PROCEDURE FOR CONVERTING CLM/ALM FIELDS TO MODEL BOUNDARY @@ -260,7 +258,7 @@ subroutine dynamics_driv(this, nc, bounds_clump, & ! link to CLM/ALM structures call this%fates2hlm_inst%ed_clm_link( bounds_clump, & this%fates(nc)%sites(bounds_clump%begg:bounds_clump%endg), & - this%phen_inst, & + this%phen_inst, & waterstate_inst, & canopystate_inst)