Skip to content

Commit

Permalink
Merge branch 'master' into ckoven/fusebug
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoven committed May 10, 2016
2 parents bb8ac55 + 0471ef9 commit 2933b0d
Show file tree
Hide file tree
Showing 10 changed files with 1,705 additions and 1,167 deletions.
1,807 changes: 978 additions & 829 deletions components/clm/src/ED/biogeophys/EDSurfaceAlbedoMod.F90

Large diffs are not rendered by default.

50 changes: 0 additions & 50 deletions components/clm/src/ED/main/EDInitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module EDInitMod
use EDGrowthFunctionsMod , only : bdead, bleaf, dbh
use EDCohortDynamicsMod , only : create_cohort, fuse_cohorts, sort_cohorts
use EDPatchDynamicsMod , only : create_patch
use EDMainMod , only : ed_update_site
use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type, area
use EDTypesMod , only : cohorts_per_gcell, ncwd, numpft_ed, udata
use EDCLMLinkMod , only : ed_clm_type
Expand All @@ -30,7 +29,6 @@ module EDInitMod

logical :: DEBUG = .false.

public :: ed_init
public :: ed_init_sites
public :: zero_site

Expand All @@ -42,55 +40,7 @@ module EDInitMod
contains

! ============================================================================
subroutine ed_init( bounds, ed_allsites_inst, ed_clm_inst, &
ed_phenology_inst, waterstate_inst, canopystate_inst)
!
! !DESCRIPTION:
! use ed_allsites_inst at the top level, then pass it through arg. list. then we can
! actually use intents
!
! !USES:
!
! !ARGUMENTS
type(bounds_type) , intent(in) :: bounds ! clump 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(waterstate_type) , intent(inout) :: waterstate_inst
type(canopystate_type) , intent(inout) :: canopystate_inst
!
! !LOCAL VARIABLES:
integer :: g
!----------------------------------------------------------------------

if (masterproc) then
if (DEBUG) then
write(iulog,*) 'ED: restart ? = ' ,is_restart()
write(iulog,*) 'ED_Mod.F90 :: SPITFIRE_SWITCH (use_ed_spit_fire) ', &
use_ed_spit_fire
write(iulog,*) 'ED_Mod.F90 :: cohorts_per_gcell ',cohorts_per_gcell
end if
end if

!
! don't call this if we are restarting
!
if ( .not. is_restart() ) then
call ed_init_sites( bounds, ed_allsites_inst(bounds%begg:bounds%endg))

do g = bounds%begg,bounds%endg
if (ed_allsites_inst(g)%istheresoil) then
call ed_update_site(ed_allsites_inst(g))
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)
endif

end subroutine ed_init

! ============================================================================
subroutine ed_init_sites( bounds, ed_allsites_inst )
!
! !DESCRIPTION:
Expand Down
26 changes: 9 additions & 17 deletions components/clm/src/ED/main/EDRestVectorMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,7 @@ subroutine setVectors( this, bounds, ed_allsites_inst )
end subroutine setVectors

!-------------------------------------------------------------------------------!
subroutine getVectors( this, bounds, ed_allsites_inst, ed_clm_inst, &
ed_phenology_inst, waterstate_inst, canopystate_inst)
subroutine getVectors( this, bounds, ed_allsites_inst )
!
! !DESCRIPTION:
! implement getVectors
Expand All @@ -642,10 +641,8 @@ subroutine getVectors( this, bounds, ed_allsites_inst, ed_clm_inst, &
class(EDRestartVectorClass) , intent(inout) :: this
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(waterstate_type) , intent(inout) :: waterstate_inst
type(canopystate_type) , intent(inout) :: canopystate_inst


!
! !LOCAL VARIABLES:
integer :: g
Expand All @@ -665,8 +662,8 @@ subroutine getVectors( this, bounds, ed_allsites_inst, ed_clm_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)
! 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) )
Expand Down Expand Up @@ -2116,26 +2113,22 @@ end subroutine convertCohortVectorToList
!--------------------------------------------!

!-------------------------------------------------------------------------------!
subroutine EDRest ( bounds, ncid, flag, ed_allsites_inst, ed_clm_inst, ed_phenology_inst, &
waterstate_inst, canopystate_inst )
subroutine EDRest ( bounds, ed_allsites_inst, ncid, flag )
!
! !DESCRIPTION:
! Read/write ED restart data
! EDRest called from restFileMod.F90
!
! !USES:

use ncdio_pio , only : file_desc_t
use EDCLMLinkMod , only : ed_clm_type
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds ! bounds
type(file_desc_t) , intent(inout) :: ncid ! netcdf id
type(ed_site_type) , intent(inout) :: ed_allsites_inst(bounds%begg:)
character(len=*) , intent(in) :: flag !'read' or 'write'
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(waterstate_type) , intent(inout) :: waterstate_inst
type(canopystate_type) , intent(inout) :: canopystate_inst
!
! !LOCAL VARIABLES:
type(EDRestartVectorClass) :: ervc
Expand All @@ -2156,8 +2149,7 @@ subroutine EDRest ( bounds, ncid, flag, ed_allsites_inst, ed_clm_inst, ed_phenol
call ervc%doVectorIO( ncid, flag )

if ( flag == 'read' ) then
call ervc%getVectors( bounds, ed_allsites_inst(bounds%begg:bounds%endg), ed_clm_inst, &
ed_phenology_inst, waterstate_inst, canopystate_inst)
call ervc%getVectors( bounds, ed_allsites_inst(bounds%begg:bounds%endg) )
endif

call ervc%deleteEDRestartVectorClass ()
Expand Down
196 changes: 196 additions & 0 deletions components/clm/src/ED/main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
module FatesInterfaceMod

! ------------------------------------------------------------------------------------
! This is the FATES public API
! A host land model has defined and allocated a structure "fates" as
! defined by fates_interface_type
!
! It is also likely/possible that this type is defined as a vector
! which is allocated by thread
! ------------------------------------------------------------------------------------

! ------------------------------------------------------------------------------------
! Used CLM Modules
! INTERF-TODO: NO CLM MODULES SHOULD BE ACCESSIBLE BY THE FATES
! PUBLIC API!!!!
use decompMod , only : bounds_type
use CanopyStateType , only : canopystate_type
use atm2lndType , only : atm2lnd_type
use ncdio_pio , only : file_desc_t
use PatchType , only : patch
! ------------------------------------------------------------------------------------

use EDtypesMod , only : ed_patch_type, ed_site_type, numpft_ed
use EDtypesMod , only : map_clmpatch_to_edpatch
use EDSurfaceRadiationMod , only : ED_SunShadeFracs
use EDInitMod , only : ed_init_sites
use EDMainMod , only : ed_update_site
use EDRestVectorMod , only : EDRest

type, public :: fates_interface_type

! This is the root of the ED/FATES hierarchy of instantaneous state variables
! ie the root of the linked lists. Each path list is currently associated
! with a grid-cell, this is intended to be migrated to columns
! prev: type(ed_site_type)::ed_allsites_inst
type(ed_site_type), allocatable :: sites(:)

! INTERF-TODO ADD THE DLM->FATES BOUNDARY CONDITION CLASS
! These are boundary condition variables populated by the DLM
! type(fates_bc_type) :: fatesbc

contains

! Procedures for initializing FATES threaded memory and communicators
procedure, public :: fates_init
procedure, public :: fates_clean
procedure, public :: site_init
procedure, public :: fates_restart
procedure, public :: canopy_sunshade_fracs

end type fates_interface_type

contains

subroutine fates_init(this,bounds_clump)

implicit none

! Input Arguments
class(fates_interface_type), intent(inout) :: this

! INTERF-TODO: AS THE FATES PUBLIC API- BOUNDS CLUMP WILL NOT BE ALLOWED
! IN HERE FOR MUCH LONGER.
type(bounds_type),intent(in) :: bounds_clump


! Initialize the mapping elements between FATES and the DLM

! These bounds are for a single clump (thread)
allocate (this%sites(bounds_clump%begg:bounds_clump%endg))

return
end subroutine fates_init

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

! INTERF-TODO: THIS IS A PLACE-HOLDER ROUTINE, NOT CALLED YET...
subroutine fates_clean(this,bounds_clump)

implicit none

! Input Arguments
class(fates_interface_type), intent(inout) :: this
type(bounds_type),intent(in) :: bounds_clump

! Incrementally walk through linked list and deallocate

! Deallocate the site list
deallocate (this%sites)

return
end subroutine fates_clean

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

subroutine site_init(this,bounds_clump)

! Input Arguments
class(fates_interface_type), intent(inout) :: this
type(bounds_type),intent(in) :: bounds_clump

! locals
integer :: g

! Initialize (INTERF-TODO THIS ROUTINE CALLS CLM STUFF-MIGRATE CODE TO HERE)
call ed_init_sites( bounds_clump, &
this%sites(bounds_clump%begg:bounds_clump%endg) )

! INTERF-TODO: WHEN WE MOVE TO COLUMNS, THIS WILL BE UNNECESSARY
do g = bounds_clump%begg,bounds_clump%endg
if (this%sites(g)%istheresoil) then
call ed_update_site(this%sites(g))
end if
end do

return
end subroutine site_init

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

subroutine fates_restart(this, bounds_clump, ncid, flag )

implicit none
class(fates_interface_type), intent(inout) :: this
type(bounds_type),intent(in) :: bounds_clump
type(file_desc_t) , intent(inout) :: ncid ! netcdf id
character(len=*) , intent(in) :: flag !'read' or 'write'

call EDRest( bounds_clump, this%sites(bounds_clump%begg:bounds_clump%endg), &
ncid, flag )
return
end subroutine fates_restart

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

subroutine canopy_sunshade_fracs(this ,filter_nourbanp, num_nourbanp, &
atm2lnd_inst,canopystate_inst)


! TODO-INTERF: THIS ROUTINE NEEDS TO BE WRAPPED BY A CLM_FATES CALL
! IN THAT CALL THE BOUNDARY CONDITIONS SHOULD BE PREPPED
! SO THAT THIS CALL DOES NOT HAVE CLM TYPES HERE

! This interface function is a wrapper call on ED_SunShadeFracs. The only
! returned variable is a patch vector, fsun_patch, which describes the fraction
! of the canopy that is exposed to sun.

implicit none

! Input Arguments
class(fates_interface_type), intent(inout) :: this

! patch filter for non-urban points
integer, intent(in),dimension(:) :: filter_nourbanp

! number of patches in non-urban points in patch filter
integer, intent(in) :: num_nourbanp

! direct and diffuse downwelling radiation (W/m2)
type(atm2lnd_type),intent(in) :: atm2lnd_inst

! Input/Output Arguments to CLM
type(canopystate_type),intent(inout) :: canopystate_inst

! Local Variables
integer :: fp ! non-urban filter patch index
integer :: p ! patch index
integer :: g ! grid cell index
integer, parameter :: ipar = 1 ! The band index for PAR
type(ed_patch_type), pointer :: cpatch ! c"urrent" patch

associate( forc_solad => atm2lnd_inst%forc_solad_grc, &
forc_solai => atm2lnd_inst%forc_solai_grc, &
fsun => canopystate_inst%fsun_patch)

do fp = 1,num_nourbanp

p = filter_nourbanp(fp)
g = patch%gridcell(p)

if ( patch%is_veg(p) ) then
cpatch => map_clmpatch_to_edpatch(this%sites(g), p)

call ED_SunShadeFracs(cpatch,forc_solad(g,ipar),forc_solai(g,ipar),fsun(p))

endif

end do
end associate
return
end subroutine canopy_sunshade_fracs




end module FatesInterfaceMod
4 changes: 2 additions & 2 deletions components/clm/src/biogeophys/SurfaceAlbedoMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module SurfaceAlbedoMod
use LandunitType , only : lun
use ColumnType , only : col
use PatchType , only : patch
use EDSurfaceAlbedoMod, only : ED_Norman_Radiation

use CanopyHydrologyMod, only : IsSnowvegFlagOn, IsSnowvegFlagOnRad
!
implicit none
Expand Down Expand Up @@ -203,7 +203,7 @@ subroutine SurfaceAlbedo(bounds, &
use abortutils , only : endrun
use clm_varctl , only : subgridflag, use_snicar_frc, use_ed
use EDTypesMod , only : ed_site_type
use EDSurfaceAlbedoMod
use EDSurfaceRadiationMod, only : ED_Norman_Radiation
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds ! bounds
Expand Down
Loading

0 comments on commit 2933b0d

Please sign in to comment.