Skip to content

Commit

Permalink
columnization first pass, build success
Browse files Browse the repository at this point in the history
  • Loading branch information
rgknox committed Jun 1, 2016
1 parent 3ddab77 commit 6e5b9cf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
29 changes: 15 additions & 14 deletions components/clm/src/ED/main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module FatesInterfaceMod
use EDSurfaceRadiationMod , only : ED_SunShadeFracs
use EDMainMod , only : ed_update_site
use EDRestVectorMod , only : EDRest
use EDInitMod , only : zero_site, set_site_properties, init_patches

type, public :: fates_interface_type

Expand All @@ -46,10 +47,9 @@ module FatesInterfaceMod
contains

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

end type fates_interface_type
Expand Down Expand Up @@ -132,17 +132,18 @@ end subroutine init_coldstart

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

subroutine init_restart(this, bounds_clump, ncid, flag, fcolumn )

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, this%nsites, fcolumn, ncid, flag )
return
end subroutine init_restart
! subroutine init_restart(this, bounds_clump, ncid, flag, fcolumn )
!
! 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
! integer , intent(in) :: fcolumn(this%nsites)
! character(len=*) , intent(in) :: flag !'read' or 'write'
!
! call EDRest( bounds_clump, this%sites, this%nsites, fcolumn, ncid, flag )
! return
! end subroutine init_restart

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

Expand Down
5 changes: 4 additions & 1 deletion components/clm/src/main/clm_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,11 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)
if (use_ed) then
! if ED enabled, summarize productivity fluxes onto CLM history file structure
call t_startf('edclmsumprodfluxes')
! INTERF-TODO: THIS NEEDS A WRAPPER call clm_fates%sumprod(bounds_clump)
call clm_fates%fates2hlm%SummarizeProductivityFluxes( bounds_clump, &
clm_fates%fates(nc)%sites,clm_fates%fates(nc)%nsites )
clm_fates%fates(nc)%sites, &
clm_fates%fates(nc)%nsites, &
clm_fates%f2hmap(nc)%fcolumn)
call t_stopf('edclmsumprodfluxes')
endif

Expand Down
12 changes: 10 additions & 2 deletions components/clm/src/main/clm_initializeMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,16 @@ subroutine initialize2( )
! INTERF-TODO: THIS CALL SHOULD NOT CALL FATES(NC) DIRECTLY
! BUT IT SHOULD PASS bounds_clump TO A CLM_FATES WRAPPER
! WHICH WILL IN TURN PASS A FATES API DEFINED BOUNDS TO SITE_INIT
call clm_fates%fates(nc)%site_init(bounds_clump)
call clm_fates%fates2hlm_link(bounds_clump,nc,waterstate_inst,canopystate_inst)
! IE CREATE clm_fates%init_coldstart()
call clm_fates%fates(nc)%init_coldstart(clm_fates%f2hmap(nc)%fcolumn )

call clm_fates%fates2hlm%ed_clm_link( bounds_clump, &
clm_fates%fates(nc)%sites, &
clm_fates%fates(nc)%nsites, &
clm_fates%f2hmap(nc)%fcolumn, &
waterstate_inst, &
canopystate_inst)

end do
!$OMP END PARALLEL DO

Expand Down
2 changes: 1 addition & 1 deletion components/clm/src/main/clm_instMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ subroutine clm_instRest(bounds, ncid, flag)

! Bounds are not passed to FATES init_restart because
! we call a loop on clumps within this subroutine anyway
call clmfates%init_restart(ncid,flag)
call clm_fates%init_restart(ncid,flag, waterstate_inst, canopystate_inst)

end if

Expand Down
39 changes: 24 additions & 15 deletions components/clm/src/utils/clmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module CLMFatesInterfaceMod
use EDMainMod , only : ed_update_site
use EDPftVarcon , only : EDpftvarcon_inst
use EDEcophysConType , only : EDecophysconInit
use EDRestVectorMod , only : EDRest
implicit none

type, private :: f2hmap_type
Expand Down Expand Up @@ -120,7 +121,7 @@ module CLMFatesInterfaceMod
contains

procedure, public :: init
procedure, public :: fates2hlm_link
procedure, public :: init_restart
procedure, public :: dynamics_driv

end type hlm_fates_interface_type
Expand Down Expand Up @@ -160,8 +161,10 @@ subroutine init(this,bounds_proc, use_ed)
integer :: nc ! thread index
integer :: s ! FATES site index
integer :: c ! HLM column index
integer :: l ! HLM LU index
integer, allocatable :: collist (:)
type(bounds_type) :: bounds_clump
integer :: nmaxcol

if (use_ed) then

Expand All @@ -187,10 +190,10 @@ subroutine init(this,bounds_proc, use_ed)
allocate(collist(1:nmaxcol))

! Allocate the mapping that points columns to FATES sites, 0 is NA
allocate(self%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc))
allocate(this%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc))

! Initialize all columns with a zero index, which indicates no FATES site
self%f2hmap(nc)%hsites(:) = 0
this%f2hmap(nc)%hsites(:) = 0

s = 0
do c = bounds_clump%begc,bounds_clump%endc
Expand All @@ -201,16 +204,16 @@ subroutine init(this,bounds_proc, use_ed)
if (col%active(c) .and. lun%itype(l) == istsoil ) then
s = s + 1
collist(s) = c
self%f2hmap(nc)%hsites(c) = s
this%f2hmap(nc)%hsites(c) = s
endif

enddo

! Allocate vectors that match FATES sites with HLM columns
allocate(self%f2hmap(nc)%fcolumn(s))
allocate(this%f2hmap(nc)%fcolumn(s))

! Assign the h2hmap indexing
self%f2hmap(nc)%fcolumn(1:s) = collist(1:s)
this%f2hmap(nc)%fcolumn(1:s) = collist(1:s)

! Deallocate the temporary arrays
deallocate(collist)
Expand Down Expand Up @@ -252,7 +255,7 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
! !LOCAL VARIABLES:
real(r8) :: dayDiff ! day of run
integer :: dayDiffInt ! integer of day of run
integer :: g ! gridcell
integer :: s ! site
integer :: yr ! year (0, ...)
integer :: mon ! month (1, ..., 12)
integer :: day ! day of month (1, ..., 31)
Expand Down Expand Up @@ -312,9 +315,11 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
enddo

! link to CLM/ALM structures
call this%fates2hlm%ed_clm_link( bounds_clump, &
this%fates(nc)%sites, &
waterstate_inst, &
call this%fates2hlm%ed_clm_link( bounds_clump, &
this%fates(nc)%sites, &
this%fates(nc)%nsites, &
this%f2hmap(nc)%fcolumn, &
waterstate_inst, &
canopystate_inst)


Expand All @@ -338,8 +343,8 @@ subroutine init_restart(this, ncid, flag, waterstate_inst, canopystate_inst )
class(hlm_fates_interface_type), intent(inout) :: this
type(file_desc_t) , intent(inout) :: ncid ! netcdf id
character(len=*) , intent(in) :: flag !'read' or 'write'
type(waterstate_type) , intent(in) :: waterstate_inst
type(canopystate_type) , intent(in) :: canopystate_inst
type(waterstate_type) , intent(inout) :: waterstate_inst
type(canopystate_type) , intent(inout) :: canopystate_inst

! Locals
type(bounds_type) :: bounds_clump
Expand All @@ -350,21 +355,25 @@ subroutine init_restart(this, ncid, flag, waterstate_inst, canopystate_inst )
do nc = 1, nclumps
call get_clump_bounds(nc, bounds_clump)

call EDRest( bounds_clump, this%fates(nc)%sites, this%fates(nc)%nsites, &
this%f2hmap(nc)%fcolumn, ncid, flag )
call EDRest( bounds_clump, &
this%fates(nc)%sites, &
this%fates(nc)%nsites, &
this%f2hmap(nc)%fcolumn, ncid, flag )

if ( trim(flag) == 'read' ) then

call this%fates2hlm%ed_clm_link( bounds_clump, &
this%fates(nc)%sites, &
this%fates(nc)%nsites, &
this%f2hmap(nc)%fcolumn, &
waterstate_inst, &
canopystate_inst)


end if
end do

call clm_fates%fates2hlm%restart(bounds, ncid, flag)
call this%fates2hlm%restart(bounds_clump, ncid, flag)

return
end subroutine init_restart
Expand Down

0 comments on commit 6e5b9cf

Please sign in to comment.